SoftwareTipsandTricks Forum

Go Back   SoftwareTipsandTricks Forum > Operating Systems > Windows XP
User Name
Password


Scripting-Python

Reply
 
Thread Tools Search this Thread Rate Thread Display Modes

  #1  
Old 07-07-2008, 10:06 AM
tarleton Offline
Registered User
 
Join Date: Apr 2007
Posts: 36
Angry Scripting-Python

Hi all not sure were this one should go so apologizes if not in the right place. Anyway I am helping a mate try and script a plugin for COD4 which KICKS players for using bad language. However he only wants this to happen when the players use certain words like the "N' word. So if they use lesser offencive language like the "S" word the are given three warnings (which is the default) before being kicked. AND to be honest we are way out of our depth. I think I've got the script for kick
Quote:
host.rcon_invoke("admin.kickPlayer " + str(name))

below is the script with the above line inserted where I think it should go. Thanks in advance!
Quote:
#
# BigBrotherBot(B3) (www.bigbrotherbot.com)
# Copyright (C) 2005 Michael "ThorN" Thornton
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#
# $Id: censor.py 6 2005-11-18 05:36:17Z thorn $
#
# CHANGELOG
# 8/13/2005 - 2.0.0 - ThorN
# Converted to use XML config
# Allow custom penalties for words and names
# 7/23/2005 - 1.1.0 - ThorN
# Added data column to penalties table
# Put censored message/name in the warning data

__author__ = 'ThorN'
__version__ = '2.0.2'

import b3, re, traceback, sys, threading
import b3.events
import b3.plugin
from b3 import functions

class PenaltyData:
def __init__(self, **kwargs):
for k, v in kwargs.iteritems():
setattr(self, k, v)

type = None
reason = None
keyword = None
duration = 0

class CensorData:
def __init__(self, **kwargs):
for k, v in kwargs.iteritems():
setattr(self, k, v)

penalty = None
regexp = None

#--------------------------------------------------------------------------------------------------
class CensorPlugin(b3.plugin.Plugin):
_adminPlugin = None
_reClean = re.compile(r'[^0-9a-z ]+', re.I)
_defaultBadWordPenalty = None
_defaultBadNamePenalty = None
_maxLevel = 0

def onStartup(self):
self._adminPlugin = self.console.getPlugin('admin')
if not self._adminPlugin:
return False

self.registerEvent(b3.events.EVT_CLIENT_SAY)
self.registerEvent(b3.events.EVT_CLIENT_TEAM_SAY)

def onLoadConfig(self):
self._maxLevel = self.config.getint('settings', 'max_level')

penalty = self.config.get('badwords/penalty')[0]

self._defaultBadWordPenalty = PenaltyData(type = penalty.get('type'),
reason = penalty.get('reason'),
keyword = penalty.get('reasonkeyword'),
duration = functions.time2minutes(penalty.get('duration')))

penalty = self.config.get('badnames/penalty')[0]

self._defaultBadNamePenalty = PenaltyData(type = penalty.get('type'),
reason = penalty.get('reason'),
keyword = penalty.get('reasonkeyword'),
duration = functions.time2minutes(penalty.get('duration')))

# load bad words into memory
self._badWords = []

for e in self.config.get('badwords/badword'):
regexp = e.find('regexp')
word = e.find('word')
penalty = e.find('penalty')

if regexp != None:
# has a regular expression
self._badWords.append(self._getCensorData(e.get('n ame'), regexp.text.strip(), penalty, self._defaultBadWordPenalty))

if word != None:
# has a plain word
self._badWords.append(self._getCensorData(e.get('n ame'), '\\s' + word.text.strip() + '\\s', penalty, self._defaultBadWordPenalty))

# load bad names into memory
self._badNames = []

for e in self.config.get('badnames/badname'):
regexp = e.find('regexp')
word = e.find('word')
penalty = e.find('penalty')

if regexp != None:
# has a regular expression
self._badNames.append(self._getCensorData(e.get('n ame'), regexp.text.strip(), penalty, self._defaultBadNamePenalty))

if word != None:
# has a plain word
self._badNames.append(self._getCensorData(e.get('n ame'), '\\s' + word.text.strip() + '\\s', penalty, self._defaultBadNamePenalty))

def _getCensorData(self, name, regexp, penalty, defaultPenalty):
try:
regexp = re.compile(regexp, re.I)
except re.error, e:
self.error('Invalid regular expression: %s - %s' % (name, regexp))
raise

if penalty != None:


### Maybe this will work? ###

host.rcon_invoke("admin.kickPlayer " + str(name))

### ###

#pd = PenaltyData(type = penalty.get('type'),
# reason = penalty.get('reason'),
# keyword = penalty.get('reasonkeyword'),
duration = functions.time2minutes(penalty.get('duration')))
else:
pd = defaultPenalty

return CensorData(penalty = pd, regexp = regexp)

def onEvent(self, event):
try:
if not event.client:
return
elif event.client.cid == None:
return
elif event.client.maxLevel > self._maxLevel:
return
elif not event.client.connected:
return

if len(event.data) > 3:
if event.type == b3.events.EVT_CLIENT_SAY or \
event.type == b3.events.EVT_CLIENT_TEAM_SAY:
sentance = ' ' + self.clean(event.data) + ' '
for w in self._badWords:
if w.regexp.search(sentance):
self.penalizeClient(w.penalty, event.client, '%s => %s' % (event.data, sentance))
raise b3.events.VetoEvent
return
elif event.type == b3.events.EVT_CLIENT_NAME_CHANGE:
self.checkBadName(event.client)

except b3.events.VetoEvent:
raise
except Exception, msg:
self.error('Censor plugin error: %s - %s', msg, traceback.extract_tb(sys.exc_info()[2]))

def penalizeClient(self, penalty, client, data=''):
self._adminPlugin.penalizeClient(penalty.type, client, penalty.reason, penalty.keyword, penalty.duration, None, data)

def checkBadName(self, client):
if not client.connected:
return

name = ' ' + self.clean(client.exactName) + ' '
for w in self._badNames:
if w.regexp.search(name):
self.penalizeClient(w.penalty, client, '%s => %s' % (client.exactName, name))

t = threading.Timer(300, self.checkBadName, (client,))
t.start()
return

if name != client.exactName:
# name has special characters, check those too
name = client.exactName
for w in self._badNames:
if w.regexp.search(name):
self.penalizeClient(w.penalty, client, client.exactName)

t = threading.Timer(300, self.checkBadName, (client,))
t.start()

return

def clean(self, data):
return re.sub(self._reClean, ' ', self.console.stripColors(data.lower()))
Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Python... jpe2000 Software Problems and Useful Utilities 3 12-04-2005 07:19 AM
Scripting Engine ??? Bobby Jones Windows XP 0 09-12-2005 06:17 PM
Scripting / Java Scripting Accap Windows XP 1 06-03-2004 10:36 PM
suspicious scripting sisyphus Windows XP 4 10-05-2003 05:20 PM
enabling VB Scripting imanangel Windows XP 0 11-17-2002 04:45 PM



All times are GMT -5. The time now is 11:23 AM.


Designed by eXtremepixels. Powered by vBulletin Version 3.5.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 2.3.2 © 2005, Crawlability, Inc.