Пример #1
0
        /// <summary>
        /// Adds the user's account to the authorized users list.  This method should also disconnect any previous sockets that might be connected using the same account
        /// </summary>
        /// <param name="client"></param>
        /// <param name="persist">Determines if the ticket should be persisted in the datastore.  Normally, you only need to do this when you are about to transfer control of the player to another server in the Hive.</param>
        /// <returns></returns>
        public static bool AuthorizeUser(ServerUser client, bool persist)
        {
            if (client == null)
            {
                return(false);
            }

            lock (m_AuthorizedAccountsSyncRoot)
            {
                if (client.MyConnection != null && client.MyConnection.IsAlive)
                {
                    client.Profile.SetLoggedIn(client.MyConnection.RemoteEndPoint.AddressFamily.ToString(), client.MyConnection.RemoteEndPoint.ToString());
                }
                ServerUser existing = null;
                if (AuthorizedAccounts.TryGetValue(client.AccountName.ToLower(), out existing))
                {
                    UnAuthorizeUser(existing);
                    if (existing.MyConnection != null)
                    {
                        existing.MyConnection.KillConnection("Logging in from another client.");
                    }
                }

                Log1.Logger("Server.Login").Debug("Authorizing *" + client.AccountName.ToLower() + "*");
                AuthorizedAccounts.Add(client.AccountName.ToLower(), client);
                AuthorizedAccounts.Associate(client.ID, client.AccountName.ToLower());
                client.RenewAuthorizationTicket(persist);
            }
            return(true);
        }
Пример #2
0
        public override bool OnBeforePacketProcessed(Packet p)
        {
            // if the base class doesn't think we should process the packet, then we don't think so either.
            if (!base.OnBeforePacketProcessed(p)) // check for duplicate requests and send ACK if requested
            {
                return(false);
            }

            // Check for authorization.  The only packet types that do not require authorization are ServerGreeting, RijndaelExchange, LineSecured, LoginRequest/Result, Null and Reply
            // these are defined as -1000 to -994.
            if (p.PacketTypeID < -1000 || p.PacketTypeID > -994 && !ServerUser.IsAuthorizedClusterServer)
            {
                if (ServerUser.AuthorizationExpires < DateTime.UtcNow)
                {
                    PacketReply rep = CreateStandardReply(p, ReplyType.AuthorizationTicketExpired, "Not authorized.");
                    p.NeedsReply  = true;
                    p.ReplyPacket = rep;
                    Send(rep);
                    KillConnection("Authorization expired.");
                    return(false); // prevent calling handler for this packet, since we're not authorized
                }
                else
                {
                    ServerUser.RenewAuthorizationTicket();
                }
            }

            if (p.PacketTypeID != (int)PacketType.ACK && p.PacketTypeID != (int)PacketType.NATInfo)
            {
                m_TimeoutTimer.Stop();
            }
            return(true);
        }