.BANCHO. Add support for locked accounts

This commit is contained in:
Nyo 2016-09-13 11:39:39 +02:00
parent 48925c58c0
commit 14348a68bb
4 changed files with 33 additions and 5 deletions

View File

@ -83,3 +83,6 @@ class haxException(Exception):
class forceUpdateException(Exception):
pass
class loginLockedException(Exception):
pass

View File

@ -16,7 +16,12 @@ def forceUpdate():
def loginBanned():
packets = packetHelper.buildPacket(packetIDs.server_userID, [[-1, dataTypes.SINT32]])
packets += notification("You are banned. You can ask to get unbanned after 1 month since your ban by contacting support@ripple.moe")
packets += notification("You are banned. You can appeal after one month since your ban by sending an email to support@ripple.moe> from the email address you've used to sign up.")
return packets
def loginLocked():
packets = packetHelper.buildPacket(packetIDs.server_userID, [[-1, dataTypes.SINT32]])
packets += notification("Your account is locked. You can't log in, but your profile and scores are still visible from the website. If you want to unlock your account, send an email to support@ripple.moe from the email address you've used to sign up.")
return packets
def loginError():

View File

@ -31,7 +31,7 @@ def handle(tornadoRequest):
# Make sure loginData is valid
if len(loginData) < 3:
raise exceptions.haxException()
raise exceptions.invalidArgumentsException()
# Get HWID, MAC address and more
# Structure (new line = "|", already split)
@ -59,10 +59,12 @@ def handle(tornadoRequest):
# Invalid password
raise exceptions.loginFailedException()
# Make sure we are not banned
# Make sure we are not banned or locked
priv = userHelper.getPrivileges(userID)
if userHelper.isBanned(userID) == True and priv & privileges.USER_PENDING_VERIFICATION == 0:
raise exceptions.loginBannedException()
if userHelper.isLocked(userID) == True and priv & privileges.USER_PENDING_VERIFICATION == 0:
raise exceptions.loginLockedException()
# 2FA check
if userHelper.check2FA(userID, requestIP):
@ -203,7 +205,7 @@ def handle(tornadoRequest):
# (we don't use enqueue because we don't have a token since login has failed)
err = True
responseData += serverPackets.loginFailed()
except exceptions.haxException:
except exceptions.invalidArgumentsException:
# Invalid POST data
# (we don't use enqueue because we don't have a token since login has failed)
err = True
@ -213,6 +215,10 @@ def handle(tornadoRequest):
# Login banned error packet
err = True
responseData += serverPackets.loginBanned()
except exceptions.loginLockedException:
# Login banned error packet
err = True
responseData += serverPackets.loginLocked()
except exceptions.banchoMaintenanceException:
# Bancho is in maintenance mode
responseData = responseToken.queue
@ -230,7 +236,7 @@ def handle(tornadoRequest):
# (we don't use enqueue because we don't have a token since login has failed)
err = True
responseData += serverPackets.forceUpdate()
responseData += serverPackets.notification("Hory shitto, your client is TOO old! Nice preistoria! Please turn off the switcher and update it.")
responseData += serverPackets.notification("Hory shitto, your client is TOO old! Nice prehistory! Please turn update it from the settings!")
except:
log.error("Unknown error!\n```\n{}\n{}```".format(sys.exc_info(), traceback.format_exc()))
finally:

View File

@ -1,5 +1,6 @@
from helpers import passwordHelper
from constants import gameModes
from constants import privileges
from helpers import generalFunctions
from objects import glob
from helpers import logHelper as log
@ -385,6 +386,19 @@ def isBanned(userID):
else:
return True
def isLocked(userID):
"""
Check if userID is locked
userID -- id of the user
return -- True if not locked, otherwise false.
"""
result = glob.db.fetch("SELECT privileges FROM users WHERE id = %s LIMIT 1", [userID])
if result != None:
return ((result["privileges"] & privileges.USER_PUBLIC > 0) and (result["privileges"] & privileges.USER_NORMAL == 0))
else:
return True
def ban(userID):
"""
Ban userID