Gamespy Client Manager This class is used to proccess the client login process, create new user accounts, and fetch profile information gpcm.gamespy.com
Inheritance: IDisposable
Exemplo n.º 1
0
        /// <summary>
        /// When a new connection is established, we the parent class are responsible
        /// for handling the processing
        /// </summary>
        /// <param name="Stream">A GamespyTcpStream object that wraps the I/O AsyncEventArgs and socket</param>
        protected override void ProcessAccept(GamespyTcpStream Stream)
        {
            // Get our connection id
            int        ConID = Interlocked.Increment(ref ConnectionCounter);
            GpcmClient client;

            try
            {
                // Create a new GpcmClient, passing the IO object for the TcpClientStream
                client = new GpcmClient(Stream, ConID);
                Processing.TryAdd(ConID, client);

                // Begin the asynchronous login process
                client.SendServerChallenge();
            }
            catch (Exception e)
            {
                // Log the error
                L.LogError("WARNING: An Error occured at [GpcmServer.ProcessAccept] : Generating Exception Log");
                ExceptionHandler.GenerateExceptionLog(e);

                // Remove pending connection
                Processing.TryRemove(ConID, out client);

                // Release this stream so it can be used again
                base.Release(Stream);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Callback for a successful login
        /// </summary>
        /// <param name="sender">The GpcmClient that is logged in</param>
        private void GpcmClient_OnSuccessfulLogin(object sender)
        {
            // Wrap this in a try/catch
            try
            {
                GpcmClient oldC;
                GpcmClient client = sender as GpcmClient;

                // Check to see if the client is already logged in, if so disconnect the old user
                if (Clients.TryRemove(client.PlayerId, out oldC))
                {
                    oldC.Disconnect(1);
                    return;
                }

                // Remove connection from processing
                Processing.TryRemove(client.ConnectionId, out oldC);

                // Add current client to the dictionary
                if (!Clients.TryAdd(client.PlayerId, client))
                {
                    L.LogError("ERROR: [GpcmServer._OnSuccessfulLogin] Unable to add client to HashSet.");
                    return;
                }

                // Fire event
                OnClientsUpdate(this, EventArgs.Empty);
            }
            catch (Exception E)
            {
                L.LogError("ERROR: [GpcmServer._OnSuccessfulLogin] Exception was thrown, Generating exception log.");
                ExceptionHandler.GenerateExceptionLog(E);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Checks the timeout on a client connection. This method is used to detect hanging connections, and
        /// forcefully disconnects them.
        /// </summary>
        /// <param name="client"></param>
        protected void CheckTimeout(GpcmClient client)
        {
            // Setup vars
            DateTime   expireTime = client.Created.AddSeconds(Timeout);
            GpcmClient oldC;

            // Remove all processing connections that are hanging
            if (client.Status != LoginStatus.Completed && expireTime <= DateTime.Now)
            {
                try
                {
                    client.Disconnect(1);
                    Processing.TryRemove(client.ConnectionId, out oldC);
                }
                catch (Exception ex)
                {
                    // Log the error
                    L.LogError("NOTICE: [GpcmServer.CheckTimeout] Error removing client from processing queue. Generating Excpetion Log");
                    ExceptionHandler.GenerateExceptionLog(ex);
                }
            }
            else if (client.Status == LoginStatus.Completed)
            {
                Processing.TryRemove(client.ConnectionId, out oldC);
            }
        }
Exemplo n.º 4
0
        public override bool Equals(object Obj)
        {
            if (Obj is GpcmClient)
            {
                GpcmClient Compare = Obj as GpcmClient;
                return(Compare.PlayerId == this.PlayerId || Compare.PlayerNick == this.PlayerNick);
            }

            return(false);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Callback for when a connection had disconnected
        /// </summary>
        /// <param name="client">The client object whom is disconnecting</param>
        private void GpcmClient_OnDisconnect(GpcmClient client)
        {
            // Remove client, and call OnUpdate Event
            try
            {
                // Remove client from online list
                if (Clients.TryRemove(client.PlayerId, out client) && !client.Disposed)
                {
                    client.Dispose();
                }

                // Call Event
                OnClientsUpdate(this, EventArgs.Empty);
            }
            catch (Exception e)
            {
                L.LogError("An Error occured at [GpcmServer.GpcmClient_OnDisconnect] : Generating Exception Log");
                ExceptionHandler.GenerateExceptionLog(e);
            }
        }
Exemplo n.º 6
0
 /// <summary>
 /// Callback for when a connection had disconnected
 /// </summary>
 /// <param name="client">The client object whom is disconnecting</param>
 private void GpcmClient_OnDisconnect(GpcmClient client)
 {
     // Remove client, and call OnUpdate Event
     Clients.Remove(client);
     OnClientsUpdate(this, new ClientList(Clients));
 }
Exemplo n.º 7
0
        /// <summary>
        /// Callback for when a connection had disconnected
        /// </summary>
        /// <param name="client">The client object whom is disconnecting</param>
        private void GpcmClient_OnDisconnect(GpcmClient client)
        {
            // Remove client, and call OnUpdate Event
            try
            {
                // Remove client from online list
                if (Clients.TryRemove(client.PlayerId, out client) && !client.Disposed)
                    client.Dispose();

                // Call Event
                OnClientsUpdate(this, EventArgs.Empty);
            }
            catch (Exception e)
            {
                Program.ErrorLog.Write("An Error occured at [GpcmServer.GpcmClient_OnDisconnect] : Generating Exception Log");
                ExceptionHandler.GenerateExceptionLog(e);
            }
        }
Exemplo n.º 8
0
        /// <summary>
        /// Checks the timeout on a client connection. This method is used to detect hanging connections, and
        /// forcefully disconnects them.
        /// </summary>
        /// <param name="client"></param>
        protected void CheckTimeout(GpcmClient client)
        {
            // Setup vars
            DateTime expireTime = client.Created.AddSeconds(Timeout);
            GpcmClient oldC;

            // Remove all processing connections that are hanging
            if (client.Status != LoginStatus.Completed && expireTime <= DateTime.Now)
            {
                try
                {
                    client.Disconnect(1);
                    Processing.TryRemove(client.ConnectionId, out oldC);
                }
                catch (Exception ex)
                {
                    // Log the error
                    Program.ErrorLog.Write(
                        "NOTICE: [GpcmServer.CheckTimeout] Error removing client from processing queue. Generating Excpetion Log"
                    );
                    ExceptionHandler.GenerateExceptionLog(ex);
                }
            }
            else if (client.Status == LoginStatus.Completed)
            {
                Processing.TryRemove(client.ConnectionId, out oldC);
            }
        }
Exemplo n.º 9
0
        /// <summary>
        /// When a new connection is established, we the parent class are responsible
        /// for handling the processing
        /// </summary>
        /// <param name="Stream">A GamespyTcpStream object that wraps the I/O AsyncEventArgs and socket</param>
        protected override void ProcessAccept(GamespyTcpStream Stream)
        {
            // Get our connection id
            int ConID = Interlocked.Increment(ref ConnectionCounter);
            GpcmClient client;

            try
            {
                // Create a new GpcmClient, passing the IO object for the TcpClientStream
                client = new GpcmClient(Stream, ConID);
                Processing.TryAdd(ConID, client);

                // Begin the asynchronous login process
                client.SendServerChallenge();
            }
            catch (Exception e)
            {
                // Log the error
                Program.ErrorLog.Write("WARNING: An Error occured at [GpcmServer.ProcessAccept] : Generating Exception Log");
                ExceptionHandler.GenerateExceptionLog(e);

                // Remove pending connection
                Processing.TryRemove(ConID, out client);

                // Release this stream so it can be used again
                base.Release(Stream);
            }
        }