diff --git a/src/engine/net/client/handlers/DeleteCharacterMsgHandler.java b/src/engine/net/client/handlers/DeleteCharacterMsgHandler.java new file mode 100644 index 00000000..72ae672d --- /dev/null +++ b/src/engine/net/client/handlers/DeleteCharacterMsgHandler.java @@ -0,0 +1,96 @@ +// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ . +// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌· +// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀ +// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌ +// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀ +// 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.DeleteCharacterMsg; +import engine.objects.GuildStatusController; +import engine.objects.PlayerCharacter; +import engine.server.MBServerStatics; +import engine.server.login.LoginServer; +import engine.server.login.LoginServerMsgHandler; +import engine.session.Session; +import org.pmw.tinylog.Logger; + +public class DeleteCharacterMsgHandler extends AbstractClientMsgHandler { + + public DeleteCharacterMsgHandler() { + super(DeleteCharacterMsg.class); + } + + @Override + protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException { + + // Member variable declaration + + DeleteCharacterMsg msg; + + // Member variable assignment + + msg = (DeleteCharacterMsg) baseMsg; + + try { + PlayerCharacter playerCharacter; + Session session; + + session = SessionManager.getSession(origin); + playerCharacter = PlayerCharacter.getPlayerCharacter(msg.getCharacterUUID()); + + if (playerCharacter == null) { + Logger.error("Delete Error: PlayerID=" + msg.getCharacterUUID() + " not found."); + LoginServerMsgHandler.sendCharacterSelectScreen(session); + return true; + } + + if (session.getAccount() == null) { + Logger.error("Delete Error: Account not found."); + LoginServerMsgHandler.sendCharacterSelectScreen(session); + return true; + } + + if (playerCharacter.getAccount().equals(session.getAccount()) == false) { + Logger.error("Delete Error: Character " + playerCharacter.getName() + " does not belong to account " + origin.getAccount().getUname()); + LoginServerMsgHandler.sendCharacterSelectScreen(session); + return true; + } + + //Can't delete as Guild Leader + //TODO either find an error or just gdisband. + + if (GuildStatusController.isGuildLeader(playerCharacter.getGuildStatus())) { + LoginServerMsgHandler.KickToLogin(MBServerStatics.LOGINERROR_UNABLE_TO_LOGIN, "Cannot delete a guild leader.", origin); + return true; + } + + // check for active banes + + if (LoginServer.getActiveBaneQuery(playerCharacter)) { + Logger.info("Character " + playerCharacter.getName() + " has unresolved bane"); + LoginServerMsgHandler.KickToLogin(MBServerStatics.LOGINERROR_UNABLE_TO_LOGIN, "Player has unresolved bane.", origin); + return true; + } + + playerCharacter.getAccount().characterMap.remove(playerCharacter.getObjectUUID()); + playerCharacter.deactivateCharacter(); + + // TODO Delete Equipment + // Resend Character Select Screen. + LoginServerMsgHandler.sendCharacterSelectScreen(session); + + } catch (Exception e) { + Logger.error(e); + } + + return true; + } + +} \ No newline at end of file