Add block-banned-player-chat to block chat from banned players matching IPs known to go with player

This commit is contained in:
Mike Primm 2012-01-08 09:06:43 +08:00 committed by mikeprimm
parent 4a80b71a12
commit 6cfeee152c
4 changed files with 29 additions and 0 deletions

View File

@ -14,6 +14,7 @@ public class InternalClientUpdateComponent extends ClientUpdateComponent {
final boolean hidewebchatip = configuration.getBoolean("hidewebchatip", false);
final boolean trust_client_name = configuration.getBoolean("trustclientname", false);
final boolean useplayerloginip = configuration.getBoolean("use-player-login-ip", true);
final boolean checkuserban = configuration.getBoolean("block-banned-player-chat", true);
final boolean requireplayerloginip = configuration.getBoolean("require-player-login-ip", false);
final float webchatInterval = configuration.getFloat("webchat-interval", 1);
final String spammessage = plugin.configuration.getString("spammessage", "You may only chat once every %interval% seconds.");
@ -37,6 +38,7 @@ public class InternalClientUpdateComponent extends ClientUpdateComponent {
this.trustclientname = trust_client_name;
this.use_player_login_ip = useplayerloginip;
this.require_player_login_ip = requireplayerloginip;
this.check_user_ban = checkuserban;
onMessageReceived.addListener(new Listener<SendMessageHandler.Message>() {
@Override
public void triggered(Message t) {

View File

@ -13,7 +13,9 @@ import java.util.List;
import java.util.Timer;
import java.util.TimerTask;
import org.bukkit.OfflinePlayer;
import org.bukkit.World;
import org.dynmap.web.HttpStatus;
import org.dynmap.web.Json;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
@ -31,6 +33,7 @@ public class JsonFileClientUpdateComponent extends ClientUpdateComponent {
private boolean useplayerloginip;
private boolean requireplayerloginip;
private boolean trust_client_name;
private boolean checkuserban;
private HashMap<String,String> useralias = new HashMap<String,String>();
private int aliasindex = 1;
@ -45,6 +48,7 @@ public class JsonFileClientUpdateComponent extends ClientUpdateComponent {
useplayerloginip = configuration.getBoolean("use-player-login-ip", true);
requireplayerloginip = configuration.getBoolean("require-player-login-ip", false);
trust_client_name = configuration.getBoolean("trustclientname", false);
checkuserban = configuration.getBoolean("block-banned-player-chat", true);
MapManager.scheduleDelayedJob(new Runnable() {
@Override
@ -230,6 +234,13 @@ public class JsonFileClientUpdateComponent extends ClientUpdateComponent {
if(ids != null) {
name = ids.get(0);
isip = false;
if(checkuserban) {
OfflinePlayer p = plugin.getServer().getOfflinePlayer(name);
if((p != null) && p.isBanned()) {
Log.info("Ignore message from '" + ip + "' - banned player (" + name + ")");
return;
}
}
}
else if(requireplayerloginip) {
Log.info("Ignore message from '" + name + "' - no matching player login recorded");

View File

@ -7,6 +7,7 @@ import java.util.LinkedList;
import java.util.List;
import java.util.logging.Logger;
import org.bukkit.OfflinePlayer;
import org.dynmap.DynmapPlugin;
import org.dynmap.Event;
import org.dynmap.Log;
@ -30,6 +31,7 @@ public class SendMessageHandler implements HttpHandler {
public boolean trustclientname = false;
public boolean use_player_login_ip = false;
public boolean require_player_login_ip = false;
public boolean check_user_ban = false;
public DynmapPlugin plug_in;
public String spamMessage = "\"You may only chat once every %interval% seconds.\"";
private HashMap<String, WebUser> disallowedUsers = new HashMap<String, WebUser>();
@ -69,6 +71,17 @@ public class SendMessageHandler implements HttpHandler {
if(use_player_login_ip) {
List<String> ids = plug_in.getIDsForIP(message.name);
if(ids != null) {
String id = ids.get(0);
if(check_user_ban) {
OfflinePlayer p = plug_in.getServer().getOfflinePlayer(id);
if((p != null) && p.isBanned()) {
Log.info("Ignore message from '" + message.name + "' - banned player (" + id + ")");
response.fields.put("Content-Length", "0");
response.status = HttpStatus.Forbidden;
response.getBody();
return;
}
}
message.name = ids.get(0);
isip = false;
}

View File

@ -31,6 +31,8 @@ components:
use-player-login-ip: true
# (optional) if use-player-login-ip is true, setting this to true will cause chat messages not matching a known player IP to be ignored
require-player-login-ip: false
# (optional) block player login IDs that are banned from chatting
block-banned-player-chat: true
# # Optional - make players hidden when they are inside/underground/in shadows (#=light level: 0=full shadow,15=sky)
# hideifshadow: 4
# # Optional - make player hidden when they are under cover (#=sky light level,0=underground,15=open to sky)
@ -47,6 +49,7 @@ components:
# includehiddenplayers: false
# use-player-login-ip: false
# require-player-login-ip: false
# block-banned-player-chat: true
# hideifshadow: 0
# hideifundercover: 0
# hideifsneaking: false