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); 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); } }
/// <summary> /// Callback for a successful login /// </summary> /// <param name="sender">The GPCMClient that is logged in</param> private void ClientSuccessfulLogin(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.PlayerInfo.PlayerId, out oldC)) { oldC.DisconnectByReason(DisconnectReason.NewLoginDetected); LogWriter.Log.Write(LogLevel.Info, "Login Clash: {0} - {1} - {2}", client.PlayerInfo.PlayerNick, client.PlayerInfo.PlayerId, client.RemoteEndPoint); } // Add current client to the dictionary if (!Clients.TryAdd(client.PlayerInfo.PlayerId, client)) { LogWriter.Log.Write("ERROR: [GPCMClient._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 when a connection had disconnected /// </summary> /// <param name="client">The client object whom is disconnecting</param> private void ClientDisconnected(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.PlayerInfo.PlayerId, out client) && !client.Disposed) { client.DisconnectByReason(DisconnectReason.NormalLogout); } // Add player to database queue PlayerStatusQueue.Enqueue(client); } catch (Exception e) { LogWriter.Log.Write(LogLevel.Error, "An Error occured at [GPCMClient._OnDisconnect] : Generating Exception Log {0}", e.ToString()); } }
/// <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.PlayerInfo.LoginStatus != LoginStatus.Completed && expireTime <= DateTime.Now) { try { client.DisconnectByReason(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); //} }
public static void Switch(GPCMClient client, Dictionary <string, string> recv, GPCMConnectionUpdate OnSuccessfulLogin, GPCMStatusChanged OnStatusChanged) { string command = recv.Keys.First(); try { switch (command) { case "inviteto": InviteToHandler.AddFriends(client, recv); break; case "login": LoginHandler.ProcessLogin(client, recv, OnSuccessfulLogin, OnStatusChanged); break; case "getprofile": GetProfileHandler.SendProfile(client, recv); break; case "addbuddy": AddBuddyHandler.Addfriends(client, recv); break; case "delbuddy": DelBuddyHandler.Handle(client, recv); break; case "updateui": UpdateUiHandler.UpdateUi(client, recv); break; case "updatepro": UpdateProHandler.UpdateUser(client, recv); break; case "registernick": RegisterNickHandler.RegisterNick(client, recv); break; case "logout": client.DisconnectByReason(DisconnectReason.NormalLogout); break; case "status": StatusHandler.UpdateStatus(client, recv, OnStatusChanged); break; case "newuser": NewUserHandler.NewUser(client, recv); break; case "ka": KAHandler.SendKeepAlive(client); break; default: LogWriter.Log.Write("[GPCM] received unknown data " + command, LogLevel.Debug); GameSpyUtils.SendGPError(client, GPErrorCode.General, "An invalid request was sended."); break; } } catch (Exception e) { LogWriter.Log.WriteException(e); } }