Beispiel #1
0
    //////////////////////////////////////////////////////////////////////////////////
    //////////////////////////////////////////////////////////////////////////////////
    //////////////////////////////////////////////////////////////////////////////////
    void TestConnections(object me)
    {
        try
        {
            if (m_Listener == null)
            {
                ThreadPool.QueueUserWorkItem(new WaitCallback(Listen));
            }

            lock (m_ServerSessions)
            {
                for (int i = 0; i < m_ServerSessions.Count; i++)
                {
                    ServerSession sess = (ServerSession)m_ServerSessions[i];
                    if (!sess.IsConnected())
                    {
                        sess.Close();
                        m_ServerSessions.RemoveAt(i--);
                    }
                }
            }
        }
        catch (Exception ex)
        {
            m_Logger.Push(LogLevel.ERROR, 0, "Error: " + ex.ToString());
        }
    }
Beispiel #2
0
        /// <summary>
        /// Called whenever an onConnect event is received by the server.
        /// </summary>
        /// <param name="session">The session instance</param>
        private void OnConnect(ServerSession session)
        {
            // The list of allowed host
            const string host = "127.0.0.1";

            // If the host matches
            bool matches = session.GetRemoteAdress() == host;

            if (!matches)
            {
                Logger.Error("Connection denied from address: {0}. Not whitelisted!", session.GetRemoteAdress());
                session.Close();
                return;
            }

            // If the host does match
            Logger.Info("Accepted connection from address: {0}", session.GetRemoteAdress());
        }
        /// <summary>
        /// Handles a terminated connection packet
        /// </summary>
        /// <param name="session">The session instance</param>
        /// <param name="length">The length of the packet</param>
        /// <param name="opcode">The opcode of the incoming packet</param>
        /// <param name="data">The packet data</param>
        /// <returns></returns>
        public override bool Handle(ServerSession session, int length, int opcode, byte[] data)
        {
            var identityKeys = session.GetIdentityKeys();

            var dbClient = LoginService.GetDbClient();

            var bldr = new PacketBuilder(Common.Database.Opcodes.DELETE_SESSION);

            bldr.WriteBytes(identityKeys);

            dbClient.Write(bldr.ToPacket());

            byte[] emptyKeys = new byte[16];

            session.SetIdentityKeys(emptyKeys);

            session.Close();

            return(false);
        }
        public void VerifyExplicitClose()
        {
            Mock<INetworkFacade> mockFacade = new Mock<INetworkFacade>();

            mockFacade.Setup( m => m.BeginClose( It.IsAny<Action<bool, INetworkFacade>>() ) )
                .Callback<Action<bool, INetworkFacade>>( callback => callback( true, mockFacade.Object ) );

            ServerSession session = new ServerSession();

            session.Start( mockFacade.Object );

            session.Close();

            Assert.That( session.HasClosed );

            mockFacade.Verify( m => m.BeginClose( It.IsAny<Action<bool, INetworkFacade>>() ), Times.Once() );
        }