Skip to content

Commit

Permalink
Use Banlist module. Prevent users banned in "Global" from using all c…
Browse files Browse the repository at this point in the history
…ommands.
  • Loading branch information
RenolY2 committed Jun 23, 2014
1 parent daf2e10 commit 9a3c202
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 9 deletions.
27 changes: 19 additions & 8 deletions IRCpackets/messages_PRIVMSG.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def execute(self, sendMsg, msgprefix, command, params):
part2 = part1[2].partition("@")

name = part1[0]
indent = part2[0]
ident = part2[0]
host = part2[2]

cmdprefix = self.cmdprefix
Expand All @@ -25,7 +25,7 @@ def execute(self, sendMsg, msgprefix, command, params):
is_channel = False
perms = ""
#print "HELP I'M GETTING PRIVMSGD BY ",name," : ",chatMessage
msg_log.info("Private message from '%s' [%s@%s]: %s", name, indent, host, chatMessage)
msg_log.info("Private message from '%s' [%s@%s]: %s", name, ident, host, chatMessage)
else:
is_channel = True
channel = self.retrieveTrueCase(channel)
Expand Down Expand Up @@ -71,6 +71,17 @@ def execute(self, sendMsg, msgprefix, command, params):
#print self.commands
#print chatCmd
if usedPrfx == cmdprefix and chatCmd in self.commands:
bannedInfo = self.Banlist.checkBan(name, ident, host)

if bannedInfo[0] == True:
msg_log.info("User '%s' uses command '%s', but user is globally banned.",
name, chatCmd)
msg_log.info("Ban information: %s",
bannedInfo[1])

return


try:
support = self.commands[chatCmd][0].privmsgEnabled
except AttributeError:
Expand All @@ -82,17 +93,17 @@ def execute(self, sendMsg, msgprefix, command, params):
msg_log.info("User '%s' uses command '%s' in channel '%s'",
name , chatCmd, channel)
msg_log.debug("User info for '%s': [%s@%s] Used parameters: %s Rank: %s",
name, indent, host, chatParams[1:], perms)
name, ident, host, chatParams[1:], perms)
else:
msg_log.info("User '%s' uses command '%s'", name , chatCmd)
msg_log.debug("User info for '%s': [%s@%s] Used parameters: %s Rank: %s",
name, indent, host, chatParams[1:], perms)
name, ident, host, chatParams[1:], perms)
msg_log.debug("User '%s' - destination: '%s' (should be the same)", name, channel)

if support == True:
self.commands[chatCmd][0].execute(self, name, chatParams[1:], channel, (indent, host), perms, is_channel)
self.commands[chatCmd][0].execute(self, name, chatParams[1:], channel, (ident, host), perms, is_channel)
elif support == False and is_channel == True:
self.commands[chatCmd][0].execute(self, name, chatParams[1:], channel, (indent, host), perms)
self.commands[chatCmd][0].execute(self, name, chatParams[1:], channel, (ident, host), perms)

except KeyError as error:
print "KeyError for command: "+str(error)
Expand All @@ -104,8 +115,8 @@ def execute(self, sendMsg, msgprefix, command, params):
channel = is_channel == True and channel or False

if channel == False:
msg_log.debug("Passing a PM from user '%s' [%s@%s] to chat events: '%s'", name, indent, host, chatMessage)
msg_log.debug("Passing a PM from user '%s' [%s@%s] to chat events: '%s'", name, ident, host, chatMessage)

self.events["chat"].tryAllEvents(self, {"name" : name, "ident" : indent, "host" : host}, chatMessage, channel)
self.events["chat"].tryAllEvents(self, {"name" : name, "ident" : ident, "host" : host}, chatMessage, channel)


7 changes: 6 additions & 1 deletion commandHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
from IRC_registration import trackVerification
from CommandHelp import HelpModule
from IRCLogging import LoggingModule
from BanList import BanList



class commandHandling():
Expand Down Expand Up @@ -50,6 +52,8 @@ def __init__(self, channels, cmdprefix, name, ident, adminlist, loglevel):
self.PacketsReceivedBeforeDeath = Queue.Queue(maxsize = 50)

self.threading = centralizedThreading.ThreadPool()
self.Banlist = BanList("BannedUsers.db")
self.Banlist.clearBanlist_all()

self.helper = HelpModule()
self.auth = None
Expand Down Expand Up @@ -126,13 +130,14 @@ def sendChatMessage(self, send, channel, msg, msgsplitter = None, splitAt = " ")
# to which we send the message. At the end, we add a constant (25) to the length to account
# for whitespaces and other characters and eventual oddities.
# The Hostname will be limited to 63, regardless of the actual length.
# 7 characters for the PRIVSM string

# if you want to create your own tweaked message splitter,
# provide it as the fourth argument to self.sendChatMessage
# otherwise, the default one, i.e. self.defaultsplitter, is used
if msgsplitter == None:
msgsplitter = self.defaultsplitter
#PRIVMSG

prefixLen = len(self.name) + len(self.ident) + 63 + 7 + len(channel) + 25
remaining = 512-prefixLen
#print remaining
Expand Down

0 comments on commit 9a3c202

Please sign in to comment.