From 652c380f1fe8a394de7793f6f386eb0df284d2aa Mon Sep 17 00:00:00 2001 From: Ketmar Dark Date: Fri, 15 Apr 2016 20:40:40 +0300 Subject: [PATCH] changed network "info" packet to include protocol version; ping packet now sends time as int64 --- src/engine/e_fixedbuffer.pas | 5 +++++ src/game/g_netmaster.pas | 17 +++++++++-------- src/game/g_netmsg.pas | 9 ++++++++- 3 files changed, 22 insertions(+), 9 deletions(-) diff --git a/src/engine/e_fixedbuffer.pas b/src/engine/e_fixedbuffer.pas index 63570f7..833fd05 100644 --- a/src/engine/e_fixedbuffer.pas +++ b/src/engine/e_fixedbuffer.pas @@ -50,6 +50,7 @@ function e_Buffer_Read_LongWord(B: pTBuffer): LongWord; function e_Buffer_Read_ShortInt(B: pTBuffer): ShortInt; function e_Buffer_Read_SmallInt(B: pTBuffer): SmallInt; function e_Buffer_Read_LongInt(B: pTBuffer): LongInt; +function e_Buffer_Read_Int64(B: pTBuffer): Int64; function e_Buffer_Read_String(B: pTBuffer): string; @@ -202,6 +203,10 @@ function e_Buffer_Read_LongInt(B: pTBuffer): LongInt; begin e_Buffer_Read_Generic(B, Result, 4); end; +function e_Buffer_Read_Int64(B: pTBuffer): Int64; +begin + e_Buffer_Read_Generic(B, Result, 8); +end; function e_Buffer_Read_String(B: pTBuffer): string; var diff --git a/src/game/g_netmaster.pas b/src/game/g_netmaster.pas index e0eed50..b05c6d4 100644 --- a/src/game/g_netmaster.pas +++ b/src/game/g_netmaster.pas @@ -23,7 +23,7 @@ type Port: Word; Map: string; Players, MaxPlayers, LocalPl, Bots: Byte; - Ping: Integer; + Ping: Int64; GameMode: Byte; Password: Boolean; PingAddr: ENetAddress; @@ -66,7 +66,7 @@ var slFetched: Boolean = False; slDirPressed: Boolean = False; -function GetTimerMS(): Integer; +function GetTimerMS(): Int64; begin Result := GetTimer() {div 1000}; end; @@ -74,17 +74,17 @@ end; procedure PingServer(var S: TNetServer; Sock: ENetSocket); var Buf: ENetBuffer; - Ping: array [0..5] of Byte; - ClTime: Integer; + Ping: array [0..9] of Byte; + ClTime: Int64; begin ClTime := GetTimerMS(); Buf.data := Addr(Ping[0]); - Buf.dataLength := 6; + Buf.dataLength := 2+8; Ping[0] := Ord('D'); Ping[1] := Ord('F'); - LongInt(Addr(Ping[2])^) := ClTime; + Int64(Addr(Ping[2])^) := ClTime; enet_socket_send(Sock, Addr(S.PingAddr), @Buf, 1); end; @@ -94,7 +94,8 @@ var Cnt: Byte; P: pENetPacket; MID: Byte; - I, T, RX: Integer; + I, RX: Integer; + T: Int64; Sock: ENetSocket; Buf: ENetBuffer; SvAddr: ENetAddress; @@ -196,7 +197,7 @@ begin begin with SL[I] do begin - Ping := e_Buffer_Read_LongInt(@NetIn); + Ping := e_Buffer_Read_Int64(@NetIn); Ping := GetTimerMS() - Ping; Name := e_Buffer_Read_String(@NetIn); Map := e_Buffer_Read_String(@NetIn); diff --git a/src/game/g_netmsg.pas b/src/game/g_netmsg.pas index a88513a..b24022f 100644 --- a/src/game/g_netmsg.pas +++ b/src/game/g_netmsg.pas @@ -5,6 +5,8 @@ interface uses g_net, g_triggers, Classes, SysUtils, md5; const + NET_PROTO_VERSION = 1; + NET_MSG_INFO = 100; NET_MSG_CHAT = 101; @@ -310,7 +312,10 @@ var PID: Word; Color: TRGB; I: Integer; + ProtoVer, Zero: Byte; begin + Zero := e_Raw_Read_Byte(P); + ProtoVer := e_Raw_Read_Byte(P); Ver := e_Raw_Read_String(P); Pw := e_Raw_Read_String(P); PName := e_Raw_Read_String(P); @@ -320,7 +325,7 @@ begin B := e_Raw_Read_Byte(P); T := e_Raw_Read_Byte(P); - if Ver <> GAME_VERSION then + if (Ver <> GAME_VERSION) or (ProtoVer <> NET_PROTO_VERSION) or (Zero <> 0) then begin g_Console_Add(_lc[I_NET_MSG] + _lc[I_NET_MSG_HOST_REJECT] + _lc[I_NET_DISC_VERSION]); @@ -2686,6 +2691,8 @@ begin e_Buffer_Clear(@NetOut); e_Buffer_Write(@NetOut, Byte(NET_MSG_INFO)); + e_Buffer_Write(@NetOut, Byte(0)); // to kill old clients + e_Buffer_Write(@NetOut, Byte(NET_PROTO_VERSION)); e_Buffer_Write(@NetOut, GAME_VERSION); e_Buffer_Write(@NetOut, Password); e_Buffer_Write(@NetOut, gPlayer1Settings.Name); -- 2.29.2