giants-stupid-server/giants/masterserver.py

22 lines
648 B
Python
Raw Normal View History

2019-01-22 01:30:42 +01:00
import socket
import threading
2020-05-27 15:45:58 +02:00
import time
2019-01-22 01:30:42 +01:00
class MasterServer:
def __init__(self, server):
self.server = server
self.socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
self.masterserverip = "gckms.no-ip.org"
self.masterserverport = 27900
def register_and_run(self):
2020-05-27 15:45:58 +02:00
register_thread = threading.Thread(target=self._register)
register_thread.start()
return register_thread
2019-01-22 01:30:42 +01:00
def _register(self):
2019-01-22 01:30:42 +01:00
while True:
2020-05-27 15:45:58 +02:00
self.socket.sendto(("0"+str(self.server.listen_port)).encode("ascii"), (self.masterserverip, self.masterserverport))
time.sleep(120)