.BANCHO. Add check silence in send message

This commit is contained in:
Nyo
2016-06-09 10:43:28 +02:00
parent b1e4314990
commit 4a1d1c6f0e
5 changed files with 46 additions and 35 deletions

View File

@@ -55,8 +55,11 @@ def handle(tornadoRequest):
responseToken = glob.tokens.addToken(userID)
responseTokenString = responseToken.token
# Get silence end
userSilenceEnd = max(0, userHelper.getSilenceEnd(userID)-int(time.time()))
# Set silence end UNIX time in token
responseToken.silenceEndTime = userHelper.getSilenceEnd(userID)
# Get only silence remaining seconds
silenceSeconds = responseToken.getSilenceSecondsLeft()
# Get supporter/GMT
userRank = userHelper.getRankPrivileges(userID)
@@ -80,7 +83,7 @@ def handle(tornadoRequest):
responseToken.enqueue(serverPackets.notification("Bancho is in maintenance mode. Only mods/admins have full access to the server.\nType !system maintenance off in chat to turn off maintenance mode."))
# Send all needed login packets
responseToken.enqueue(serverPackets.silenceEndTime(userSilenceEnd))
responseToken.enqueue(serverPackets.silenceEndTime(silenceSeconds))
responseToken.enqueue(serverPackets.userID(userID))
responseToken.enqueue(serverPackets.protocolVersion())
responseToken.enqueue(serverPackets.userSupporterGMT(userSupporter, userGMT))
@@ -104,6 +107,7 @@ def handle(tornadoRequest):
if value.publicRead == True:
responseToken.enqueue(serverPackets.channelInfo(key))
# Send friends list
responseToken.enqueue(serverPackets.friendList(userID))
# Send main menu icon and login notification if needed

View File

@@ -27,6 +27,10 @@ def handle(userToken, packetData):
# Private message packet
packetData = clientPackets.sendPrivateMessage(packetData)
# Make sure the user is not silenced
if userToken.isSilenced() == True:
raise exceptions.userSilencedException
# Check message length
if len(packetData["message"]) > 256:
if userToken.longMessageWarning == True:
@@ -62,6 +66,9 @@ def handle(userToken, packetData):
# Console and file output
log.pm("{} -> {}: {}".format(username, packetData["to"], packetData["message"]))
except exceptions.userSilencedException:
userToken.enqueue(serverPackets.silenceEndTime(userToken.getSilenceSecondsLeft()))
log.warning("{} tried to send a message during silence".format(username))
except exceptions.tokenNotFoundException:
# Token not found, user disconnected
log.warning("{} tried to send a message to {}, but their token couldn't be found".format(username, packetData["to"]))

View File

@@ -28,6 +28,10 @@ def handle(userToken, packetData):
# Receivers
who = []
# Make sure the user is not silenced
if userToken.isSilenced() == True:
raise exceptions.userSilencedException
# Check message length
if len(packetData["message"]) > 256:
if userToken.longMessageWarning == True:
@@ -116,6 +120,9 @@ def handle(userToken, packetData):
# Discord log
discordBotHelper.sendChatlog("**{fro} @ {to}:** {message}".format(fro=username, to=packetData["to"], message=str(packetData["message"].encode("utf-8"))[2:-1]))
except exceptions.userSilencedException:
userToken.enqueue(serverPackets.silenceEndTime(userToken.getSilenceSecondsLeft()))
log.warning("{} tried to send a message during silence".format(username))
except exceptions.channelModeratedException:
log.warning("{} tried to send a message to a channel that is in moderated mode ({})".format(username, packetData["to"]))
except exceptions.channelUnknownException: