/// <summary>
        /// Handles a newly created IonTcpConnection and performs some checks, before adding it to the connection collection and starting the client session.
        /// </summary>
        /// <param name="connection">The IonTcpConnection instance representing the new connection to handle.</param>
        public void HandleNewConnection(IonTcpConnection connection)
        {
            // INFO: client ID = connection ID, client ID = session ID
            // Add connection to collection
            mConnections.Add(connection.ID, connection);

            // Create session for new client
            AleedaEnvironment.GetHabboHotel().GetClients().StartClient(connection.ID);
        }
        public bool TestConnection(uint clientID)
        {
            IonTcpConnection connection = GetConnection(clientID);

            if (connection != null)
            {
                return(connection.TestConnection()); // Try to send data
            }
            return(false);                           // Connection not here!
        }
        public void DropConnection(uint clientID)
        {
            IonTcpConnection connection = GetConnection(clientID);

            if (connection != null)
            {
                //AleedaEnvironment.GetLog().WriteInformation("Dropped IonTcpConnection [" + clientID + "] of " + connection.ipAddress);

                connection.Stop();
                mConnections.Remove(clientID);
            }
        }
Beispiel #4
0
        /// <summary>
        /// Creates an IonTcpConnection instance for a given socket and assigns it an unique ID.
        /// </summary>
        /// <param name="pSocket">The System.Net.Socket.Sockets object to base the connection on.</param>
        /// <returns>IonTcpConnection</returns>
        public IonTcpConnection CreateConnection(Socket pSocket)
        {
            if (pSocket == null)
            {
                return(null);
            }

            IonTcpConnection connection = new IonTcpConnection(++mConnectionCounter, pSocket);

            //AleedaEnvironment.GetLog().WriteInformation(string.Format("Created IonTcpConnection [{0}] for {1}.", connection.ID, connection.ipAddress));

            return(connection);
        }
        /// <summary>
        /// Invoked when the listener asynchronously accepts a new connection request.
        /// </summary>
        /// <param name="iAr">The IAsyncResult object holding the results of the asynchronous BeginAcceptSocket operation.</param>
        private void ConnectionRequest(IAsyncResult iAr)
        {
            try
            {
                Socket pSocket = mListener.EndAcceptSocket(iAr);
                // TODO: IP blacklist

                IonTcpConnection connection = mFactory.CreateConnection(pSocket);
                if (connection != null)
                {
                    mManager.HandleNewConnection(connection);
                }
            }
            catch { } // TODO: handle exceptions
            finally
            {
                if (mIsListening)
                {
                    WaitForNextConnection(); // Re-start the process for next connection
                }
            }
        }