.BANCHO. New privileges system, add restricted mode

This commit is contained in:
Nyo
2016-07-03 20:51:19 +02:00
parent 99276d83b3
commit 6ac3b853f4
16 changed files with 291 additions and 116 deletions

View File

@@ -11,10 +11,15 @@ def handle(userToken, packetData):
username = userToken.username
# Make sure we are not banned
if userHelper.getAllowed(userID) == 0:
if userHelper.isBanned(userID) == True:
userToken.enqueue(serverPackets.loginBanned())
return
# Send restricted message if needed
if userToken.restricted == False:
if userHelper.isRestricted(userID) == True:
userToken.setRestricted()
# Change action packet
packetData = clientPackets.userActionChange(packetData)

View File

@@ -26,7 +26,6 @@ def joinChannel(userToken, channelName):
# Get usertoken data
username = userToken.username
userID = userToken.userID
userRank = userToken.rank
# Check spectator channel
# If it's spectator channel, skip checks and list stuff
@@ -37,7 +36,7 @@ def joinChannel(userToken, channelName):
raise exceptions.channelUnknownException
# Check channel permissions
if glob.channels.channels[channelName].publicRead == False and userRank <= 2:
if glob.channels.channels[channelName].publicRead == False and userToken.admin == False:
raise exceptions.channelNoPermissionsException
# Add our userID to users in that channel

View File

@@ -31,7 +31,8 @@ def handle(tornadoRequest):
err = False
# Try to get the ID from username
userID = userHelper.getID(str(loginData[0]))
username = str(loginData[0])
userID = userHelper.getID(username)
if userID == False:
# Invalid username
@@ -41,9 +42,7 @@ def handle(tornadoRequest):
raise exceptions.loginFailedException()
# Make sure we are not banned
userAllowed = userHelper.getAllowed(userID)
if userAllowed == 0:
# Banned
if userHelper.isBanned(userID) == True:
raise exceptions.loginBannedException()
# 2FA check
@@ -67,10 +66,9 @@ def handle(tornadoRequest):
silenceSeconds = responseToken.getSilenceSecondsLeft()
# Get supporter/GMT
userRank = userHelper.getRankPrivileges(userID)
userGMT = False
userSupporter = True
if userRank >= 3:
if responseToken.admin == True:
userGMT = True
# Server restarting check
@@ -105,9 +103,9 @@ def handle(tornadoRequest):
# TODO: Configurable default channels
channelJoinEvent.joinChannel(responseToken, "#osu")
channelJoinEvent.joinChannel(responseToken, "#announce")
if userRank >= 3:
# Join admin chanenl if we are mod/admin
# TODO: Separate channels for mods and admins
# Join admin channel if we are an admin
if responseToken.admin == True:
channelJoinEvent.joinChannel(responseToken, "#admin")
# Output channels info
@@ -122,12 +120,6 @@ def handle(tornadoRequest):
if glob.banchoConf.config["menuIcon"] != "":
responseToken.enqueue(serverPackets.mainMenuIcon(glob.banchoConf.config["menuIcon"]))
# Get everyone else userpanel
# TODO: Better online users handling
#for key, value in glob.tokens.tokens.items():
# responseToken.enqueue(serverPackets.userPanel(value.userID))
# responseToken.enqueue(serverPackets.userStats(value.userID))
# Send online users IDs array
responseToken.enqueue(serverPackets.onlineUsers())
@@ -151,10 +143,10 @@ def handle(tornadoRequest):
# Set country in db if user has no country (first bancho login)
if userHelper.getCountry(userID) == "XX":
userHelper.setCountry(userID, countryLetters)
# Send to everyone our userpanel
glob.tokens.enqueueAll(serverPackets.userPanel(userID))
#glob.tokens.enqueueAll(serverPackets.userStats(userID))
# Send to everyone our userpanel if we are not restricted
if responseToken.restricted == False:
glob.tokens.enqueueAll(serverPackets.userPanel(userID))
# Set reponse data to right value and reset our queue
responseData = responseToken.queue

View File

@@ -24,6 +24,10 @@ def handle(userToken, packetData):
username = userToken.username
userID = userToken.userID
# Make sure the user is not in restricted mode
if userToken.restricted == True:
raise exceptions.userRestrictedException
# Private message packet
packetData = clientPackets.sendPrivateMessage(packetData)
@@ -47,7 +51,7 @@ def handle(userToken, packetData):
raise exceptions.tokenNotFoundException()
# Check message templates (mods/admins only)
if packetData["message"] in messageTemplates.templates and userToken.rank >= 3:
if packetData["message"] in messageTemplates.templates and userToken.admin == True:
packetData["message"] = messageTemplates.templates[packetData["message"]]
# Send message to target
@@ -71,3 +75,5 @@ def handle(userToken, packetData):
except exceptions.messageTooLongException:
# Message > 256 silence
userToken.silence(2*3600, "Sending messages longer than 256 characters")
except exceptions.userRestrictedException:
pass

View File

@@ -20,7 +20,10 @@ def handle(userToken, packetData):
# Get userToken data
userID = userToken.userID
username = userToken.username
userRank = userToken.rank
# Make sure the user is not in restricted mode
if userToken.restricted == True:
raise exceptions.userRestrictedException
# Public chat packet
packetData = clientPackets.sendPublicMessage(packetData)
@@ -85,11 +88,11 @@ def handle(userToken, packetData):
raise exceptions.channelUnknownException
# Make sure the channel is not in moderated mode
if glob.channels.channels[packetData["to"]].moderated == True and userRank <= 2:
if glob.channels.channels[packetData["to"]].moderated == True and userToken.admin == False:
raise exceptions.channelModeratedException
# Make sure we have write permissions
if glob.channels.channels[packetData["to"]].publicWrite == False and userRank <= 2:
if glob.channels.channels[packetData["to"]].publicWrite == False and userToken.admin == False:
raise exceptions.channelNoPermissionsException
# Send this packet to everyone in that channel except us
@@ -128,3 +131,5 @@ def handle(userToken, packetData):
except exceptions.messageTooLongException:
# Message > 256 silence
userToken.silence(2*3600, "Sending messages longer than 256 characters")
except exceptions.userRestrictedException:
pass