Exemplo n.º 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);
        }
Exemplo n.º 2
0
        public void TestSerde()
        {
            var a = new AuthenticationPacket("hello");
            var b = SerializeAndDeserialize(a);

            Assert.Equal(a, b);
        }
Exemplo n.º 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);
        }
Exemplo n.º 4
0
        private void HandleAuthentication(AuthenticationPacket authenticationPacket)
        {
            var result = Authentication(authenticationPacket.Username, authenticationPacket.Password);

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

            DbUser dbUser = _database.Users.First(x => x.Username.Equals(authenticationPacket.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);
        }
Exemplo n.º 5
0
        public async Task <int> Authentication(string uuid)
        {
            var send = new AuthenticationPacket(uuid);
            var recv = await conn.SendRecv <AuthenticationPacket, AuthenticationResultPacket>(send);

            return(recv.ResultCode);
        }
Exemplo n.º 6
0
        private static void Authenticator_AuthenticationSuccess(TcpClient client, AuthenticationPacket packet)
        {
            Console.WriteLine("authentication ok, adding player to the matchmaker...");
            Console.WriteLine("client responded: " + packet.response);

            var name = packet.response.Substring(packet.response.IndexOf(":") + 1).Trim();
            var guid = Guid.Parse(packet.guid);

            matchmaker.Add(new Client(client, name, guid));
        }
Exemplo n.º 7
0
        /// <inheritdoc/>
        public override void HandleMessageContents(NetworkMessage message, Connection connection)
        {
            if (connection == null)
            {
                throw new System.ArgumentNullException(nameof(connection));
            }

            var authPacket = new AuthenticationPacket(message);

            var result = authPacket.Password.Equals(ServiceConfiguration.GetConfiguration().QueryManagerPassword);

            connection.IsAuthenticated = result;

            ResponsePackets.Add(new AuthenticationResultPacket {
                HadError = !result
            });
        }
Exemplo n.º 8
0
        async void HandleAuthentication(Session session, AuthenticationPacket packet)
        {
            var option = await conn.GetUser(packet.Uuid);

            option.MatchSome(user =>
            {
                session.UserID = user.ID;
                log.Info($"authentication: uuid={packet.Uuid} user_id={session.UserID}");
                var result = new AuthenticationResultPacket(0);
                session.SendLazy(result);
            });
            option.MatchNone(() =>
            {
                log.Info($"authentication: uuid={packet.Uuid} not found");
                var notFound = new AuthenticationResultPacket(-1);
                session.SendLazy(notFound);
            });
        }
Exemplo n.º 9
0
        public void Authenticate(TcpClient client)
        {
            var guid   = Guid.NewGuid();
            var packet = new AuthenticationPacket(Configuration.Version, DateTime.Now.ToString(), guid.ToString());

            var buffer = PacketSerializer.Serialize(packet);

            client.Client.BeginSend(buffer,
                                    0,
                                    buffer.Length,
                                    SocketFlags.None,
                                    BeginSendCallback,
                                    new AuthenticationState()
            {
                client = client,
                buffer = new byte[4096],
                auth   = packet,
                guid   = guid
            });
        }
Exemplo n.º 10
0
 private void HandleLoginRequest(AuthenticationPacket authenticationPacket)
 {
     HandleAuthentication(authenticationPacket.Username, authenticationPacket.Password);
 }
Exemplo n.º 11
0
 public async Task Handle(LoginClient sender, AuthenticationPacket packet)
 {
     await HandleAuthentication(sender, packet.Username, packet.Password);
 }
Exemplo n.º 12
0
        private void Start()
        {
            var conn = ConnectionManager.Instance;

            genUUIDButton.OnClickAsObservable().Subscribe(_ =>
            {
                // 같은 클라에서 같은 uuid 생성되는게 싫을떄
                // 같은 컴퓨터에서 실행할 경우
                var uuid       = Guid.NewGuid();
                uuidField.text = uuid.ToString();
            }).AddTo(this);

            ConnectionManager.Instance.ReadyObservable.ObserveOnMainThread().Subscribe(_ =>
            {
                joinPlayerButton.interactable   = true;
                joinObserverButton.interactable = true;
            }).AddTo(this);

            joinPlayerButton.OnClickAsObservable().Subscribe(_ =>
            {
                OnJoinButtonClicked(PlayerMode.Player);
            }).AddTo(this);

            joinObserverButton.OnClickAsObservable().Subscribe(_ =>
            {
                OnJoinButtonClicked(PlayerMode.Observer);
            }).AddTo(this);

            conn.Welcome.Received.ObserveOnMainThread().Subscribe(p =>
            {
                var info      = ConnectionInfo.Info;
                info.PlayerID = p.UserID;
            });

            conn.SignUp.Received.ObserveOnMainThread().Subscribe(p =>
            {
                Debug.Log($"sign up result: {p.ResultCode}");

                var auth = new AuthenticationPacket(UUID);
                conn.SendImmediate(auth);
            }).AddTo(this);

            conn.Authentication.Received.ObserveOnMainThread().Subscribe(p =>
            {
                Debug.Log($"authentication result: {p.ResultCode}");

                if (p.ResultCode == 0)
                {
                    Debug.Assert(mode != PlayerMode.None);

                    var info        = ConnectionInfo.Info;
                    info.WorldID    = WorldID;
                    info.Nickname   = Nickname;
                    info.PlayerMode = mode;

                    var join = new WorldJoinPacket(WorldID, Nickname, mode);
                    conn.SendImmediate(join);
                }
            }).AddTo(this);

            conn.WorldJoin.Received.ObserveOnMainThread().Subscribe(p =>
            {
                Debug.Log($"player id={p.PlayerID}");
                if (p.ResultCode != 0)
                {
                    var info      = ConnectionInfo.Info;
                    info.WorldID  = "";
                    info.Nickname = "";
                }


                // TOOD async scene loading
                SceneManager.LoadScene("Game", LoadSceneMode.Single);
            }).AddTo(this);
        }