diff --git a/fokabotCommands.py b/fokabotCommands.py index 0bdd615..3cedc7a 100644 --- a/fokabotCommands.py +++ b/fokabotCommands.py @@ -180,6 +180,43 @@ def removeSilence(fro, chan, message): return "{}'s silence reset".format(target) +def ban(fro, chan, message): + # Get parameters + for i in message: + i = i.lower() + target = message[0].replace("_", " ") + + # Make sure the user exists + targetUserID = userHelper.getID(target) + if targetUserID == False: + return "{}: user not found".format(target) + + # Set allowed to 0 + userHelper.setAllowed(targetUserID, 0) + + # Send ban packet to the user if he's online + targetToken = glob.tokens.getTokenFromUsername(target) + if targetToken != None: + targetToken.enqueue(serverPackets.loginBanned()) + + return "RIP {}. You will not be missed.".format(target) + +def unban(fro, chan, message): + # Get parameters + for i in message: + i = i.lower() + target = message[0].replace("_", " ") + + # Make sure the user exists + targetUserID = userHelper.getID(target) + if targetUserID == False: + return "{}: user not found".format(target) + + # Set allowed to 1 + userHelper.setAllowed(targetUserID, 1) + + return "Welcome back {}!".format(target) + def restartShutdown(restart): """Restart (if restart = True) or shutdown (if restart = False) pep.py safely""" msg = "We are performing some maintenance. Bancho will {} in 5 seconds. Thank you for your patience.".format("restart" if restart else "shutdown") @@ -344,6 +381,16 @@ commands = [ "trigger": "!system status", "minRank": 3, "callback": systemStatus + }, { + "trigger": "!ban", + "syntax": "", + "minRank": 3, + "callback": ban + }, { + "trigger": "!unban", + "syntax": "", + "minRank": 3, + "callback": unban } ] diff --git a/serverPackets.py b/serverPackets.py index 2cd6c2c..f660cf2 100644 --- a/serverPackets.py +++ b/serverPackets.py @@ -18,7 +18,10 @@ def forceUpdate(): return packetHelper.buildPacket(packetIDs.server_userID, [[-2, dataTypes.sInt32]]) def loginBanned(): - return packetHelper.buildPacket(packetIDs.server_userID, [[-3, dataTypes.sInt32]]) + 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") + return packets + #return packetHelper.buildPacket(packetIDs.server_userID, [[-3, dataTypes.sInt32]]) def loginError(): return packetHelper.buildPacket(packetIDs.server_userID, [[-5, dataTypes.sInt32]]) diff --git a/userHelper.py b/userHelper.py index 7d0aa41..9030135 100644 --- a/userHelper.py +++ b/userHelper.py @@ -261,8 +261,17 @@ def getPP(userID, gameMode): Get userID's PP relative to gameMode userID -- user - return -- gameMode number + return -- PP """ modeForDB = gameModes.getGameModeForDB(gameMode) return glob.db.fetch("SELECT pp_{} FROM users_stats WHERE id = ?".format(modeForDB), [userID])["pp_{}".format(modeForDB)] + +def setAllowed(userID, allowed): + """ + Set userID's allowed status + + userID -- user + allowed -- allowed status. 1: normal, 0: banned + """ + glob.db.execute("UPDATE users SET allowed = ? WHERE id = ?", [allowed, userID])