Fixed and working gckms!

This commit is contained in:
Amazed 2019-02-12 17:24:58 +01:00
parent c23a7ed0af
commit da10458aa5

View File

@ -45,34 +45,27 @@ def queryloop(querysock):
b += b'\x00' b += b'\x00'
print("Sending back", b) print("Sending back", b)
clientsocket.send(b) clientsocket.send(b)
clientsocket.close()
def registerloop(registersock): def registerloop(registersock):
while True: while True:
data, (ip, port) = registersock.recvfrom(1024) data, (ip, port) = registersock.recvfrom(1024)
print("New register", data)
print(ip, port)
try: try:
if data[0] == 49: gameport = data[1:].decode("ascii")
gameport = data[1:].decode("ascii") if int(gameport):
print("Gameport %s" % gameport) tempsocket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
if int(gameport): tempsocket.settimeout(5)
tempsocket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) tempsocket.sendto("\\status\\".encode("ascii"), (ip, port))
tempsocket.settimeout(5) tempsocket.recvfrom(1024)
tempsocket.sendto("\\status\\".encode("ascii"), (ip, port)) server = next((x for x in SERVERS if x["ip"] == ip and x["port"] == gameport), None)
tempsocket.recvfrom(1024) if not server:
server = next((x for x in SERVERS if x["ip"] == ip and x["port"] == gameport), None) SERVERS.append({"ip": ip, "port": gameport, "last": datetime.datetime.now()})
if not server: print("New server: %s:%s" % (ip, gameport))
SERVERS.append({"ip": ip, "port": gameport, "last": datetime.datetime.now()})
print("New server: %s:%s" % (ip, gameport))
else:
server["last"] = datetime.datetime.now()
print("Keepalive from: %s:%s" % (ip, gameport))
tempsocket.close()
else: else:
print("Fuck it, wasn't int: ", gameport) server["last"] = datetime.datetime.now()
print("Keepalive from: %s:%s" % (ip, gameport))
tempsocket.close()
else: else:
print('data[0]: ', data[0]) print("Fuck it, wasn't int: ", data)
except Exception as e: except Exception as e:
print("Exception") print("Exception")
traceback.print_exc() traceback.print_exc()
@ -82,7 +75,7 @@ def cleanloop():
now = datetime.datetime.now() now = datetime.datetime.now()
for server in SERVERS: for server in SERVERS:
if now > server["last"] + datetime.timedelta(minutes=2): if now > server["last"] + datetime.timedelta(minutes=2):
if server["ip"] == "163.158.182.243" or server["ip"] == "206.55.174.10": if server["ip"] == "163.158.182.243" or server["ip"] == "73.181.147.35":
# do not remove usual dedicated servers # do not remove usual dedicated servers
continue continue
print("Deleting %s:%s" % (server["ip"], server["port"])) print("Deleting %s:%s" % (server["ip"], server["port"]))