Beispiel #1
0
        public static void OnLoginRequest(LoginClient client, IPacketStream packet)
        {
            if (packet.Length != 52)
            {
                return;
            }

            var authenticationPacket = new AuthenticationPacket(packet);

            var result = Authentication(authenticationPacket.Username, authenticationPacket.Password);

            if (result != AuthenticationResult.SUCCESS)
            {
                LoginPacketFactory.AuthenticationFailed(client, result);
                return;
            }
            var loginServer = DependencyContainer.Instance.Resolve <ILoginServer>();

            using var database = DependencyContainer.Instance.Resolve <IDatabase>();
            DbUser dbUser = database.Users.Get(x => x.Username.Equals(authenticationPacket.Username, StringComparison.OrdinalIgnoreCase));

            if (loginServer.IsClientConnected(dbUser.Id))
            {
                client.Disconnect();
                return;
            }

            dbUser.LastConnectionTime = DateTime.Now;
            database.Users.Update(dbUser);
            database.Complete();

            client.SetClientUserID(dbUser.Id);

            LoginPacketFactory.AuthenticationFailed(client, result, dbUser);
        }
Beispiel #2
0
        private void HandleAuthentication(string username, string password)
        {
            var result = Authentication(username, password);

            if (result != AuthenticationResult.SUCCESS)
            {
                LoginPacketFactory.AuthenticationFailed(_client, result);
                return;
            }

            DbUser dbUser = _database.Users.First(x => x.Username.Equals(username, StringComparison.OrdinalIgnoreCase));

            if (_server.IsClientConnected(dbUser.Id))
            {
                _client.Disconnect();
                return;
            }

            dbUser.LastConnectionTime = DateTime.UtcNow;
            _database.Users.Update(dbUser);
            _database.SaveChanges();

            _client.SetClientUserID(dbUser.Id);

            LoginPacketFactory.AuthenticationSuccess(_client, result, dbUser);
        }
Beispiel #3
0
        private void HandleAuthentication(AuthenticationPacket authenticationPacket)
        {
            var result = Authentication(authenticationPacket.Username, authenticationPacket.Password);

            if (result != AuthenticationResult.SUCCESS)
            {
                LoginPacketFactory.AuthenticationFailed(_client, result);
                return;
            }

            var loginServer = DependencyContainer.Instance.Resolve <ILoginServer>();

            using var database = DependencyContainer.Instance.Resolve <IDatabase>();
            DbUser dbUser = database.Users.First(x => x.Username.Equals(authenticationPacket.Username, StringComparison.OrdinalIgnoreCase));

            if (loginServer.IsClientConnected(dbUser.Id))
            {
                _client.Disconnect();
                return;
            }

            dbUser.LastConnectionTime = DateTime.Now;
            database.Users.Update(dbUser);
            database.SaveChanges();

            _client.SetClientUserID(dbUser.Id);

            LoginPacketFactory.AuthenticationSuccess(_client, result, dbUser);
        }