MagicBot
8 months ago
2 changed files with 65 additions and 38 deletions
@ -0,0 +1,64 @@
@@ -0,0 +1,64 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// 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.CommitNewCharacterMsg; |
||||
import engine.objects.PlayerCharacter; |
||||
import engine.server.MBServerStatics; |
||||
import engine.server.login.LoginServerMsgHandler; |
||||
import org.pmw.tinylog.Logger; |
||||
|
||||
public class CommitNewCharacterMsgHandler extends AbstractClientMsgHandler { |
||||
|
||||
public CommitNewCharacterMsgHandler() { |
||||
super(CommitNewCharacterMsg.class); |
||||
} |
||||
|
||||
@Override |
||||
protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException { |
||||
|
||||
if (origin.getAccount() == null) |
||||
return true; |
||||
|
||||
CommitNewCharacterMsg msg = (CommitNewCharacterMsg) baseMsg; |
||||
|
||||
try { |
||||
// Check to see if there is an available slot.
|
||||
if (origin.getAccount().characterMap.size() >= MBServerStatics.MAX_NUM_OF_CHARACTERS) { |
||||
LoginServerMsgHandler.sendCharacterSelectScreen(SessionManager.getSession(origin)); |
||||
return true; |
||||
} |
||||
|
||||
PlayerCharacter newPlayer = PlayerCharacter.generatePCFromCommitNewCharacterMsg(origin.getAccount(), msg, origin); |
||||
|
||||
if (newPlayer == null) { |
||||
Logger.info("Player returned null while creating character."); |
||||
LoginServerMsgHandler.sendCharacterSelectScreen(SessionManager.getSession(origin), true); |
||||
return true; |
||||
} |
||||
|
||||
PlayerCharacter.initializePlayer(newPlayer); |
||||
origin.getAccount().characterMap.putIfAbsent(newPlayer.getObjectUUID(), newPlayer); |
||||
|
||||
// Send back to Character Select Screen
|
||||
LoginServerMsgHandler.sendCharacterSelectScreen(SessionManager.getSession(origin), true); |
||||
|
||||
} catch (Exception e) { |
||||
Logger.error(e); |
||||
LoginServerMsgHandler.sendCharacterSelectScreen(SessionManager.getSession(origin), true); |
||||
} |
||||
|
||||
return true; |
||||
} |
||||
|
||||
} |
Loading…
Reference in new issue