Compare commits

...

12 Commits

15 changed files with 603 additions and 589 deletions
@@ -13,7 +13,6 @@ package engine.gameManager;
*/
import engine.Enum;
import engine.net.NetMsgHandler;
import engine.server.login.LoginServer;
import engine.server.world.WorldServer;
import org.pmw.tinylog.Logger;
@@ -108,7 +107,6 @@ public enum ConfigManager {
public static final String DEFAULT_DATA_DIR = "mb.data/";
public static Map<String, String> configMap = new HashMap(System.getenv());
public static Enum.ServerType serverType = Enum.ServerType.NONE;
public static NetMsgHandler handler;
public static WorldServer worldServer;
public static LoginServer loginServer;
public static Map<ConfigManager, Pattern> regex = new HashMap<>();
+2 -2
View File
@@ -8,8 +8,8 @@
package engine.net;
import engine.gameManager.ConfigManager;
import engine.job.AbstractJob;
import engine.net.client.Protocol;
import engine.net.client.msg.ClientNetMsg;
import org.pmw.tinylog.Logger;
@@ -40,7 +40,7 @@ public class CheckNetMsgFactoryJob extends AbstractJob {
}
if (msg instanceof engine.net.client.msg.ClientNetMsg) {
ConfigManager.handler.handleClientMsg((ClientNetMsg) msg);
Protocol.handleClientMsg((ClientNetMsg) msg);
} else {
Logger.error("Unrouteable message of type '" + msg.getClass().getSimpleName() + '\'');
+1 -1
View File
@@ -296,7 +296,7 @@ public class ClientConnection extends AbstractConnection {
if (MBServerStatics.DEBUG_PROTOCOL)
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) {
@@ -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;
}
}
+9 -9
View File
@@ -82,7 +82,7 @@ public enum Protocol {
COMBATMODE(0xFE4BF353, ToggleCombatMsg.class, ToggleCombatMsgHandler.class), //Toggle Combat mode
CONFIRMPROMOTE(0x153BB5F9, ConfirmPromoteMsg.class, null),
COSTTOOPENBANK(0x135BE5E8, CostOpenBankMsg.class, null), // ACK Bank Window Opened
CREATECHAR(0x5D18B5C8, CommitNewCharacterMsg.class, null), // Commit New Character,
CREATECHAR(0x5D18B5C8, CommitNewCharacterMsg.class, CommitNewCharacterMsgHandler.class), // Commit New Character,
CREATEPETITION(0xD489CFED, GuildCreationFinalizeMsg.class, GuildCreationFinalizeHandler.class), //Confirm guild creation
CUSTOMERPETITION(0x7F9D7D6D, PetitionReceivedMsg.class, PetitionReceivedMsgHandler.class),
DELETEOBJECT(0x57F069D8, DeleteItemMsg.class, DeleteItemMsgHandler.class), //Delete Item from Inventory
@@ -133,7 +133,7 @@ public enum Protocol {
LOADCHARACTER(0x5756BC53, null, null), // Load Player/NPC/Mob, other then self
LOADSTRUCTURE(0xB8A3A654, LoadStructureMsg.class, null), //Load Buildings and World Detail Objects
LOCKUNLOCKDOOR(0x8D0E8C44, LockUnlockDoorMsg.class, LockUnlockDoorMsgHandler.class), // Lock/Unlock Door
LOGIN(0x3D51E445, ClientLoginInfoMsg.class, null), // Login Information
LOGIN(0x3D51E445, ClientLoginInfoMsg.class, ClientLoginInfoMsgHandler.class), // Login Information
LOGINFAILED(0x47B867F6, null, null), // Login Error
LOGINTOGAMESERVER(0x77910FDF, LoginToGameServerMsg.class, LoginToGameServerMsgHandler.class), // Login to Game Server
MANAGECITYASSETS(0xCFF01225, ManageCityAssetsMsg.class, ManageCityAssetMsgHandler.class), // Manage city assets
@@ -168,7 +168,7 @@ public enum Protocol {
REALMDATA(0x2399B775, null, null), //Realm Data - Optional(?)
RECOMMENDNATION(0x6D4579E9, RecommendNationMsg.class, RecommendNationMsgHandler.class), // Recommend as Ally/Enemy, error
RECYCLEPOWER(0x24033B67, RecyclePowerMsg.class, null), //Unlock power for reUse
REMOVECHAR(0x5D3F9739, DeleteCharacterMsg.class, null), // Delete Character
REMOVECHAR(0x5D3F9739, DeleteCharacterMsg.class, DeleteCharacterMsgHandler.class), // Delete Character
REMOVEFRIEND(0xE0D5DB42, RemoveFriendMessage.class, RemoveFriendHandler.class),
REPAIRBUILDING(0xAF8C2560, RepairBuildingMsg.class, RepairBuildingMsgHandler.class),
REPAIROBJECT(0x782219CE, RepairMsg.class, RepairMsgHandler.class), //Repair Window Req/Ack, RepairObject item Req/Ack
@@ -184,9 +184,9 @@ public enum Protocol {
ROTATEMSG(0x57F2088E, RotateObjectMsg.class, null),
SAFEMODE(0x9CF3922A, SafeModeMsg.class, null), //Tell client they're in safe mode
SCALEOBJECT(0xE2B392D9, null, null), // Adjust scale of object
SELECTCHAR(0x7E6A9338, GameServerIPRequestMsg.class, null), // Game Server IP Request
SELECTCHAR(0x7E6A9338, GameServerIPRequestMsg.class, GameServerIPRequestMsgHandler.class), // Game Server IP Request
SELECTCITY(0x7E6BE630, null, null),
SELECTSERVER(0x440D28B7, ServerInfoMsg.class, null), // Server Info Request/Response
SELECTSERVER(0x440D28B7, ServerInfoMsg.class, ServerInfoMsgHandler.class), // Server Info Request/Response
SELLTONPC(0x57111C67, VendorSellMsg.class, VendorSellMsgHandler.class), //Sell to NPC
SENDCITYENTRY(0xBC3B5E72, null, null), //Send Teleport/Repledge List
SENDGUILDENTRY(0x6D5EF164, null, null),
@@ -240,7 +240,7 @@ public enum Protocol {
VENDORDIALOG(0x98ACD594, VendorDialogMsg.class, VendorDialogMsgHandler.class), // Send/Recv Vendor Dialog
VENDORSELLWINDOW(0x267DAB90, VendorSellWindowMsg.class, VendorSellWindowMsgHandler.class), //open Sell to NPC Window
VENDORBUYWINDOW(0x682DAB4D, VendorBuyWindowMsg.class, VendorBuyWindowMsgHandler.class), // Open Buy From NPC Window
VERSIONINFO(0x4B7EE463, VersionInfoMsg.class, null), // Version Information
VERSIONINFO(0x4B7EE463, VersionInfoMsg.class, VersionInfoMsgHandler.class), // Version Information
VIEWRESOURCES(0xCEFD0346, ViewResourcesMsg.class, ViewResourcesMsgHandler.class),
VISUALUPDATE(0x33402fd2, null, null),
WEIGHTINVENTORY(0xF1B6A85C, LootWindowResponseMsg.class, null), // MoveObjectToContainer Window Response
@@ -300,13 +300,13 @@ public enum Protocol {
if (protocol == null)
return true;
AbstractClientMsgHandler msgHandler = protocol.handler;
// Eat this message; no or empty handler
if (msgHandler == null)
if (protocol.handler == null)
return true;
protocol.handler.handleNetMsg(msg);
} catch (Exception e) {
Logger.error("handler for " + msg.getProtocolMsg() + " failed: " + e);
return false;
@@ -0,0 +1,171 @@
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
// Magicbane Emulator Project © 2013 - 2022
// www.magicbane.com
package engine.net.client.handlers;
import engine.Enum;
import engine.exception.MsgSendException;
import engine.gameManager.ConfigManager;
import engine.gameManager.DbManager;
import engine.gameManager.SessionManager;
import engine.net.client.ClientConnection;
import engine.net.client.msg.ClientNetMsg;
import engine.net.client.msg.login.ClientLoginInfoMsg;
import engine.objects.Account;
import engine.objects.PlayerCharacter;
import engine.server.MBServerStatics;
import engine.server.login.LoginServer;
import engine.session.Session;
import org.pmw.tinylog.Logger;
public class ClientLoginInfoMsgHandler extends AbstractClientMsgHandler {
public ClientLoginInfoMsgHandler() {
super(ClientLoginInfoMsg.class);
}
@Override
protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException {
PlayerCharacter playerCharacter = origin.getPlayerCharacter();
// Member variable declaration
ClientLoginInfoMsg msg;
// Member variable assignment
msg = (ClientLoginInfoMsg) baseMsg;
// Add zero length strings to eliminate the need for null checking.
String uname = msg.getUname();
String pass = msg.getPword();
// Check to see if there is actually any data in uname.pass
if (uname.length() == 0) {
LoginServer.KickToLogin(MBServerStatics.LOGINERROR_UNABLE_TO_LOGIN, "The username provided was zero length.", origin);
return true;
}
if (pass.length() == 0) {
LoginServer.KickToLogin(MBServerStatics.LOGINERROR_UNABLE_TO_LOGIN, "The password provided was zero length.", origin);
return true;
}
if (LoginServer.loginServerRunning == false) {
LoginServer.KickToLogin(MBServerStatics.LOGINERROR_LOGINSERVER_BUSY, "", origin);
return true;
}
Account account;
account = DbManager.AccountQueries.GET_ACCOUNT(uname);
// Create the account if it doesn't exist and MB_LOGIN_AUTOREG is TRUE;
// This is to support MagicBox users without a web hosting skillset.
if (account == null) {
if (ConfigManager.MB_LOGIN_AUTOREG.getValue().equalsIgnoreCase("false")) {
LoginServer.KickToLogin(MBServerStatics.LOGINERROR_INVALID_USERNAME_PASSWORD, "Could not find account (" + uname + ')', origin);
Logger.info("Could not find account (" + uname + ')');
return true;
}
Logger.info("AutoRegister: " + uname + "/" + pass);
DbManager.AccountQueries.CREATE_SINGLE(uname, pass);
account = DbManager.AccountQueries.GET_ACCOUNT(uname);
if (account == null) {
LoginServer.KickToLogin(MBServerStatics.LOGINERROR_INVALID_USERNAME_PASSWORD, "Could not find account (" + uname + ')', origin);
Logger.info("Could not auto-create (" + uname + ')');
return true;
}
}
if (account.getLastLoginFailure() + MBServerStatics.RESET_LOGIN_ATTEMPTS_AFTER < System.currentTimeMillis())
account.resetLoginAttempts();
// TODO: Log the login attempts IP, name, password and timestamp
// Check number invalid login attempts. If 5 or greater, kick to login.
if (account.getLoginAttempts() >= MBServerStatics.MAX_LOGIN_ATTEMPTS) {
LoginServer.KickToLogin(MBServerStatics.LOGINERROR_UNABLE_TO_LOGIN, "Too many login in attempts for '" + uname + '\'', origin);
Logger.info("Too many login in attempts for '" + uname + '\'');
return true;
}
if (account.lastPasswordCheck < System.currentTimeMillis()) {
account.lastPasswordCheck = System.currentTimeMillis() + MBServerStatics.ONE_MINUTE;
}
// Attempt to validate login
try {
if (!account.passIsValid(pass, origin.getClientIpAddress(), origin.machineID)) {
account.incrementLoginAttempts();
LoginServer.KickToLogin(MBServerStatics.LOGINERROR_INVALID_USERNAME_PASSWORD, "", origin);
Logger.info("Incorrect password(" + uname + ')');
return true;
}
} catch (IllegalArgumentException e1) {
LoginServer.KickToLogin(MBServerStatics.LOGINERROR_UNABLE_TO_LOGIN, "", origin);
Logger.info("Failed forum account validation(" + uname + ')');
}
// Account deactivated
if (account.status.equals(Enum.AccountStatus.BANNED)) {
LoginServer.KickToLogin(MBServerStatics.LOGINERROR_NO_MORE_PLAYTIME_ON_ACCOUNT, "", origin);
return true;
}
// Check to see if we have a Session mapped with this Account:
Session session = SessionManager.getSession(account);
// If there is, then the account is in use and must be handled:
// kick the 'other connection'
if (session != null)
LoginServer.KickToLogin(MBServerStatics.LOGINERROR_UNABLE_TO_LOGIN, "Your account has been accessed from a different IP & Port.", session.getConn()); // Logout the character
// TODO implement character logout
// Get a new session
session = SessionManager.getNewSession(account, origin);
// Set Invalid Login Attempts to 0
account.resetLoginAttempts();
// Send Login Response
ClientLoginInfoMsg loginResponse = new ClientLoginInfoMsg(msg);
loginResponse.setUnknown06(8323072);
loginResponse.setUnknown07(3276800);
loginResponse.setUnknown08(196608);
loginResponse.setUnknown09((short) 15);
origin.sendMsg(loginResponse);
// send character select screen
try {
LoginServer.sendCharacterSelectScreen(session);
} catch (Exception e) {
Logger.error("Unable to Send Character Select Screen to client");
LoginServer.KickToLogin(MBServerStatics.LOGINERROR_UNABLE_TO_LOGIN, "Unable to send Character Select Screen to client.", origin);
return true;
}
// Logging
String addyPort = origin.getRemoteAddressAndPortAsString();
int id = account.getObjectUUID();
Logger.info(uname + '(' + id + ") has successfully logged in from " + addyPort);
return true;
}
}
@@ -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.LoginServer;
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) {
LoginServer.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.");
LoginServer.sendCharacterSelectScreen(SessionManager.getSession(origin), true);
return true;
}
PlayerCharacter.initializePlayer(newPlayer);
origin.getAccount().characterMap.putIfAbsent(newPlayer.getObjectUUID(), newPlayer);
// Send back to Character Select Screen
LoginServer.sendCharacterSelectScreen(SessionManager.getSession(origin), true);
} catch (Exception e) {
Logger.error(e);
LoginServer.sendCharacterSelectScreen(SessionManager.getSession(origin), true);
}
return true;
}
}
@@ -0,0 +1,95 @@
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
// 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.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.");
LoginServer.sendCharacterSelectScreen(session);
return true;
}
if (session.getAccount() == null) {
Logger.error("Delete Error: Account not found.");
LoginServer.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());
LoginServer.sendCharacterSelectScreen(session);
return true;
}
//Can't delete as Guild Leader
//TODO either find an error or just gdisband.
if (GuildStatusController.isGuildLeader(playerCharacter.getGuildStatus())) {
LoginServer.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");
LoginServer.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.
LoginServer.sendCharacterSelectScreen(session);
} catch (Exception e) {
Logger.error(e);
}
return true;
}
}
@@ -0,0 +1,79 @@
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
// 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.LoginServer;
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 {
Session session = SessionManager.getSession(origin);
// Member variable declaration
GameServerIPRequestMsg msg;
// Member variable assignment
msg = (GameServerIPRequestMsg) baseMsg;
PlayerCharacter playerCharacter = PlayerCharacter.getPlayerCharacter(msg.getCharacterUUID());
if (playerCharacter == null) {
Logger.info("Unable to find character ID " + msg.getCharacterUUID());
LoginServer.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());
LoginServer.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");
LoginServer.KickToLogin(MBServerStatics.LOGINERROR_UNABLE_TO_LOGIN, "Unable to send GameServerIPResponseMsg to client.", origin);
}
return true;
}
}
@@ -0,0 +1,49 @@
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
// Magicbane Emulator Project © 2013 - 2022
// www.magicbane.com
package engine.net.client.handlers;
import engine.exception.MsgSendException;
import engine.net.client.ClientConnection;
import engine.net.client.msg.ClientNetMsg;
import engine.net.client.msg.ServerInfoMsg;
import engine.objects.PlayerCharacter;
import engine.server.MBServerStatics;
import engine.server.login.LoginServer;
import org.pmw.tinylog.Logger;
public class ServerInfoMsgHandler extends AbstractClientMsgHandler {
public ServerInfoMsgHandler() {
super(ServerInfoMsg.class);
}
@Override
protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException {
PlayerCharacter playerCharacter = origin.getPlayerCharacter();
// Member variable declaration
ServerInfoMsg msg;
// Member variable assignment
msg = (ServerInfoMsg) baseMsg;
ServerInfoMsg sim = new ServerInfoMsg();
if (!origin.sendMsg(sim)) {
Logger.error("Failed to send message");
LoginServer.KickToLogin(MBServerStatics.LOGINERROR_UNABLE_TO_LOGIN, "Unable to send ServerInfoMsg to client.", origin);
}
return true;
}
}
@@ -0,0 +1,75 @@
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
// Magicbane Emulator Project © 2013 - 2022
// www.magicbane.com
package engine.net.client.handlers;
import engine.exception.MsgSendException;
import engine.net.client.ClientConnection;
import engine.net.client.msg.ClientNetMsg;
import engine.net.client.msg.login.VersionInfoMsg;
import engine.objects.PlayerCharacter;
import engine.server.MBServerStatics;
import engine.server.login.LoginServer;
public class VersionInfoMsgHandler extends AbstractClientMsgHandler {
public VersionInfoMsgHandler() {
super(VersionInfoMsg.class);
}
@Override
protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException {
PlayerCharacter playerCharacter = origin.getPlayerCharacter();
String cMajorVer;
String cMinorVer;
VersionInfoMsg outVim;
// Member variable declaration
VersionInfoMsg msg;
// Member variable assignment
msg = (VersionInfoMsg) baseMsg;
cMajorVer = msg.getMajorVersion();
cMinorVer = msg.getMinorVersion();
if (!cMajorVer.equals(LoginServer.getDefaultVersionInfo().getMajorVersion())) {
LoginServer.KickToLogin(MBServerStatics.LOGINERROR_INCORRECT_CLIENT_VERSION, "Major Version Failure: " + cMajorVer, origin);
return true;
}
/* if (!cMinorVer.equals(this.server.getDefaultVersionInfo().getMinorVersion())) {
this.KickToLogin(MBServerStatics.LOGINERROR_INCORRECT_CLIENT_VERSION, "Minor Version Failure: " + cMinorVer, cc);
return;
} */
if (cMinorVer == null) {
LoginServer.KickToLogin(MBServerStatics.LOGINERROR_INCORRECT_CLIENT_VERSION, "Minor Version Failure: ", origin);
return true;
}
if (cMinorVer.length() < 8 || cMinorVer.length() > 16) {
LoginServer.KickToLogin(MBServerStatics.LOGINERROR_INCORRECT_CLIENT_VERSION, "Minor Version Failure: ", origin);
return true;
}
// set MachineID for this connection
origin.machineID = cMinorVer;
// send fake right back to the client
outVim = new VersionInfoMsg(msg.getMajorVersion(), LoginServer.getDefaultVersionInfo().getMinorVersion());
origin.sendMsg(outVim);
return true;
}
}
+5 -6
View File
@@ -38,7 +38,6 @@ import engine.net.client.msg.login.CommitNewCharacterMsg;
import engine.powers.EffectsBase;
import engine.server.MBServerStatics;
import engine.server.login.LoginServer;
import engine.server.login.LoginServerMsgHandler;
import engine.server.world.WorldServer;
import engine.util.MiscUtils;
import org.joda.time.DateTime;
@@ -740,28 +739,28 @@ public class PlayerCharacter extends AbstractCharacter {
String lastName = msg.getLastName().trim();
if (firstName.length() < 3) {
LoginServerMsgHandler.sendInvalidNameMsg(firstName, lastName, MBServerStatics.INVALIDNAME_FIRSTNAME_MUST_BE_LONGER,
LoginServer.sendInvalidNameMsg(firstName, lastName, MBServerStatics.INVALIDNAME_FIRSTNAME_MUST_BE_LONGER,
clientConnection);
return null;
}
// Ensure names are below required length
if (firstName.length() > 15 || lastName.length() > 15) {
LoginServerMsgHandler.sendInvalidNameMsg(firstName, lastName, MBServerStatics.INVALIDNAME_FIRSTANDLAST_MUST_BE_SHORTER,
LoginServer.sendInvalidNameMsg(firstName, lastName, MBServerStatics.INVALIDNAME_FIRSTANDLAST_MUST_BE_SHORTER,
clientConnection);
return null;
}
// Check if firstname is valid
if (MiscUtils.checkIfFirstNameInvalid(firstName)) {
LoginServerMsgHandler.sendInvalidNameMsg(firstName, lastName, MBServerStatics.INVALIDNAME_PLEASE_CHOOSE_ANOTHER_FIRSTNAME,
LoginServer.sendInvalidNameMsg(firstName, lastName, MBServerStatics.INVALIDNAME_PLEASE_CHOOSE_ANOTHER_FIRSTNAME,
clientConnection);
return null;
}
// Check if last name is valid
if (MiscUtils.checkIfLastNameInvalid(lastName)) {
LoginServerMsgHandler.sendInvalidNameMsg(firstName, lastName, MBServerStatics.INVALIDNAME_LASTNAME_UNAVAILABLE,
LoginServer.sendInvalidNameMsg(firstName, lastName, MBServerStatics.INVALIDNAME_LASTNAME_UNAVAILABLE,
clientConnection);
return null;
}
@@ -1136,7 +1135,7 @@ public class PlayerCharacter extends AbstractCharacter {
// This must be the very last check before calling the
// DB to create the character record
if (DbManager.PlayerCharacterQueries.IS_CHARACTER_NAME_UNIQUE(firstName) == false) {
LoginServerMsgHandler.sendInvalidNameMsg(firstName, lastName, MBServerStatics.INVALIDNAME_FIRSTNAME_UNAVAILABLE,
LoginServer.sendInvalidNameMsg(firstName, lastName, MBServerStatics.INVALIDNAME_FIRSTNAME_UNAVAILABLE,
clientConnection);
return null;
}
+53 -6
View File
@@ -13,15 +13,18 @@ import engine.Enum;
import engine.gameManager.*;
import engine.job.JobScheduler;
import engine.jobs.CSessionCleanupJob;
import engine.jobs.DisconnectJob;
import engine.net.Dispatch;
import engine.net.DispatchMessage;
import engine.net.Network;
import engine.net.client.ClientConnection;
import engine.net.client.ClientConnectionManager;
import engine.net.client.Protocol;
import engine.net.client.msg.login.ServerStatusMsg;
import engine.net.client.msg.login.VersionInfoMsg;
import engine.net.client.msg.login.*;
import engine.objects.*;
import engine.server.MBServerStatics;
import engine.server.world.WorldServer;
import engine.session.Session;
import engine.util.ByteUtils;
import engine.util.ThreadUtils;
import org.pmw.tinylog.Configurator;
@@ -55,7 +58,7 @@ public class LoginServer {
public static boolean worldServerRunning = false;
public static boolean loginServerRunning = false;
public static ServerStatusMsg serverStatusMsg = new ServerStatusMsg(0, (byte) 1);
private VersionInfoMsg versionInfoMessage;
private static VersionInfoMsg versionInfoMessage;
// This is the entrypoint for the MagicBane Login Server when
// it is executed by the command line scripts. The fun begins here!
@@ -84,8 +87,6 @@ public class LoginServer {
loginServer = new LoginServer();
ConfigManager.loginServer = loginServer;
ConfigManager.handler = new LoginServerMsgHandler(loginServer);
ConfigManager.serverType = Enum.ServerType.LOGINSERVER;
if (ConfigManager.init() == false) {
@@ -170,6 +171,52 @@ public class LoginServer {
return portInUse;
}
public static void sendInvalidNameMsg(String firstName, String lastName, int errorCode, ClientConnection clientConnection) {
InvalidNameMsg invalidNameMessage;
if (firstName.length() > 256 || lastName.length() > 256)
invalidNameMessage = new InvalidNameMsg(firstName, lastName, errorCode);
else
invalidNameMessage = new InvalidNameMsg(firstName, lastName, errorCode);
clientConnection.sendMsg(invalidNameMessage);
}
public static void KickToLogin(int errCode, String message, ClientConnection origin) {
LoginErrorMsg msg = new LoginErrorMsg(errCode, message);
PlayerCharacter player = origin.getPlayerCharacter();
if (player == null) {
origin.sendMsg(msg);
} else {
Dispatch dispatch = Dispatch.borrow(player, msg);
DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.PRIMARY);
}
Logger.info("Kicking to Login. Message: '" + message + '\'');
DisconnectJob dj = new DisconnectJob(origin);
JobScheduler.getInstance().scheduleJob(dj, 250);
}
public static void sendCharacterSelectScreen(Session s) {
sendCharacterSelectScreen(s, false);
}
public static void sendCharacterSelectScreen(Session s, boolean fromCommit) {
if (s.getAccount() != null) {
CharSelectScreenMsg cssm = new CharSelectScreenMsg(s, fromCommit);
s.getConn().sendMsg(cssm);
} else {
Logger.error("No Account Found: Unable to Send Character Select Screen");
KickToLogin(MBServerStatics.LOGINERROR_UNABLE_TO_LOGIN, "Unable to send Character Select Screen to client.", s.getConn());
}
}
private void exec() {
@@ -365,7 +412,7 @@ public class LoginServer {
}
}
public VersionInfoMsg getDefaultVersionInfo() {
public static VersionInfoMsg getDefaultVersionInfo() {
return versionInfoMessage;
}
@@ -1,459 +0,0 @@
// ·. · · · · .
// · ·
// · ·
//
// · · ·
// Magicbane Emulator Project © 2013 - 2022
// www.magicbane.com
package engine.server.login;
import engine.Enum;
import engine.Enum.DispatchChannel;
import engine.Enum.GameObjectType;
import engine.gameManager.ConfigManager;
import engine.gameManager.DbManager;
import engine.gameManager.SessionManager;
import engine.job.JobScheduler;
import engine.jobs.DisconnectJob;
import engine.net.Dispatch;
import engine.net.DispatchMessage;
import engine.net.NetMsgHandler;
import engine.net.client.ClientConnection;
import engine.net.client.Protocol;
import engine.net.client.msg.ClientNetMsg;
import engine.net.client.msg.ServerInfoMsg;
import engine.net.client.msg.login.*;
import engine.objects.Account;
import engine.objects.GuildStatusController;
import engine.objects.PlayerCharacter;
import engine.server.MBServerStatics;
import engine.session.CSSession;
import engine.session.Session;
import engine.util.ByteUtils;
import engine.util.StringUtils;
import org.pmw.tinylog.Logger;
public class LoginServerMsgHandler implements NetMsgHandler {
private final LoginServer server;
LoginServerMsgHandler(LoginServer server) {
super();
this.server = server;
}
public static void sendInvalidNameMsg(String firstName, String lastName, int errorCode, ClientConnection clientConnection) {
InvalidNameMsg invalidNameMessage;
if (firstName.length() > 256 || lastName.length() > 256)
invalidNameMessage = new InvalidNameMsg(firstName, lastName, errorCode);
else
invalidNameMessage = new InvalidNameMsg(firstName, lastName, errorCode);
clientConnection.sendMsg(invalidNameMessage);
}
/*
* =========================================================================
* 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();
try {
switch (protocolMsg) {
case VERSIONINFO:
this.VerifyCorrectClientVersion((VersionInfoMsg) clientNetMsg);
break;
case LOGIN:
if (LoginServer.loginServerRunning == true)
this.Login((ClientLoginInfoMsg) clientNetMsg, origin);
else
this.KickToLogin(MBServerStatics.LOGINERROR_LOGINSERVER_BUSY, "", origin);
break;
case KEEPALIVESERVERCLIENT:
// echo the keep alive back
origin.sendMsg(clientNetMsg);
break;
case SELECTSERVER:
this.SendServerInfo(origin);
break;
case CREATECHAR:
this.CommitNewCharacter((CommitNewCharacterMsg) clientNetMsg, origin);
break;
case REMOVECHAR:
this.DeleteCharacter((DeleteCharacterMsg) clientNetMsg, origin);
break;
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;
}
private void VerifyCorrectClientVersion(VersionInfoMsg vim) {
ClientConnection cc;
String cMajorVer;
String cMinorVer;
VersionInfoMsg outVim;
cc = (ClientConnection) vim.getOrigin();
cMajorVer = vim.getMajorVersion();
cMinorVer = vim.getMinorVersion();
// if (!cMajorVer.equals(this.server.getDefaultVersionInfo().getMajorVersion())) {
// this.KickToLogin(MBServerStatics.LOGINERROR_INCORRECT_CLIENT_VERSION, "Major Version Failure: " + cMajorVer, cc);
// return;
// }
/* if (!cMinorVer.equals(this.server.getDefaultVersionInfo().getMinorVersion())) {
this.KickToLogin(MBServerStatics.LOGINERROR_INCORRECT_CLIENT_VERSION, "Minor Version Failure: " + cMinorVer, cc);
return;
} */
// if (cMinorVer == null) {
// this.KickToLogin(MBServerStatics.LOGINERROR_INCORRECT_CLIENT_VERSION, "Minor Version Failure: ", cc);
// return;
// }
// if (cMinorVer.length() < 8 || cMinorVer.length() > 16) {
// this.KickToLogin(MBServerStatics.LOGINERROR_INCORRECT_CLIENT_VERSION, "Minor Version Failure: ", cc);
// return;
// }
// set MachineID for this connection
cc.machineID = cMinorVer;
// send fake right back to the client
outVim = new VersionInfoMsg(vim.getMajorVersion(), this.server.getDefaultVersionInfo().getMinorVersion());
cc.sendMsg(outVim);
}
// our data access should be in a separate object
private void Login(ClientLoginInfoMsg clientLoginInfoMessage, ClientConnection clientConnection) {
// Add zero length strings to eliminate the need for null checking.
String uname = clientLoginInfoMessage.getUname();
String pass = clientLoginInfoMessage.getPword();
// Check to see if there is actually any data in uname.pass
if (uname.length() == 0) {
this.KickToLogin(MBServerStatics.LOGINERROR_UNABLE_TO_LOGIN, "The username provided was zero length.", clientConnection);
return;
}
if (pass.length() == 0) {
this.KickToLogin(MBServerStatics.LOGINERROR_UNABLE_TO_LOGIN, "The password provided was zero length.", clientConnection);
return;
}
Account account;
account = DbManager.AccountQueries.GET_ACCOUNT(uname);
// Create the account if it doesn't exist and MB_LOGIN_AUTOREG is TRUE;
// This is to support MagicBox users without a web hosting skillset.
if (account == null) {
if (ConfigManager.MB_LOGIN_AUTOREG.getValue().equalsIgnoreCase("false")) {
this.KickToLogin(MBServerStatics.LOGINERROR_INVALID_USERNAME_PASSWORD, "Could not find account (" + uname + ')', clientConnection);
Logger.info("Could not find account (" + uname + ')');
return;
}
Logger.info("AutoRegister: " + uname + "/" + pass);
DbManager.AccountQueries.CREATE_SINGLE(uname, pass);
account = DbManager.AccountQueries.GET_ACCOUNT(uname);
if (account == null) {
this.KickToLogin(MBServerStatics.LOGINERROR_INVALID_USERNAME_PASSWORD, "Could not find account (" + uname + ')', clientConnection);
Logger.info("Could not auto-create (" + uname + ')');
return;
}
}
if (account.getLastLoginFailure() + MBServerStatics.RESET_LOGIN_ATTEMPTS_AFTER < System.currentTimeMillis())
account.resetLoginAttempts();
// TODO: Log the login attempts IP, name, password and timestamp
// Check number invalid login attempts. If 5 or greater, kick to login.
if (account.getLoginAttempts() >= MBServerStatics.MAX_LOGIN_ATTEMPTS) {
this.KickToLogin(MBServerStatics.LOGINERROR_UNABLE_TO_LOGIN, "Too many login in attempts for '" + uname + '\'', clientConnection);
Logger.info("Too many login in attempts for '" + uname + '\'');
return;
}
if (account.lastPasswordCheck < System.currentTimeMillis()) {
account.lastPasswordCheck = System.currentTimeMillis() + MBServerStatics.ONE_MINUTE;
}
// Attempt to validate login
try {
if (!account.passIsValid(pass, clientConnection.getClientIpAddress(), clientConnection.machineID)) {
account.incrementLoginAttempts();
this.KickToLogin(MBServerStatics.LOGINERROR_INVALID_USERNAME_PASSWORD, "", clientConnection);
Logger.info("Incorrect password(" + uname + ')');
return;
}
} catch (IllegalArgumentException e1) {
this.KickToLogin(MBServerStatics.LOGINERROR_UNABLE_TO_LOGIN, "", clientConnection);
Logger.info("Failed forum account validation(" + uname + ')');
}
// Account deactivated
if (account.status.equals(Enum.AccountStatus.BANNED)) {
this.KickToLogin(MBServerStatics.LOGINERROR_NO_MORE_PLAYTIME_ON_ACCOUNT, "", clientConnection);
return;
}
// Check to see if we have a Session mapped with this Account:
Session session = SessionManager.getSession(account);
// If there is, then the account is in use and must be handled:
// kick the 'other connection'
if (session != null)
this.KickToLogin(MBServerStatics.LOGINERROR_UNABLE_TO_LOGIN, "Your account has been accessed from a different IP & Port.", session.getConn()); // Logout the character
// TODO implement character logout
// Get a new session
session = SessionManager.getNewSession(account, clientConnection);
// Set Invalid Login Attempts to 0
account.resetLoginAttempts();
// Send Login Response
ClientLoginInfoMsg loginResponse = new ClientLoginInfoMsg(clientLoginInfoMessage);
loginResponse.setUnknown06(8323072);
loginResponse.setUnknown07(3276800);
loginResponse.setUnknown08(196608);
loginResponse.setUnknown09((short) 15);
clientConnection.sendMsg(loginResponse);
// send character select screen
try {
this.sendCharacterSelectScreen(session);
} catch (Exception e) {
Logger.error("Unable to Send Character Select Screen to client");
this.KickToLogin(MBServerStatics.LOGINERROR_UNABLE_TO_LOGIN, "Unable to send Character Select Screen to client.", clientConnection);
return;
}
// Logging
String addyPort = clientConnection.getRemoteAddressAndPortAsString();
int id = account.getObjectUUID();
Logger.info(uname + '(' + id + ") has successfully logged in from " + addyPort);
}
private void KickToLogin(int errCode, String message, ClientConnection origin) {
LoginErrorMsg msg = new LoginErrorMsg(errCode, message);
PlayerCharacter player = origin.getPlayerCharacter();
if (player == null) {
origin.sendMsg(msg);
} else {
Dispatch dispatch = Dispatch.borrow(player, msg);
DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.PRIMARY);
}
Logger.info("Kicking to Login. Message: '" + message + '\'');
DisconnectJob dj = new DisconnectJob(origin);
JobScheduler.getInstance().scheduleJob(dj, 250);
}
protected void sendCharacterSelectScreen(Session s) {
sendCharacterSelectScreen(s, false);
}
private void sendCharacterSelectScreen(Session s, boolean fromCommit) {
if (s.getAccount() != null) {
CharSelectScreenMsg cssm = new CharSelectScreenMsg(s, fromCommit);
s.getConn().sendMsg(cssm);
} else {
Logger.error("No Account Found: Unable to Send Character Select Screen");
this.KickToLogin(MBServerStatics.LOGINERROR_UNABLE_TO_LOGIN, "Unable to send Character Select Screen to client.", s.getConn());
}
}
private void SendServerInfo(ClientConnection conn) {
ServerInfoMsg sim = new ServerInfoMsg();
if (!conn.sendMsg(sim)) {
Logger.error("Failed to send message");
this.KickToLogin(MBServerStatics.LOGINERROR_UNABLE_TO_LOGIN, "Unable to send ServerInfoMsg to client.", conn);
}
}
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) {
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.");
this.sendCharacterSelectScreen(session);
return;
}
if (session.getAccount() == null) {
Logger.error("Delete Error: Account not found.");
this.sendCharacterSelectScreen(session);
return;
}
if (playerCharacter.getAccount().equals(session.getAccount()) == false) {
Logger.error("Delete Error: Character " + playerCharacter.getName() + " does not belong to account " + origin.getAccount().getUname());
this.sendCharacterSelectScreen(session);
return;
}
//Can't delete as Guild Leader
//TODO either find an error or just gdisband.
if (GuildStatusController.isGuildLeader(playerCharacter.getGuildStatus())) {
this.KickToLogin(MBServerStatics.LOGINERROR_UNABLE_TO_LOGIN, "Cannot delete a guild leader.", origin);
return;
}
// check for active banes
if (LoginServer.getActiveBaneQuery(playerCharacter)) {
Logger.info("Character " + playerCharacter.getName() + " has unresolved bane");
this.KickToLogin(MBServerStatics.LOGINERROR_UNABLE_TO_LOGIN, "Player has unresolved bane.", origin);
return;
}
playerCharacter.getAccount().characterMap.remove(playerCharacter.getObjectUUID());
playerCharacter.deactivateCharacter();
// TODO Delete Equipment
// Resend Character Select Screen.
this.sendCharacterSelectScreen(session);
} catch (Exception e) {
Logger.error(e);
}
}
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());
this.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);
}
}
}
-2
View File
@@ -30,7 +30,6 @@ import engine.net.ItemProductionManager;
import engine.net.Network;
import engine.net.client.ClientConnection;
import engine.net.client.ClientConnectionManager;
import engine.net.client.ClientMessagePump;
import engine.net.client.Protocol;
import engine.net.client.msg.UpdateStateMsg;
import engine.net.client.msg.chat.ChatSystemMsg;
@@ -103,7 +102,6 @@ public class WorldServer {
ConfigManager.serverType = Enum.ServerType.WORLDSERVER;
ConfigManager.worldServer = worldServer;
ConfigManager.handler = new ClientMessagePump(worldServer);
worldServer.init();