mirror of
https://github.com/webbukkit/dynmap.git
synced 2024-11-25 03:35:18 +01:00
Add support for hidewebchatip option, to replace webchat IP with alias
This commit is contained in:
parent
40ee132277
commit
e8a6bf46cf
@ -8,11 +8,13 @@ components:
|
|||||||
sendposition: true
|
sendposition: true
|
||||||
allowwebchat: true
|
allowwebchat: true
|
||||||
webchat-interval: 5
|
webchat-interval: 5
|
||||||
|
hidewebchatip: false
|
||||||
#- class: org.dynmap.JsonFileClientUpdateComponent
|
#- class: org.dynmap.JsonFileClientUpdateComponent
|
||||||
# writeinterval: 1
|
# writeinterval: 1
|
||||||
# sendhealth: true
|
# sendhealth: true
|
||||||
# sendposition: true
|
# sendposition: true
|
||||||
# allowwebchat: false
|
# allowwebchat: false
|
||||||
|
# hidewebchatip: false
|
||||||
|
|
||||||
- class: org.dynmap.SimpleWebChatComponent
|
- class: org.dynmap.SimpleWebChatComponent
|
||||||
allowchat: true
|
allowchat: true
|
||||||
|
@ -12,6 +12,7 @@ public class InternalClientUpdateComponent extends ClientUpdateComponent {
|
|||||||
public InternalClientUpdateComponent(DynmapPlugin plugin, final ConfigurationNode configuration) {
|
public InternalClientUpdateComponent(DynmapPlugin plugin, final ConfigurationNode configuration) {
|
||||||
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 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.");
|
||||||
|
|
||||||
@ -29,6 +30,7 @@ public class InternalClientUpdateComponent extends ClientUpdateComponent {
|
|||||||
SendMessageHandler messageHandler = new SendMessageHandler() {{
|
SendMessageHandler messageHandler = new SendMessageHandler() {{
|
||||||
maximumMessageInterval = (int)(webchatInterval * 1000);
|
maximumMessageInterval = (int)(webchatInterval * 1000);
|
||||||
spamMessage = "\""+spammessage+"\"";
|
spamMessage = "\""+spammessage+"\"";
|
||||||
|
hideip = hidewebchatip;
|
||||||
onMessageReceived.addListener(new Listener<SendMessageHandler.Message>() {
|
onMessageReceived.addListener(new Listener<SendMessageHandler.Message>() {
|
||||||
@Override
|
@Override
|
||||||
public void triggered(Message t) {
|
public void triggered(Message t) {
|
||||||
|
@ -8,6 +8,7 @@ import java.io.InputStreamReader;
|
|||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.Reader;
|
import java.io.Reader;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.Timer;
|
import java.util.Timer;
|
||||||
import java.util.TimerTask;
|
import java.util.TimerTask;
|
||||||
@ -30,11 +31,17 @@ public class JsonFileClientUpdateComponent extends ClientUpdateComponent {
|
|||||||
protected long currentTimestamp = 0;
|
protected long currentTimestamp = 0;
|
||||||
protected long lastTimestamp = 0;
|
protected long lastTimestamp = 0;
|
||||||
protected JSONParser parser = new JSONParser();
|
protected JSONParser parser = new JSONParser();
|
||||||
|
private Boolean hidewebchatip;
|
||||||
|
|
||||||
|
private HashMap<String,String> useralias = new HashMap<String,String>();
|
||||||
|
private int aliasindex = 1;
|
||||||
|
|
||||||
private Charset cs_utf8 = Charset.forName("UTF-8");
|
private Charset cs_utf8 = Charset.forName("UTF-8");
|
||||||
public JsonFileClientUpdateComponent(final DynmapPlugin plugin, final ConfigurationNode configuration) {
|
public JsonFileClientUpdateComponent(final DynmapPlugin plugin, final ConfigurationNode configuration) {
|
||||||
super(plugin, configuration);
|
super(plugin, configuration);
|
||||||
final boolean allowwebchat = configuration.getBoolean("allowwebchat", false);
|
final boolean allowwebchat = configuration.getBoolean("allowwebchat", false);
|
||||||
jsonInterval = (long)(configuration.getFloat("writeinterval", 1) * 1000);
|
jsonInterval = (long)(configuration.getFloat("writeinterval", 1) * 1000);
|
||||||
|
hidewebchatip = configuration.getBoolean("hidewebchatip", false);
|
||||||
task = new TimerTask() {
|
task = new TimerTask() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
@ -151,6 +158,15 @@ public class JsonFileClientUpdateComponent extends ClientUpdateComponent {
|
|||||||
if(ts.equals("null")) ts = "0";
|
if(ts.equals("null")) ts = "0";
|
||||||
if (Long.parseLong(ts) >= (lastTimestamp)) {
|
if (Long.parseLong(ts) >= (lastTimestamp)) {
|
||||||
String name = String.valueOf(o.get("name"));
|
String name = String.valueOf(o.get("name"));
|
||||||
|
if(hidewebchatip) {
|
||||||
|
String n = useralias.get(name);
|
||||||
|
if(n == null) { /* Make ID */
|
||||||
|
n = String.format("web-%03d", aliasindex);
|
||||||
|
aliasindex++;
|
||||||
|
useralias.put(name, n);
|
||||||
|
}
|
||||||
|
name = n;
|
||||||
|
}
|
||||||
String message = String.valueOf(o.get("message"));
|
String message = String.valueOf(o.get("message"));
|
||||||
webChat(name, message);
|
webChat(name, message);
|
||||||
}
|
}
|
||||||
|
@ -24,10 +24,13 @@ public class SendMessageHandler implements HttpHandler {
|
|||||||
public Event<Message> onMessageReceived = new Event<SendMessageHandler.Message>();
|
public Event<Message> onMessageReceived = new Event<SendMessageHandler.Message>();
|
||||||
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 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>();
|
||||||
private Object disallowedUsersLock = new Object();
|
private Object disallowedUsersLock = new Object();
|
||||||
|
private HashMap<String,String> useralias = new HashMap<String,String>();
|
||||||
|
private int aliasindex = 1;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handle(String path, HttpRequest request, HttpResponse response) throws Exception {
|
public void handle(String path, HttpRequest request, HttpResponse response) throws Exception {
|
||||||
@ -49,6 +52,17 @@ 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 */
|
||||||
|
synchronized(disallowedUsersLock) {
|
||||||
|
String n = useralias.get(message.name);
|
||||||
|
if(n == null) { /* Make ID */
|
||||||
|
n = String.format("web-%03d", aliasindex);
|
||||||
|
aliasindex++;
|
||||||
|
useralias.put(message.name, n);
|
||||||
|
}
|
||||||
|
message.name = n;
|
||||||
|
}
|
||||||
|
}
|
||||||
message.message = String.valueOf(o.get("message"));
|
message.message = String.valueOf(o.get("message"));
|
||||||
|
|
||||||
final long now = System.currentTimeMillis();
|
final long now = System.currentTimeMillis();
|
||||||
|
Loading…
Reference in New Issue
Block a user