Files
Server/src/engine/net/client/handlers/ArcLoginNotifyMsgHandler.java
T

149 lines
5.4 KiB
Java
Raw Normal View History

2022-04-30 09:41:17 -04:00
package engine.net.client.handlers;
import engine.Enum;
2022-04-30 09:41:17 -04:00
import engine.Enum.DispatchChannel;
import engine.exception.MsgSendException;
import engine.gameManager.*;
import engine.job.JobScheduler;
import engine.net.Dispatch;
import engine.net.DispatchMessage;
import engine.net.client.ClientConnection;
import engine.net.client.msg.ArcLoginNotifyMsg;
import engine.net.client.msg.ClientNetMsg;
import engine.net.client.msg.HotzoneChangeMsg;
import engine.net.client.msg.PetMsg;
import engine.objects.Account;
import engine.objects.Guild;
import engine.objects.PlayerCharacter;
import engine.objects.PlayerFriends;
2022-04-30 09:41:17 -04:00
import engine.server.MBServerStatics;
import engine.session.Session;
import org.pmw.tinylog.Logger;
public class ArcLoginNotifyMsgHandler extends AbstractClientMsgHandler {
2023-07-15 09:23:48 -04:00
public ArcLoginNotifyMsgHandler() {
super(ArcLoginNotifyMsg.class);
}
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
@Override
protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException {
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
PlayerCharacter player = SessionManager.getPlayerCharacter(origin);
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
if (player == null) {
Logger.error(ConfigManager.MB_WORLD_NAME.getValue() + ".EnterWorld", "Unable to find player for session");
origin.kickToLogin(MBServerStatics.LOGINERROR_UNABLE_TO_LOGIN, "Player not found.");
return true;
}
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
// cancel logout Timer if exists
if (player.getTimers().containsKey("Logout")) {
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
JobScheduler.getInstance().cancelScheduledJob(player.getTimers().get("Logout"));
player.getTimers().remove("Logout");
}
player.setTimeStamp("logout", 0);
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
// refresh group window if still in group for both this player
// and everyone else in the group
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
if (GroupManager.getGroup(player) != null) {
GroupManager.RefreshMyGroupList(player, origin);
GroupManager.RefreshOthersGroupList(player);
}
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
player.setEnteredWorld(true);
// Set player active
player.resetRegenUpdateTime();
player.setActive(true);
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
//player.sendAllEffects(player.getClientConnection());
// Send Enter world message to guild
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
ChatManager.GuildEnterWorldMsg(player, origin);
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
// Send Guild, Nation and IC MOTD
GuildManager.enterWorldMOTD(player);
ChatManager.sendSystemMessage(player, ConfigManager.MB_WORLD_GREETING.getValue());
2022-04-30 09:41:17 -04:00
// Send branch string if available from ConfigManager.
if (ConfigManager.currentRepoBranch != "")
ChatManager.sendSystemMessage(player, ConfigManager.currentRepoBranch);
2023-07-15 09:23:48 -04:00
// Set player mask for QT
if (player.getRace() != null && player.getRace().getToken() == -524731385)
player.setObjectTypeMask(MBServerStatics.MASK_PLAYER | MBServerStatics.MASK_UNDEAD);
else
player.setObjectTypeMask(MBServerStatics.MASK_PLAYER);
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
// If player not already in world, then set them to bind loc and add
// to world
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
if (player.newChar)
player.newChar = false; // TODO Fix safe mode
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
// PowersManager.applyPower(player, player, new
// Vector3f(0f, 0f, 0f), -1661758934, 50, false);
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
// Add player to the QT for tracking
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
player.setLoc(player.getLoc());
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
//send online status to friends.
PlayerFriends.SendFriendsStatus(player, true);
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
// Handle too many simultaneous logins from the same forum account by disconnecting the other account(s)
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
Account thisAccount = SessionManager.getAccount(player);
int maxAccounts = MBServerStatics.MAX_ACTIVE_GAME_ACCOUNTS_PER_DISCORD_ACCOUNT;
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
if (maxAccounts > 0) {
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
int count = 1;
for (Account othAccount : SessionManager.getAllActiveAccounts()) {
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
if (othAccount.equals(thisAccount))
continue;
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
if (thisAccount.discordAccount.equals(othAccount.discordAccount) == false)
continue;
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
count++;
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
if (count > maxAccounts) {
Session otherSession = SessionManager.getSession(othAccount);
if (otherSession != null) {
ClientConnection otherConn = otherSession.getConn();
if (otherConn != null) {
ChatManager.chatSystemInfo(player, "Only 4 accounts may be used simultaneously. Account '" + othAccount.getUname() + "' has been disconnected.");
otherConn.disconnect();
}
}
}
}
}
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
player.setTimeStamp("logout", 0);
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
if (player.getPet() != null) {
PetMsg pm = new PetMsg(5, player.getPet());
Dispatch dispatch = Dispatch.borrow(player, pm);
DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY);
}
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
//Send current hotzone
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
if (ZoneManager.hotZone != null) {
HotzoneChangeMsg hcm = new HotzoneChangeMsg(Enum.GameObjectType.Zone.ordinal(), ZoneManager.hotZone.getObjectUUID());
Dispatch dispatch = Dispatch.borrow(player, hcm);
DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY);
}
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
if (player.getGuild() != null && !player.getGuild().isEmptyGuild()) {
Guild.UpdateClientAlliancesForPlayer(player);
}
return true;
}
2022-04-30 09:41:17 -04:00
}