Browse Source

Handler created for commitnewcharmsg

combat-2
MagicBot 8 months ago
parent
commit
854d0a8a68
  1. 64
      src/engine/net/client/handlers/CommitNewCharacterMsgHandler.java
  2. 39
      src/engine/server/login/LoginServerMsgHandler.java

64
src/engine/net/client/handlers/CommitNewCharacterMsgHandler.java

@ -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;
}
}

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

@ -72,10 +72,6 @@ public class LoginServerMsgHandler implements NetMsgHandler {
try { try {
switch (protocolMsg) { switch (protocolMsg) {
case CREATECHAR:
this.CommitNewCharacter((CommitNewCharacterMsg) clientNetMsg, origin);
break;
case REMOVECHAR: case REMOVECHAR:
this.DeleteCharacter((DeleteCharacterMsg) clientNetMsg, origin); this.DeleteCharacter((DeleteCharacterMsg) clientNetMsg, origin);
break; break;
@ -126,7 +122,7 @@ public class LoginServerMsgHandler implements NetMsgHandler {
sendCharacterSelectScreen(s, false); sendCharacterSelectScreen(s, false);
} }
private static void sendCharacterSelectScreen(Session s, boolean fromCommit) { public static void sendCharacterSelectScreen(Session s, boolean fromCommit) {
if (s.getAccount() != null) { if (s.getAccount() != null) {
CharSelectScreenMsg cssm = new CharSelectScreenMsg(s, fromCommit); CharSelectScreenMsg cssm = new CharSelectScreenMsg(s, fromCommit);
@ -137,39 +133,6 @@ public class LoginServerMsgHandler implements NetMsgHandler {
} }
} }
private void CommitNewCharacter(CommitNewCharacterMsg commitNewCharacterMessage, ClientConnection clientConnection) {
Session session = SessionManager.getSession(clientConnection);
if (session.getAccount() == null)
return;
try {
// Check to see if there is an available slot.
if (session.getAccount().characterMap.size() >= MBServerStatics.MAX_NUM_OF_CHARACTERS) {
this.sendCharacterSelectScreen(session);
return;
}
PlayerCharacter pc = PlayerCharacter.generatePCFromCommitNewCharacterMsg(session.getAccount(), commitNewCharacterMessage, clientConnection);
if (pc == null) {
Logger.info("Player returned null while creating character.");
this.sendCharacterSelectScreen(session, true);
return;
}
PlayerCharacter.initializePlayer(pc);
session.getAccount().characterMap.putIfAbsent(pc.getObjectUUID(), pc);
// Send back to Character Select Screen
this.sendCharacterSelectScreen(session, true);
} catch (Exception e) {
Logger.error(e);
this.sendCharacterSelectScreen(session, true);
}
}
private void DeleteCharacter(DeleteCharacterMsg msg, ClientConnection origin) { private void DeleteCharacter(DeleteCharacterMsg msg, ClientConnection origin) {
try { try {

Loading…
Cancel
Save