Exemplo n.º 1
0
        protected override void ProcessAccept(TCPStream Stream)
        {
            // Get our connection id
            long       connId = Interlocked.Increment(ref ConnectionCounter);
            GPCMClient client;

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

                // Begin the asynchronous login process
                client.SendServerChallenge(1);
            }
            catch (Exception e)
            {
                // Log the error
                LogWriter.Log.WriteException(e);

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

                // Release this stream so it can be used again
                Release(Stream);
            }
        }
Exemplo n.º 2
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)
        {
            // If we are exiting, don't do anything here.
            if (Exiting)
            {
                return;
            }

            // Remove client, and call OnUpdate Event
            try
            {
                // Remove client from online list
                if (Clients.TryRemove(client.PlayerId, out client) && !client.Disposed)
                {
                    client.Dispose();
                }

                // Add player to database queue
                PlayerStatusQueue.Enqueue(client);
            }
            catch (Exception e)
            {
                LogWriter.Log.Write("An Error occured at [GpcmServer._OnDisconnect] : Generating Exception Log {0}", LogLevel.Error, e.ToString());
            }
        }
Exemplo n.º 3
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;

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

                // 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(DisconnectReason.NewLoginDetected);
                    LogWriter.Log.Write("Login Clash:   {0} - {1} - {2}", LogLevel.Information, client.PlayerNick, client.PlayerId, client.RemoteEndPoint);
                }

                // Add current client to the dictionary
                if (!Clients.TryAdd(client.PlayerId, client))
                {
                    LogWriter.Log.Write("ERROR: [GpcmServer._OnSuccessfulLogin] Unable to add client to HashSet.", LogLevel.Error);
                }

                // Add player to database queue
                PlayerStatusQueue.Enqueue(client);
            }
            catch (Exception E)
            {
                LogWriter.Log.WriteException(E);
            }
        }
Exemplo n.º 4
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.LoginStatus != LoginStatus.Completed && expireTime <= DateTime.Now)
            {
                try
                {
                    client.Disconnect(DisconnectReason.LoginTimedOut);
                    Processing.TryRemove(client.ConnectionId, out oldC);
                }
                catch (Exception e)
                {
                    LogWriter.Log.WriteException(e);
                }
            }
            //else if (client.Status == LoginStatus.Completed)
            //{
            //Processing.TryRemove(client.ConnectionId, out oldC);
            //}
        }