mirror of
https://github.com/webbukkit/dynmap.git
synced 2024-11-12 13:34:47 +01:00
46 lines
1.2 KiB
JavaScript
46 lines
1.2 KiB
JavaScript
var ip;
|
|
$.ajax({
|
|
type: "GET",
|
|
url: "//jsonip.appspot.com/?callback=?",
|
|
dataType: "jsonp",
|
|
success: function(getip) { ip = getip.ip; }
|
|
});
|
|
|
|
componentconstructors['chat'] = function(dynmap, configuration) {
|
|
return {
|
|
dynmap: dynmap,
|
|
initialize: function() {
|
|
// Provides 'chat'-events by monitoring the world-updates.
|
|
$(dynmap).bind('worldupdate', function(event, update) {
|
|
swtch(update.type, {
|
|
chat: function() {
|
|
$(dynmap).trigger('chat', [{source: 'player', name: update.playerName, text: update.message}]);
|
|
},
|
|
webchat: function() {
|
|
$(dynmap).trigger('chat', [{source: 'web', name: update.playerName, text: update.message}]);
|
|
}
|
|
});
|
|
});
|
|
|
|
if (dynmap.options.allowwebchat) {
|
|
// Accepts 'sendchat'-events to send chat messages to the server.
|
|
$(dynmap).bind('sendchat', function(event, message) {
|
|
var data = '{"name":"'+ip+'","message":"'+message+'"}';
|
|
$.ajax({
|
|
type: 'POST',
|
|
url: 'up/sendmessage',
|
|
data: data,
|
|
dataType: 'json',
|
|
success: function(response) {
|
|
//handle response
|
|
if(response) {
|
|
$(dynmap).trigger('chat', [{source: 'me', name: ip, text: message}]);
|
|
}
|
|
}
|
|
});
|
|
});
|
|
}
|
|
}
|
|
};
|
|
};
|