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
|
|
|
|
2023-12-26 17:15:10 +00:00
|
|
|
import ipaddress
|
|
|
|
|
2016-01-19 21:32:16 +00:00
|
|
|
class ServerEntry:
|
2016-01-20 23:24:37 +00:00
|
|
|
challenge2 = 0
|
2024-01-08 19:09:01 +00:00
|
|
|
gamedir = 'valve'
|
2016-01-20 23:24:37 +00:00
|
|
|
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
|
2024-01-08 19:09:01 +00:00
|
|
|
key = None
|
2022-12-07 19:03:24 +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:
|
2024-01-08 19:09:01 +00:00
|
|
|
value = split[i + 1]
|
2016-01-20 23:24:37 +00:00
|
|
|
if( split[i] == 'challenge' ):
|
2024-01-08 19:09:01 +00:00
|
|
|
self.challenge2 = int(value)
|
2016-01-20 23:24:37 +00:00
|
|
|
elif( split[i] == 'gamedir' ):
|
2024-01-08 19:09:01 +00:00
|
|
|
self.gamedir = value.lower() # keep gamedir lowercase
|
2016-01-20 23:24:37 +00:00
|
|
|
elif( split[i] == 'protocol' ):
|
2024-01-08 19:09:01 +00:00
|
|
|
self.protocol = int(value)
|
2016-01-20 23:24:37 +00:00
|
|
|
elif( split[i] == 'players' ):
|
2024-01-08 19:09:01 +00:00
|
|
|
self.players = int(value)
|
2016-01-20 23:24:37 +00:00
|
|
|
elif( split[i] == 'max' ):
|
2024-01-08 19:09:01 +00:00
|
|
|
self.maxplayers = int(value.split('.')[0])
|
2016-01-20 23:24:37 +00:00
|
|
|
elif( split[i] == 'bots' ):
|
2024-01-08 19:09:01 +00:00
|
|
|
self.bots = int(value)
|
2016-01-20 23:24:37 +00:00
|
|
|
elif( split[i] == 'map' ):
|
2024-01-08 19:09:01 +00:00
|
|
|
self.gamemap = value
|
2016-01-20 23:24:37 +00:00
|
|
|
elif( split[i] == 'version' ):
|
2024-01-08 19:09:01 +00:00
|
|
|
self.version = value
|
2016-01-20 23:24:37 +00:00
|
|
|
elif( split[i] == 'type' ):
|
2024-01-08 19:09:01 +00:00
|
|
|
self.servtype = value
|
2016-01-20 23:24:37 +00:00
|
|
|
elif( split[i] == 'password' ):
|
2024-01-08 19:09:01 +00:00
|
|
|
self.password = value
|
2016-01-20 23:24:37 +00:00
|
|
|
elif( split[i] == 'os' ):
|
2024-01-08 19:09:01 +00:00
|
|
|
self.os = value
|
2016-01-20 23:24:37 +00:00
|
|
|
elif( split[i] == 'secure' ):
|
2024-01-08 19:09:01 +00:00
|
|
|
self.secure = value
|
2016-01-20 23:24:37 +00:00
|
|
|
elif( split[i] == 'lan' ):
|
2024-01-08 19:09:01 +00:00
|
|
|
self.lan = value
|
2016-01-20 23:24:37 +00:00
|
|
|
elif( split[i] == 'region' ):
|
2024-01-08 19:09:01 +00:00
|
|
|
self.region = value
|
2016-01-20 23:24:37 +00:00
|
|
|
elif( split[i] == 'product' ):
|
2024-01-08 19:09:01 +00:00
|
|
|
self.product = value
|
2017-03-23 21:30:03 +00:00
|
|
|
elif( split[i] == 'nat' ):
|
2024-01-08 19:09:01 +00:00
|
|
|
self.nat = int(value)
|
|
|
|
elif split[i] == 'key':
|
|
|
|
self.nat = int(value, 16)
|
2016-01-20 23:24:37 +00:00
|
|
|
except IndexError:
|
|
|
|
pass
|
|
|
|
self.check = self.challenge == self.challenge2
|
2022-12-07 19:03:24 +00:00
|
|
|
return self.check
|
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''
|
2023-12-26 17:13:30 +00:00
|
|
|
self.queryAddr += ipaddress.ip_address(addr[0]).packed
|
2016-01-22 10:15:02 +00:00
|
|
|
self.queryAddr += pack('!H', int(addr[1]))
|
2022-12-07 19:03:24 +00:00
|
|
|
|
|
|
|
# Random number that server must return
|
2016-01-19 21:32:16 +00:00
|
|
|
self.challenge = challenge
|
2022-12-07 19:03:24 +00:00
|
|
|
self.sentChallengeAt = time()
|
|
|
|
|
2016-01-19 21:32:16 +00:00
|
|
|
# This server is not checked
|
|
|
|
# So it will not get into queries
|
|
|
|
self.check = False
|
2022-12-07 19:03:24 +00:00
|
|
|
|
2016-01-19 21:32:16 +00:00
|
|
|
# Remove server after this time.
|
|
|
|
# This maybe not instant
|
2022-12-07 19:03:24 +00:00
|
|
|
self.die = self.sentChallengeAt + 600
|