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
|
||||
|
||||
@@ -9,13 +9,11 @@
|
||||
|
||||
package engine.net.client;
|
||||
|
||||
import engine.gameManager.ChatManager;
|
||||
import engine.gameManager.SessionManager;
|
||||
import engine.gameManager.TradeManager;
|
||||
import engine.net.NetMsgHandler;
|
||||
import engine.net.client.handlers.AbstractClientMsgHandler;
|
||||
import engine.net.client.msg.*;
|
||||
import engine.net.client.msg.chat.AbstractChatMsg;
|
||||
import engine.server.world.WorldServer;
|
||||
import engine.session.Session;
|
||||
import engine.util.StringUtils;
|
||||
@@ -89,8 +87,6 @@ public class ClientMessagePump implements NetMsgHandler {
|
||||
case SYSTEMCHANNEL:
|
||||
case GLOBALCHANNELMESSAGE:
|
||||
case LEADERCHANNELMESSAGE:
|
||||
ChatManager.handleChatMsg(s, (AbstractChatMsg) msg);
|
||||
break;
|
||||
case READYTOENTER:
|
||||
break;
|
||||
case OPENVAULT:
|
||||
|
||||
@@ -60,16 +60,16 @@ public enum Protocol {
|
||||
CHANGEGUILDLEADER(0xE40BC95D, ChangeGuildLeaderMsg.class, ChangeGuildLeaderHandler.class),
|
||||
CHANNELMUTE(0xC1BDC53A, ChatFilterMsg.class, ChannelMuteMsgHandler.class), //Chat Channels that are turned on
|
||||
CHARSELECTSCREEN(0x682C935D, null, null), // Character Selection Screen
|
||||
CHATCITY(0x9D402901, ChatCityMsg.class, null), // Chat Channel: /City
|
||||
CHATCSR(0x14EBA1C3, ChatCSRMsg.class, null), //Chat Channel: CSR
|
||||
CHATGROUP(0xA895B634, ChatGroupMsg.class, null), // Chat Channel: /group
|
||||
CHATGUILD(0xA9D92ED4, ChatGuildMsg.class, null), // Chat Channel: /guild
|
||||
CHATIC(0x00A75F35, ChatICMsg.class, null), // Chat Channel: /IC
|
||||
CHATINFO(0x9D4B61EB, ChatInfoMsg.class, null), // Chat Channel: /Info
|
||||
CHATPVP(0x14EBA570, ChatPvPMsg.class, null), // Chat Channel: PVP
|
||||
CHATSAY(0x14EA0393, ChatSayMsg.class, null), // Chat Channel: /say
|
||||
CHATSHOUT(0xA8D5B560, ChatShoutMsg.class, null), // Chat Channel: /shout
|
||||
CHATTELL(0x9D4AC896, ChatTellMsg.class, null), // Chat Channel: /tell
|
||||
CHATCITY(0x9D402901, ChatCityMsg.class, AbstractChatMsgHandler.class), // Chat Channel: /City
|
||||
CHATCSR(0x14EBA1C3, ChatCSRMsg.class, AbstractChatMsgHandler.class), //Chat Channel: CSR
|
||||
CHATGROUP(0xA895B634, ChatGroupMsg.class, AbstractChatMsgHandler.class), // Chat Channel: /group
|
||||
CHATGUILD(0xA9D92ED4, ChatGuildMsg.class, AbstractChatMsgHandler.class), // Chat Channel: /guild
|
||||
CHATIC(0x00A75F35, ChatICMsg.class, AbstractChatMsgHandler.class), // Chat Channel: /IC
|
||||
CHATINFO(0x9D4B61EB, ChatInfoMsg.class, AbstractChatMsgHandler.class), // Chat Channel: /Info
|
||||
CHATPVP(0x14EBA570, ChatPvPMsg.class, AbstractChatMsgHandler.class), // Chat Channel: PVP
|
||||
CHATSAY(0x14EA0393, ChatSayMsg.class, AbstractChatMsgHandler.class), // Chat Channel: /say
|
||||
CHATSHOUT(0xA8D5B560, ChatShoutMsg.class, AbstractChatMsgHandler.class), // Chat Channel: /shout
|
||||
CHATTELL(0x9D4AC896, ChatTellMsg.class, AbstractChatMsgHandler.class), // Chat Channel: /tell
|
||||
CHECKUNIQUEGUILD(0x689097D7, GuildCreationOptionsMsg.class, GuildCreationOptionsHandler.class), // Set Guild Name/Motto in Use Guild Charter
|
||||
CITYASSET(0x7cae1678, CityAssetMsg.class, null),
|
||||
CITYCHOICE(0x406610BB, CityChoiceMsg.class, CityChoiceMsgHandler.class),
|
||||
|
||||
@@ -0,0 +1,95 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
package engine.net.client.handlers;
|
||||
|
||||
import engine.exception.MsgSendException;
|
||||
import engine.gameManager.ChatManager;
|
||||
import engine.net.client.ClientConnection;
|
||||
import engine.net.client.Protocol;
|
||||
import engine.net.client.msg.ClientNetMsg;
|
||||
import engine.net.client.msg.chat.*;
|
||||
import engine.objects.PlayerCharacter;
|
||||
|
||||
import static engine.gameManager.ChatManager.FLOOD_QTY_THRESHOLD;
|
||||
import static engine.gameManager.ChatManager.FLOOD_TIME_THRESHOLD;
|
||||
|
||||
public class AbstractChatMsgHandler extends AbstractClientMsgHandler {
|
||||
|
||||
public AbstractChatMsgHandler() {
|
||||
super(AbstractChatMsg.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException {
|
||||
|
||||
PlayerCharacter playerCharacter = origin.getPlayerCharacter();
|
||||
|
||||
// Member variable declaration
|
||||
|
||||
AbstractChatMsg msg;
|
||||
|
||||
// Member variable assignment
|
||||
|
||||
msg = (AbstractChatMsg) baseMsg;
|
||||
|
||||
if (msg == null)
|
||||
return true;
|
||||
|
||||
if (playerCharacter == null)
|
||||
return true;
|
||||
|
||||
Protocol protocolMsg = msg.getProtocolMsg();
|
||||
|
||||
// Flood control, implemented per channel
|
||||
|
||||
boolean isFlood = false;
|
||||
long curMsgTime = System.currentTimeMillis();
|
||||
long checkTime = playerCharacter.chatFloodTime(protocolMsg.opcode, curMsgTime, FLOOD_QTY_THRESHOLD - 1);
|
||||
|
||||
if ((checkTime > 0L) && (curMsgTime - checkTime < FLOOD_TIME_THRESHOLD))
|
||||
isFlood = true;
|
||||
|
||||
switch (protocolMsg) {
|
||||
case CHATSAY:
|
||||
ChatManager.chatSay(playerCharacter, msg.getMessage(), isFlood);
|
||||
return true;
|
||||
case CHATCSR:
|
||||
ChatManager.chatCSR(msg);
|
||||
return true;
|
||||
case CHATTELL:
|
||||
ChatTellMsg ctm = (ChatTellMsg) msg;
|
||||
ChatManager.chatTell(playerCharacter, ctm.getTargetName(), ctm.getMessage(), isFlood);
|
||||
return true;
|
||||
case CHATSHOUT:
|
||||
ChatManager.chatShout(playerCharacter, msg.getMessage(), isFlood);
|
||||
return true;
|
||||
case CHATGUILD:
|
||||
ChatManager.chatGuild(playerCharacter, (ChatGuildMsg) msg);
|
||||
return true;
|
||||
case CHATGROUP:
|
||||
ChatManager.chatGroup(playerCharacter, (ChatGroupMsg) msg);
|
||||
return true;
|
||||
case CHATIC:
|
||||
ChatManager.chatIC(playerCharacter, (ChatICMsg) msg);
|
||||
return true;
|
||||
case LEADERCHANNELMESSAGE:
|
||||
ChatManager.chatGlobal(playerCharacter, msg.getMessage(), isFlood);
|
||||
return true;
|
||||
case GLOBALCHANNELMESSAGE:
|
||||
case CHATPVP:
|
||||
case CHATCITY:
|
||||
case CHATINFO:
|
||||
case SYSTEMBROADCASTCHANNEL:
|
||||
default:
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user