public void StartCharacterSelection(Client client) { if (client.State != ClientState.LoggedIn) { return; } client.CallMethod(SysEntity.ClientMethodId, new BeginCharacterSelectionPacket(client.AccountEntry.FamilyName, client.AccountEntry.Characters.Any(), client.AccountEntry.Id, client.AccountEntry.CanSkipBootcamp)); using var unitOfWork = _gameUnitOfWorkFactory.CreateChar(); var charactersBySlot = unitOfWork.Characters.GetByAccountId(client.AccountEntry.Id); for (byte i = 1; i <= MaxSelectionPods; ++i) { CharacterEntry character = null; if (charactersBySlot.ContainsKey(i)) { character = charactersBySlot[i]; } SendCharacterInfoProdCreate(client, i, character); } client.State = ClientState.CharacterSelection; }
private void HandleProtocolPacket(ProtocolPacket protocolPacket) { switch (protocolPacket.Type) { case ClientMessageOpcode.Login: var loginMsg = GetMessageAs <LoginMessage>(protocolPacket); if (loginMsg.Version.Length != 8 || loginMsg.Version != "1.16.5.0") { Logger.WriteLog(LogType.Error, $"Client version mismatch: Server: 1.16.5.0 | Client: {loginMsg.Version}"); SendMessage(new LoginResponseMessage { ErrorCode = LoginErrorCodes.VersionMismatch, Subtype = LoginResponseMessageSubtype.Failed }, delay: false); return; } var loginEntry = Server.AuthenticateClient(this, loginMsg.AccountId, loginMsg.OneTimeKey); if (loginEntry == null) { Logger.WriteLog(LogType.Error, "Client with ip: {0} tried to log in with invalid session data! User Id: {1} | OneTimeKey: {2}", Socket.RemoteAddress, loginMsg.AccountId, loginMsg.OneTimeKey); SendMessage(new LoginResponseMessage { ErrorCode = LoginErrorCodes.AuthenticationFailed, Subtype = LoginResponseMessageSubtype.Failed }, delay: false); return; } using (var unitOfWork = _gameUnitOfWorkFactory.CreateChar()) { unitOfWork.GameAccounts.CreateOrUpdate(loginEntry.Id, loginEntry.Name, loginEntry.Email); if (Server.IsBanned(loginMsg.AccountId)) { Logger.WriteLog(LogType.Error, "Client with ip: {0} tried to log in while the account is banned! User Id: {1}", Socket.RemoteAddress, loginMsg.AccountId); SendMessage(new LoginResponseMessage { ErrorCode = LoginErrorCodes.AccountLocked, Subtype = LoginResponseMessageSubtype.Failed }, delay: false); return; } if (Server.IsAlreadyLoggedIn(loginMsg.AccountId)) { Logger.WriteLog(LogType.Error, "Client with ip: {0} tried to log in while the account is being played on! User Id: {1}", Socket.RemoteAddress, loginMsg.AccountId); SendMessage(new LoginResponseMessage { ErrorCode = LoginErrorCodes.AlreadyLoggedIn, Subtype = LoginResponseMessageSubtype.Failed }, delay: false); return; } LoadGameAccountEntry(unitOfWork, loginEntry.Id); unitOfWork.GameAccounts.UpdateLoginData(loginEntry.Id, Socket.RemoteAddress); unitOfWork.Complete(); } SendMessage(new LoginResponseMessage { AccountId = loginMsg.AccountId, Subtype = LoginResponseMessageSubtype.Success }); State = ClientState.LoggedIn; _characterManager.StartCharacterSelection(this); return; case ClientMessageOpcode.Move: if (Player == null) { return; } var moveMessage = GetMessageAs <MoveMessage>(protocolPacket); if (moveMessage.Movement == null) { return; } Player.Position = moveMessage.Movement.Position; Player.Rotation = moveMessage.Movement.ViewDirection.X; break; case ClientMessageOpcode.CallServerMethod: var csmPacket = GetMessageAs <CallServerMethodMessage>(protocolPacket); if (!csmPacket.ReadPacket()) { Close(true); return; } PacketRouter.RoutePacket(_handler, csmPacket.Packet); break; case ClientMessageOpcode.Ping: var pingMessage = GetMessageAs <PingMessage>(protocolPacket); SendMessage(pingMessage, delay: false); break; } }