2011-03-16 01:17:58 +01:00
|
|
|
var ip;
|
|
|
|
$.ajax({
|
|
|
|
type: "GET",
|
2011-03-23 21:06:37 +01:00
|
|
|
url: "//jsonip.appspot.com/?callback=?",
|
2011-03-16 01:17:58 +01:00
|
|
|
dataType: "jsonp",
|
|
|
|
success: function(getip) { ip = getip.ip; }
|
|
|
|
});
|
2011-03-29 23:42:56 +02:00
|
|
|
|
|
|
|
componentconstructors['chat'] = function(dynmap, configuration) {
|
2011-03-31 12:54:32 +02:00
|
|
|
var me = this;
|
2012-01-08 18:53:28 +01:00
|
|
|
|
|
|
|
if(dynmap.getBoolParameterByName("hidechat"))
|
|
|
|
return;
|
|
|
|
|
2011-03-31 12:54:32 +02:00
|
|
|
// Provides 'chat'-events by monitoring the world-updates.
|
|
|
|
$(dynmap).bind('worldupdate', function(event, update) {
|
|
|
|
swtch(update.type, {
|
|
|
|
chat: function() {
|
2011-05-22 06:58:48 +02:00
|
|
|
$(dynmap).trigger('chat', [{source: update.source, name: update.playerName, text: update.message, account: update.account,
|
|
|
|
channel: update.channel}]);
|
2011-03-31 12:54:32 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
2011-12-22 17:50:41 +01:00
|
|
|
var pname = null;
|
|
|
|
if(configuration.allowurlname) {
|
2011-12-26 06:10:08 +01:00
|
|
|
pname = dynmap.getParameterByName("chatname");
|
2011-12-22 17:50:41 +01:00
|
|
|
if(pname == "") pname = null;
|
|
|
|
}
|
2011-03-31 12:54:32 +02:00
|
|
|
|
|
|
|
if (dynmap.options.allowwebchat) {
|
|
|
|
// Accepts 'sendchat'-events to send chat messages to the server.
|
|
|
|
$(dynmap).bind('sendchat', function(event, message) {
|
2011-12-22 17:50:41 +01:00
|
|
|
var data = '{"name":'+JSON.stringify(pname?pname:(ip?ip:""))+',"message":'+JSON.stringify(message)+'}';
|
2011-03-31 12:54:32 +02:00
|
|
|
$.ajax({
|
|
|
|
type: 'POST',
|
2012-01-06 07:30:04 +01:00
|
|
|
contentType: "application/json; charset=utf-8",
|
2011-06-02 22:41:09 +02:00
|
|
|
url: config.url.sendmessage,
|
2011-03-31 12:54:32 +02:00
|
|
|
data: data,
|
|
|
|
dataType: 'json',
|
|
|
|
success: function(response) {
|
|
|
|
//handle response
|
|
|
|
if(response) {
|
|
|
|
$(dynmap).trigger('chat', [{source: 'me', name: ip, text: message}]);
|
2011-03-29 23:42:56 +02:00
|
|
|
}
|
2011-04-05 22:30:43 +02:00
|
|
|
},
|
|
|
|
error: function(xhr) {
|
|
|
|
if (xhr.status === 403) {
|
|
|
|
$(dynmap).trigger('chat', [{source: 'me', name: 'Error', text: dynmap.options.spammessage.replace('%interval%', dynmap.options['webchat-interval'])}]);
|
|
|
|
}
|
2011-03-31 12:54:32 +02:00
|
|
|
}
|
2011-03-29 23:42:56 +02:00
|
|
|
});
|
2011-03-31 12:54:32 +02:00
|
|
|
});
|
|
|
|
}
|
2011-03-31 11:25:09 +02:00
|
|
|
};
|