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