Ejemplo n.º 1
0
        public static CharacterInfo GetCharacterInfo(SqlDatabaseClient MySqlClient, uint CharacterId, uint LinkedClientId, bool IgnoreCache)
        {
            if (SessionManager.ContainsCharacterId(CharacterId))
            {
                Session Session = SessionManager.GetSessionByCharacterId(CharacterId);
                return Session.CharacterInfo;
            }

            if (!IgnoreCache)
            {
                CharacterInfo CachedInfo = TryGetInfoFromCache(CharacterId);

                if (CachedInfo != null)
                {
                    return CachedInfo;
                }
            }

            MySqlClient.SetParameter("id", CharacterId);
            DataRow Row = MySqlClient.ExecuteQueryRow("SELECT * FROM characters WHERE id = @id LIMIT 1");

            if (Row != null)
            {
                return GenerateCharacterInfoFromRow(MySqlClient, LinkedClientId, Row);
            }

            return null;
        }
Ejemplo n.º 2
0
        public static bool FriendshipExists(SqlDatabaseClient MySqlClient, uint UserId1, uint UserId2, bool ConfirmedOnly)
        {
            MySqlClient.SetParameter("user1", UserId1);
            MySqlClient.SetParameter("user2", UserId2);
            MySqlClient.SetParameter("confirmed", (ConfirmedOnly ? 0 : 2));

            return (MySqlClient.ExecuteQueryRow("SELECT null FROM messenger_friendships WHERE user_1_id = @user1 AND user_2_id = @user2 AND confirmed != @confirmed OR user_2_id = @user1 AND user_1_id = @user2 AND confirmed != @confirmed LIMIT 1") != null);
        }
Ejemplo n.º 3
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++;
                    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 || ModerationBanManager.IsUserIdBlacklisted(UserId))
                {
                    mFailedLoginCount++;
                    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 + ".");

                mSuccessfulLoginCount++;
                return UserId;
            }
        }