/// <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); } }
/// <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)) { Program.ErrorLog.Write("ERROR: [GpcmServer._OnSuccessfulLogin] Unable to add client to HashSet."); return; } } catch (Exception E) { Program.ErrorLog.Write("ERROR: [GpcmServer._OnSuccessfulLogin] Exception was thrown, Generating exception log."); ExceptionHandler.GenerateExceptionLog(E); } }
/// <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 long 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); } }
/// <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); ServerManager.Log("Login Clash: {0} - {1} - {2}", client.PlayerNick, client.PlayerId, client.RemoteEndPoint); } // Add current client to the dictionary if (!Clients.TryAdd(client.PlayerId, client)) { Program.ErrorLog.Write("ERROR: [GpcmServer._OnSuccessfulLogin] Unable to add client to HashSet."); } // Add player to database queue var status = new PlayerStatusUpdate(client, LoginStatus.Completed); PlayerStatusQueue.Enqueue(status); } catch (Exception E) { Program.ErrorLog.Write("ERROR: [GpcmServer._OnSuccessfulLogin] Exception was thrown, Generating exception log."); ExceptionHandler.GenerateExceptionLog(E); } }
/// <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 var status = new PlayerStatusUpdate(client, LoginStatus.Disconnected); PlayerStatusQueue.Enqueue(status); } catch (Exception e) { Program.ErrorLog.Write("An Error occured at [GpcmServer._OnDisconnect] : Generating Exception Log"); ExceptionHandler.GenerateExceptionLog(e); } }
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); }
/// <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(); } } catch (Exception e) { Program.ErrorLog.Write("An Error occured at [GpcmServer._OnDisconnect] : Generating Exception Log"); ExceptionHandler.GenerateExceptionLog(e); } }