forked from osuripple/pep.py
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
.BANCHO. Add pubsub handlers for username changes, bans, restrictions…
…, silences, stats update, kicks and bancho settings reload.
- Loading branch information
Showing
13 changed files
with
220 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from common.redis import generalPubSubHandler | ||
from common.ripple import userUtils | ||
from objects import glob | ||
|
||
class handler(generalPubSubHandler.generalPubSubHandler): | ||
def __init__(self): | ||
super().__init__() | ||
self.type = "int" | ||
|
||
def handle(self, userID): | ||
userID = super().parseData(userID) | ||
if userID is None: | ||
return | ||
targetToken = glob.tokens.getTokenFromUserID(userID) | ||
if targetToken is not None: | ||
targetToken.privileges = userUtils.getPrivileges(userID) | ||
targetToken.checkBanned() | ||
targetToken.checkRestricted() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
from common.redis import generalPubSubHandler | ||
from common.ripple import userUtils | ||
from common.log import logUtils as log | ||
from common.constants import actions | ||
from objects import glob | ||
|
||
def handleUsernameChange(userID, newUsername, targetToken=None): | ||
try: | ||
userUtils.changeUsername(userID, newUsername=newUsername) | ||
if targetToken is not None: | ||
targetToken.kick("Your username has been changed to {}. Please log in again.".format(newUsername), "username_change") | ||
except userUtils.usernameAlreadyInUseError: | ||
log.rap(999, "Username change: {} is already in use!", through="Bancho") | ||
if targetToken is not None: | ||
targetToken.kick("There was a critical error while trying to change your username. Please contact a developer.", "username_change_fail") | ||
except userUtils.invalidUsernameError: | ||
log.rap(999, "Username change: {} is not a valid username!", through="Bancho") | ||
if targetToken is not None: | ||
targetToken.kick("There was a critical error while trying to change your username. Please contact a developer.", "username_change_fail") | ||
|
||
class handler(generalPubSubHandler.generalPubSubHandler): | ||
def __init__(self): | ||
super().__init__() | ||
self.structure = { | ||
"userID": 0, | ||
"newUsername": "" | ||
} | ||
|
||
def handle(self, data): | ||
data = super().parseData(data) | ||
if data is None: | ||
return | ||
# Get the user's token | ||
targetToken = glob.tokens.getTokenFromUserID(data["userID"]) | ||
if targetToken is None: | ||
# If the user is offline change username immediately | ||
handleUsernameChange(data["userID"], data["newUsername"]) | ||
else: | ||
if targetToken.irc or (targetToken.actionID != actions.PLAYING and targetToken.actionID != actions.MULTIPLAYING): | ||
# If the user is online and he's connected through IRC or he's not playing, | ||
# change username and kick the user immediately | ||
handleUsernameChange(data["userID"], data["newUsername"], targetToken) | ||
else: | ||
# If the user is playing, delay the username change until he submits the score | ||
# On submit modular, lets will send the username change request again | ||
# through redis once the score has been submitted | ||
# The check is performed on bancho logout too, so if the user disconnects | ||
# without submitting a score, the username gets changed on bancho logout | ||
glob.redis.set("ripple:change_username_pending:{}".format(data["userID"]), data["newUsername"]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from common.redis import generalPubSubHandler | ||
from objects import glob | ||
|
||
class handler(generalPubSubHandler.generalPubSubHandler): | ||
def __init__(self): | ||
super().__init__() | ||
self.structure = { | ||
"userID": 0, | ||
"reason": "" | ||
} | ||
|
||
def handle(self, data): | ||
data = super().parseData(data) | ||
if data is None: | ||
return | ||
targetToken = glob.tokens.getTokenFromUserID(data["userID"]) | ||
if targetToken is not None: | ||
targetToken.kick(data["reason"], "pubsub_kick") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
from common.redis import generalPubSubHandler | ||
from objects import glob | ||
|
||
class handler(generalPubSubHandler.generalPubSubHandler): | ||
def __init__(self): | ||
super().__init__() | ||
self.type = "int" | ||
|
||
def handle(self, userID): | ||
userID = super().parseData(userID) | ||
if userID is None: | ||
return | ||
targetToken = glob.tokens.getTokenFromUserID(userID) | ||
if targetToken is not None: | ||
targetToken.silence() |
Oops, something went wrong.