pep.py/events/logoutEvent.py

45 lines
1.3 KiB
Python
Raw Normal View History

2016-04-19 17:40:59 +00:00
import time
2016-10-02 20:48:14 +00:00
from common.log import logUtils as log
from constants import serverPackets
from helpers import chatHelper as chat
2016-10-02 20:48:14 +00:00
from objects import glob
2016-04-19 17:40:59 +00:00
def handle(userToken, _=None):
2016-04-19 17:40:59 +00:00
# get usertoken data
userID = userToken.userID
username = userToken.username
requestToken = userToken.token
# Big client meme here. If someone logs out and logs in right after,
# 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
# 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):
# Stop spectating
userToken.stopSpectating()
2016-04-19 17:40:59 +00:00
# Part matches
userToken.leaveMatch()
2016-04-19 17:40:59 +00:00
# Part all joined channels
for i in userToken.joinedChannels:
chat.partChannel(token=userToken, channel=i)
2016-04-19 17:40:59 +00:00
# Leave all joined streams
userToken.leaveAllStreams()
2016-04-19 17:40:59 +00:00
# Enqueue our disconnection to everyone else
glob.streams.broadcast("main", serverPackets.userLogout(userID))
2016-04-19 17:40:59 +00:00
# Disconnect from IRC if needed
if userToken.irc == True and glob.irc == True:
glob.ircServer.forceDisconnection(userToken.username)
2016-04-19 17:40:59 +00:00
# Delete token
glob.tokens.deleteToken(requestToken)
# Console output
log.info("{} has been disconnected. (logout)".format(username))