39 lines
1.1 KiB
Python
39 lines
1.1 KiB
Python
from dpnet.netserver import Netserver
|
|
from giants.masterserver import MasterServer
|
|
from utils.logger import setup_logger
|
|
import asyncio
|
|
|
|
logger = setup_logger(__name__)
|
|
|
|
|
|
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)
|
|
|
|
async def on_connection_received(self, ip, port):
|
|
version = 1.497
|
|
server_name = "My server name"
|
|
player_count = 2
|
|
max_player_count = 20
|
|
map_name = "Map name"
|
|
return version, server_name, player_count, max_player_count, map_name
|
|
|
|
|
|
if __name__ == '__main__':
|
|
server = Server()
|
|
if server.register_with_ms:
|
|
ms = MasterServer(server)
|
|
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))
|
|
transport, protocol = loop.run_until_complete(listen)
|
|
try:
|
|
loop.run_forever()
|
|
except KeyboardInterrupt:
|
|
pass
|
|
transport.close()
|
|
loop.close()
|