Exemple #1
0
 public static void VersionInfo(LoginClient pClient, Packet pPacket)
 {
     ushort year;
     ushort version;
     if (!pPacket.TryReadUShort(out year) ||
         !pPacket.TryReadUShort(out version))
     {
         Log.WriteLine(LogLevel.Warn, "Invalid client version.");
         pClient.Disconnect();
         return;
     }
     Log.WriteLine(LogLevel.Debug, "Client version {0}:{1}.", year, version);
     using (Packet response = new Packet(SH3Type.VersionAllowed))
     {
         response.WriteShort(1);
         pClient.SendPacket(response);
     }
 }
Exemple #2
0
        public static void Login(LoginClient pClient, Packet pPacket)
        {
            string hash;
            string username;

            if (!pPacket.TryReadString(out username, 32) ||
                !pPacket.TryReadString(out hash, 32))
            {
                Log.WriteLine(LogLevel.Warn, "Could not read user token.");
                SendFailedLogin(pClient, ServerError.EXCEPTION);
                return;
            }

            Log.WriteLine(LogLevel.Debug, "{0} tries to login.", username);

            User user;
            if (Program.Entity.Users.Count() > 0 && (user = Program.Entity.Users.First(u => u.Username == username)) != null)
            {
                if (user.Password.ToLower() == hash.ToLower())
                {
                    if (ClientManager.Instance.IsLoggedIn(user.Username))
                    {
                        Log.WriteLine(LogLevel.Warn, "{0} is trying dual login. Disconnecting.", user.Username);
                        pClient.Disconnect();
                    }
                    else if (user.Banned)
                    {
                        SendFailedLogin(pClient, ServerError.BLOCKED);
                    }
                    else
                    {
                        pClient.IsAuthenticated = true;
                        pClient.Username = user.Username;
                        pClient.AccountID = user.ID;
                        pClient.Admin = user.Admin;
                        AllowFiles(pClient, true);
                        WorldList(pClient, false);
                    }
                }
                else SendFailedLogin(pClient, ServerError.INVALID_CREDENTIALS);
            }
            else SendFailedLogin(pClient, ServerError.INVALID_CREDENTIALS);
        }