/// <summary> /// This when a cross-server ping response is received. Its purpose is /// to compute the channel latency and send a message to that effect to /// the requesting player. /// </summary> /// <param name="SourceServerId">Supplies the server id of the server /// that completed the ping request.</param> /// <param name="Arguments">Supplies the serialized state arguments /// string.</param> /// <param name="Script">Supplies the current script object.</param> /// <returns>TRUE on success, else FALSE on failure.</returns> public static int HandleServerPingResponse(int SourceServerId, string Arguments, ACR_ServerCommunicator Script) { int Tick = Environment.TickCount; try { PingState RemoteState; // // Deserialize the remote ping state. If null, a protocol // violation has occurred. // if ((RemoteState = PingState.FromString(Arguments)) == null) { Script.WriteTimestampedLogEntry(String.Format( "ACR_ServerCommunicator.ServerLatencyMeasurer.HandleServerPingResponse({0}, {1}): Invalid request.", SourceServerId, Arguments)); return(ACR_ServerCommunicator.FALSE); } string ServerName = Script.GetServerName(SourceServerId); if (ServerName == null) { return(ACR_ServerCommunicator.FALSE); } Script.SendMessageToPC(RemoteState.PCObjectId, String.Format( "IPC channel latency to {0}: {1}ms", ServerName, Tick - RemoteState.TickCount)); } catch (Exception e) { Script.WriteTimestampedLogEntry(String.Format( "ACR_ServerCommunicator.ServerLatencyMeasurer.HandleServerPingResponse({0}, {1}): Exception: {0}", SourceServerId, Arguments, e)); return(ACR_ServerCommunicator.FALSE); } return(ACR_ServerCommunicator.TRUE); }
/// <summary> /// This when a cross-server ping response is received. Its purpose is /// to compute the channel latency and send a message to that effect to /// the requesting player. /// </summary> /// <param name="SourceServerId">Supplies the server id of the server /// that completed the ping request.</param> /// <param name="Arguments">Supplies the serialized state arguments /// string.</param> /// <param name="Script">Supplies the current script object.</param> /// <returns>TRUE on success, else FALSE on failure.</returns> public static int HandleServerPingResponse(int SourceServerId, string Arguments, ACR_ServerCommunicator Script) { int Tick = Environment.TickCount; try { PingState RemoteState; // // Deserialize the remote ping state. If null, a protocol // violation has occurred. // if ((RemoteState = PingState.FromString(Arguments)) == null) { Script.WriteTimestampedLogEntry(String.Format( "ACR_ServerCommunicator.ServerLatencyMeasurer.HandleServerPingResponse({0}, {1}): Invalid request.", SourceServerId, Arguments)); return ACR_ServerCommunicator.FALSE; } string ServerName = Script.GetServerName(SourceServerId); if (ServerName == null) return ACR_ServerCommunicator.FALSE; Script.SendMessageToPC(RemoteState.PCObjectId, String.Format( "IPC channel latency to {0}: {1}ms", ServerName, Tick - RemoteState.TickCount)); } catch (Exception e) { Script.WriteTimestampedLogEntry(String.Format( "ACR_ServerCommunicator.ServerLatencyMeasurer.HandleServerPingResponse({0}, {1}): Exception: {0}", SourceServerId, Arguments, e)); return ACR_ServerCommunicator.FALSE; } return ACR_ServerCommunicator.TRUE; }