2016-01-19 21:32:16 +00:00
|
|
|
from time import time
|
2016-01-20 23:24:37 +00:00
|
|
|
from struct import pack
|
2016-01-19 21:32:16 +00:00
|
|
|
|
|
|
|
class ServerEntry:
|
2016-01-20 23:24:37 +00:00
|
|
|
challenge2 = 0
|
|
|
|
gamedir = ''
|
|
|
|
protocol = 0
|
|
|
|
players = 0
|
|
|
|
maxplayers = 0
|
|
|
|
bots = 0
|
|
|
|
gamemap = ''
|
|
|
|
version = '0'
|
|
|
|
servtype = 'd'
|
|
|
|
password = 0
|
|
|
|
os = 'l'
|
|
|
|
secure = 0
|
|
|
|
lan = 0
|
|
|
|
region = 255
|
|
|
|
product = ''
|
2017-03-23 21:30:03 +00:00
|
|
|
nat = 0
|
2016-01-20 23:24:37 +00:00
|
|
|
|
2016-01-19 21:32:16 +00:00
|
|
|
def setInfoString(self, data):
|
2016-01-20 23:24:37 +00:00
|
|
|
infostring = data.replace('\n', '').replace('\r', '').replace('\0', '')
|
2016-01-19 21:32:16 +00:00
|
|
|
split = infostring.split('\\')
|
2016-01-20 23:24:37 +00:00
|
|
|
for i in range(0, len(split), 2):
|
|
|
|
try:
|
|
|
|
key = split[i + 1]
|
|
|
|
if( split[i] == 'challenge' ):
|
|
|
|
self.challenge2 = int(key)
|
|
|
|
elif( split[i] == 'gamedir' ):
|
2018-12-30 11:43:52 +00:00
|
|
|
self.gamedir = key.lower() # keep gamedir lowercase
|
2016-01-20 23:24:37 +00:00
|
|
|
elif( split[i] == 'protocol' ):
|
|
|
|
self.protocol = int(key)
|
|
|
|
elif( split[i] == 'players' ):
|
|
|
|
self.players = int(key)
|
|
|
|
elif( split[i] == 'max' ):
|
|
|
|
self.maxplayers = int(key)
|
|
|
|
elif( split[i] == 'bots' ):
|
|
|
|
self.bots = int(key)
|
|
|
|
elif( split[i] == 'map' ):
|
|
|
|
self.gamemap = key
|
|
|
|
elif( split[i] == 'version' ):
|
|
|
|
self.version = key
|
|
|
|
elif( split[i] == 'type' ):
|
|
|
|
self.servtype = key
|
|
|
|
elif( split[i] == 'password' ):
|
|
|
|
self.password = key
|
|
|
|
elif( split[i] == 'os' ):
|
|
|
|
self.os = key
|
|
|
|
elif( split[i] == 'secure' ):
|
|
|
|
self.secure = key
|
|
|
|
elif( split[i] == 'lan' ):
|
|
|
|
self.lan = key
|
|
|
|
elif( split[i] == 'region' ):
|
|
|
|
self.region = key
|
|
|
|
elif( split[i] == 'product' ):
|
|
|
|
self.product = key
|
2017-03-23 21:30:03 +00:00
|
|
|
elif( split[i] == 'nat' ):
|
|
|
|
self.nat = int(key)
|
2016-01-20 23:24:37 +00:00
|
|
|
except IndexError:
|
|
|
|
pass
|
|
|
|
self.check = self.challenge == self.challenge2
|
2016-01-19 21:32:16 +00:00
|
|
|
|
|
|
|
def __init__(self, addr, challenge):
|
|
|
|
# Address
|
|
|
|
self.addr = addr
|
|
|
|
|
|
|
|
# Shortcuts for generating query
|
2016-01-20 23:24:37 +00:00
|
|
|
self.queryAddr = b''
|
2016-01-19 21:32:16 +00:00
|
|
|
for i in addr[0].split('.'):
|
2016-01-22 10:15:02 +00:00
|
|
|
self.queryAddr += pack('!B', int(i))
|
|
|
|
self.queryAddr += pack('!H', int(addr[1]))
|
2016-01-19 21:32:16 +00:00
|
|
|
|
|
|
|
# Random number that server must return
|
|
|
|
self.challenge = challenge
|
|
|
|
|
|
|
|
# This server is not checked
|
|
|
|
# So it will not get into queries
|
|
|
|
self.check = False
|
|
|
|
|
|
|
|
# Remove server after this time.
|
|
|
|
# This maybe not instant
|
2018-12-30 11:43:52 +00:00
|
|
|
self.die = time() + 600.0
|