Ejemplo n.º 1
0
        /// <summary>
        /// Returns the authorized user object, or null if the user isn't currently authorized
        /// </summary>
        /// <param name="account"></param>
        /// <returns></returns>
        public static ServerUser GetAuthorizedUser(string account, ServerBase server, PacketLoginRequest.ConnectionType conType)
        {
            ServerUser u = null;

            if (conType == PacketLoginRequest.ConnectionType.AssistedTransfer)
            {
                lock (m_AuthorizedAccountsSyncRoot)
                {
                    AuthorizedAccounts.TryGetValue(account.ToLower(), out u);
                }
            }

            else if (conType == PacketLoginRequest.ConnectionType.UnassistedTransfer)
            {
                Guid     ticket         = Guid.Empty;
                string   authServer     = "";
                DateTime whenAuthd      = DateTime.MinValue;
                int      character      = -1;
                string   targetServerID = "";
                Guid     accountID      = Guid.Empty;
                if (!DB.Instance.User_GetAuthorizationTicket(account, out authServer, out ticket, out whenAuthd, out character, out targetServerID, out accountID) || ticket == Guid.Empty)
                {
                    return(null);
                }

                if (targetServerID != server.ServerUserID)
                {
                    // we weren't authorized to be on this server.
                    Log1.Logger(server.ServerUserID).Error("[" + account + "] attempted unassisted transfer to [" + server.ServerUserID + "], but that user was only authorized to transfer to target server ID [" + targetServerID + "]. Connection denied.");
                    return(null);
                }

                if (whenAuthd + AuthTicketLifetime < DateTime.UtcNow)
                {
                    // ticket expired.
                    Log1.Logger(server.ServerUserID).Error("[" + account + "] attempted unassisted transfer to [" + server.ServerUserID + "], but that user's auth ticket is expired. Connection denied.");
                    return(null);
                }

                // Got a ticket.  Load up the user from the DB.
                u = new ServerUser();

                u.OwningServer = server.ServerUserID;
                u.AuthTicket   = ticket;
                u.ID           = accountID;
                u.AccountName  = account;


                // load the profile
                AccountProfile ap = new AccountProfile(account);
                u.Profile = ap;
                ap.Load(server.RequireAuthentication);

                // load the character
                if (character > -1)
                {
                    string msg = "";
                    u.CurrentCharacter = CharacterUtil.Instance.LoadCharacter(u, character, ref msg);
                    if (u.CurrentCharacter == null)
                    {
                        // Couldn't load character.
                        Log1.Logger(server.ServerUserID).Error("[" + account + "] attempted unassisted transfer with characer [" + character + "], but that character could not be loaded from the DB: [" + msg + "]. Connection denied.");
                        return(null);
                    }
                    u.CurrentCharacter.OwningAccount = u;
                    CharacterCache.CacheCharacter(u.CurrentCharacter, server.ServerUserID);
                }
            }

            AuthorizeUser(u); // gotta call this to activate/renew the auth ticket on this server.
            return(u);
        }