1
0
Fork 0
mirror of https://github.com/de2tla2f/pymaster.git synced 2024-11-30 06:41:27 +00:00

Compare commits

..

4 commits

Author SHA1 Message Date
ghost 76079d0fdb remove extra debug 2024-01-08 21:58:44 +02:00
ghost e9b16fd990 fix var name 2024-01-08 21:53:44 +02:00
ghost f50347eac6 improve debug 2024-01-08 21:10:13 +02:00
ghost 45f1378679 define gamedir, add key support 2024-01-08 21:09:01 +02:00
2 changed files with 28 additions and 18 deletions

View file

@ -100,16 +100,20 @@ class PyMaster:
for i in self.serverList:
if time() > i.die:
logging.debug("Server removed by timeout")
self.serverList.remove(i)
continue
if not i.check:
logging.debug("Invalid request")
continue
if nat != i.nat:
logging.debug("NAT {0} mismatch {1}".format(i.nat, nat))
continue
if gamedir is not None and gamedir != i.gamedir:
logging.debug("Game dir {0} mismatch node settings: {1}".format(i.gamedir, gamedir))
continue
if nat:
@ -172,11 +176,13 @@ class PyMaster:
else:
count += 1
if count > MAX_SERVERS_FOR_IP:
logging.debug("Reached MAX_SERVERS_FOR_IP: {0}".format(MAX_SERVERS_FOR_IP))
return
challenge = random.randint(0, 2**32 - 1)
# Add server to list
logging.debug("Added new server {0}:{1} with challenge {2}".format(addr[0], addr[1], challenge))
self.serverList.append(ServerEntry(addr, challenge))
# And send him a challenge
@ -193,6 +199,7 @@ class PyMaster:
# Find a server with same address
for serverEntry in self.serverList:
if serverEntry.addr == addr:
logging.debug("Skipped same server address: {0}:{1}".format(addr[0], addr[1]))
break
serverEntry.setInfoString(serverInfo)

View file

@ -5,7 +5,7 @@ import ipaddress
class ServerEntry:
challenge2 = 0
gamedir = ''
gamedir = 'valve'
protocol = 0
players = 0
maxplayers = 0
@ -20,45 +20,48 @@ class ServerEntry:
region = 255
product = ''
nat = 0
key = None
def setInfoString(self, data):
infostring = data.replace('\n', '').replace('\r', '').replace('\0', '')
split = infostring.split('\\')
for i in range(0, len(split), 2):
try:
key = split[i + 1]
value = split[i + 1]
if( split[i] == 'challenge' ):
self.challenge2 = int(key)
self.challenge2 = int(value)
elif( split[i] == 'gamedir' ):
self.gamedir = key.lower() # keep gamedir lowercase
self.gamedir = value.lower() # keep gamedir lowercase
elif( split[i] == 'protocol' ):
self.protocol = int(key)
self.protocol = int(value)
elif( split[i] == 'players' ):
self.players = int(key)
self.players = int(value)
elif( split[i] == 'max' ):
self.maxplayers = int(key.split('.')[0])
self.maxplayers = int(value.split('.')[0])
elif( split[i] == 'bots' ):
self.bots = int(key)
self.bots = int(value)
elif( split[i] == 'map' ):
self.gamemap = key
self.gamemap = value
elif( split[i] == 'version' ):
self.version = key
self.version = value
elif( split[i] == 'type' ):
self.servtype = key
self.servtype = value
elif( split[i] == 'password' ):
self.password = key
self.password = value
elif( split[i] == 'os' ):
self.os = key
self.os = value
elif( split[i] == 'secure' ):
self.secure = key
self.secure = value
elif( split[i] == 'lan' ):
self.lan = key
self.lan = value
elif( split[i] == 'region' ):
self.region = key
self.region = value
elif( split[i] == 'product' ):
self.product = key
self.product = value
elif( split[i] == 'nat' ):
self.nat = int(key)
self.nat = int(value)
elif split[i] == 'key':
self.key = int(value, 16)
except IndexError:
pass
self.check = self.challenge == self.challenge2