Browse Source

Migration to protocol class

combat-2
MagicBot 8 months ago
parent
commit
504e26114e
  1. 2
      src/engine/gameManager/ConfigManager.java
  2. 4
      src/engine/net/CheckNetMsgFactoryJob.java
  3. 2
      src/engine/net/client/ClientConnection.java
  4. 102
      src/engine/net/client/ClientMessagePump.java
  5. 2
      src/engine/server/login/LoginServer.java
  6. 47
      src/engine/server/login/LoginServerMsgHandler.java
  7. 2
      src/engine/server/world/WorldServer.java

2
src/engine/gameManager/ConfigManager.java

@ -13,7 +13,6 @@ package engine.gameManager;
*/ */
import engine.Enum; import engine.Enum;
import engine.net.NetMsgHandler;
import engine.server.login.LoginServer; import engine.server.login.LoginServer;
import engine.server.world.WorldServer; import engine.server.world.WorldServer;
import org.pmw.tinylog.Logger; import org.pmw.tinylog.Logger;
@ -108,7 +107,6 @@ public enum ConfigManager {
public static final String DEFAULT_DATA_DIR = "mb.data/"; public static final String DEFAULT_DATA_DIR = "mb.data/";
public static Map<String, String> configMap = new HashMap(System.getenv()); public static Map<String, String> configMap = new HashMap(System.getenv());
public static Enum.ServerType serverType = Enum.ServerType.NONE; public static Enum.ServerType serverType = Enum.ServerType.NONE;
public static NetMsgHandler handler;
public static WorldServer worldServer; public static WorldServer worldServer;
public static LoginServer loginServer; public static LoginServer loginServer;
public static Map<ConfigManager, Pattern> regex = new HashMap<>(); public static Map<ConfigManager, Pattern> regex = new HashMap<>();

4
src/engine/net/CheckNetMsgFactoryJob.java

@ -8,8 +8,8 @@
package engine.net; package engine.net;
import engine.gameManager.ConfigManager;
import engine.job.AbstractJob; import engine.job.AbstractJob;
import engine.net.client.Protocol;
import engine.net.client.msg.ClientNetMsg; import engine.net.client.msg.ClientNetMsg;
import org.pmw.tinylog.Logger; import org.pmw.tinylog.Logger;
@ -40,7 +40,7 @@ public class CheckNetMsgFactoryJob extends AbstractJob {
} }
if (msg instanceof engine.net.client.msg.ClientNetMsg) { if (msg instanceof engine.net.client.msg.ClientNetMsg) {
ConfigManager.handler.handleClientMsg((ClientNetMsg) msg); Protocol.handleClientMsg((ClientNetMsg) msg);
} else { } else {
Logger.error("Unrouteable message of type '" + msg.getClass().getSimpleName() + '\''); Logger.error("Unrouteable message of type '" + msg.getClass().getSimpleName() + '\'');

2
src/engine/net/client/ClientConnection.java

@ -296,7 +296,7 @@ public class ClientConnection extends AbstractConnection {
if (MBServerStatics.DEBUG_PROTOCOL) if (MBServerStatics.DEBUG_PROTOCOL)
applicationProtocolLogger(msg, MessageSource.SOURCE_CLIENT); applicationProtocolLogger(msg, MessageSource.SOURCE_CLIENT);
return ConfigManager.handler.handleClientMsg(msg); // *** Refactor : Null check then call return Protocol.handleClientMsg(msg);
} }
private void applicationProtocolLogger(AbstractNetMsg msg, MessageSource origin) { private void applicationProtocolLogger(AbstractNetMsg msg, MessageSource origin) {

102
src/engine/net/client/ClientMessagePump.java

@ -1,102 +0,0 @@
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
// Magicbane Emulator Project © 2013 - 2022
// www.magicbane.com
package engine.net.client;
import engine.gameManager.SessionManager;
import engine.net.NetMsgHandler;
import engine.net.client.handlers.AbstractClientMsgHandler;
import engine.net.client.msg.ClientNetMsg;
import engine.server.world.WorldServer;
import engine.session.Session;
import engine.util.StringUtils;
import org.pmw.tinylog.Logger;
/**
* @author:
* @summary: This class is the mainline router for application protocol
* messages received by the client.
*/
public class ClientMessagePump implements NetMsgHandler {
// Instance variable declaration
private final WorldServer server;
public ClientMessagePump(WorldServer server) {
super();
this.server = server;
}
//Handle RepairObject Window and RepairObject Requests
@Override
public boolean handleClientMsg(ClientNetMsg msg) {
if (msg == null) {
Logger.error("handleClientMsg", "Recieved null msg. Returning.");
return false;
}
ClientConnection origin;
Protocol protocolMsg = Protocol.NONE;
Session s;
try {
// Try registered opcodes first as we take a hatchet to this GodObject
AbstractClientMsgHandler msgHandler = msg.getProtocolMsg().handler;
if (msgHandler != null)
return msgHandler.handleNetMsg(msg);
// Any remaining opcodes fall through and are routed
// through this ungodly switch of doom.
origin = (ClientConnection) msg.getOrigin();
s = SessionManager.getSession(origin);
protocolMsg = msg.getProtocolMsg();
switch (protocolMsg) {
case READYTOENTER:
break;
case OPENVAULT:
break;
case CHANNELMUTE:
break;
case KEEPALIVESERVERCLIENT:
break;
case UNKNOWN:
break;
case CONFIRMPROMOTE:
break;
default:
String ocHex = StringUtils.toHexString(protocolMsg.opcode);
Logger.error("Cannot handle Opcode: " + ocHex + " " + protocolMsg.name());
return false;
}
} catch (Exception e) {
Logger.error("handler for " + protocolMsg + " failed: " + e);
return false;
}
return true;
}
}

2
src/engine/server/login/LoginServer.java

@ -87,8 +87,6 @@ public class LoginServer {
loginServer = new LoginServer(); loginServer = new LoginServer();
ConfigManager.loginServer = loginServer; ConfigManager.loginServer = loginServer;
ConfigManager.handler = new LoginServerMsgHandler(loginServer);
ConfigManager.serverType = Enum.ServerType.LOGINSERVER; ConfigManager.serverType = Enum.ServerType.LOGINSERVER;
if (ConfigManager.init() == false) { if (ConfigManager.init() == false) {

47
src/engine/server/login/LoginServerMsgHandler.java

@ -1,47 +0,0 @@
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
// Magicbane Emulator Project © 2013 - 2022
// www.magicbane.com
package engine.server.login;
import engine.net.NetMsgHandler;
import engine.net.client.ClientConnection;
import engine.net.client.Protocol;
import engine.net.client.msg.ClientNetMsg;
import org.pmw.tinylog.Logger;
public class LoginServerMsgHandler implements NetMsgHandler {
private final LoginServer server;
LoginServerMsgHandler(LoginServer server) {
super();
this.server = server;
}
/*
* =========================================================================
* Client Messages
* =========================================================================
*/
@Override
public boolean handleClientMsg(ClientNetMsg clientNetMsg) {
if (clientNetMsg == null) {
Logger.error("Recieved null msg. Returning.");
return false;
}
ClientConnection origin = (ClientConnection) clientNetMsg.getOrigin();
Protocol protocolMsg = clientNetMsg.getProtocolMsg();
return true;
}
}

2
src/engine/server/world/WorldServer.java

@ -30,7 +30,6 @@ import engine.net.ItemProductionManager;
import engine.net.Network; import engine.net.Network;
import engine.net.client.ClientConnection; import engine.net.client.ClientConnection;
import engine.net.client.ClientConnectionManager; import engine.net.client.ClientConnectionManager;
import engine.net.client.ClientMessagePump;
import engine.net.client.Protocol; import engine.net.client.Protocol;
import engine.net.client.msg.UpdateStateMsg; import engine.net.client.msg.UpdateStateMsg;
import engine.net.client.msg.chat.ChatSystemMsg; import engine.net.client.msg.chat.ChatSystemMsg;
@ -103,7 +102,6 @@ public class WorldServer {
ConfigManager.serverType = Enum.ServerType.WORLDSERVER; ConfigManager.serverType = Enum.ServerType.WORLDSERVER;
ConfigManager.worldServer = worldServer; ConfigManager.worldServer = worldServer;
ConfigManager.handler = new ClientMessagePump(worldServer);
worldServer.init(); worldServer.init();

Loading…
Cancel
Save