From 141b1913cbfe1c9b7d2f8ac224e53f877790c7a2 Mon Sep 17 00:00:00 2001 From: Melledy <52122272+Melledy@users.noreply.github.com> Date: Fri, 27 May 2022 00:22:55 -0700 Subject: [PATCH] Refactor accounts to not use a player uid --- .../command/commands/AccountCommand.java | 6 +- .../command/commands/KickCommand.java | 2 +- .../command/commands/SendMailCommand.java | 2 +- .../grasscutter/database/DatabaseHelper.java | 54 +++++++----- .../java/emu/grasscutter/game/Account.java | 10 +-- .../emu/grasscutter/game/player/Player.java | 30 ++++--- .../grasscutter/server/game/GameServer.java | 8 +- .../server/http/handlers/GachaHandler.java | 4 +- .../packet/recv/HandlerGetPlayerTokenReq.java | 53 ++++++++---- .../packet/recv/HandlerPlayerLoginReq.java | 18 ++-- .../recv/HandlerSetPlayerBornDataReq.java | 84 +++++++------------ .../packet/send/PacketGetPlayerTokenRsp.java | 6 +- 12 files changed, 144 insertions(+), 133 deletions(-) diff --git a/src/main/java/emu/grasscutter/command/commands/AccountCommand.java b/src/main/java/emu/grasscutter/command/commands/AccountCommand.java index 0578ddf46..4bb369886 100644 --- a/src/main/java/emu/grasscutter/command/commands/AccountCommand.java +++ b/src/main/java/emu/grasscutter/command/commands/AccountCommand.java @@ -52,7 +52,7 @@ public final class AccountCommand implements CommandHandler { account.addPermission("*"); account.save(); // Save account to database. - CommandHandler.sendMessage(null, translate(sender, "commands.account.create", Integer.toString(account.getPlayerUid()))); + CommandHandler.sendMessage(null, translate(sender, "commands.account.create", Integer.toString(account.getReservedPlayerUid()))); } return; case "delete": @@ -63,10 +63,10 @@ public final class AccountCommand implements CommandHandler { CommandHandler.sendMessage(null, translate(sender, "commands.account.no_account")); return; } - + // Get the player for the account. // If that player is currently online, we kick them before proceeding with the deletion. - Player player = Grasscutter.getGameServer().getPlayerByUid(toDelete.getPlayerUid()); + Player player = Grasscutter.getGameServer().getPlayerByAccountId(toDelete.getId()); if (player != null) { player.getSession().close(); } diff --git a/src/main/java/emu/grasscutter/command/commands/KickCommand.java b/src/main/java/emu/grasscutter/command/commands/KickCommand.java index 8b3b93e77..546fe905d 100644 --- a/src/main/java/emu/grasscutter/command/commands/KickCommand.java +++ b/src/main/java/emu/grasscutter/command/commands/KickCommand.java @@ -15,7 +15,7 @@ public final class KickCommand implements CommandHandler { public void execute(Player sender, Player targetPlayer, List args) { if (sender != null) { CommandHandler.sendMessage(sender, translate(sender, "commands.kick.player_kick_player", - Integer.toString(sender.getAccount().getPlayerUid()), sender.getAccount().getUsername(), + Integer.toString(sender.getUid()), sender.getAccount().getUsername(), Integer.toString(targetPlayer.getUid()), targetPlayer.getAccount().getUsername())); } else { CommandHandler.sendMessage(null, translate(sender, "commands.kick.server_kick_player", Integer.toString(targetPlayer.getUid()), targetPlayer.getAccount().getUsername())); diff --git a/src/main/java/emu/grasscutter/command/commands/SendMailCommand.java b/src/main/java/emu/grasscutter/command/commands/SendMailCommand.java index 85e929f72..c4369fa86 100644 --- a/src/main/java/emu/grasscutter/command/commands/SendMailCommand.java +++ b/src/main/java/emu/grasscutter/command/commands/SendMailCommand.java @@ -44,7 +44,7 @@ public final class SendMailCommand implements CommandHandler { } case "all" -> mailBuilder = new MailBuilder(true, new Mail()); default -> { - if (DatabaseHelper.getPlayerById(Integer.parseInt(args.get(0))) != null) { + if (DatabaseHelper.getPlayerByUid(Integer.parseInt(args.get(0))) != null) { mailBuilder = new MailBuilder(Integer.parseInt(args.get(0)), new Mail()); } else { CommandHandler.sendMessage(sender, translate(sender, "commands.sendMail.user_not_exist", args.get(0))); diff --git a/src/main/java/emu/grasscutter/database/DatabaseHelper.java b/src/main/java/emu/grasscutter/database/DatabaseHelper.java index f89779fee..057b450cb 100644 --- a/src/main/java/emu/grasscutter/database/DatabaseHelper.java +++ b/src/main/java/emu/grasscutter/database/DatabaseHelper.java @@ -8,6 +8,7 @@ import dev.morphia.query.FindOptions; import dev.morphia.query.Sort; import dev.morphia.query.experimental.filters.Filters; import emu.grasscutter.GameConstants; +import emu.grasscutter.Grasscutter; import emu.grasscutter.game.Account; import emu.grasscutter.game.avatar.Avatar; import emu.grasscutter.game.friends.Friendship; @@ -49,7 +50,7 @@ public final class DatabaseHelper { account.setId(Integer.toString(DatabaseManager.getNextId(account))); if (reservedId > 0) { - account.setPlayerId(reservedId); + account.setReservedPlayerUid(reservedId); } DatabaseHelper.saveAccount(account); @@ -104,25 +105,28 @@ public final class DatabaseHelper { // This should optimally be wrapped inside a transaction, to make sure an error thrown mid-way does not leave the // database in an inconsistent state, but unfortunately Mongo only supports that when we have a replica set ... - // Delete Mail.class data - DatabaseManager.getGameDatabase().getCollection("mail").deleteMany(eq("ownerUid", target.getPlayerUid())); - // Delete Avatar.class data - DatabaseManager.getGameDatabase().getCollection("avatars").deleteMany(eq("ownerId", target.getPlayerUid())); - // Delete GachaRecord.class data - DatabaseManager.getGameDatabase().getCollection("gachas").deleteMany(eq("ownerId", target.getPlayerUid())); - // Delete GameItem.class data - DatabaseManager.getGameDatabase().getCollection("items").deleteMany(eq("ownerId", target.getPlayerUid())); - // Delete GameMainQuest.class data - DatabaseManager.getGameDatabase().getCollection("quests").deleteMany(eq("ownerUid", target.getPlayerUid())); + Player player = Grasscutter.getGameServer().getPlayerByAccountId(target.getId()); + + if (player != null) { + // Close session first + player.getSession().close(); + + // Delete data from collections + DatabaseManager.getGameDatabase().getCollection("mail").deleteMany(eq("ownerUid", player.getUid())); + DatabaseManager.getGameDatabase().getCollection("avatars").deleteMany(eq("ownerId", player.getUid())); + DatabaseManager.getGameDatabase().getCollection("gachas").deleteMany(eq("ownerId", player.getUid())); + DatabaseManager.getGameDatabase().getCollection("items").deleteMany(eq("ownerId", player.getUid())); + DatabaseManager.getGameDatabase().getCollection("quests").deleteMany(eq("ownerUid", player.getUid())); - // Delete friendships. - // Here, we need to make sure to not only delete the deleted account's friendships, - // but also all friendship entries for that account's friends. - DatabaseManager.getGameDatabase().getCollection("friendships").deleteMany(eq("ownerId", target.getPlayerUid())); - DatabaseManager.getGameDatabase().getCollection("friendships").deleteMany(eq("friendId", target.getPlayerUid())); + // Delete friendships. + // Here, we need to make sure to not only delete the deleted account's friendships, + // but also all friendship entries for that account's friends. + DatabaseManager.getGameDatabase().getCollection("friendships").deleteMany(eq("ownerId", player.getUid())); + DatabaseManager.getGameDatabase().getCollection("friendships").deleteMany(eq("friendId", player.getUid())); - // Delete the player. - DatabaseManager.getGameDatastore().find(Player.class).filter(Filters.eq("id", target.getPlayerUid())).delete(); + // Delete the player last. + DatabaseManager.getGameDatastore().find(Player.class).filter(Filters.eq("id", player.getUid())).delete(); + } // Finally, delete the account itself. DatabaseManager.getGameDatastore().find(Account.class).filter(Filters.eq("id", target.getId())).delete(); @@ -132,15 +136,19 @@ public final class DatabaseHelper { return DatabaseManager.getGameDatastore().find(Player.class).stream().toList(); } - public static Player getPlayerById(int id) { + public static Player getPlayerByUid(int id) { return DatabaseManager.getGameDatastore().find(Player.class).filter(Filters.eq("_id", id)).first(); } - - public static boolean checkPlayerExists(int id) { - return DatabaseManager.getGameDatastore().find(Player.class).filter(Filters.eq("_id", id)).first() != null; + + public static Player getPlayerByAccount(Account account) { + return DatabaseManager.getGameDatastore().find(Player.class).filter(Filters.eq("accountId", account.getId())).first(); + } + + public static boolean checkPlayerExists(int uid) { + return DatabaseManager.getGameDatastore().find(Player.class).filter(Filters.eq("_id", uid)).count() > 0; } - public static synchronized Player createPlayer(Player character, int reservedId) { + public static synchronized Player generatePlayerUid(Player character, int reservedId) { // Check if reserved id int id; if (reservedId > 0 && !checkPlayerExists(reservedId)) { diff --git a/src/main/java/emu/grasscutter/game/Account.java b/src/main/java/emu/grasscutter/game/Account.java index 00a18c4b7..3697dade5 100644 --- a/src/main/java/emu/grasscutter/game/Account.java +++ b/src/main/java/emu/grasscutter/game/Account.java @@ -21,7 +21,7 @@ public class Account { private String username; private String password; // Unused for now - @AlsoLoad("playerUid") private int playerId; + private int reservedPlayerId; private String email; private String token; @@ -67,12 +67,12 @@ public class Account { this.token = token; } - public int getPlayerUid() { - return this.playerId; + public int getReservedPlayerUid() { + return this.reservedPlayerId; } - public void setPlayerId(int playerId) { - this.playerId = playerId; + public void setReservedPlayerUid(int playerId) { + this.reservedPlayerId = playerId; } public String getEmail() { diff --git a/src/main/java/emu/grasscutter/game/player/Player.java b/src/main/java/emu/grasscutter/game/player/Player.java index 6e9b77eb6..3c741e269 100644 --- a/src/main/java/emu/grasscutter/game/player/Player.java +++ b/src/main/java/emu/grasscutter/game/player/Player.java @@ -50,6 +50,7 @@ import emu.grasscutter.server.event.player.PlayerJoinEvent; import emu.grasscutter.server.event.player.PlayerQuitEvent; import emu.grasscutter.server.game.GameServer; import emu.grasscutter.server.game.GameSession; +import emu.grasscutter.server.game.GameSession.SessionState; import emu.grasscutter.server.packet.send.*; import emu.grasscutter.utils.DateHelper; import emu.grasscutter.utils.Position; @@ -247,7 +248,6 @@ public class Player { public void setAccount(Account account) { this.account = account; - this.account.setPlayerId(getUid()); } public GameSession getSession() { @@ -1017,8 +1017,8 @@ public class Player { } } } else { - List showAvatarList = DatabaseHelper.getPlayerById(id).getShowAvatarList(); - AvatarStorage avatars = DatabaseHelper.getPlayerById(id).getAvatars(); + List showAvatarList = DatabaseHelper.getPlayerByUid(id).getShowAvatarList(); + AvatarStorage avatars = DatabaseHelper.getPlayerByUid(id).getAvatars(); avatars.loadFromDatabase(); if (showAvatarList != null) { for (int avatarId : showAvatarList) { @@ -1058,7 +1058,7 @@ public class Player { player = this; shouldRecalc = false; } else { - player = DatabaseHelper.getPlayerById(id); + player = DatabaseHelper.getPlayerByUid(id); player.getAvatars().loadFromDatabase(); player.getInventory().loadFromDatabase(); shouldRecalc = true; @@ -1176,8 +1176,9 @@ public class Player { public void save() { DatabaseHelper.savePlayer(this); } - - public void onLogin() { + + // Called from tokenrsp + public void loadFromDatabase() { // Make sure these exist if (this.getTeamManager() == null) { this.teamManager = new TeamManager(this); @@ -1205,6 +1206,14 @@ public class Player { this.getMailHandler().loadFromDatabase(); this.getQuestManager().loadFromDatabase(); + // Add to gameserver (Always handle last) + if (getSession().isActive()) { + getServer().registerPlayer(this); + getProfile().setPlayer(this); // Set online + } + } + + public void onLogin() { // Quest - Commented out because a problem is caused if you log out while this quest is active /* if (getQuestManager().getMainQuestById(351) == null) { @@ -1224,12 +1233,6 @@ public class Player { World world = new World(this); world.addPlayer(this); - // Add to gameserver - if (getSession().isActive()) { - getServer().registerPlayer(this); - getProfile().setPlayer(this); // Set online - } - // Multiplayer setting this.setProperty(PlayerProperty.PROP_PLAYER_MP_SETTING_TYPE, this.getMpSetting().getNumber()); this.setProperty(PlayerProperty.PROP_IS_MP_MODE_AVAILABLE, 1); @@ -1255,6 +1258,9 @@ public class Player { // First notify packets sent this.setHasSentAvatarDataNotify(true); + + // Set session state + session.setState(SessionState.ACTIVE); // Call join event. PlayerJoinEvent event = new PlayerJoinEvent(this); event.call(); diff --git a/src/main/java/emu/grasscutter/server/game/GameServer.java b/src/main/java/emu/grasscutter/server/game/GameServer.java index 663d99728..3f05fbfd9 100644 --- a/src/main/java/emu/grasscutter/server/game/GameServer.java +++ b/src/main/java/emu/grasscutter/server/game/GameServer.java @@ -118,6 +118,7 @@ public final class GameServer extends KcpServer { public ChatManagerHandler getChatManager() { return chatManager; } + public void setChatManager(ChatManagerHandler chatManager) { this.chatManager = chatManager; } @@ -189,12 +190,17 @@ public final class GameServer extends KcpServer { // Check database if character isnt here if (player == null) { - player = DatabaseHelper.getPlayerById(id); + player = DatabaseHelper.getPlayerByUid(id); } return player; } + public Player getPlayerByAccountId(String accountId) { + Optional playerOpt = getPlayers().values().stream().filter(player -> player.getAccount().getId().equals(accountId)).findFirst(); + return playerOpt.orElse(null); + } + public SocialDetail.Builder getSocialDetailByUid(int id) { // Get from online players Player player = this.getPlayerByUid(id, true); diff --git a/src/main/java/emu/grasscutter/server/http/handlers/GachaHandler.java b/src/main/java/emu/grasscutter/server/http/handlers/GachaHandler.java index 071ffb01a..5aacb76d8 100644 --- a/src/main/java/emu/grasscutter/server/http/handlers/GachaHandler.java +++ b/src/main/java/emu/grasscutter/server/http/handlers/GachaHandler.java @@ -52,7 +52,7 @@ public final class GachaHandler implements Router { response.status(403).send("Requested account was not found"); return; } - Player player = Grasscutter.getGameServer().getPlayerByUid(account.getPlayerUid()); + Player player = Grasscutter.getGameServer().getPlayerByAccountId(account.getId()); if (player == null) { response.status(403).send("No player associated with requested account"); return; @@ -88,7 +88,7 @@ public final class GachaHandler implements Router { response.status(403).send("Requested account was not found"); return; } - Player player = Grasscutter.getGameServer().getPlayerByUid(account.getPlayerUid()); + Player player = Grasscutter.getGameServer().getPlayerByAccountId(account.getId()); if (player == null) { response.status(403).send("No player associated with requested account"); return; diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerGetPlayerTokenReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerGetPlayerTokenReq.java index 5034fb01a..1e68377a4 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerGetPlayerTokenReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerGetPlayerTokenReq.java @@ -1,11 +1,16 @@ package emu.grasscutter.server.packet.recv; +import static emu.grasscutter.Configuration.ACCOUNT; + +import emu.grasscutter.Grasscutter; import emu.grasscutter.database.DatabaseHelper; import emu.grasscutter.game.Account; +import emu.grasscutter.game.player.Player; import emu.grasscutter.net.packet.Opcodes; import emu.grasscutter.net.packet.PacketOpcodes; import emu.grasscutter.net.proto.GetPlayerTokenReqOuterClass.GetPlayerTokenReq; import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.server.event.game.PlayerCreationEvent; import emu.grasscutter.server.game.GameSession; import emu.grasscutter.server.game.GameSession.SessionState; import emu.grasscutter.server.packet.send.PacketGetPlayerTokenRsp; @@ -15,6 +20,12 @@ public class HandlerGetPlayerTokenReq extends PacketHandler { @Override public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + // Max players limit + if (ACCOUNT.maxPlayer > -1 && Grasscutter.getGameServer().getPlayers().size() >= ACCOUNT.maxPlayer) { + session.close(); + return; + } + GetPlayerTokenReq req = GetPlayerTokenReq.parseFrom(payload); // Authenticate @@ -30,27 +41,35 @@ public class HandlerGetPlayerTokenReq extends PacketHandler { // Set account session.setAccount(account); + + // Get player + Player player = DatabaseHelper.getPlayerByAccount(account); + + if (player == null) { + int nextPlayerUid = DatabaseHelper.getNextPlayerId(session.getAccount().getReservedPlayerUid()); + + // Call creation event. + PlayerCreationEvent event = new PlayerCreationEvent(session, Player.class); event.call(); + + // Create player instance from event. + player = event.getPlayerClass().getDeclaredConstructor(GameSession.class).newInstance(session); + + // Save to db + DatabaseHelper.generatePlayerUid(player, nextPlayerUid); + } + + // Set player object for session + session.setPlayer(player); + + // Load player from database + player.loadFromDatabase(); + + // Set session state session.setUseSecretKey(true); session.setState(SessionState.WAITING_FOR_LOGIN); - - // Has character - boolean doesPlayerExist = false; - if (account.getPlayerUid() > 0) { - // Set flag for player existing - doesPlayerExist = DatabaseHelper.checkPlayerExists(account.getPlayerUid()); - } - - // Set reserve player id if account doesnt exist - if (!doesPlayerExist) { - int id = DatabaseHelper.getNextPlayerId(session.getAccount().getPlayerUid()); - if (id != session.getAccount().getPlayerUid()) { - session.getAccount().setPlayerId(id); - session.getAccount().save(); - } - } // Send packet - session.send(new PacketGetPlayerTokenRsp(session, doesPlayerExist)); + session.send(new PacketGetPlayerTokenRsp(session)); } } diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerPlayerLoginReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerPlayerLoginReq.java index d7aedb757..d5aea0db1 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerPlayerLoginReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerPlayerLoginReq.java @@ -22,11 +22,7 @@ public class HandlerPlayerLoginReq extends PacketHandler { public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { // Check if (session.getAccount() == null) { - return; - } - - // Max players limit - if (ACCOUNT.maxPlayer > -1 && Grasscutter.getGameServer().getPlayers().size() >= ACCOUNT.maxPlayer) { + session.close(); return; } @@ -35,23 +31,21 @@ public class HandlerPlayerLoginReq extends PacketHandler { // Authenticate session if (!req.getToken().equals(session.getAccount().getToken())) { + session.close(); return; } // Load character from db - Player player = DatabaseHelper.getPlayerById(session.getAccount().getPlayerUid()); + Player player = session.getPlayer(); - if (player == null) { - // Send packets + // Show opening cutscene if player has no avatars + if (player.getAvatars().getAvatarCount() == 0) { + // Pick character session.setState(SessionState.PICKING_CHARACTER); session.send(new BasePacket(PacketOpcodes.DoSetPlayerBornDataNotify)); } else { - // Set character - session.setPlayer(player); - // Login done session.getPlayer().onLogin(); - session.setState(SessionState.ACTIVE); } // Final packet to tell client logging in is done diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerSetPlayerBornDataReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerSetPlayerBornDataReq.java index 064481680..aca362f3f 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerSetPlayerBornDataReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerSetPlayerBornDataReq.java @@ -46,60 +46,38 @@ public class HandlerSetPlayerBornDataReq extends PacketHandler { return; } - String nickname = req.getNickName(); - if (nickname == null) { - nickname = "Traveler"; - } - - // Call creation event. - PlayerCreationEvent event = new PlayerCreationEvent(session, Player.class); event.call(); - // Create player instance from event. - Player player = event.getPlayerClass().getDeclaredConstructor(GameSession.class).newInstance(session); - player.setNickname(nickname); - - try { - // Save to db - DatabaseHelper.createPlayer(player, session.getAccount().getPlayerUid()); - - // Create avatar - if (player.getAvatars().getAvatarCount() == 0) { - Avatar mainCharacter = new Avatar(avatarId); - mainCharacter.setSkillDepotData(GameData.getAvatarSkillDepotDataMap().get(startingSkillDepot)); - // Manually handle adding to team - player.addAvatar(mainCharacter, false); - player.setMainCharacterId(avatarId); - player.setHeadImage(avatarId); - player.getTeamManager().getCurrentSinglePlayerTeamInfo().getAvatars().add(mainCharacter.getAvatarId()); - player.save(); // TODO save player team in different object - } - - // Save account - session.getAccount().setPlayerId(player.getUid()); - session.getAccount().save(); - - // Set character - session.setPlayer(player); - - // Login done - session.getPlayer().onLogin(); - session.setState(SessionState.ACTIVE); - - // Born resp packet - session.send(new BasePacket(PacketOpcodes.SetPlayerBornDataRsp)); + // Get player object + Player player = session.getPlayer(); - // Default mail - var welcomeMail = GAME_INFO.joinOptions.welcomeMail; - MailBuilder mailBuilder = new MailBuilder(player.getUid(), new Mail()); - mailBuilder.mail.mailContent.title = welcomeMail.title; - mailBuilder.mail.mailContent.sender = welcomeMail.sender; - // Please credit Grasscutter if changing something here. We don't condone commercial use of the project. - mailBuilder.mail.mailContent.content = welcomeMail.content + "\n"; - mailBuilder.mail.itemList.addAll(Arrays.asList(welcomeMail.items)); - mailBuilder.mail.importance = 1; - player.sendMail(mailBuilder.mail); - } catch (Exception e) { - Grasscutter.getLogger().error("Error creating player object: ", e); - session.close(); + // Create avatar + if (player.getAvatars().getAvatarCount() == 0) { + Avatar mainCharacter = new Avatar(avatarId); + mainCharacter.setSkillDepotData(GameData.getAvatarSkillDepotDataMap().get(startingSkillDepot)); + // Manually handle adding to team + player.addAvatar(mainCharacter, false); + player.setMainCharacterId(avatarId); + player.setHeadImage(avatarId); + player.getTeamManager().getCurrentSinglePlayerTeamInfo().getAvatars().add(mainCharacter.getAvatarId()); + player.save(); // TODO save player team in different object + } else { + return; } + + // Login done + session.getPlayer().onLogin(); + + // Born resp packet + session.send(new BasePacket(PacketOpcodes.SetPlayerBornDataRsp)); + + // Default mail + var welcomeMail = GAME_INFO.joinOptions.welcomeMail; + MailBuilder mailBuilder = new MailBuilder(player.getUid(), new Mail()); + mailBuilder.mail.mailContent.title = welcomeMail.title; + mailBuilder.mail.mailContent.sender = welcomeMail.sender; + // Please credit Grasscutter if changing something here. We don't condone commercial use of the project. + mailBuilder.mail.mailContent.content = welcomeMail.content + "\n"; + mailBuilder.mail.itemList.addAll(Arrays.asList(welcomeMail.items)); + mailBuilder.mail.importance = 1; + player.sendMail(mailBuilder.mail); } } diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketGetPlayerTokenRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketGetPlayerTokenRsp.java index 3a5e0f08c..f48c40873 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketGetPlayerTokenRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketGetPlayerTokenRsp.java @@ -10,16 +10,16 @@ import emu.grasscutter.utils.Crypto; public class PacketGetPlayerTokenRsp extends BasePacket { - public PacketGetPlayerTokenRsp(GameSession session, boolean doesPlayerExist) { + public PacketGetPlayerTokenRsp(GameSession session) { super(PacketOpcodes.GetPlayerTokenRsp, true); this.setUseDispatchKey(true); GetPlayerTokenRsp p = GetPlayerTokenRsp.newBuilder() - .setUid(session.getAccount().getPlayerUid()) + .setUid(session.getPlayer().getUid()) .setToken(session.getAccount().getToken()) .setAccountType(1) - .setIsProficientPlayer(doesPlayerExist) // Not sure where this goes + .setIsProficientPlayer(session.getPlayer().getAvatars().getAvatarCount() > 0) // Not sure where this goes .setSecretKeySeed(Crypto.ENCRYPT_SEED) .setSecurityCmdBuffer(ByteString.copyFrom(Crypto.ENCRYPT_SEED_BUFFER)) .setPlatformType(3)