Ejemplo n.º 1
0
 public static void IncrementTutorialStep()
 {
     Session = new PlayerSessionDto
     {
         TutorialStep = Session.TutorialStep + 1
     };
 }
Ejemplo n.º 2
0
        public void UnregisterSession(int sessionId)
        {
            PlayerSessionDto session = GetBySessionId(sessionId);

            session.State = PlayerSessionState.Unauthed;
            _client.Store(session);
        }
Ejemplo n.º 3
0
        public void UpdateSession(PlayerSessionDto dto)
        {
            if (!_cache.ExistsAsync(ToKey(dto)).GetAwaiter().GetResult())
            {
                return;
            }

            _cache.ReplaceAsync(ToKey(dto), dto).GetAwaiter().GetResult();
        }
Ejemplo n.º 4
0
        private async Task <bool> AccountChecks(EntryPointPacketBase packetBase, ISession session)
        {
            string     name       = packetBase.Name;
            AccountDto accountDto = await _accountService.GetByNameAsync(name);

            if (accountDto == null)
            {
                Log.Warn($"Invalid account {name}");
                session.Disconnect();
                return(false);
            }

            if (!string.Equals(packetBase.Password.ToSha512(), accountDto.Password, StringComparison.OrdinalIgnoreCase))
            {
                Log.Warn($"Invalid account password {name}");
                //Logger.Log.ErrorFormat("Invalid Password");
                session.Disconnect();
                return(false);
            }

            PlayerSessionDto sessionDto = _sessionService.GetByAccountName(name);

            if (sessionDto == null || sessionDto.Id != session.SessionId)
            {
                Log.Warn($"No session, hijacking tried by {session.Ip}");
                session.Disconnect();
                return(false);
            }

            if (!string.Equals(sessionDto.Username, accountDto.Name, StringComparison.CurrentCultureIgnoreCase) ||
                !string.Equals(sessionDto.Password, accountDto.Password, StringComparison.CurrentCultureIgnoreCase))
            {
                Log.Warn($"Info mismatch with session {sessionDto.Id}");
                session.Disconnect();
                return(false);
            }

            if (sessionDto.State == PlayerSessionState.Connected)
            {
                Log.Warn($"{sessionDto.State} Already connected !");
                session.Disconnect();
                return(false);
            }

            var accountobject = new AccountDto
            {
                Id        = accountDto.Id,
                Name      = accountDto.Name,
                Password  = accountDto.Password.ToLower(),
                Authority = accountDto.Authority
            };

            session.InitializeAccount(accountobject);
            return(true);
        }
Ejemplo n.º 5
0
        public void RegisterSession(PlayerSessionDto dto)
        {
            if (GetBySessionId(dto.Id) != null)
            {
                _log.Info($"Session {dto.Id} already registered");
                return;
            }

            dto.Id = (int)_client.GetNextSequence();
            _client.Store(dto);
        }
Ejemplo n.º 6
0
        public void UpdateSession(PlayerSessionDto dto)
        {
            PlayerSessionDto session = GetBySessionId(dto.Id);

            if (session == null)
            {
                _log.Info($"Session {dto.Id} not found");
                return;
            }

            session.State         = dto.State;
            session.WorldServerId = dto.WorldServerId;
            _client.Store(session);
        }
Ejemplo n.º 7
0
 private static string ToKey(PlayerSessionDto obj) => ToKey(obj.Id);
Ejemplo n.º 8
0
 public void RegisterSession(PlayerSessionDto dto)
 {
     _cache.AddAsync(ToKey(dto), dto).GetAwaiter().GetResult();
 }
Ejemplo n.º 9
0
 public static void Reset()
 {
     Session = new PlayerSessionDto();
 }
Ejemplo n.º 10
0
        public override void ChannelRead(IChannelHandlerContext context, object message)
        {
            try
            {
                if (!(message is string buff))
                {
                    return;
                }

                string[] packet = buff.Split(' ');
                if (packet.Length <= 4 || packet[0] != "NoS0575")
                {
                    Log.Info($"[{_endPoint.Address.MapToIPv4()}][CONNECT_REQUEST] Wrong packet");
                    SendPacket(GetFailPacket(AuthResponse.CantConnect));
                    Disconnect();
                    return;
                }

                string     accountName  = packet[2];
                string     passwordHash = packet[3];
                AccountDto dto          = AccountService.GetByName(accountName.ToLower());
                if (dto == null)
                {
                    Log.Info($"[{_endPoint.Address.MapToIPv4()}][CONNECT_REQUEST] {accountName} Not found in database");
                    SendPacket(GetFailPacket(AuthResponse.AccountOrPasswordWrong));
                    Disconnect();
                    return;
                }

                if (!string.Equals(dto.Password, passwordHash, StringComparison.CurrentCultureIgnoreCase))
                {
                    Log.Info($"[{_endPoint.Address.MapToIPv4()}][CONNECT_REQUEST] {accountName} Wrong password");
                    SendPacket(GetFailPacket(AuthResponse.AccountOrPasswordWrong));
                    Disconnect();
                    return;
                }

                var response = AuthResponse.Ok;

                if (response != AuthResponse.Ok)
                {
                    Log.Info($"[{_endPoint.Address.MapToIPv4()}][CONNECT_REQUEST] MAINTENANCE MODE");
                    SendPacket(GetFailPacket(AuthResponse.AccountOrPasswordWrong));
                    Disconnect();
                    return;
                }

                PlayerSessionDto session = SessionService.GetByAccountName(accountName);
                if (session != null && session.State == PlayerSessionState.Connected)
                {
                    Log.Info($"[{_endPoint.Address}][CONNECT_REQUEST] {accountName} already connected on World {session.WorldServerId}");
                    SendPacket(GetFailPacket(AuthResponse.AlreadyConnected));
                    Disconnect();
                    return;
                }


                if (session == null)
                {
                    session = new PlayerSessionDto
                    {
                        Password = passwordHash,
                        Username = accountName,
                        State    = PlayerSessionState.Unauthed
                    };
                    SessionService.RegisterSession(session);
                    Log.Info($"[{_endPoint.Address.MapToIPv4()}][CONNECT_ACCEPT] {accountName} waiting for world endpoint");
                }

                IEnumerable <WorldServerDto> test = ServerApi.GetServers();
                SendPacket(GenerateWorldListPacket(accountName, session.Id, test));

                Log.Info($"[{_endPoint.Address.MapToIPv4()}][CONNECT_ACCEPT] Server list sent to {accountName}");
                Disconnect();
            }
            catch (Exception e)
            {
                Log.Error("[PACKET_RECV]", e);
                _channel.WriteAndFlushAsync(GetFailPacket(AuthResponse.CantConnect)).Wait();
                _channel.DisconnectAsync().Wait();
            }
        }