.BANCHO. .FIX. Code cleaning
This commit is contained in:
@@ -3,7 +3,7 @@ from constants import serverPackets
|
||||
from constants import exceptions
|
||||
from helpers import logHelper as log
|
||||
|
||||
def handle(userToken, packetData):
|
||||
def handle(userToken, _):
|
||||
# get usertoken data
|
||||
userID = userToken.userID
|
||||
|
||||
|
@@ -11,13 +11,13 @@ def handle(userToken, packetData):
|
||||
username = userToken.username
|
||||
|
||||
# Make sure we are not banned
|
||||
if userHelper.isBanned(userID) == True:
|
||||
if userHelper.isBanned(userID):
|
||||
userToken.enqueue(serverPackets.loginBanned())
|
||||
return
|
||||
|
||||
# Send restricted message if needed
|
||||
if userToken.restricted == False:
|
||||
if userHelper.isRestricted(userID) == True:
|
||||
if not userToken.restricted:
|
||||
if userHelper.isRestricted(userID):
|
||||
userToken.setRestricted()
|
||||
|
||||
# Change action packet
|
||||
@@ -55,7 +55,7 @@ def handle(userToken, packetData):
|
||||
else:
|
||||
token = glob.tokens.getTokenFromUserID(i)
|
||||
|
||||
if token != None:
|
||||
if token is not None:
|
||||
# Force our own packet
|
||||
force = True if token.userID == userID else False
|
||||
token.enqueue(serverPackets.userPanel(userID, force))
|
||||
|
@@ -40,7 +40,7 @@ def handle(userToken, packetData):
|
||||
|
||||
# Set slot mods
|
||||
slotID = match.getUserSlotID(userID)
|
||||
if slotID != None:
|
||||
if slotID is not None:
|
||||
match.setSlotMods(slotID, packetData["mods"])
|
||||
else:
|
||||
# Not freemod, set match mods
|
||||
|
@@ -34,7 +34,7 @@ def handle(userToken, packetData):
|
||||
for i in glob.matches.usersInLobby:
|
||||
# Make sure this user is still connected
|
||||
token = glob.tokens.getTokenFromUserID(i)
|
||||
if token != None:
|
||||
if token is not None:
|
||||
token.enqueue(serverPackets.createMatch(matchID))
|
||||
|
||||
# Console output
|
||||
|
@@ -45,7 +45,7 @@ def joinMatch(userToken, matchID, password, isPasswordHashed = False):
|
||||
result = match.userJoin(userID)
|
||||
|
||||
# Check if we've joined the match successfully
|
||||
if result == False:
|
||||
if not result:
|
||||
raise exceptions.matchJoinErrorException
|
||||
|
||||
# Match joined, set matchID for usertoken
|
||||
|
@@ -52,10 +52,10 @@ def handle(tornadoRequest):
|
||||
username = str(loginData[0])
|
||||
userID = userHelper.getID(username)
|
||||
|
||||
if userID == False:
|
||||
if not userID:
|
||||
# Invalid username
|
||||
raise exceptions.loginFailedException()
|
||||
if userHelper.checkLogin(userID, loginData[1]) == False:
|
||||
if not userHelper.checkLogin(userID, loginData[1]):
|
||||
# Invalid password
|
||||
raise exceptions.loginFailedException()
|
||||
|
||||
@@ -65,7 +65,7 @@ def handle(tornadoRequest):
|
||||
raise exceptions.loginBannedException()
|
||||
|
||||
# 2FA check
|
||||
if userHelper.check2FA(userID, requestIP) == True:
|
||||
if userHelper.check2FA(userID, requestIP):
|
||||
log.warning("Need 2FA check for user {}".format(loginData[0]))
|
||||
raise exceptions.need2FAException()
|
||||
|
||||
@@ -74,7 +74,7 @@ def handle(tornadoRequest):
|
||||
# Verify this user (if pending activation)
|
||||
firstLogin = False
|
||||
if priv & privileges.USER_PENDING_VERIFICATION > 0 or userHelper.hasVerifiedHardware(userID) == False:
|
||||
if userHelper.verifyUser(userID, clientData) == True:
|
||||
if userHelper.verifyUser(userID, clientData):
|
||||
# Valid account
|
||||
log.info("Account {} verified successfully!".format(userID))
|
||||
glob.verifiedCache[str(userID)] = 1
|
||||
@@ -92,7 +92,7 @@ def handle(tornadoRequest):
|
||||
# This is false only if HWID is empty
|
||||
# if HWID is banned, we get restricted so there's no
|
||||
# need to deny bancho access
|
||||
if hwAllowed == False:
|
||||
if not hwAllowed:
|
||||
raise exceptions.haxException()
|
||||
|
||||
# Log user IP
|
||||
@@ -115,11 +115,11 @@ def handle(tornadoRequest):
|
||||
# Get supporter/GMT
|
||||
userGMT = False
|
||||
userSupporter = True
|
||||
if responseToken.admin == True:
|
||||
if responseToken.admin:
|
||||
userGMT = True
|
||||
|
||||
# Server restarting check
|
||||
if glob.restarting == True:
|
||||
if glob.restarting:
|
||||
raise exceptions.banchoRestartingException()
|
||||
|
||||
# Send login notification before maintenance message
|
||||
@@ -127,8 +127,8 @@ def handle(tornadoRequest):
|
||||
responseToken.enqueue(serverPackets.notification(glob.banchoConf.config["loginNotification"]))
|
||||
|
||||
# Maintenance check
|
||||
if glob.banchoConf.config["banchoMaintenance"] == True:
|
||||
if userGMT == False:
|
||||
if glob.banchoConf.config["banchoMaintenance"]:
|
||||
if not userGMT:
|
||||
# We are not mod/admin, delete token, send notification and logout
|
||||
glob.tokens.deleteToken(responseTokenString)
|
||||
raise exceptions.banchoMaintenanceException()
|
||||
@@ -152,7 +152,7 @@ def handle(tornadoRequest):
|
||||
chat.joinChannel(token=responseToken, channel="#announce")
|
||||
|
||||
# Join admin channel if we are an admin
|
||||
if responseToken.admin == True:
|
||||
if responseToken.admin:
|
||||
chat.joinChannel(token=responseToken, channel="#admin")
|
||||
|
||||
# Output channels info
|
||||
@@ -171,7 +171,7 @@ def handle(tornadoRequest):
|
||||
responseToken.enqueue(serverPackets.onlineUsers())
|
||||
|
||||
# Get location and country from ip.zxq.co or database
|
||||
if glob.localize == True:
|
||||
if glob.localize:
|
||||
# Get location and country from IP
|
||||
location = locationHelper.getLocation(requestIP)
|
||||
countryLetters = locationHelper.getCountry(requestIP)
|
||||
@@ -192,7 +192,7 @@ def handle(tornadoRequest):
|
||||
userHelper.setCountry(userID, countryLetters)
|
||||
|
||||
# Send to everyone our userpanel if we are not restricted
|
||||
if responseToken.restricted == False:
|
||||
if not responseToken.restricted:
|
||||
glob.tokens.enqueueAll(serverPackets.userPanel(userID))
|
||||
|
||||
# Set reponse data to right value and reset our queue
|
||||
@@ -242,4 +242,4 @@ def handle(tornadoRequest):
|
||||
log.info(msg, "bunker")
|
||||
|
||||
# Return token string and data
|
||||
return (responseTokenString, responseData)
|
||||
return responseTokenString, responseData
|
@@ -27,5 +27,5 @@ def handle(userToken, packetData):
|
||||
for i in range(0,16):
|
||||
if match.slots[i].userID > -1 and match.slots[i].status == slotStatuses.playing:
|
||||
token = glob.tokens.getTokenFromUserID(match.slots[i].userID)
|
||||
if token != None:
|
||||
if token is not None:
|
||||
token.enqueue(serverPackets.matchFrames(slotID, packetData))
|
||||
|
@@ -12,5 +12,5 @@ def handle(userToken, _):
|
||||
|
||||
# Get our slotID and change ready status
|
||||
slotID = match.getUserSlotID(userID)
|
||||
if slotID != None:
|
||||
if slotID is not None:
|
||||
match.toggleSlotReady(slotID)
|
||||
|
@@ -23,7 +23,7 @@ def handle(userToken, _):
|
||||
return
|
||||
|
||||
# Make sure we have enough players
|
||||
if (match.countUsers() < 2 or match.checkTeams() == False):
|
||||
if match.countUsers() < 2 or match.checkTeams() == False:
|
||||
return
|
||||
|
||||
# Change inProgress value
|
||||
@@ -41,7 +41,7 @@ def handle(userToken, _):
|
||||
for i in range(0,16):
|
||||
if (match.slots[i].status & slotStatuses.playing) > 0 and match.slots[i].userID != -1:
|
||||
token = glob.tokens.getTokenFromUserID(match.slots[i].userID)
|
||||
if token != None:
|
||||
if token is not None:
|
||||
token.enqueue(serverPackets.matchStart(matchID))
|
||||
|
||||
# Send updates
|
||||
|
@@ -15,7 +15,7 @@ def handle(userToken, packetData):
|
||||
spectatorToken = glob.tokens.getTokenFromUserID(i)
|
||||
|
||||
# Make sure the token exists
|
||||
if spectatorToken == None:
|
||||
if spectatorToken is None:
|
||||
raise exceptions.stopSpectating
|
||||
|
||||
# Make sure this user is spectating us
|
||||
|
@@ -26,7 +26,7 @@ def handle(userToken, packetData):
|
||||
|
||||
# Get host token
|
||||
targetToken = glob.tokens.getTokenFromUserID(packetData["userID"])
|
||||
if targetToken == None:
|
||||
if targetToken is None:
|
||||
raise exceptions.tokenNotFoundException
|
||||
|
||||
# Add us to host's spectators
|
||||
|
Reference in New Issue
Block a user