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;
|
|
|
|
// 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
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
if (dynmap.options.allowwebchat) {
|
|
|
|
// Accepts 'sendchat'-events to send chat messages to the server.
|
|
|
|
$(dynmap).bind('sendchat', function(event, message) {
|
2011-06-13 06:33:36 +02:00
|
|
|
var data = '{"name":'+JSON.stringify(ip?ip:"")+',"message":'+JSON.stringify(message)+'}';
|
2011-03-31 12:54:32 +02:00
|
|
|
$.ajax({
|
|
|
|
type: 'POST',
|
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
|
|
|
};
|