forked from MagicBane/Server
Handler created for AbstractChatMsg
This commit is contained in:
@@ -20,13 +20,11 @@ import engine.net.Dispatch;
|
||||
import engine.net.DispatchMessage;
|
||||
import engine.net.MessageDispatcher;
|
||||
import engine.net.client.ClientConnection;
|
||||
import engine.net.client.Protocol;
|
||||
import engine.net.client.handlers.ClientAdminCommandMsgHandler;
|
||||
import engine.net.client.msg.chat.*;
|
||||
import engine.objects.*;
|
||||
import engine.server.MBServerStatics;
|
||||
import engine.server.world.WorldServer;
|
||||
import engine.session.Session;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -42,8 +40,8 @@ public enum ChatManager {
|
||||
// (FLOOD_TIME_THRESHOLD) ms will flag as a flood message
|
||||
// Example, set to 3 & 2000 to flag the 3rd message within 2000 ms.
|
||||
|
||||
private static final int FLOOD_QTY_THRESHOLD = 3;
|
||||
private static final int FLOOD_TIME_THRESHOLD = 2000;
|
||||
public static final int FLOOD_QTY_THRESHOLD = 3;
|
||||
public static final int FLOOD_TIME_THRESHOLD = 2000;
|
||||
private static final String FLOOD_USER_ERROR = "You talk too much!";
|
||||
private static final String SILENCED = "You find yourself mute!";
|
||||
private static final String UNKNOWN_COMMAND = "No such command.";
|
||||
@@ -51,74 +49,6 @@ public enum ChatManager {
|
||||
/**
|
||||
* This method used when handling a ChatMsg received from the network.
|
||||
*/
|
||||
public static void handleChatMsg(Session sender, AbstractChatMsg msg) {
|
||||
|
||||
if (msg == null) {
|
||||
Logger.warn(
|
||||
"null message: ");
|
||||
return;
|
||||
}
|
||||
|
||||
if (sender == null) {
|
||||
Logger.warn(
|
||||
"null sender: ");
|
||||
return;
|
||||
}
|
||||
|
||||
PlayerCharacter pc = sender.getPlayerCharacter();
|
||||
|
||||
if (pc == null) {
|
||||
Logger.warn(
|
||||
"invalid sender: ");
|
||||
return;
|
||||
}
|
||||
|
||||
Protocol protocolMsg = msg.getProtocolMsg();
|
||||
|
||||
// Flood control, implemented per channel
|
||||
|
||||
boolean isFlood = false;
|
||||
long curMsgTime = System.currentTimeMillis();
|
||||
long checkTime = pc.chatFloodTime(protocolMsg.opcode, curMsgTime, FLOOD_QTY_THRESHOLD - 1);
|
||||
|
||||
if ((checkTime > 0L) && (curMsgTime - checkTime < FLOOD_TIME_THRESHOLD))
|
||||
isFlood = true;
|
||||
|
||||
switch (protocolMsg) {
|
||||
case CHATSAY:
|
||||
ChatManager.chatSay(pc, msg.getMessage(), isFlood);
|
||||
return;
|
||||
case CHATCSR:
|
||||
ChatManager.chatCSR(msg);
|
||||
return;
|
||||
case CHATTELL:
|
||||
ChatTellMsg ctm = (ChatTellMsg) msg;
|
||||
ChatManager.chatTell(pc, ctm.getTargetName(), ctm.getMessage(), isFlood);
|
||||
return;
|
||||
case CHATSHOUT:
|
||||
ChatManager.chatShout(pc, msg.getMessage(), isFlood);
|
||||
return;
|
||||
case CHATGUILD:
|
||||
ChatManager.chatGuild(pc, (ChatGuildMsg) msg);
|
||||
return;
|
||||
case CHATGROUP:
|
||||
ChatManager.chatGroup(pc, (ChatGroupMsg) msg);
|
||||
return;
|
||||
case CHATIC:
|
||||
ChatManager.chatIC(pc, (ChatICMsg) msg);
|
||||
return;
|
||||
case LEADERCHANNELMESSAGE:
|
||||
ChatManager.chatGlobal(pc, msg.getMessage(), isFlood);
|
||||
return;
|
||||
case GLOBALCHANNELMESSAGE:
|
||||
case CHATPVP:
|
||||
case CHATCITY:
|
||||
case CHATINFO:
|
||||
case SYSTEMBROADCASTCHANNEL:
|
||||
default:
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* Channels
|
||||
|
||||
Reference in New Issue
Block a user