forked from hipstercat/giantsd
prod
This commit is contained in:
parent
0636f72717
commit
0ffcb98d83
@ -1,6 +1,7 @@
|
|||||||
import socket
|
import socket
|
||||||
import threading
|
import threading
|
||||||
import time
|
import time
|
||||||
|
import traceback
|
||||||
|
|
||||||
|
|
||||||
class MasterServer:
|
class MasterServer:
|
||||||
@ -18,5 +19,8 @@ class MasterServer:
|
|||||||
def _register(self):
|
def _register(self):
|
||||||
while True:
|
while True:
|
||||||
print("Sending register")
|
print("Sending register")
|
||||||
self.socket.sendto(("0"+str(self.server.listen_port)).encode("ascii"), (self.masterserverip, self.masterserverport))
|
try:
|
||||||
|
self.socket.sendto(("0"+str(self.server.listen_port)).encode("ascii"), (self.masterserverip, self.masterserverport))
|
||||||
|
except:
|
||||||
|
traceback.print_exc()
|
||||||
time.sleep(120)
|
time.sleep(120)
|
||||||
|
29
server.py
29
server.py
@ -11,24 +11,33 @@ class Server:
|
|||||||
def __init__(self, **kwargs):
|
def __init__(self, **kwargs):
|
||||||
self.listen_ip = kwargs.get("ip", "0.0.0.0")
|
self.listen_ip = kwargs.get("ip", "0.0.0.0")
|
||||||
self.listen_port = kwargs.get("port", 19711)
|
self.listen_port = kwargs.get("port", 19711)
|
||||||
self.register_with_ms = kwargs.get("register", False)
|
self.register_with_ms = kwargs.get("register", True)
|
||||||
## stats
|
## stats
|
||||||
self.db = pymysql.connect(host='192.168.40.2', user="gck", passwd="gck", db="gck", autocommit=True)
|
self.db = pymysql.connect(host='192.168.40.2', user="gck", passwd="gck", db="gck", autocommit=True)
|
||||||
|
|
||||||
def db_execute(self, sql, args=None):
|
def db_execute(self, sql, args=None):
|
||||||
with self.db.cursor() as cursor:
|
try:
|
||||||
cursor.execute(sql, args)
|
with self.db.cursor() as cursor:
|
||||||
|
cursor.execute(sql, args)
|
||||||
|
except:
|
||||||
|
self.db = pymysql.connect(host='192.168.40.2', user="gck", passwd="gck", db="gck", autocommit=True)
|
||||||
|
return self.db_execute(sql, args)
|
||||||
|
|
||||||
def db_query(self, sql, args=None):
|
def db_query(self, sql, args=None):
|
||||||
with self.db.cursor() as cursor:
|
try:
|
||||||
cursor.execute(sql, args)
|
with self.db.cursor() as cursor:
|
||||||
t = cursor.fetchall()
|
cursor.execute(sql, args)
|
||||||
return t
|
t = cursor.fetchall()
|
||||||
|
return t
|
||||||
|
except:
|
||||||
|
self.db = pymysql.connect(host='192.168.40.2', user="gck", passwd="gck", db="gck", autocommit=True)
|
||||||
|
return self.db_query(sql, args)
|
||||||
|
|
||||||
|
|
||||||
async def on_connection_received(self, ip, port):
|
async def on_connection_received(self, ip, port):
|
||||||
version = 1.497
|
version = 1.5
|
||||||
map_name = "Players last 24h/last 48h"
|
map_name = "Players last 24h/last 48h"
|
||||||
server_name = "\x04Don't forget to join our Discord: \x06https://discord.gg/Avj4azU\x01"
|
server_name = "\x03!! V1.5 IS OUT !! \x04 Download on Discord: \x06https://discord.gg/Avj4azU\x01"
|
||||||
|
|
||||||
self.db_execute("INSERT INTO multiplayer_stats(ip, date) VALUES (%s, NOW())", (ip,))
|
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_24 = self.db_query("SELECT COUNT(DISTINCT ip) FROM multiplayer_stats WHERE date + INTERVAL 1 DAY > NOW()")[0][0]
|
||||||
@ -41,7 +50,7 @@ class Server:
|
|||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
server = Server()
|
server = Server(port=19110)
|
||||||
if server.register_with_ms:
|
if server.register_with_ms:
|
||||||
ms = MasterServer(server)
|
ms = MasterServer(server)
|
||||||
register_thread = ms.register_and_run()
|
register_thread = ms.register_and_run()
|
||||||
|
Loading…
Reference in New Issue
Block a user