示例#1
0
        /// <summary>
        ///   Stops the Connection, disconnects the socket and disposes used resources.
        /// </summary>
        internal void Stop()
        {
            if (!IsAlive())
                return; // Already stopped

            if (Habbo.IsLoggedIn())
            {
                Habbo.SetLoggedIn(false);
                CoreManager.ServerCore.GetStandardOut().PrintNotice("Connection stopped [" + GetIPAddressString() +
                                                                    ", " + Habbo.GetUsername() + ']');
            }
            else
            {
                CoreManager.ServerCore.GetStandardOut().PrintNotice("Connection stopped [" + GetIPAddressString() +
                                                                    ", UNKNOWN]");
            }
            try
            {
                _socket.Close();
            }
            catch (NullReferenceException)
            {
                throw;
            }
            _socket = null;
            _dataBuffer = null;
            _dataReceivedCallback = null;
        }
        private static void ProcessSSOTicket(Habbo sender, IncomingMessage message)
        {
            Habbo loggedInHabbo = CoreManager.ServerCore.GetHabboDistributor().GetHabbo(
                message.PopPrefixedString(), sender.GetConnection().GetIPAddressRaw());

            if (loggedInHabbo == null)
            {
                new MConnectionClosed
                {
                    Reason = ConnectionClosedReason.InvalidSSOTicket
                }.Send(sender);

                // TODO: Is delay needed?

                sender.GetConnection().Disconnect(); // Invalid SSO Ticket
            }
            else
            {
                // If this Habbo is already connected...
                if (loggedInHabbo.IsLoggedIn())
                {
                    // Disconnect them.
                    new MConnectionClosed
                    {
                        Reason = ConnectionClosedReason.ConcurrentLogin
                    }.Send(loggedInHabbo);
                    loggedInHabbo.GetConnection().Disconnect();
                }
                loggedInHabbo.LoginMerge(sender);
                sender = loggedInHabbo;
                sender.SetLoggedIn(true);
            }
        }