Add 'allowurlname' setting for 'chat' - permits web name set with playername= parameter

This commit is contained in:
Mike Primm 2011-12-23 00:50:41 +08:00 committed by mikeprimm
parent 756202affd
commit 44106a799a
2 changed files with 8 additions and 1 deletions

View File

@ -44,6 +44,8 @@ components:
- class: org.dynmap.SimpleWebChatComponent - class: org.dynmap.SimpleWebChatComponent
allowchat: true allowchat: true
# If true, web UI users can supply name for chat using 'playername' URL parameter. 'trustclientname' must also be set true.
allowurlname: false
#- class: org.dynmap.herochat.HeroWebChatComponent #- class: org.dynmap.herochat.HeroWebChatComponent
# # Control which HeroChat channel messages from web are directed to # # Control which HeroChat channel messages from web are directed to
# herochatwebchannel: Global # herochatwebchannel: Global

View File

@ -17,11 +17,16 @@ componentconstructors['chat'] = function(dynmap, configuration) {
} }
}); });
}); });
var pname = null;
if(configuration.allowurlname) {
pname = dynmap.getParameterByName("playername");
if(pname == "") pname = null;
}
if (dynmap.options.allowwebchat) { if (dynmap.options.allowwebchat) {
// Accepts 'sendchat'-events to send chat messages to the server. // Accepts 'sendchat'-events to send chat messages to the server.
$(dynmap).bind('sendchat', function(event, message) { $(dynmap).bind('sendchat', function(event, message) {
var data = '{"name":'+JSON.stringify(ip?ip:"")+',"message":'+JSON.stringify(message)+'}'; var data = '{"name":'+JSON.stringify(pname?pname:(ip?ip:""))+',"message":'+JSON.stringify(message)+'}';
$.ajax({ $.ajax({
type: 'POST', type: 'POST',
url: config.url.sendmessage, url: config.url.sendmessage,