Browse Source

Handler created for GameServerIPRequestMsg

combat-2
MagicBot 8 months ago
parent
commit
f62f11a66c
  1. 78
      src/engine/net/client/handlers/GameServerIPRequestMsgHandler.java
  2. 70
      src/engine/server/login/LoginServerMsgHandler.java

78
src/engine/net/client/handlers/GameServerIPRequestMsgHandler.java

@ -0,0 +1,78 @@
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
// Magicbane Emulator Project © 2013 - 2022
// www.magicbane.com
package engine.net.client.handlers;
import engine.exception.MsgSendException;
import engine.gameManager.SessionManager;
import engine.net.client.ClientConnection;
import engine.net.client.msg.ClientNetMsg;
import engine.net.client.msg.login.GameServerIPRequestMsg;
import engine.net.client.msg.login.GameServerIPResponseMsg;
import engine.objects.Account;
import engine.objects.PlayerCharacter;
import engine.server.MBServerStatics;
import engine.server.login.LoginServerMsgHandler;
import engine.session.CSSession;
import engine.session.Session;
import engine.util.ByteUtils;
import org.pmw.tinylog.Logger;
public class GameServerIPRequestMsgHandler extends AbstractClientMsgHandler {
public GameServerIPRequestMsgHandler() {
super(GameServerIPRequestMsg.class);
}
@Override
protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException {
PlayerCharacter playerCharacter = origin.getPlayerCharacter();
Session session = SessionManager.getSession(origin);
// Member variable declaration
GameServerIPRequestMsg msg;
// Member variable assignment
msg = (GameServerIPRequestMsg) baseMsg;
if (playerCharacter == null) {
Logger.info("Unable to find character ID " + msg.getCharacterUUID());
LoginServerMsgHandler.KickToLogin(MBServerStatics.LOGINERROR_UNABLE_TO_LOGIN, "PlayerCharacter lookup failed in .RequestGameServer().", origin);
return true;
}
try {
if (!CSSession.updateCrossServerSession(ByteUtils.byteArrayToSafeStringHex(origin.getSecretKeyBytes()), msg.getCharacterUUID())) {
Logger.info("Failed to update Cross server session, Kicking to Login for Character " + playerCharacter.getObjectUUID());
LoginServerMsgHandler.KickToLogin(MBServerStatics.LOGINERROR_UNABLE_TO_LOGIN, "Failed to update Session Information", origin);
return true;
}
} catch (Exception e) {
Logger.info("Failed to update Cross server session, Kicking to Login for Character " + playerCharacter.getObjectUUID());
Logger.error(e);
}
// Set the last character used.
Account account = session.getAccount();
account.setLastCharIDUsed(msg.getCharacterUUID());
GameServerIPResponseMsg gameServerIPResponseMsg = new GameServerIPResponseMsg();
if (!origin.sendMsg(gameServerIPResponseMsg)) {
Logger.error("Failed to send message");
LoginServerMsgHandler.KickToLogin(MBServerStatics.LOGINERROR_UNABLE_TO_LOGIN, "Unable to send GameServerIPResponseMsg to client.", origin);
}
return true;
}
}

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

@ -10,9 +10,6 @@
package engine.server.login; package engine.server.login;
import engine.Enum.DispatchChannel; import engine.Enum.DispatchChannel;
import engine.Enum.GameObjectType;
import engine.gameManager.DbManager;
import engine.gameManager.SessionManager;
import engine.job.JobScheduler; import engine.job.JobScheduler;
import engine.jobs.DisconnectJob; import engine.jobs.DisconnectJob;
import engine.net.Dispatch; import engine.net.Dispatch;
@ -21,14 +18,12 @@ import engine.net.NetMsgHandler;
import engine.net.client.ClientConnection; import engine.net.client.ClientConnection;
import engine.net.client.Protocol; import engine.net.client.Protocol;
import engine.net.client.msg.ClientNetMsg; import engine.net.client.msg.ClientNetMsg;
import engine.net.client.msg.login.*; import engine.net.client.msg.login.CharSelectScreenMsg;
import engine.objects.Account; import engine.net.client.msg.login.InvalidNameMsg;
import engine.net.client.msg.login.LoginErrorMsg;
import engine.objects.PlayerCharacter; import engine.objects.PlayerCharacter;
import engine.server.MBServerStatics; import engine.server.MBServerStatics;
import engine.session.CSSession;
import engine.session.Session; import engine.session.Session;
import engine.util.ByteUtils;
import engine.util.StringUtils;
import org.pmw.tinylog.Logger; import org.pmw.tinylog.Logger;
public class LoginServerMsgHandler implements NetMsgHandler { public class LoginServerMsgHandler implements NetMsgHandler {
@ -68,29 +63,6 @@ public class LoginServerMsgHandler implements NetMsgHandler {
ClientConnection origin = (ClientConnection) clientNetMsg.getOrigin(); ClientConnection origin = (ClientConnection) clientNetMsg.getOrigin();
Protocol protocolMsg = clientNetMsg.getProtocolMsg(); Protocol protocolMsg = clientNetMsg.getProtocolMsg();
try {
switch (protocolMsg) {
case SELECTCHAR:
this.RequestGameServer((GameServerIPRequestMsg) clientNetMsg, origin);
break;
case TARGETOBJECT:
// Why is this being sent to login server?
break;
default:
String ocHex = StringUtils.toHexString(protocolMsg.opcode);
Logger.error("Cannot not handle Opcode: " + ocHex);
return false;
}
} catch (Exception e) {
Logger.error("protocolMsg:" + protocolMsg + e.toString());
return false;
}
return true; return true;
} }
@ -129,40 +101,4 @@ public class LoginServerMsgHandler implements NetMsgHandler {
} }
} }
private void RequestGameServer(GameServerIPRequestMsg gameServerIPRequestMessage, ClientConnection conn) {
Session session;
PlayerCharacter player;
session = SessionManager.getSession(conn);
player = (PlayerCharacter) DbManager.getObject(GameObjectType.PlayerCharacter, gameServerIPRequestMessage.getCharacterUUID());
if (player == null) {
Logger.info("Unable to find character ID " + gameServerIPRequestMessage.getCharacterUUID());
KickToLogin(MBServerStatics.LOGINERROR_UNABLE_TO_LOGIN, "PlayerCharacter lookup failed in .RequestGameServer().", conn);
return;
}
try {
if (!CSSession.updateCrossServerSession(ByteUtils.byteArrayToSafeStringHex(conn.getSecretKeyBytes()), gameServerIPRequestMessage.getCharacterUUID())) {
Logger.info("Failed to update Cross server session, Kicking to Login for Character " + player.getObjectUUID());
this.KickToLogin(MBServerStatics.LOGINERROR_UNABLE_TO_LOGIN, "Failed to update Session Information", conn);
return;
}
} catch (Exception e) {
Logger.info("Failed to update Cross server session, Kicking to Login for Character " + player.getObjectUUID());
Logger.error(e);
}
// Set the last character used.
Account account = session.getAccount();
account.setLastCharIDUsed(gameServerIPRequestMessage.getCharacterUUID());
GameServerIPResponseMsg gameServerIPResponseMsg = new GameServerIPResponseMsg();
if (!conn.sendMsg(gameServerIPResponseMsg)) {
Logger.error("Failed to send message");
this.KickToLogin(MBServerStatics.LOGINERROR_UNABLE_TO_LOGIN, "Unable to send GameServerIPResponseMsg to client.", conn);
}
}
} }

Loading…
Cancel
Save