.BANCHO. .FIX. Don't time out tourney clients
This commit is contained in:
parent
e7b7dc932a
commit
90dfb2c705
|
@ -16,7 +16,7 @@ def handle(userToken, _=None):
|
||||||
# the old logout packet will still be in the queue and will be sent to
|
# the old logout packet will still be in the queue and will be sent to
|
||||||
# the server, so we accept logout packets sent at least 5 seconds after login
|
# the server, so we accept logout packets sent at least 5 seconds after login
|
||||||
# if the user logs out before 5 seconds, he will be disconnected later with timeout check
|
# if the user logs out before 5 seconds, he will be disconnected later with timeout check
|
||||||
if (int(time.time()-userToken.loginTime) >= 5 or userToken.irc) or userToken.tournament:
|
if (int(time.time()-userToken.loginTime) >= 5 or userToken.irc):
|
||||||
# Stop spectating
|
# Stop spectating
|
||||||
userToken.stopSpectating()
|
userToken.stopSpectating()
|
||||||
|
|
||||||
|
@ -41,4 +41,4 @@ def handle(userToken, _=None):
|
||||||
glob.tokens.deleteToken(requestToken)
|
glob.tokens.deleteToken(requestToken)
|
||||||
|
|
||||||
# Console output
|
# Console output
|
||||||
log.info("{} has been disconnected.".format(username))
|
log.info("{} has been disconnected. (logout)".format(username))
|
||||||
|
|
25
handlers/heavyHandler.py
Normal file
25
handlers/heavyHandler.py
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
import tornado.gen
|
||||||
|
import tornado.web
|
||||||
|
from common.web import requestsManager
|
||||||
|
from objects import glob
|
||||||
|
import time
|
||||||
|
|
||||||
|
class handler(requestsManager.asyncRequestHandler):
|
||||||
|
@tornado.web.asynchronous
|
||||||
|
@tornado.gen.engine
|
||||||
|
def asyncGet(self):
|
||||||
|
if not glob.debug:
|
||||||
|
self.write("Nope")
|
||||||
|
return
|
||||||
|
time.sleep(0.5)
|
||||||
|
self.write("meemmeemmeemmeemmeemmeemmeemmeemmeemmeemmeemmeemmeemmeemmeemmeemmeemmeemmeemmeemmeemmeemmeemmeemmeemmeemmeemmeem")
|
||||||
|
self.set_status(200)
|
||||||
|
self.add_header("cho-token", "tua madre")
|
||||||
|
self.add_header("cho-protocol", "19")
|
||||||
|
self.add_header("Connection", "keep-alive")
|
||||||
|
self.add_header("Keep-Alive", "timeout=5, max=100")
|
||||||
|
self.add_header("Content-Type", "text/html; charset=UTF-8")
|
||||||
|
#glob.db.fetchAll("SELECT SQL_NO_CACHE * FROM beatmaps")
|
||||||
|
#glob.db.fetchAll("SELECT SQL_NO_CACHE * FROM users")
|
||||||
|
#glob.db.fetchAll("SELECT SQL_NO_CACHE * FROM scores")
|
||||||
|
#self.write("ibmd")
|
|
@ -195,9 +195,6 @@ class handler(SentryMixin, requestsManager.asyncRequestHandler):
|
||||||
responseTokenString = userToken.token
|
responseTokenString = userToken.token
|
||||||
responseData = userToken.queue
|
responseData = userToken.queue
|
||||||
userToken.resetQueue()
|
userToken.resetQueue()
|
||||||
|
|
||||||
# Update ping time for timeout
|
|
||||||
userToken.updatePingTime()
|
|
||||||
except exceptions.tokenNotFoundException:
|
except exceptions.tokenNotFoundException:
|
||||||
# Token not found. Disconnect that user
|
# Token not found. Disconnect that user
|
||||||
responseData = serverPackets.loginError()
|
responseData = serverPackets.loginError()
|
||||||
|
@ -207,6 +204,9 @@ class handler(SentryMixin, requestsManager.asyncRequestHandler):
|
||||||
finally:
|
finally:
|
||||||
# Unlock token
|
# Unlock token
|
||||||
if userToken is not None:
|
if userToken is not None:
|
||||||
|
# Update ping time for timeout
|
||||||
|
userToken.updatePingTime()
|
||||||
|
# Release token lock
|
||||||
userToken.lock.release()
|
userToken.lock.release()
|
||||||
|
|
||||||
if glob.outputRequestTime:
|
if glob.outputRequestTime:
|
||||||
|
|
|
@ -190,7 +190,7 @@ class token:
|
||||||
self.enqueue(serverPackets.fellowSpectatorJoined(glob.tokens.tokens[i].userID))
|
self.enqueue(serverPackets.fellowSpectatorJoined(glob.tokens.tokens[i].userID))
|
||||||
|
|
||||||
# Log
|
# Log
|
||||||
log.info("{} is spectating {}".format(self.username, userUtils.getUsername(host.username)))
|
log.info("{} is spectating {}".format(self.username, host.username))
|
||||||
|
|
||||||
def stopSpectating(self):
|
def stopSpectating(self):
|
||||||
# Remove our userID from host's spectators
|
# Remove our userID from host's spectators
|
||||||
|
@ -316,14 +316,14 @@ class token:
|
||||||
# Set usertoken match to -1
|
# Set usertoken match to -1
|
||||||
self.matchID = -1
|
self.matchID = -1
|
||||||
|
|
||||||
def kick(self, message="You have been kicked from the server. Please login again."):
|
def kick(self, message="You have been kicked from the server. Please login again.", reason="kick"):
|
||||||
"""
|
"""
|
||||||
Kick this user from the server
|
Kick this user from the server
|
||||||
|
|
||||||
message -- Notification message to send to this user. Optional.
|
message -- Notification message to send to this user. Optional.
|
||||||
"""
|
"""
|
||||||
# Send packet to target
|
# Send packet to target
|
||||||
log.info("{} has been disconnected. (kick)".format(self.username))
|
log.info("{} has been disconnected. ({})".format(self.username, reason))
|
||||||
if message != "":
|
if message != "":
|
||||||
self.enqueue(serverPackets.notification(message))
|
self.enqueue(serverPackets.notification(message))
|
||||||
self.enqueue(serverPackets.loginFailed())
|
self.enqueue(serverPackets.loginFailed())
|
||||||
|
|
|
@ -2,6 +2,8 @@ import threading
|
||||||
import time
|
import time
|
||||||
|
|
||||||
from common.ripple import userUtils
|
from common.ripple import userUtils
|
||||||
|
from common.log import logUtils as log
|
||||||
|
from constants import serverPackets
|
||||||
from events import logoutEvent
|
from events import logoutEvent
|
||||||
from objects import glob
|
from objects import glob
|
||||||
from objects import osuToken
|
from objects import osuToken
|
||||||
|
@ -108,7 +110,7 @@ class tokenList:
|
||||||
for key, value in list(self.tokens.items()):
|
for key, value in list(self.tokens.items()):
|
||||||
if value.userID == userID:
|
if value.userID == userID:
|
||||||
# Delete this token from the dictionary
|
# Delete this token from the dictionary
|
||||||
self.tokens[key].kick("You have logged in from somewhere else. You can't connect to Bancho/IRC from more than one device at the same time.")
|
self.tokens[key].kick("You have logged in from somewhere else. You can't connect to Bancho/IRC from more than one device at the same time.", "kicked, multiple clients")
|
||||||
|
|
||||||
def multipleEnqueue(self, packet, who, but = False):
|
def multipleEnqueue(self, packet, who, but = False):
|
||||||
"""
|
"""
|
||||||
|
@ -146,11 +148,12 @@ class tokenList:
|
||||||
timeoutTime - seconds of inactivity required to disconnect someone (Default: 100)
|
timeoutTime - seconds of inactivity required to disconnect someone (Default: 100)
|
||||||
checkTime - seconds between loops (Default: 100)
|
checkTime - seconds between loops (Default: 100)
|
||||||
"""
|
"""
|
||||||
|
log.debug("Checking timed out clients")
|
||||||
timedOutTokens = [] # timed out users
|
timedOutTokens = [] # timed out users
|
||||||
timeoutLimit = time.time()-timeoutTime
|
timeoutLimit = int(time.time())-timeoutTime
|
||||||
for key, value in self.tokens.items():
|
for key, value in self.tokens.items():
|
||||||
# Check timeout (fokabot is ignored)
|
# Check timeout (fokabot is ignored)
|
||||||
if value.pingTime < timeoutLimit and value.userID != 999 and value.irc == False:
|
if value.pingTime < timeoutLimit and value.userID != 999 and value.irc == False and value.tournament == False:
|
||||||
# That user has timed out, add to disconnected tokens
|
# That user has timed out, add to disconnected tokens
|
||||||
# We can't delete it while iterating or items() throws an error
|
# We can't delete it while iterating or items() throws an error
|
||||||
timedOutTokens.append(key)
|
timedOutTokens.append(key)
|
||||||
|
@ -158,6 +161,8 @@ class tokenList:
|
||||||
# Delete timed out users from self.tokens
|
# Delete timed out users from self.tokens
|
||||||
# i is token string (dictionary key)
|
# i is token string (dictionary key)
|
||||||
for i in timedOutTokens:
|
for i in timedOutTokens:
|
||||||
|
log.debug("{} timed out!!".format(self.tokens[i].username))
|
||||||
|
self.tokens[i].enqueue(serverPackets.notification("Your connection to the server timed out."))
|
||||||
logoutEvent.handle(self.tokens[i], None)
|
logoutEvent.handle(self.tokens[i], None)
|
||||||
|
|
||||||
# Schedule a new check (endless loop)
|
# Schedule a new check (endless loop)
|
||||||
|
|
4
pep.py
4
pep.py
|
@ -24,6 +24,7 @@ from handlers import apiServerStatusHandler
|
||||||
from handlers import apiVerifiedStatusHandler
|
from handlers import apiVerifiedStatusHandler
|
||||||
from handlers import ciTriggerHandler
|
from handlers import ciTriggerHandler
|
||||||
from handlers import mainHandler
|
from handlers import mainHandler
|
||||||
|
from handlers import heavyHandler
|
||||||
from helpers import configHelper
|
from helpers import configHelper
|
||||||
from helpers import consoleHelper
|
from helpers import consoleHelper
|
||||||
from helpers import systemHelper as system
|
from helpers import systemHelper as system
|
||||||
|
@ -42,7 +43,8 @@ def make_app():
|
||||||
(r"/api/v1/serverStatus", apiServerStatusHandler.handler),
|
(r"/api/v1/serverStatus", apiServerStatusHandler.handler),
|
||||||
(r"/api/v1/ciTrigger", ciTriggerHandler.handler),
|
(r"/api/v1/ciTrigger", ciTriggerHandler.handler),
|
||||||
(r"/api/v1/verifiedStatus", apiVerifiedStatusHandler.handler),
|
(r"/api/v1/verifiedStatus", apiVerifiedStatusHandler.handler),
|
||||||
(r"/api/v1/fokabotMessage", apiFokabotMessageHandler.handler)
|
(r"/api/v1/fokabotMessage", apiFokabotMessageHandler.handler),
|
||||||
|
(r"/stress", heavyHandler.handler)
|
||||||
])
|
])
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
Loading…
Reference in New Issue
Block a user