mirror of
https://github.com/webbukkit/dynmap.git
synced 2024-11-28 21:25:46 +01:00
Merge pull request #234 from mikeprimm/master
Per request, add 'trustclientname' option to sendMessage on InternalClientUpdaeComponent
This commit is contained in:
commit
2ab7339381
@ -9,6 +9,7 @@ components:
|
|||||||
allowwebchat: true
|
allowwebchat: true
|
||||||
webchat-interval: 5
|
webchat-interval: 5
|
||||||
hidewebchatip: false
|
hidewebchatip: false
|
||||||
|
trustclientname: false
|
||||||
#- class: org.dynmap.JsonFileClientUpdateComponent
|
#- class: org.dynmap.JsonFileClientUpdateComponent
|
||||||
# writeinterval: 1
|
# writeinterval: 1
|
||||||
# sendhealth: true
|
# sendhealth: true
|
||||||
|
@ -12,6 +12,7 @@ public class InternalClientUpdateComponent extends ClientUpdateComponent {
|
|||||||
super(plugin, configuration);
|
super(plugin, configuration);
|
||||||
final Boolean allowwebchat = configuration.getBoolean("allowwebchat", false);
|
final Boolean allowwebchat = configuration.getBoolean("allowwebchat", false);
|
||||||
final Boolean hidewebchatip = configuration.getBoolean("hidewebchatip", false);
|
final Boolean hidewebchatip = configuration.getBoolean("hidewebchatip", false);
|
||||||
|
final Boolean trust_client_name = configuration.getBoolean("trustclientname", false);
|
||||||
final float webchatInterval = configuration.getFloat("webchat-interval", 1);
|
final float webchatInterval = configuration.getFloat("webchat-interval", 1);
|
||||||
final String spammessage = plugin.configuration.getString("spammessage", "You may only chat once every %interval% seconds.");
|
final String spammessage = plugin.configuration.getString("spammessage", "You may only chat once every %interval% seconds.");
|
||||||
|
|
||||||
@ -30,6 +31,7 @@ public class InternalClientUpdateComponent extends ClientUpdateComponent {
|
|||||||
maximumMessageInterval = (int)(webchatInterval * 1000);
|
maximumMessageInterval = (int)(webchatInterval * 1000);
|
||||||
spamMessage = "\""+spammessage+"\"";
|
spamMessage = "\""+spammessage+"\"";
|
||||||
hideip = hidewebchatip;
|
hideip = hidewebchatip;
|
||||||
|
this.trustclientname = trust_client_name;
|
||||||
onMessageReceived.addListener(new Listener<SendMessageHandler.Message>() {
|
onMessageReceived.addListener(new Listener<SendMessageHandler.Message>() {
|
||||||
@Override
|
@Override
|
||||||
public void triggered(Message t) {
|
public void triggered(Message t) {
|
||||||
|
@ -117,9 +117,8 @@ public class FileLockManager {
|
|||||||
while(!done) {
|
while(!done) {
|
||||||
try {
|
try {
|
||||||
ImageIO.write(img, type, fname);
|
ImageIO.write(img, type, fname);
|
||||||
fname.setLastModified(System.currentTimeMillis());
|
|
||||||
done = true;
|
done = true;
|
||||||
} catch (FileNotFoundException fnfx) { /* This seems to be what we get when file is locked by reader */
|
} catch (IOException fnfx) {
|
||||||
if(retrycnt < MAX_WRITE_RETRIES) {
|
if(retrycnt < MAX_WRITE_RETRIES) {
|
||||||
Log.info("Image file " + fname.getPath() + " - unable to write - retry #" + retrycnt);
|
Log.info("Image file " + fname.getPath() + " - unable to write - retry #" + retrycnt);
|
||||||
try { Thread.sleep(50 << retrycnt); } catch (InterruptedException ix) { throw fnfx; }
|
try { Thread.sleep(50 << retrycnt); } catch (InterruptedException ix) { throw fnfx; }
|
||||||
|
@ -25,6 +25,7 @@ public class SendMessageHandler implements HttpHandler {
|
|||||||
private Charset cs_utf8 = Charset.forName("UTF-8");
|
private Charset cs_utf8 = Charset.forName("UTF-8");
|
||||||
public int maximumMessageInterval = 1000;
|
public int maximumMessageInterval = 1000;
|
||||||
public boolean hideip = false;
|
public boolean hideip = false;
|
||||||
|
public boolean trustclientname = false;
|
||||||
public String spamMessage = "\"You may only chat once every %interval% seconds.\"";
|
public String spamMessage = "\"You may only chat once every %interval% seconds.\"";
|
||||||
private HashMap<String, WebUser> disallowedUsers = new HashMap<String, WebUser>();
|
private HashMap<String, WebUser> disallowedUsers = new HashMap<String, WebUser>();
|
||||||
private LinkedList<WebUser> disallowedUserQueue = new LinkedList<WebUser>();
|
private LinkedList<WebUser> disallowedUserQueue = new LinkedList<WebUser>();
|
||||||
@ -44,6 +45,11 @@ public class SendMessageHandler implements HttpHandler {
|
|||||||
|
|
||||||
JSONObject o = (JSONObject)parser.parse(reader);
|
JSONObject o = (JSONObject)parser.parse(reader);
|
||||||
final Message message = new Message();
|
final Message message = new Message();
|
||||||
|
|
||||||
|
if(trustclientname) {
|
||||||
|
message.name = String.valueOf(o.get("name"));
|
||||||
|
}
|
||||||
|
else {
|
||||||
/* If proxied client address, get original */
|
/* If proxied client address, get original */
|
||||||
if(request.fields.containsKey("X-Forwarded-For"))
|
if(request.fields.containsKey("X-Forwarded-For"))
|
||||||
message.name = request.fields.get("X-Forwarded-For");
|
message.name = request.fields.get("X-Forwarded-For");
|
||||||
@ -52,6 +58,7 @@ public class SendMessageHandler implements HttpHandler {
|
|||||||
message.name = String.valueOf(o.get("name"));
|
message.name = String.valueOf(o.get("name"));
|
||||||
else
|
else
|
||||||
message.name = request.rmtaddr.getAddress().getHostAddress();
|
message.name = request.rmtaddr.getAddress().getHostAddress();
|
||||||
|
}
|
||||||
if(hideip) { /* If hiding IP, find or assign alias */
|
if(hideip) { /* If hiding IP, find or assign alias */
|
||||||
synchronized(disallowedUsersLock) {
|
synchronized(disallowedUsersLock) {
|
||||||
String n = useralias.get(message.name);
|
String n = useralias.get(message.name);
|
||||||
|
Loading…
Reference in New Issue
Block a user