remove recursion

This commit is contained in:
Alberto Xamin 2023-01-21 14:41:53 +00:00
parent 1b263adc80
commit 28a093d337
No known key found for this signature in database
GPG Key ID: 4F026F48309500A2

View File

@ -27,6 +27,10 @@ Metrics.init()
sio = socketio.Server(cors_allowed_origins="*") sio = socketio.Server(cors_allowed_origins="*")
G.sio = sio G.sio = sio
import faulthandler
faulthandler.enable()
static_files={ static_files={
'/': {'content_type': 'text/html', 'filename': 'index.html'}, '/': {'content_type': 'text/html', 'filename': 'index.html'},
'/game': {'content_type': 'text/html', 'filename': 'index.html'}, '/game': {'content_type': 'text/html', 'filename': 'index.html'},
@ -73,7 +77,7 @@ def bang_handler(func):
def advertise_lobbies(): def advertise_lobbies():
sio.emit('lobbies', room='lobby', data=[{'name': g.name, 'players': len(g.players), 'locked': g.password != ''} for g in games if not g.started and len(g.players) < 10 and not g.is_hidden]) sio.emit('lobbies', room='lobby', data=[{'name': g.name, 'players': len(g.players), 'locked': g.password != ''} for g in games if not g.started and len(g.players) < 10 and not g.is_hidden])
sio.emit('spectate_lobbies', room='lobby', data=[{'name': g.name, 'players': len(g.players), 'locked': g.password != ''} for g in games if g.started and not g.is_hidden]) sio.emit('spectate_lobbies', room='lobby', data=[{'name': g.name, 'players': len(g.players), 'locked': g.password != ''} for g in games if g.started and not g.is_hidden and len(g.players) > 0])
Metrics.send_metric('lobbies', points=[sum(not g.is_replay for g in games)]) Metrics.send_metric('lobbies', points=[sum(not g.is_replay for g in games)])
Metrics.send_metric('online_players', points=[online_players]) Metrics.send_metric('online_players', points=[online_players])
@ -777,10 +781,10 @@ def discord_auth(sid, data):
def pool_metrics(): def pool_metrics():
sio.sleep(60) while True:
Metrics.send_metric('lobbies', points=[sum(not g.is_replay for g in games)]) sio.sleep(60)
Metrics.send_metric('online_players', points=[online_players]) Metrics.send_metric('lobbies', points=[sum(not g.is_replay for g in games)])
pool_metrics() Metrics.send_metric('online_players', points=[online_players])
import urllib.parse import urllib.parse
class CustomProxyFix(object): class CustomProxyFix(object):
@ -806,11 +810,11 @@ discord_cs = 'Mc8ZlMQhayzi1eOqWFtGHs3L0iXCzaEu'
import pickle import pickle
def save_games(): def save_games():
global save_lock global save_lock
if not save_lock: while True:
sio.sleep(2) if not save_lock:
with open('games.pickle', 'wb') as f: sio.sleep(2)
pickle.dump([g for g in games if g.started and not g.is_replay], f) with open('games.pickle', 'wb') as f:
save_games() pickle.dump([g for g in games if g.started and not g.is_replay], f)
if __name__ == '__main__': if __name__ == '__main__':
if os.path.exists('games.pickle'): if os.path.exists('games.pickle'):