Beispiel #1
0
 public void TryAuthenticate(string Username, string Password, string RemoteAddress, bool Register = false)
 {
     using (SqlDatabaseClient client = SqlDatabaseManager.GetClient())
     {
         uint characterId = UserCredentialsAuthenticator.TryAuthenticate(client, Username, Password, RemoteAddress);
         if (characterId == 0)
         {
             this.SendData(AuthenticationKoComposer.Compose(false), false);
         }
         else
         {
             BoomBang.Game.Characters.CharacterInfo info = CharacterInfoLoader.GetCharacterInfo(client, characterId, this.uint_0, true);
             if (ModerationBanManager.IsUserIdBlacklisted(info.UInt32_0))
             {
                 this.SendData(ModerationBanComposer.Compose(ModerationBanManager.GetBanDetails(info.UInt32_0)), false);
                 SessionManager.StopSession(this.uint_0);
             }
             else if ((info != null) && info.HasLinkedSession)
             {
                 this.characterInfo_0 = info;
                 this.characterInfo_0.TimestampLastOnline = UnixTimestamp.GetCurrent();
                 CharacterResolverCache.AddToCache(this.characterInfo_0.UInt32_0, this.characterInfo_0.Username, true);
                 this.sessionLaptopFriendCache_0 = new SessionLaptopFriendCache(client, this.CharacterId);
                 this.userIgnoreCache_0          = new UserIgnoreCache(client, this.CharacterId);
                 this.bool_1 = true;
                 if (Register)
                 {
                     this.SendData(RegisterComposer.Compose(this.characterInfo_0), false);
                 }
                 else
                 {
                     this.SendData(AuthenticationOkComposer.Compose(this.characterInfo_0), false);
                 }
                 LaptopHandler.MarkUpdateNeeded(this, 0, true);
             }
             else
             {
                 SessionManager.StopSession(this.uint_0);
             }
         }
     }
 }
        /// <summary>
        /// Attemps to authenticate an user using an SSO (Single Sign On) ticket.
        /// </summary>
        /// <param name="Ticket">The ticket string.</param>
        /// <returns>Character id on success, 0 on authentication failure.</returns>
        public static uint TryAuthenticate(SqlDatabaseClient MySqlClient, string Ticket, string RemoteAddress)
        {
            lock (mAuthSyncRoot)
            {
                // Remove any spacing from single sign on ticket
                Ticket = Ticket.Trim();

                // Ensure the ticket meets the minimum length requirement
                if (Ticket.Length <= 5)
                {
                    mFailedLoginCount++;
                    Output.WriteLine("Login from " + RemoteAddress + " rejected: SSO ticket too short.");
                    return(0);
                }

                // Debug
                string DebugTicket = (string)ConfigManager.GetValue("debug.sso");
                if (DebugTicket.Length > 0 && Ticket == DebugTicket)
                {
                    return(1);
                }

                // Check the database for a matching single sign on ticket
                uint   UserId  = 0;
                string LogName = string.Empty;

                MySqlClient.SetParameter("ticket", Ticket);
                DataRow Row = MySqlClient.ExecuteQueryRow("SELECT id,username FROM characters WHERE auth_ticket = @ticket LIMIT 1");

                if (Row != null)
                {
                    UserId  = (uint)Row["id"];
                    LogName = (string)Row["username"];

                    RemoveTicket(MySqlClient, (uint)Row["id"], RemoteAddress);
                }

                // Check if ticket was OK + Check for user id bans
                if (UserId <= 0)
                {
                    mFailedLoginCount++;
                    Output.WriteLine("Login from " + RemoteAddress + " rejected: invalid SSO ticket.");
                    return(0);
                }

                if (ModerationBanManager.IsUserIdBlacklisted(UserId))
                {
                    mFailedLoginCount++;
                    Output.WriteLine("Login from " + RemoteAddress + " rejected: blacklisted IP address.");
                    return(0);
                }

                // Disconnect any previous sessions for this account
                if (SessionManager.ContainsCharacterId(UserId))
                {
                    Session TargetSession = SessionManager.GetSessionByCharacterId(UserId);
                    SessionManager.StopSession(TargetSession.Id);
                }

                // Mark as a successful login and continue

                Output.WriteLine("User " + LogName + " (ID " + UserId + ") has logged in from " + RemoteAddress + ".");
                MySqlClient.ExecuteNonQuery("UPDATE characters SET online = '1' WHERE id = " + UserId + " LIMIT 1");
                mSuccessfulLoginCount++;
                return(UserId);
            }
        }