MagicBot
8 months ago
4 changed files with 107 additions and 86 deletions
@ -0,0 +1,95 @@
@@ -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; |
||||
} |
||||
|
||||
} |
Loading…
Reference in new issue