Пример #1
0
        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);
                }
            });
        }
Пример #2
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   = 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);
            }
        }
Пример #3
0
 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);
     }
 }
Пример #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);
        }
Пример #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);
            }
        }