Exemplo n.º 1
0
Arquivo: KNet.cs Projeto: isaveu/KNet
        private async void LoginUser(Socket socket)
        {
            if (KNet.debug)
            {
                Console.WriteLine("Received connection from {0}", socket.RemoteEndPoint);
            }

            await Task.Run(() =>
            {
                byte[] buffer = new byte[1024];
                int received  = socket.Receive(buffer);

                KNet_Packet packet = KNet.DeserializePacket(buffer, 0, received);
                if (packet.rpcName == KNet.INTERNAL_LOGIN && (activeUsers.Count < maxPlayers || maxPlayers == 0))
                {
                    KNet_User user = new KNet_User(packet.rpcArgs[0] as string, packet.rpcArgs[1] as string,
                                                   DateTime.UtcNow.Ticks, socket);
                    if (KNet.debug)
                    {
                        Console.WriteLine("{0} is logging in with ID {1}", socket.RemoteEndPoint, user.id);
                    }
                    loginQueue.Enqueue(user);
                }
                else
                {
                    socket.Disconnect(false);
                }
            });
        }
Exemplo n.º 2
0
Arquivo: KNet.cs Projeto: isaveu/KNet
        private void HandleLogins()
        {
            while (!isShutdownRequested)
            {
                while (loginQueue.Count == 0)
                {
                    ;
                }

                KNet_User user = loginQueue.Dequeue();
                //Check database for user, send user data; if user not found, refuse them.
                //If login success:
                KNet_Packet packet = new KNet_Packet {
                    rpcName   = KNet.INTERNAL_LOGIN_SUCCESS,
                    rpcArgs   = new object[0], //This will be Account Data in the future
                    rpcTarget = user.id
                };

                if (KNet.debug)
                {
                    Console.WriteLine("{0} has been logged in.", user.username);
                }
                activeUsers.Add(user);
                SendPacket(packet);
            }
        }
Exemplo n.º 3
0
Arquivo: KNet.cs Projeto: isaveu/KNet
 private void SendData(byte[] buffer, KNet_User user)
 {
     try
     {
         user.socket.Send(buffer);
     }
     catch (Exception)
     {
         if (KNet.debug)
         {
             Console.WriteLine("{0} has disconnected.", user.username);
         }
         activeUsers.Remove(user);
     }
 }
Exemplo n.º 4
0
        public void CMD_Login(string username, string passwordHash)
        {
            if (activeUsers.Count >= maxPlayers && maxPlayers > 0)
            {
                KNet_Packet packet = new KNet_Packet
                {
                    rpcName    = "RPC_LoginFailed",
                    rpcArgs    = new object[] { "The Server was full." }, //Reason for failure
                    rpcTarget  = originOfCurrentProcessedPacket,
                    packetID   = DateTime.UtcNow.Ticks,
                    isReliable = true
                };

                SendPacket(packet);
            }

            KNet_User user = new KNet_User(username, passwordHash, originOfCurrentProcessedPacket);

            loginQueue.Enqueue(user);
        }
Exemplo n.º 5
0
        private void HandleLogins()
        {
            while (!isShutdownRequested)
            {
                while (loginQueue.Count == 0)
                {
                    ;
                }

                KNet_User user = loginQueue.Dequeue();
                //Check database for user, send user data; if user not found, refuse them.
                //If login success:
                KNet_Packet packet = new KNet_Packet {
                    rpcName    = "RPC_LoginSuccess",
                    rpcArgs    = new object[0], //This will be Account Data in the future
                    rpcTarget  = user.id,
                    packetID   = DateTime.UtcNow.Ticks,
                    isReliable = true
                };

                SendPacket(packet);
                activeUsers.Add(user);
            }
        }