def testPlugin(p): joe.connects(1) joe.gear = None joe.team = b3.TEAM_SPEC joe.changesGear('GLAOWRA') joe.gear = None joe.team = b3.TEAM_BLUE joe.changesGear('GLAOWRA') print "\nJoe takes smoke grenades" joe.changesGear('GLAQWRA') time.sleep(1) print "\nJoe goes to red team" joe.team = b3.TEAM_RED time.sleep(1) print "\nJoe takes HE grenades and goes to RED" joe.changesGear('GLAOWRA') joe.team = b3.TEAM_RED superadmin.connects(0) superadmin.says('!wpctrl -he') time.sleep(2) joe.disconnects() superadmin.disconnects()
def test_joe_says_badword(self, timer_patch): from b3.fake import joe joe.warn = Mock() joe.connects(0) joe.says("qsfdl f0o!") self.assertEqual(1, joe.warn.call_count)
def setUpClass(cls): global p, joe, conf ## create an instance of the plugin to test p = TeamspeakPlugin(fakeConsole, conf) p.onLoadConfig() p.onStartup() joe.connects('Joe') timeout = time.time() + 10 while not p.tsconnection and time.time() < timeout: time.sleep(.1) if not p.tsconnection: raise AssertionError("Could not connect to TeamSpeak server") if not p.tsGetClient(joe): raise unittest.SkipTest( "please connect to the test Teamspeak server first and make sure your ip is %s as set in config.ini" % config.get("me", "ip")) channellist = p.tsSendCommand('channellist') cls.tsDefaultChannel = p.tsGetChannelIdByName(u'Default Channel', channellist) if not cls.tsDefaultChannel: raise unittest.SkipTest("Could not get default teamspeak channel")
def testAdmins(): conf = XmlConfigParser() conf.setXml(""" <configuration plugin="adv"> <settings name="settings"> <set name="rate">1s</set> </settings> <ads> <ad>^2Do you like B3? Consider donating to the project at www.BigBrotherBot.net</ad> <ad>@admins</ad> </ads> </configuration> """) p = AdvPlugin(fakeConsole, conf) p.onStartup() p.adv() print "-----------------------------" time.sleep(4) joe.connects(1) time.sleep(4) moderator.connects(2) time.sleep(4) superadmin.connects(3) time.sleep(60)
def test_cunt_connects(self, timer_patch): from b3.fake import joe joe.name = joe.exactName = "c**t" joe.warn = Mock() joe.connects(0) self.assertEqual(1, joe.warn.call_count)
def test_ban_event(): superadmin.connects(0) time.sleep(1) joe.connects(1) time.sleep(1) superadmin.says('!permban joe test_perm_ban') time.sleep(3) joe.connects(2)
def testAutomation3(): from b3.fake import superadmin, joe p._automation_enabled = True p._delay = 3 p._total_slots = 2 p._min_free_slots = 1 joe.connects(1) time.sleep(.3) superadmin.connects(0) time.sleep(.3)
def testAutomation4(): from b3.fake import superadmin, joe p._automation_enabled = True p._delay = 0 p._total_slots = 3 p._min_free_slots = 1 joe.connects(0) time.sleep(.3) superadmin.connects(1) time.sleep(.3) jack = FakeClient(fakeConsole, name="Jack", guid="qsd654sqf", _maxLevel=2) jack.connects(2)
def setUpClass(cls): global p, joe, conf ## create an instance of the plugin to test p = TeamspeakbfPlugin(fakeConsole, conf) p.onLoadConfig() p.onStartup() joe.connects('Joe') timeout = time.time() + 10 while not p.tsconnection and time.time() < timeout: time.sleep(.1) if not p.tsconnection: raise AssertionError("Could not connect to TeamSpeak server") if not p.tsGetClient(joe): raise unittest.SkipTest("please connect to the test Teamspeak server first and make sure your ip is %s as set in config.ini" % config.get("me", "ip")) channellist = p.tsSendCommand('channellist') cls.tsDefaultChannel= p.tsGetChannelIdByName(u'Default Channel', channellist) if not cls.tsDefaultChannel: raise unittest.SkipTest("Could not get default teamspeak channel")
def test_tempban_event(): joe.connects(1) time.sleep(2) superadmin.connects(0) superadmin.says('!unban @%s' % joe.id) time.sleep(1) joe.connects(1) time.sleep(1) superadmin.says('!tempban joe 1w racism') time.sleep(3) joe.connects(2)
def test_tempban_expiration(): joe.connects(1) time.sleep(2) superadmin.connects(0) moderator.connects(2) superadmin.says('!unban @%s' % joe.id) time.sleep(1) joe.connects(1) time.sleep(1) superadmin.says('!tempban joe 1 test_1_minute') for i in range(8): time.sleep(10) print(" -"*20) joe.connects(3) joe.auth()
input = self._adminPlugin.parseUserCmd(data) if not input: client.message('^7Invalid data, try !help tell') return False clients = self.console.clients.getList() for c in clients: if c.maxLevel >= self._admin_level: c.message('^5%s^7: %s' % (client.name, input[0])) return True if __name__ == '__main__': from b3.fake import fakeConsole from b3.fake import joe, simon, moderator, superadmin import time p = MessengerPlugin(fakeConsole) p.onStartup() joe.connects(cid=1) simon.connects(cid=2) moderator.connects(cid=3) superadmin.connects(cid=4) joe.says('!tell 2 hola') print "-------------------------" joe.says('!telladmin ayuda') print "-------------------------"
<set name="max_age">0</set> <!-- The purge action takes place once a day at the time define below. Default time is midnight --> <set name="hour">0</set> <!-- hour between 0 and 23 --> <set name="min">0</set> <!-- min between 0 and 59 --> </settings> </configuration> """) p = ChatloggerPlugin(fakeConsole, conf1) p.onLoadConfig() p.onStartup() joe.connects(1) simon.connects(3) joe.says("sql injec;tion ' test") joe.sendsPM("sql; injection ' test", simon) joe.says("!help sql injection ' test;") joe.name = "j'oe" simon.name = "s;m'n" joe.says("sql injection test2") joe.sendsPM("sql injection test2", simon) joe.says("!help sql injection test2") joe.name = "Joe" simon.name = "Simon"
def test1(): conf = XmlConfigParser() conf.setXml(""" <configuration plugin="adv"> <!-- Note: within ads, you can use the following variables : @nextmap @time or rules as defined in the admin plugin config file. ie: /spam#rule1 --> <settings name="settings"> <!-- rate in minutes--> <set name="rate">5</set> <!-- you can either set here a text file that will contain one ad per line or fill the <ads> section below --> <!-- <set name="ads">c:/somewhere/my_ads.txt</set> --> </settings> <settings name="newsfeed"> <!-- you can include newsitems in your adds by setting the section below you can add feeditems in the adds like this: @feed (will pick the next newsitem each time it is included in the rotation, rotating until 'items' is reached and then start over.) @feed 0 (will pick the latest newsitem available from the feed and add it in the rotation) @feed 1 (will pick the second latest item in line) etc. --> <set name="url">http://forum.bigbrotherbot.net/news-2/?type=rss;action=.xml</set> <set name="url.bak"></set> <set name="items">5</set> <set name="pretext">News: </set> </settings> <ads> <ad>^2Big Brother Bot is watching you... www.BigBrotherBot.net</ad> <ad>@topstats</ad> <ad>@feed</ad> <ad>/spam#rule1</ad> <ad>@time</ad> <ad>@feed</ad> <ad>^2Do you like B3? Consider donating to the project at www.BigBrotherBot.net</ad> <ad>@nextmap</ad> </ads> </configuration> """) p = AdvPlugin(fakeConsole, conf) p.onStartup() p.adv() print "-----------------------------" time.sleep(2) joe.connects(1) joe._maxLevel = 100 joe.says('!advlist') time.sleep(2) joe.says('!advrem 0') time.sleep(2) joe.says('!advrate 5s') time.sleep(5) time.sleep(60)
</settings> </configuration> """) ## trick the console in thinking it was started an hour ago def myUpTime_func(): return 3600 fakeConsole.upTime = myUpTime_func p = WelcomePlugin(fakeConsole, conf) p.onStartup() # override _welcomeDelay which makes testing a pain p._welcomeDelay = 1 print "--------------------------------" joe.connects(0) time.sleep(2) joe.disconnects() joe.connected = True joe.connects(2) time.sleep(8) joe.disconnects() joe.connected = True joe.connects(4) time.sleep(5) time.sleep(60)
<set name="tsreconnect">100</set> <set name="tsdisconnect">100</set> <set name="teamspeak-ts">0</set> <set name="tsauto-tsa">0</set> </settings> </configuration> """) fakeConsole.gameName = 'moh' ## create an instance of the plugin to test p = TeamspeakmohPlugin(fakeConsole, conf) p.onStartup() joe.team = b3.TEAM_UNKNOWN joe.connects('Joe') import unittest class TestTeamspeakmoh(unittest.TestCase): def test_cmd_ts(self): joe.clearMessageHistory() joe.says('!ts') self.assertNotEqual(0, len(joe.message_history)) def test_cmd_tsauto(self): joe.clearMessageHistory() joe.says('!tsauto') self.assertNotEqual(0, len(joe.message_history))
import time def sendsPM(self, msg, target): print "\n%s PM to %s : \"%s\"" % (self.name, msg, target) self.console.queueEvent( b3.events.Event(b3.events.EVT_CLIENT_PRIVATE_SAY, msg, self, target)) FakeClient.sendsPM = sendsPM p = ChatloggerPlugin(fakeConsole) p.onStartup() time.sleep(2) joe.connects(1) simon.connects(3) joe.says("sql injec;tion ' test") joe.sendsPM("sql; injection ' test", simon) joe.says("!help sql injection ' test;") joe.name = "j'oe" simon.name = "s;m'n" joe.says("sql injection test2") joe.sendsPM("sql injection test2", simon) joe.says("!help sql injection test2") joe.says("holas \" como va") joe.name = "Joe"
<set name="greeting_cleared">^7Greeting cleared</set> </settings> </configuration> """) ## trick the console in thinking it was started an hour ago def myUpTime_func(): return 3600 fakeConsole.upTime = myUpTime_func p = WelcomePlugin(fakeConsole, conf) p.onStartup() # override _welcomeDelay which makes testing a pain p._welcomeDelay = 1 print "--------------------------------" joe.connects(0) time.sleep(2) joe.disconnects() joe.connected = True joe.connects(2) time.sleep(8) joe.disconnects() joe.connected = True joe.connects(4) time.sleep(5) time.sleep(60)
def test_Command_check(): superadmin.connects(0) time.sleep(1) joe.connects(1) time.sleep(1) superadmin.says('!metabanscheck joe')
</settings> <settings name="settings"> <set name="startPoints">100</set> <set name="resetscore">no</set> <set name="resetxp">no</set> </settings> </configuration> """) p = StatsPlugin(fakeConsole, conf) p.onStartup() p.onLoadConfig() time.sleep(1) joe.connects(cid=3) joe.says("!mapstats") joe.says("!mystatalias") joe.says("!testscore") joe.says("!tscr") joe.says("!topstats") joe.says("!tops") joe.says("!topxp") joe.says("!txp") superadmin.connects(cid=2) joe.kills(superadmin) joe.kills(superadmin) joe.kills(superadmin) superadmin.kills(joe)
conf = XmlConfigParser() conf.loadFromString(""" <configuration plugin="poweradminbf3"> <settings name="commands"> <set name="changeteam-ct">0</set> </settings> </configuration> """) p = Poweradminbf3Plugin(fakeConsole, conf) p.onLoadConfig() p.onStartup() simon.connects("simon") simon.teamId = 1 joe.connects('Joe') joe.teamId = 1 jack = FakeClient(fakeConsole, name="Jack", exactName="Jack", guid="azerazerzarazrzae", groupBits=1) jack.connects('Jack') jack.teamId = 1 superadmin.connects('superadmin') superadmin.teamId = 2 print "Joe's group is " + joe.maxGroup.name print "Jack's group is " + jack.maxGroup.name print "Simon's group is " + simon.maxGroup.name print "superadmin's group is " + superadmin.maxGroup.name
self.clear() # add list of matching clients for cid, c in mlist.iteritems(): self[cid] = c def authorizeClients(self): if not self._authorizing: # lookup is delayed to allow time for auth # it will also allow us to batch the lookups if several players # are joining at once self._authorizing = True t = threading.Timer(5, self._authorizeClients) t.start() def _authorizeClients(self): self.console.authorizeClients() self._authorizing = False if __name__ == '__main__': from b3.fake import fakeConsole from b3.fake import joe game = b3.game.Game(fakeConsole, 'fakegamename') joe.connects(cid=3) print 'maxLevel: ' print joe.maxLevel print type(joe.maxLevel)
for k, v in opts: if k == "-h": server_ip = v elif k == "-p": server_port = int(v) try: p = TelnetPlugin(fakeConsole, conf1) if server_port: p.telnetPort = server_port if server_ip: p.telnetIp = server_ip p.onLoadConfig() p.onStartup() joe.connects(0) fakeConsole.storage.query( QueryBuilder(fakeConsole.storage.db).UpdateQuery( {"login": "******", "password": md5("test").hexdigest()}, "clients", {"id": joe.id} ) ) print "Joe id : %s" % joe.id moderator.connects(1) fakeConsole.storage.query( QueryBuilder(fakeConsole.storage.db).UpdateQuery( {"password": md5("test").hexdigest()}, "clients", {"id": moderator.id} ) ) print "Moderator id : %s" % moderator.id
else: sclient.setGroup(group) sclient.save() cmd.sayLoudOrPM( client, self._adminPlugin.getMessage('groups_put', sclient.exactName, group.name)) return True if __name__ == '__main__': from b3.fake import fakeConsole from b3.fake import superadmin, joe fakeConsole.setCvar('g_mapcycle', 'mapcycle.txt') setattr(fakeConsole.game, 'fs_basepath', '/home/gabriel/urbanterror') setattr(fakeConsole.game, 'fs_game', 'q3ut4') p = ExtraadminPlugin(fakeConsole, '@b3/extplugins/conf/extraadmin.xml') p.onStartup() #print p._nextMap #print p._currentMap #p.find_next_map_rotation('ut4_tejen_beta3') #print p._nextMap superadmin.connects(cid=1) joe.connects(cid=2) time.sleep(2) superadmin.says("!cinfo 2")
if sclient.inGroup(group): client.message(self._adminPlugin.getMessage('groups_already_in', sclient.exactName, group.name)) elif sclient.maxLevel >= group.level: client.message('^7%s ^7is already in a higher level group' % sclient.exactName) else: sclient.setGroup(group) sclient.save() cmd.sayLoudOrPM(client, self._adminPlugin.getMessage('groups_put', sclient.exactName, group.name)) return True if __name__ == '__main__': from b3.fake import fakeConsole from b3.fake import superadmin, joe fakeConsole.setCvar('g_mapcycle','mapcycle.txt') setattr(fakeConsole.game,'fs_basepath','/home/gabriel/urbanterror') setattr(fakeConsole.game,'fs_game','q3ut4') p = ExtraadminPlugin(fakeConsole, '@b3/extplugins/conf/extraadmin.xml') p.onStartup() #print p._nextMap #print p._currentMap #p.find_next_map_rotation('ut4_tejen_beta3') #print p._nextMap superadmin.connects(cid=1) joe.connects(cid=2) time.sleep(2) superadmin.says("!cinfo 2")