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

define gamedir, add key support

This commit is contained in:
ghost 2024-01-08 21:09:01 +02:00
parent 4ad8a8a59c
commit 45f1378679

View file

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