Example #1
0
        public override async Task RunImpl()
        {
            await Task.Run(() =>
            {
                _authThread.SetInGameAccount(_client.AccountName);

                L2Player player = _client.CurrentPlayer;

                if (player == null)
                {
                    return;
                }

                if (player.PBlockAct == 1)
                {
                    player.SendActionFailedAsync();
                    return;
                }

                if (player.isInCombat())
                {
                    player.SendSystemMessage(SystemMessage.SystemMessageId.CantLogoutWhileFighting);
                    player.SendActionFailedAsync();
                    return;
                }

                if (player.Online == 1)
                {
                    player.Online = 0;
                    player.DeleteMe();
                }
                player.SendPacketAsync(new LeaveWorld());
            });
        }
Example #2
0
        public override async Task RunImpl()
        {
            if (_client.AccountName == null)
            {
                _client.SessionKey = new SessionKey(_loginKey1, _loginKey2, _playKey1, _playKey2);

                _client.AccountName = _loginName;

                var players = await _accountService.GetPlayerIdsListByAccountName(_loginName);

                int slot = 0;
                foreach (var p in players.Select(id => _playerService.RestorePlayer(id, _client)))
                {
                    //TODO: Make delete on startup server or timer listener
                    // See if the char must be deleted
                    if (p.CharDeleteTimeExpired())
                    {
                        _playerService.DeleteCharByObjId(p.ObjId);
                        continue;
                    }

                    p.CharSlot = slot;
                    slot++;
                    _client.AccountChars.Add(p);
                }

                _client.SendPacketAsync(new CharacterSelectionInfo(_client.AccountName, _client.AccountChars, _client.SessionKey.PlayOkId1));
                _authThread.SetInGameAccount(_client.AccountName, true);
            }
            else
            {
                _client.Termination();
            }
        }
Example #3
0
        public override async Task RunImpl()
        {
            if (_client.Account != null)
            {
                await _client.Disconnect();

                return;
            }

            Tuple <AccountContract, SessionKey, DateTime> accountTuple = _authThread.GetAwaitingAccount(_loginName);

            if (accountTuple == null)
            {
                Log.Error($"Account is not awaited. Disconnecting. Login: {_loginName}");
                await _client.Disconnect();

                return;
            }

            AccountContract account      = accountTuple.Item1;
            SessionKey      accountKey   = accountTuple.Item2;
            DateTime        waitStarTime = accountTuple.Item3;

            if (_clientManager.IsConnected(account.AccountId))
            {
                _clientManager.Disconnect(account.AccountId);
            }

            // TODO: move 5s to config
            if ((DateTime.UtcNow - waitStarTime).TotalMilliseconds > 5000)
            {
                Log.Error($"Account login timeout. AccountId: {account.AccountId}");
                await _client.Disconnect();

                return;
            }

            if (accountKey != _key)
            {
                Log.Error($"Invalid SessionKey. AccountId: {account.AccountId}");
                await _client.Disconnect();

                return;
            }

            _client.SessionKey = accountKey;

            _client.Account = account;

            await _client.FetchAccountCharacters();

            _client.SendPacketAsync(new CharList(_client, _client.SessionKey.PlayOkId1));
            _authThread.SetInGameAccount(_client.Account.AccountId, true);
        }
Example #4
0
        public async Task Disconnect()
        {
            await SendPacketAsync(new ServerClose());

            if (CurrentPlayer?.Online == 1)
            {
                await CurrentPlayer.SendMessageAsync("Server closed the connection.");

                await CurrentPlayer.SetOffline();
            }

            _authThread.SetInGameAccount(Account.AccountId, false);

            CloseConnection();
        }