From fff6fc933292fead4778ac6b07728fa6bf2d7704 Mon Sep 17 00:00:00 2001 From: mittorn Date: Thu, 23 Mar 2017 21:30:03 +0000 Subject: [PATCH] Add simple nat bypass --- pymaster.py | 13 ++++++++++++- server_entry.py | 3 +++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/pymaster.py b/pymaster.py index cfa54bf..f37d914 100755 --- a/pymaster.py +++ b/pymaster.py @@ -78,6 +78,7 @@ class PyMaster: # Use NoneType as undefined gamedir = None gamemap = None # UNUSED: until Xash3D will not support full filter + nat = 0 for i in range( 0, len(split), 2 ): try: @@ -86,6 +87,8 @@ class PyMaster: gamedir = key elif( split[i] == 'map' ): gamemap = key + elif( split[i] == 'nat' ): + nat = int(key) else: logPrint('Unhandled info string entry: {0}/{1}'.format(split[i], key)) except IndexError: @@ -100,9 +103,17 @@ class PyMaster: if( not i.check ): continue + if( nat != i.nat ): + continue + if( gamedir != None ): - if( gamedir != i.gamedir): + if( gamedir != i.gamedir ): continue + + if( nat ): + # Tell server to send info reply + self.sock.sendto( '\xff\xff\xff\xffc {0}:{1}'.format( addr[0], addr[1] ), i.addr ) + # Use pregenerated address string packet += i.queryAddr packet += b'\0\0\0\0\0\0' # Fill last IP:Port with \0 diff --git a/server_entry.py b/server_entry.py index 9fdab53..46a2209 100644 --- a/server_entry.py +++ b/server_entry.py @@ -17,6 +17,7 @@ class ServerEntry: lan = 0 region = 255 product = '' + nat = 0 def setInfoString(self, data): infostring = data.replace('\n', '').replace('\r', '').replace('\0', '') @@ -54,6 +55,8 @@ class ServerEntry: self.region = key elif( split[i] == 'product' ): self.product = key + elif( split[i] == 'nat' ): + self.nat = int(key) except IndexError: pass self.check = self.challenge == self.challenge2