Compare commits

..

2 Commits

Author SHA1 Message Date
acf7392d86 fix 2020-04-22 13:04:15 +02:00
a5d2629096 stuff 2020-04-22 02:22:34 +02:00
3 changed files with 68 additions and 10 deletions

1
countries.json Normal file

File diff suppressed because one or more lines are too long

View File

@ -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?

View File

@ -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,33 @@ class Server:
def get_player_by_index(self, playerindex):
return self.players[playerindex]
def ms_register_thread(s):
ms = MasterServer(s)
while True:
try:
print("Registering again")
ms._register()
except:
traceback.print_exc()
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()