public void TestPingTimestamp() { var timestamp = new TimeSpan(12, 34, 56); var ping = new PingRequestMessage(); ping.Timestamp = timestamp; var pingData = new byte[65536]; var pingWriter = NetworkBinaryWriter.Create(new MemoryStream(pingData)); ping.Serialize(pingWriter); var ping2 = (PingRequestMessage)Message.Deserialize(new ArraySegment<byte>(pingData), TimeSpan.Zero); var totalGameTime = new TimeSpan(23, 45, 67); var frameNumber = 123; var pong = ping2.GetPingReplyMessage(totalGameTime, frameNumber); var pongData = new byte[65536]; var pongWriter = NetworkBinaryWriter.Create(new MemoryStream(pongData)); pong.Serialize(pongWriter); var pong2 = (PingReplyMessage)Message.Deserialize(new ArraySegment<byte>(pongData), TimeSpan.Zero); Assert.AreEqual(timestamp, pong2.Timestamp); Assert.AreEqual(totalGameTime, pong2.TotalGameTimeOnReply); Assert.AreEqual(frameNumber, pong2.FrameNumberOnReply); }
private void HandleGameServerHandshakeRequestTCP(GameServerHandshakeRequestTCP mess) { var net = Game.NetworkEngine; string clientDiff, serverDiff; int diffIndex; bool differ = MiscHelper.FirstDifference(mess.CanonicalStrings, CanonicalString.CanonicalForms, out clientDiff, out serverDiff, out diffIndex); var connection = net.GetGameClientConnection(mess.ConnectionID); if (differ) { var mismatchInfo = string.Format("First mismatch is index: {0}, client: {1}, server: {2}", diffIndex, clientDiff ?? "<missing>", serverDiff ?? "<missing>"); var extraInfo = diffIndex == 0 ? "" : string.Format(", client previous: {0}, server previous: {1}", mess.CanonicalStrings[diffIndex - 1], CanonicalString.CanonicalForms[diffIndex - 1]); Log.Write("Client's CanonicalStrings don't match ours. " + mismatchInfo + extraInfo); var reply = new ConnectionClosingMessage { Info = "of version mismatch (canonical strings).\nPlease install the latest version from\nwww.assaultwing.com" }; connection.Send(reply); net.DropClient(mess.ConnectionID); } else { connection.ConnectionStatus.ClientKey = mess.GameClientKey; connection.ConnectionStatus.State = ConnectionUtils.GameClientStatus.StateType.Active; // Send dummy UDP packets to probable UDP end points of the client to increase // probability of our NAT forwarding UDP packets from the client to us. var ping = new PingRequestMessage(); for (int port = NetworkEngine.UDP_CONNECTION_PORT_FIRST; port <= NetworkEngine.UDP_CONNECTION_PORT_LAST; port++) net.UDPSocket.Send(ping.Serialize, new IPEndPoint(net.GetConnection(mess.ConnectionID).RemoteTCPEndPoint.Address, port)); } }
private void SendPing() { if (NowRealTime < _nextPingSend) return; _nextPingSend = NowRealTime + PING_INTERVAL; var pingSend = new PingRequestMessage { Timestamp = NowRealTime }; BaseConnection.Send(pingSend); }