forked from hipstercat/giantsd
clean and fix
This commit is contained in:
parent
c9d424b7f7
commit
fff7d0a865
@ -73,13 +73,12 @@ class Netserver(asyncio.DatagramProtocol):
|
||||
appdata.putShort(0) # points per kill
|
||||
appdata.write(b'\x00\x00') # original: 0000 - does not seem to affect client
|
||||
appdata.putShort(0) # detente time
|
||||
appdata.write("\x00\x00\x00\x00") # Seems to be a checksum of current map OR linked to the number of chars in the map name
|
||||
appdata.write(b"\xff\xff\xff\xff") # Seems to be a checksum of current map OR linked to the number of chars in the map name
|
||||
appdata.write(map_name.encode("ascii"))
|
||||
appdata.write(b'\x00' * (32 - len(map_name)))
|
||||
er.ApplicationReservedData = appdata.getvalue()
|
||||
|
||||
logger.debug("Current map: %s, checksum: %s", self.server.currentmap.mapname, self.server.currentmap.checksum)
|
||||
er.ApplicationReservedData += b'\x00' * (32 - len(self.server.currentmap.mapname))
|
||||
er.ApplicationReservedData += b'\x00' * (32 - len(map_name))
|
||||
self.send_packet(addr, er.to_packet())
|
||||
except Exception:
|
||||
logger.error("Could not parse EnumQuery or forge EnumResponse: ")
|
||||
|
@ -1,9 +1,6 @@
|
||||
import socket
|
||||
from dpnet.packet import Packet
|
||||
import threading
|
||||
from utils.logger import setup_logger
|
||||
|
||||
logger = setup_logger(__name__)
|
||||
import time
|
||||
|
||||
|
||||
class MasterServer:
|
||||
@ -13,42 +10,12 @@ class MasterServer:
|
||||
self.masterserverip = "gckms.no-ip.org"
|
||||
self.masterserverport = 27900
|
||||
|
||||
def register(self):
|
||||
statsserverthread = threading.Thread(target=self.register_and_run)
|
||||
statsserverthread.start()
|
||||
statsserverthread.join()
|
||||
|
||||
def register_and_run(self):
|
||||
self.socket.bind((self.server.listen_ip, 8911))
|
||||
logger.info("Listening to " + self.server.listen_ip + ":" + str(8911))
|
||||
logger.info("Registering to Master Server")
|
||||
self._register()
|
||||
self.keepalive()
|
||||
self.handle_packets()
|
||||
register_thread = threading.Thread(target=self._register)
|
||||
register_thread.start()
|
||||
return register_thread
|
||||
|
||||
def _register(self):
|
||||
packet = Packet()
|
||||
packet.write(("0"+str(self.server.listen_port)).encode("ascii"))
|
||||
self.socket.sendto(packet.getvalue(), (self.masterserverip, self.masterserverport))
|
||||
|
||||
def keepalive(self):
|
||||
packet = Packet()
|
||||
packet.write(("1"+str(self.server.listen_port)).encode("ascii"))
|
||||
self.socket.sendto(packet.getvalue(), (self.masterserverip, self.masterserverport))
|
||||
|
||||
def handle_packets(self):
|
||||
while True:
|
||||
data, addr = self.socket.recvfrom(1024)
|
||||
print(addr[0], ":", addr[1], ">", data.hex())
|
||||
data = Packet(data)
|
||||
command = data.read().decode("ascii")
|
||||
print("Received command:", command)
|
||||
if command == "\\status\\":
|
||||
resp = Packet()
|
||||
respstr = "\\gamename\\giants\\gamever\\"+str(self.server.version)+"\\hostname\\" + self.server.name + "\\hostport\\" + str(
|
||||
self.server.listen_port) + "\\mapname\\" + self.server.currentmap.mapname + "\\gametype\\Capture Smartie with full base\\numplayers\\" + str(
|
||||
len(self.server.players)) + "\\maxplayers\\" + str(
|
||||
self.server.maxplayers) + "\\gamemode\\openplaying\\timelimit\\60\\fraglimit\\0\\teamfraglimit\\0\\firstbasecomplete\\0\\player_0\\Amazed\\frags_0\\0\\deaths_0\\0\\ping_0\\0\\team_0\\Green\\final\\\\queryid\\2.1"
|
||||
resp.putBytes(respstr.encode("ascii"))
|
||||
self.socket.sendto(resp.getvalue(), addr)
|
||||
print(addr[0], ":", addr[1], "<", resp.getvalue().hex())
|
||||
self.socket.sendto(("0"+str(self.server.listen_port)).encode("ascii"), (self.masterserverip, self.masterserverport))
|
||||
time.sleep(120)
|
||||
|
@ -10,14 +10,14 @@ class Server:
|
||||
def __init__(self, **kwargs):
|
||||
self.listen_ip = kwargs.get("ip", "0.0.0.0")
|
||||
self.listen_port = kwargs.get("port", 19711)
|
||||
self.register_with_ms = kwargs.get("register", True)
|
||||
self.register_with_ms = kwargs.get("register", False)
|
||||
|
||||
async def on_connection_received(self, ip, port):
|
||||
version = 1.497
|
||||
server_name = "Okay"
|
||||
server_name = "My server name"
|
||||
player_count = 2
|
||||
max_player_count = 20
|
||||
map_name = "blah"
|
||||
map_name = "Map name"
|
||||
return version, server_name, player_count, max_player_count, map_name
|
||||
|
||||
|
||||
@ -25,7 +25,7 @@ if __name__ == '__main__':
|
||||
server = Server()
|
||||
if server.register_with_ms:
|
||||
ms = MasterServer(server)
|
||||
ms.register()
|
||||
register_thread = ms.register_and_run()
|
||||
|
||||
loop = asyncio.get_event_loop()
|
||||
listen = loop.create_datagram_endpoint(lambda: Netserver(server), local_addr=(server.listen_ip, server.listen_port))
|
||||
|
Loading…
Reference in New Issue
Block a user