From a5d2629096799c0659af745e68359cfc1c639f45 Mon Sep 17 00:00:00 2001 From: Hipstercat Date: Wed, 22 Apr 2020 02:22:34 +0200 Subject: [PATCH] stuff --- countries.json | 1 + dpnet/netserver.py | 48 ++++++++++++++++++++++++++++++++++++++++------ server.py | 26 +++++++++++++++++++++---- 3 files changed, 65 insertions(+), 10 deletions(-) create mode 100644 countries.json diff --git a/countries.json b/countries.json new file mode 100644 index 0000000..5546382 --- /dev/null +++ b/countries.json @@ -0,0 +1 @@ +[{"Country":"British Indian Ocean Territory","Slug":"british-indian-ocean-territory","ISO2":"IO"},{"Country":"Holy See (Vatican City State)","Slug":"holy-see-vatican-city-state","ISO2":"VA"},{"Country":"Kazakhstan","Slug":"kazakhstan","ISO2":"KZ"},{"Country":"Macao, SAR China","Slug":"macao-sar-china","ISO2":"MO"},{"Country":"Afghanistan","Slug":"afghanistan","ISO2":"AF"},{"Country":"Burkina Faso","Slug":"burkina-faso","ISO2":"BF"},{"Country":"Denmark","Slug":"denmark","ISO2":"DK"},{"Country":"Lithuania","Slug":"lithuania","ISO2":"LT"},{"Country":"Palestinian Territory","Slug":"palestine","ISO2":"PS"},{"Country":"Australia","Slug":"australia","ISO2":"AU"},{"Country":"Brazil","Slug":"brazil","ISO2":"BR"},{"Country":"Lesotho","Slug":"lesotho","ISO2":"LS"},{"Country":"Mongolia","Slug":"mongolia","ISO2":"MN"},{"Country":"Palau","Slug":"palau","ISO2":"PW"},{"Country":"Seychelles","Slug":"seychelles","ISO2":"SC"},{"Country":"South Africa","Slug":"south-africa","ISO2":"ZA"},{"Country":"Norway","Slug":"norway","ISO2":"NO"},{"Country":"Senegal","Slug":"senegal","ISO2":"SN"},{"Country":"Sierra Leone","Slug":"sierra-leone","ISO2":"SL"},{"Country":"Germany","Slug":"germany","ISO2":"DE"},{"Country":"Mali","Slug":"mali","ISO2":"ML"},{"Country":"Namibia","Slug":"namibia","ISO2":"NA"},{"Country":"Puerto Rico","Slug":"puerto-rico","ISO2":"PR"},{"Country":"Réunion","Slug":"réunion","ISO2":"RE"},{"Country":"Sudan","Slug":"sudan","ISO2":"SD"},{"Country":"Yemen","Slug":"yemen","ISO2":"YE"},{"Country":"Zambia","Slug":"zambia","ISO2":"ZM"},{"Country":"Maldives","Slug":"maldives","ISO2":"MV"},{"Country":"Côte d'Ivoire","Slug":"cote-divoire","ISO2":"CI"},{"Country":"Gabon","Slug":"gabon","ISO2":"GA"},{"Country":"Samoa","Slug":"samoa","ISO2":"WS"},{"Country":"Saudi Arabia","Slug":"saudi-arabia","ISO2":"SA"},{"Country":"Costa Rica","Slug":"costa-rica","ISO2":"CR"},{"Country":"Trinidad and Tobago","Slug":"trinidad-and-tobago","ISO2":"TT"},{"Country":"Uzbekistan","Slug":"uzbekistan","ISO2":"UZ"},{"Country":"Svalbard and Jan Mayen Islands","Slug":"svalbard-and-jan-mayen-islands","ISO2":"SJ"},{"Country":"Gibraltar","Slug":"gibraltar","ISO2":"GI"},{"Country":"Guinea","Slug":"guinea","ISO2":"GN"},{"Country":"Marshall Islands","Slug":"marshall-islands","ISO2":"MH"},{"Country":"Mauritius","Slug":"mauritius","ISO2":"MU"},{"Country":"Netherlands Antilles","Slug":"netherlands-antilles","ISO2":"AN"},{"Country":"Sri Lanka","Slug":"sri-lanka","ISO2":"LK"},{"Country":"French Southern Territories","Slug":"french-southern-territories","ISO2":"TF"},{"Country":"Bangladesh","Slug":"bangladesh","ISO2":"BD"},{"Country":"Cayman Islands","Slug":"cayman-islands","ISO2":"KY"},{"Country":"Guatemala","Slug":"guatemala","ISO2":"GT"},{"Country":"American Samoa","Slug":"american-samoa","ISO2":"AS"},{"Country":"Bermuda","Slug":"bermuda","ISO2":"BM"},{"Country":"Israel","Slug":"israel","ISO2":"IL"},{"Country":"Pitcairn","Slug":"pitcairn","ISO2":"PN"},{"Country":"Taiwan, Republic of China","Slug":"taiwan","ISO2":"TW"},{"Country":"French Guiana","Slug":"french-guiana","ISO2":"GF"},{"Country":"Martinique","Slug":"martinique","ISO2":"MQ"},{"Country":"Uganda","Slug":"uganda","ISO2":"UG"},{"Country":"United Arab Emirates","Slug":"united-arab-emirates","ISO2":"AE"},{"Country":"Falkland Islands (Malvinas)","Slug":"falkland-islands-malvinas","ISO2":"FK"},{"Country":"Guernsey","Slug":"guernsey","ISO2":"GG"},{"Country":"Norfolk Island","Slug":"norfolk-island","ISO2":"NF"},{"Country":"Timor-Leste","Slug":"timor-leste","ISO2":"TL"},{"Country":"Nauru","Slug":"nauru","ISO2":"NR"},{"Country":"Andorra","Slug":"andorra","ISO2":"AD"},{"Country":"Anguilla","Slug":"anguilla","ISO2":"AI"},{"Country":"Armenia","Slug":"armenia","ISO2":"AM"},{"Country":"Greenland","Slug":"greenland","ISO2":"GL"},{"Country":"Kenya","Slug":"kenya","ISO2":"KE"},{"Country":"Comoros","Slug":"comoros","ISO2":"KM"},{"Country":"Ethiopia","Slug":"ethiopia","ISO2":"ET"},{"Country":"Gambia","Slug":"gambia","ISO2":"GM"},{"Country":"Morocco","Slug":"morocco","ISO2":"MA"},{"Country":"Sao Tome and Principe","Slug":"sao-tome-and-principe","ISO2":"ST"},{"Country":"Singapore","Slug":"singapore","ISO2":"SG"},{"Country":"South Georgia and the South Sandwich Islands","Slug":"south-georgia-and-the-south-sandwich-islands","ISO2":"GS"},{"Country":"Bhutan","Slug":"bhutan","ISO2":"BT"},{"Country":"Ukraine","Slug":"ukraine","ISO2":"UA"},{"Country":"Dominican Republic","Slug":"dominican-republic","ISO2":"DO"},{"Country":"Serbia","Slug":"serbia","ISO2":"RS"},{"Country":"Benin","Slug":"benin","ISO2":"BJ"},{"Country":"Georgia","Slug":"georgia","ISO2":"GE"},{"Country":"Iran, Islamic Republic of","Slug":"iran","ISO2":"IR"},{"Country":"Turkmenistan","Slug":"turkmenistan","ISO2":"TM"},{"Country":"Vanuatu","Slug":"vanuatu","ISO2":"VU"},{"Country":"Cameroon","Slug":"cameroon","ISO2":"CM"},{"Country":"Haiti","Slug":"haiti","ISO2":"HT"},{"Country":"Switzerland","Slug":"switzerland","ISO2":"CH"},{"Country":"Finland","Slug":"finland","ISO2":"FI"},{"Country":"Jamaica","Slug":"jamaica","ISO2":"JM"},{"Country":"Philippines","Slug":"philippines","ISO2":"PH"},{"Country":"Thailand","Slug":"thailand","ISO2":"TH"},{"Country":"Argentina","Slug":"argentina","ISO2":"AR"},{"Country":"Christmas Island","Slug":"christmas-island","ISO2":"CX"},{"Country":"Cocos (Keeling) Islands","Slug":"cocos-keeling-islands","ISO2":"CC"},{"Country":"Panama","Slug":"panama","ISO2":"PA"},{"Country":"Suriname","Slug":"suriname","ISO2":"SR"},{"Country":"Papua New Guinea","Slug":"papua-new-guinea","ISO2":"PG"},{"Country":"Grenada","Slug":"grenada","ISO2":"GD"},{"Country":"New Zealand","Slug":"new-zealand","ISO2":"NZ"},{"Country":"Bosnia and Herzegovina","Slug":"bosnia-and-herzegovina","ISO2":"BA"},{"Country":"Djibouti","Slug":"djibouti","ISO2":"DJ"},{"Country":"Dominica","Slug":"dominica","ISO2":"DM"},{"Country":"Egypt","Slug":"egypt","ISO2":"EG"},{"Country":"Niger","Slug":"niger","ISO2":"NE"},{"Country":"ALA Aland Islands","Slug":"ala-aland-islands","ISO2":"AX"},{"Country":"Saint Helena","Slug":"saint-helena","ISO2":"SH"},{"Country":"Iceland","Slug":"iceland","ISO2":"IS"},{"Country":"Luxembourg","Slug":"luxembourg","ISO2":"LU"},{"Country":"Portugal","Slug":"portugal","ISO2":"PT"},{"Country":"US Minor Outlying Islands","Slug":"us-minor-outlying-islands","ISO2":"UM"},{"Country":"New Caledonia","Slug":"new-caledonia","ISO2":"NC"},{"Country":"Syrian Arab Republic (Syria)","Slug":"syria","ISO2":"SY"},{"Country":"Equatorial Guinea","Slug":"equatorial-guinea","ISO2":"GQ"},{"Country":"Niue","Slug":"niue","ISO2":"NU"},{"Country":"Belgium","Slug":"belgium","ISO2":"BE"},{"Country":"Central African Republic","Slug":"central-african-republic","ISO2":"CF"},{"Country":"Cyprus","Slug":"cyprus","ISO2":"CY"},{"Country":"Guinea-Bissau","Slug":"guinea-bissau","ISO2":"GW"},{"Country":"Jordan","Slug":"jordan","ISO2":"JO"},{"Country":"Kiribati","Slug":"kiribati","ISO2":"KI"},{"Country":"Moldova","Slug":"moldova","ISO2":"MD"},{"Country":"Paraguay","Slug":"paraguay","ISO2":"PY"},{"Country":"Congo (Kinshasa)","Slug":"congo-kinshasa","ISO2":"CD"},{"Country":"Cape Verde","Slug":"cape-verde","ISO2":"CV"},{"Country":"Bahrain","Slug":"bahrain","ISO2":"BH"},{"Country":"Iraq","Slug":"iraq","ISO2":"IQ"},{"Country":"Jersey","Slug":"jersey","ISO2":"JE"},{"Country":"Montserrat","Slug":"montserrat","ISO2":"MS"},{"Country":"South Sudan","Slug":"south-sudan","ISO2":"SS"},{"Country":"Tokelau","Slug":"tokelau","ISO2":"TK"},{"Country":"Nepal","Slug":"nepal","ISO2":"NP"},{"Country":"Belarus","Slug":"belarus","ISO2":"BY"},{"Country":"China","Slug":"china","ISO2":"CN"},{"Country":"French Polynesia","Slug":"french-polynesia","ISO2":"PF"},{"Country":"Korea (North)","Slug":"korea-north","ISO2":"KP"},{"Country":"Liechtenstein","Slug":"liechtenstein","ISO2":"LI"},{"Country":"Oman","Slug":"oman","ISO2":"OM"},{"Country":"Pakistan","Slug":"pakistan","ISO2":"PK"},{"Country":"Angola","Slug":"angola","ISO2":"AO"},{"Country":"Swaziland","Slug":"swaziland","ISO2":"SZ"},{"Country":"Bolivia","Slug":"bolivia","ISO2":"BO"},{"Country":"India","Slug":"india","ISO2":"IN"},{"Country":"Lao PDR","Slug":"lao-pdr","ISO2":"LA"},{"Country":"Macedonia, Republic of","Slug":"macedonia","ISO2":"MK"},{"Country":"Madagascar","Slug":"madagascar","ISO2":"MG"},{"Country":"Republic of Kosovo","Slug":"kosovo","ISO2":"XK"},{"Country":"Indonesia","Slug":"indonesia","ISO2":"ID"},{"Country":"Saint Kitts and Nevis","Slug":"saint-kitts-and-nevis","ISO2":"KN"},{"Country":"Somalia","Slug":"somalia","ISO2":"SO"},{"Country":"Estonia","Slug":"estonia","ISO2":"EE"},{"Country":"Colombia","Slug":"colombia","ISO2":"CO"},{"Country":"El Salvador","Slug":"el-salvador","ISO2":"SV"},{"Country":"Solomon Islands","Slug":"solomon-islands","ISO2":"SB"},{"Country":"Belize","Slug":"belize","ISO2":"BZ"},{"Country":"Canada","Slug":"canada","ISO2":"CA"},{"Country":"Togo","Slug":"togo","ISO2":"TG"},{"Country":"Chad","Slug":"chad","ISO2":"TD"},{"Country":"Ghana","Slug":"ghana","ISO2":"GH"},{"Country":"Japan","Slug":"japan","ISO2":"JP"},{"Country":"Malaysia","Slug":"malaysia","ISO2":"MY"},{"Country":"Turks and Caicos Islands","Slug":"turks-and-caicos-islands","ISO2":"TC"},{"Country":"Viet Nam","Slug":"vietnam","ISO2":"VN"},{"Country":"Honduras","Slug":"honduras","ISO2":"HN"},{"Country":"Rwanda","Slug":"rwanda","ISO2":"RW"},{"Country":"Saint-Martin (French part)","Slug":"saint-martin-french-part","ISO2":"MF"},{"Country":"Chile","Slug":"chile","ISO2":"CL"},{"Country":"Faroe Islands","Slug":"faroe-islands","ISO2":"FO"},{"Country":"Liberia","Slug":"liberia","ISO2":"LR"},{"Country":"Venezuela (Bolivarian Republic)","Slug":"venezuela","ISO2":"VE"},{"Country":"Bahamas","Slug":"bahamas","ISO2":"BS"},{"Country":"Montenegro","Slug":"montenegro","ISO2":"ME"},{"Country":"Cook Islands","Slug":"cook-islands","ISO2":"CK"},{"Country":"Lebanon","Slug":"lebanon","ISO2":"LB"},{"Country":"Libya","Slug":"libya","ISO2":"LY"},{"Country":"Malta","Slug":"malta","ISO2":"MT"},{"Country":"Saint Pierre and Miquelon","Slug":"saint-pierre-and-miquelon","ISO2":"PM"},{"Country":"Tajikistan","Slug":"tajikistan","ISO2":"TJ"},{"Country":"Tanzania, United Republic of","Slug":"tanzania","ISO2":"TZ"},{"Country":"Nicaragua","Slug":"nicaragua","ISO2":"NI"},{"Country":"Italy","Slug":"italy","ISO2":"IT"},{"Country":"Guyana","Slug":"guyana","ISO2":"GY"},{"Country":"Isle of Man","Slug":"isle-of-man","ISO2":"IM"},{"Country":"Mexico","Slug":"mexico","ISO2":"MX"},{"Country":"Northern Mariana Islands","Slug":"northern-mariana-islands","ISO2":"MP"},{"Country":"Spain","Slug":"spain","ISO2":"ES"},{"Country":"Bulgaria","Slug":"bulgaria","ISO2":"BG"},{"Country":"Albania","Slug":"albania","ISO2":"AL"},{"Country":"Heard and Mcdonald Islands","Slug":"heard-and-mcdonald-islands","ISO2":"HM"},{"Country":"Kyrgyzstan","Slug":"kyrgyzstan","ISO2":"KG"},{"Country":"Bouvet Island","Slug":"bouvet-island","ISO2":"BV"},{"Country":"Cambodia","Slug":"cambodia","ISO2":"KH"},{"Country":"Myanmar","Slug":"myanmar","ISO2":"MM"},{"Country":"United Kingdom","Slug":"united-kingdom","ISO2":"GB"},{"Country":"Algeria","Slug":"algeria","ISO2":"DZ"},{"Country":"Hungary","Slug":"hungary","ISO2":"HU"},{"Country":"Malawi","Slug":"malawi","ISO2":"MW"},{"Country":"San Marino","Slug":"san-marino","ISO2":"SM"},{"Country":"Slovenia","Slug":"slovenia","ISO2":"SI"},{"Country":"Tuvalu","Slug":"tuvalu","ISO2":"TV"},{"Country":"Zimbabwe","Slug":"zimbabwe","ISO2":"ZW"},{"Country":"Guadeloupe","Slug":"guadeloupe","ISO2":"GP"},{"Country":"Barbados","Slug":"barbados","ISO2":"BB"},{"Country":"Brunei Darussalam","Slug":"brunei","ISO2":"BN"},{"Country":"Burundi","Slug":"burundi","ISO2":"BI"},{"Country":"Hong Kong, SAR China","Slug":"hong-kong-sar-china","ISO2":"HK"},{"Country":"Kuwait","Slug":"kuwait","ISO2":"KW"},{"Country":"Nigeria","Slug":"nigeria","ISO2":"NG"},{"Country":"Antarctica","Slug":"antarctica","ISO2":"AQ"},{"Country":"Cuba","Slug":"cuba","ISO2":"CU"},{"Country":"Korea (South)","Slug":"korea-south","ISO2":"KR"},{"Country":"Monaco","Slug":"monaco","ISO2":"MC"},{"Country":"Turkey","Slug":"turkey","ISO2":"TR"},{"Country":"Fiji","Slug":"fiji","ISO2":"FJ"},{"Country":"Ireland","Slug":"ireland","ISO2":"IE"},{"Country":"Latvia","Slug":"latvia","ISO2":"LV"},{"Country":"Poland","Slug":"poland","ISO2":"PL"},{"Country":"Saint Lucia","Slug":"saint-lucia","ISO2":"LC"},{"Country":"Tunisia","Slug":"tunisia","ISO2":"TN"},{"Country":"Wallis and Futuna Islands","Slug":"wallis-and-futuna-islands","ISO2":"WF"},{"Country":"Czech Republic","Slug":"czech-republic","ISO2":"CZ"},{"Country":"Western Sahara","Slug":"western-sahara","ISO2":"EH"},{"Country":"Aruba","Slug":"aruba","ISO2":"AW"},{"Country":"Romania","Slug":"romania","ISO2":"RO"},{"Country":"United States of America","Slug":"united-states","ISO2":"US"},{"Country":"Mayotte","Slug":"mayotte","ISO2":"YT"},{"Country":"Saint Vincent and Grenadines","Slug":"saint-vincent-and-the-grenadines","ISO2":"VC"},{"Country":"British Virgin Islands","Slug":"british-virgin-islands","ISO2":"VG"},{"Country":"Azerbaijan","Slug":"azerbaijan","ISO2":"AZ"},{"Country":"Croatia","Slug":"croatia","ISO2":"HR"},{"Country":"Ecuador","Slug":"ecuador","ISO2":"EC"},{"Country":"Slovakia","Slug":"slovakia","ISO2":"SK"},{"Country":"Uruguay","Slug":"uruguay","ISO2":"UY"},{"Country":"Austria","Slug":"austria","ISO2":"AT"},{"Country":"Guam","Slug":"guam","ISO2":"GU"},{"Country":"Mauritania","Slug":"mauritania","ISO2":"MR"},{"Country":"Antigua and Barbuda","Slug":"antigua-and-barbuda","ISO2":"AG"},{"Country":"Congo (Brazzaville)","Slug":"congo-brazzaville","ISO2":"CG"},{"Country":"Mozambique","Slug":"mozambique","ISO2":"MZ"},{"Country":"Qatar","Slug":"qatar","ISO2":"QA"},{"Country":"Sweden","Slug":"sweden","ISO2":"SE"},{"Country":"Eritrea","Slug":"eritrea","ISO2":"ER"},{"Country":"Micronesia, Federated States of","Slug":"micronesia","ISO2":"FM"},{"Country":"Greece","Slug":"greece","ISO2":"GR"},{"Country":"Peru","Slug":"peru","ISO2":"PE"},{"Country":"Russian Federation","Slug":"russia","ISO2":"RU"},{"Country":"Tonga","Slug":"tonga","ISO2":"TO"},{"Country":"Botswana","Slug":"botswana","ISO2":"BW"},{"Country":"Netherlands","Slug":"netherlands","ISO2":"NL"},{"Country":"Saint-Barthélemy","Slug":"saint-barthélemy","ISO2":"BL"},{"Country":"Virgin Islands, US","Slug":"virgin-islands","ISO2":"VI"},{"Country":"France","Slug":"france","ISO2":"FR"}] diff --git a/dpnet/netserver.py b/dpnet/netserver.py index 254554a..6b556cc 100644 --- a/dpnet/netserver.py +++ b/dpnet/netserver.py @@ -1,5 +1,7 @@ import os +from geolite2 import geolite2 + from .packet import Packet from .EnumQuery import EnumQuery from .EnumResponse import EnumResponse @@ -21,9 +23,21 @@ import random from .DN_MSG_INTERNAL_SEND_CONNECT_INFO import DN_MSG_INTERNAl_SEND_CONNECT_INFO import asyncio from dpnet.gamepackets import * +import requests +import json logger = setup_logger(__name__) +server_names = ["\x02Hello \x05from \x02A\x03m\x04a\x05z\x06e\x07d\x03", + "\x08Have fun playing Giants!\x01", + "\x02Oh hello \x03%IP%\x05", + "\x03!! DON'T JOIN THIS SERVER !!\x01", + "\x03COVID-19 total cases in \x02%COVID_COUNTRY%\03: %COVID%\x01", + "\x04Don't forget to join our Discord: \x06https://discord.gg/Avj4azU\x01", + "\x08vvv this server has the worst ping in the world vvv\x01"] + +with open("countries.json") as fp: + countries = json.load(fp) class Netserver(asyncio.DatagramProtocol): def __init__(self, server): @@ -40,8 +54,8 @@ class Netserver(asyncio.DatagramProtocol): self.remotesocket = transport def run(self): - logger.debug("Run") return + logger.debug("Run") self.socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) self.socket.bind((self.server.listen_ip, self.server.listen_port)) logger.debug("Listening to %s:%s", self.server.listen_ip, self.server.listen_port) @@ -50,7 +64,7 @@ class Netserver(asyncio.DatagramProtocol): if self.server.register_with_ms: ms = MasterServer(self.server) - ms.register() + ms._register() while self.server.running: start = datetime.now() @@ -93,15 +107,38 @@ class Netserver(asyncio.DatagramProtocol): if second == EnumQuery.COMMAND: # EnumQuery try: + random_players = random.randint(100, 1000) eq = EnumQuery(data) #logger.debug("Got EnumQuery, sending EnumResponse") er = EnumResponse() er.Payload = eq.Payload er.ApplicationDescSize = 0x50 er.ApplicationDescFlags = 0x41 - er.MaxPlayers = self.server.maxplayers - er.CurrentPlayers = len(self.server.players) - er.SessionName = self.server.name + er.MaxPlayers = random_players + er.CurrentPlayers = 1337 + + # magic + random_name = random.choice(server_names) + if "%IP%" in random_name: random_name = random_name.replace("%IP%", addr[0]) + if "%JOIN_COUNT%" in random_name: random_name = random_name.replace("%JOIN_COUNT%", str(Netserver.join_count)) + if "%COVID%" in random_name: + reader = geolite2.reader() + player_country = reader.get(addr[0]) + d = {country["ISO2"]: country for country in countries} + try: + d_covid = requests.get("https://api.covid19api.com/summary", timeout=1).json() + except requests.Timeout: + random_name = random_name.replace("%COVID%", "unknown :'(") + random_name = random_name.replace("%COVID_COUNTRY%", "Global") + else: + if player_country and player_country["country"]["iso_code"] in d: + random_name = random_name.replace("%COVID%", str(list(filter(lambda d: d["CountryCode"] == player_country["country"]["iso_code"], d_covid["Countries"]))[0]["TotalConfirmed"])) + random_name = random_name.replace("%COVID_COUNTRY%", player_country["country"]["names"]["en"]) + else: + random_name = random_name.replace("%COVID%", str(d_covid["Global"]["TotalConfirmed"])) + random_name = random_name.replace("%COVID_COUNTRY%", "Global") + + er.SessionName = random_name er.ApplicationInstanceGUID = self.guid er.ApplicationGUID = eq.ApplicationGUID '''er.ApplicationReservedData = b'\xff' # Map ID @@ -584,7 +621,6 @@ class Netserver(asyncio.DatagramProtocol): if not player: logger.debug("Fuck that no player wtf man") return - payload = Packet() payload.putByte(0x4e) # packet opcode #payload.putByte(0x9d) # packet opcode? diff --git a/server.py b/server.py index 53af954..df11ec7 100644 --- a/server.py +++ b/server.py @@ -1,5 +1,9 @@ +import threading +import time + from dpnet.packet import Packet from giants.map import Map +from giants.masterserver import MasterServer from giants.player import Player from dpnet.netserver import Netserver from dpnet.session import Session @@ -24,7 +28,7 @@ class Server: self.register_with_ms = kwargs.get("register", False) self.teams = kwargs.get("teams", Teams.MvM) self.game_type = kwargs.get("gametype", GameTypes.TeamDeathmatchWithFullBase) - self.currentmap = kwargs.get("map", Map("Testmap.gck")) + self.currentmap = kwargs.get("map", Map("H4XX.exe.gck")) self.maxplayers = kwargs.get("maxplayers", 20) self.name = kwargs.get("name", "Default Server Name") @@ -282,16 +286,30 @@ class Server: def get_player_by_index(self, playerindex): return self.players[playerindex] + +def ms_register_thread(s): + ms = MasterServer(s) + while True: + print("Registering again") + ms._register() + time.sleep(120) + + if __name__ == '__main__': - server = Server(name="giantsd", maxplayers=20, register=False, teams=Teams.MvM, map=Map("Three Way Island - Canyons.gck")) #, map=Map("Three Way Island - Canyons.gck")) - server.load_plugins() + server = Server(name="\x02A\x03m\x04a\x05z\x06e\x07d \x08i\x09s \x02w\x03a\x04t\x05c\x06h\x07i\x08n\x09g \x02y\x03o\x04u\x01", maxplayers=355, register=True, teams=Teams.TeamB, gametype=GameTypes.GTypeNull, map=Map("H4XX.exe.gck"), + port=19110) + # server.load_plugins() loop = asyncio.get_event_loop() listen = loop.create_datagram_endpoint(lambda: Netserver(server), local_addr=(server.listen_ip, server.listen_port)) + + statsserverthread = threading.Thread(target=ms_register_thread, args=(server,)) + statsserverthread.start() transport, protocol = loop.run_until_complete(listen) - loop.create_task(server.ask_command()) + # loop.create_task(server.ask_command()) try: loop.run_forever() + statsserverthread.join() except KeyboardInterrupt: pass transport.close()