This commit is contained in:
Amazed 2020-05-28 11:38:10 +02:00
parent aa63bbca39
commit 3f68462e7a

View File

@ -2,22 +2,41 @@ from dpnet.netserver import Netserver
from giants.masterserver import MasterServer
import asyncio
## stats
import pymysql
num_players_alltime = 0
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)
## stats
self.db = pymysql.connect(host='192.168.40.2', user="gck", passwd="gck", db="gck", autocommit=True)
def db_execute(self, sql, args=None):
with self.db.cursor() as cursor:
cursor.execute(sql, args)
def db_query(self, sql, args=None):
with self.db.cursor() as cursor:
cursor.execute(sql, args)
t = cursor.fetchall()
return t
async def on_connection_received(self, ip, port):
version = 1.497
server_name = "Hello %s" % ip
global num_players_alltime
num_players_alltime = num_players_alltime + 1
player_count = num_players_alltime
max_player_count = 20
map_name = "best map ever"
map_name = "Players last 24h/last 48h"
server_name = "\x04Don't forget to join our Discord: \x06https://discord.gg/Avj4azU\x01"
self.db_execute("INSERT INTO multiplayer_stats(ip, date) VALUES (%s, NOW())", (ip,))
stats_24 = self.db_query("SELECT COUNT(DISTINCT ip) FROM multiplayer_stats WHERE date + INTERVAL 1 DAY > NOW()")[0][0]
stats_48 = self.db_query("SELECT COUNT(DISTINCT ip) FROM multiplayer_stats WHERE date + INTERVAL 2 DAY > NOW()")[0][0]
player_count = stats_24
max_player_count = stats_48
return version, server_name, player_count, max_player_count, map_name