Merged with upstream

This commit is contained in:
Sunpy
2018-04-08 21:20:26 +02:00
11 changed files with 114 additions and 44 deletions

View File

@@ -1,6 +1,9 @@
import copy
import json
import threading
import time
from common.log import logUtils as log
from constants import dataTypes
from constants import matchModModes
@@ -62,6 +65,7 @@ class match:
self.isLocked = False # if True, users can't change slots/teams. Used in tourney matches
self.isStarting = False
self._lock = threading.Lock()
self.createTime = int(time.time())
# Create all slots and reset them
self.slots = []

View File

@@ -1,3 +1,6 @@
import threading
import time
from objects import match
from objects import glob
from constants import serverPackets
@@ -62,4 +65,32 @@ class matchList:
# Send match dispose packet to everyone in lobby
glob.streams.broadcast("lobby", serverPackets.disposeMatch(matchID))
del self.matches[matchID]
log.info("MPROOM{}: Room disposed manually".format(_match.matchID))
log.info("MPROOM{}: Room disposed manually".format(_match.matchID))
def cleanupLoop(self):
"""
Start match cleanup loop.
Empty matches that have been created more than 60 seconds ago will get deleted.
Useful when people create useless lobbies with `!mp make`.
The check is done every 30 seconds.
This method starts an infinite loop, call it only once!
:return:
"""
log.debug("Checking empty matches")
t = int(time.time())
emptyMatches = []
# Collect all empty matches
for key, m in self.matches.items():
if [x for x in m.slots if x.user is not None]:
continue
if t - m.createTime >= 120:
log.debug("Match #{} marked for cleanup".format(m.matchID))
emptyMatches.append(m.matchID)
# Dispose all empty matches
for matchID in emptyMatches:
self.disposeMatch(matchID)
# Schedule a new check (endless loop)
threading.Timer(30, self.cleanupLoop).start()

View File

@@ -171,19 +171,16 @@ class tokenList:
for _, value in self.tokens.items():
value.enqueue(packet)
def usersTimeoutCheckLoop(self, timeoutTime = 100, checkTime = 100):
def usersTimeoutCheckLoop(self):
"""
Start timed out users disconnect loop.
This function will be called every `checkTime` seconds and so on, forever.
CALL THIS FUNCTION ONLY ONCE!
:param timeoutTime: seconds of inactivity required to disconnect someone. Default: 100
:param checkTime: seconds between loops. Default: 100
:return:
"""
log.debug("Checking timed out clients")
timedOutTokens = [] # timed out users
timeoutLimit = int(time.time())-timeoutTime
timeoutLimit = int(time.time()) - 100
for key, value in self.tokens.items():
# Check timeout (fokabot is ignored)
if value.pingTime < timeoutLimit and value.userID != 999 and value.irc == False and value.tournament == False:
@@ -200,7 +197,7 @@ class tokenList:
del timedOutTokens
# Schedule a new check (endless loop)
threading.Timer(checkTime, self.usersTimeoutCheckLoop, [timeoutTime, checkTime]).start()
threading.Timer(100, self.usersTimeoutCheckLoop).start()
def spamProtectionResetLoop(self):
"""