Exemple #1
0
 def test_nominal(self):
     conf = XmlConfigParser()
     conf.setXml("""
     <configuration plugin="teamspeakbf">
     	<settings name="teamspeakServer">
             <set name="host">foo_host</set>
             <set name="queryport">foo_queryport</set>
             <set name="id">1</set>
             <set name="login">foo_login</set>
             <set name="password">foo_password</set>
         </settings>
         <settings name="teamspeakChannels">
             <set name="B3">channel name</set>
             <set name="team1">Team 1 name</set>
             <set name="team2">Team 2 name</set>
             <set name="DefaultTarget">team</set>
         </settings>
     </configuration>
     """)
     p = TeamspeakbfPlugin(fakeConsole, conf)
     p.readConfig()
     self.assertEqual('channel name', p.TS3ChannelB3)
     self.assertEqual('Team 1 name', p.TS3ChannelTeam1)
     self.assertEqual('Team 2 name', p.TS3ChannelTeam2)
     self.assertEqual('team', p.autoswitchDefaultTarget)
class CensorurtTestCase(B3TestCase):
    """
    Ease testcases that need an working B3 console and need to control the censorurt plugin config
    """
    def setUp(self):
        # Timer needs to be patched or the Censor plugin would schedule a 2nd check one minute after
        # penalizing a player.
        self.timer_patcher = patch('threading.Timer')
        self.timer_patcher.start()

        self.log = logging.getLogger('output')
        self.log.propagate = False

        B3TestCase.setUp(self)
        self.console.startup()
        self.log.propagate = True

        self.joe = FakeClient(self.console, name="Joe", exactName="Joe", guid="zaerezarezar", groupBits=1, team=b3.TEAM_UNKNOWN)

        self.conf = XmlConfigParser()
        self.p = CensorurtPlugin(self.console, self.conf)

    def tearDown(self):
        B3TestCase.tearDown(self)
        self.timer_patcher.stop()

    def init_plugin(self, config_content):
        self.conf.setXml(config_content)
        self.log.setLevel(logging.DEBUG)
        self.log.info("============================= Censor plugin: loading config ============================")
        self.p.onLoadConfig()
        self.log.info("============================= Censor plugin: starting  =================================")
        self.p.onStartup()
Exemple #3
0
class SpamcontrolTestCase(B3TestCase):
    """ Ease testcases that need an working B3 console and need to control the Spamcontrol plugin config """
    def setUp(self):
        self.timer_patcher = patch('threading.Timer')
        self.timer_patcher.start()

        self.log = logging.getLogger('output')
        self.log.propagate = False

        B3TestCase.setUp(self)
        self.console.startup()
        self.log.propagate = True

    def tearDown(self):
        B3TestCase.tearDown(self)
        self.timer_patcher.stop()

    def init_plugin(self, config_content):
        self.conf = XmlConfigParser()
        self.conf.setXml(config_content)
        self.p = SpamcontrolPlugin(self.console, self.conf)

        self.log.setLevel(logging.DEBUG)
        self.log.info(
            "============================= Spamcontrol plugin: loading config ============================"
        )
        self.p.onLoadConfig()
        self.log.info(
            "============================= Spamcontrol plugin: starting  ================================="
        )
        self.p.onStartup()
class SpamcontrolTestCase(B3TestCase):
    """ Ease testcases that need an working B3 console and need to control the Spamcontrol plugin config """

    def setUp(self):
        self.timer_patcher = patch('threading.Timer')
        self.timer_patcher.start()

        self.log = logging.getLogger('output')
        self.log.propagate = False

        B3TestCase.setUp(self)
        self.console.startup()
        self.log.propagate = True

    def tearDown(self):
        B3TestCase.tearDown(self)
        self.timer_patcher.stop()

    def init_plugin(self, config_content):
        self.conf = XmlConfigParser()
        self.conf.setXml(config_content)
        self.p = SpamcontrolPlugin(self.console, self.conf)

        self.log.setLevel(logging.DEBUG)
        self.log.info("============================= Spamcontrol plugin: loading config ============================")
        self.p.onLoadConfig()
        self.log.info("============================= Spamcontrol plugin: starting  =================================")
        self.p.onStartup()
Exemple #5
0
 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)
Exemple #6
0
    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)
class CensorurtTestCase(B3TestCase):
    """
    Ease testcases that need an working B3 console and need to control the censorurt plugin config
    """
    def setUp(self):
        # Timer needs to be patched or the Censor plugin would schedule a 2nd check one minute after
        # penalizing a player.
        self.timer_patcher = patch('threading.Timer')
        self.timer_patcher.start()

        self.log = logging.getLogger('output')
        self.log.propagate = False

        B3TestCase.setUp(self)
        self.console.startup()
        self.log.propagate = True

        self.joe = FakeClient(self.console, name="Joe", exactName="Joe", guid="zaerezarezar", groupBits=1, team=b3.TEAM_UNKNOWN)

        self.conf = XmlConfigParser()
        self.p = CensorurtPlugin(self.console, self.conf)

    def tearDown(self):
        B3TestCase.tearDown(self)
        self.timer_patcher.stop()

    def init_plugin(self, config_content):
        self.conf.setXml(config_content)
        self.log.setLevel(logging.DEBUG)
        self.log.info("============================= Censor plugin: loading config ============================")
        self.p.onLoadConfig()
        self.log.info("============================= Censor plugin: starting  =================================")
        self.p.onStartup()
Exemple #8
0
class CensorTestCase(B3TestCase):
    """base class for TestCase to apply to the Censor plugin"""

    def setUp(self):
        # Timer needs to be patched or the Censor plugin would schedule a 2nd check one minute after
        # penalizing a player.
        self.timer_patcher = patch('threading.Timer')
        self.timer_patcher.start()

        super(CensorTestCase, self).setUp()
        self.conf = XmlConfigParser()
        self.conf.setXml(r"""
            <configuration plugin="censor">
                <badwords>
                    <penalty type="warning" reasonkeyword="racist"/>
                </badwords>
                <badnames>
                    <penalty type="warning" reasonkeyword="badname"/>
                </badnames>
            </configuration>
        """)
        self.p = CensorPlugin(b3.console, self.conf)
        self.p.onLoadConfig()

    def tearDown(self):
        self.timer_patcher.stop()

    def assert_name_penalized_count(self, name, count):
        self.p.penalizeClientBadname = Mock()

        mock_client = Mock()
        mock_client.connected = True
        mock_client.exactName = name

        self.p.checkBadName(mock_client)
        self.assertEquals(count, self.p.penalizeClientBadname.call_count, "name '%s' should have been penalized %s time" % (name, count))

    def assert_name_is_penalized(self, name):
        self.assert_name_penalized_count(name, 1)

    def assert_name_is_not_penalized(self, name):
        self.assert_name_penalized_count(name, 0)

    def assert_chat_is_penalized(self, text):
        self.p.penalizeClient = Mock()

        mock_client = Mock()
        mock_client.connected = True

        try:
            self.p.checkBadWord(text, mock_client)
            self.fail("text [%s] should have raised a VetoEvent" % text)
        except b3.events.VetoEvent, e:
            self.assertEquals(1, self.p.penalizeClient.call_count, "text [%s] should have been penalized" % text)
            return self.p.penalizeClient.call_args[0] if len(self.p.penalizeClient.call_args) else None
Exemple #9
0
class CensorTestCase(B3TestCase):
    """base class for TestCase to apply to the Censor plugin"""

    def setUp(self):
        # Timer needs to be patched or the Censor plugin would schedule a 2nd check one minute after
        # penalizing a player.
        self.timer_patcher = patch('threading.Timer')
        self.timer_patcher.start()

        super(CensorTestCase, self).setUp()
        self.conf = XmlConfigParser()
        self.conf.setXml(r"""
            <configuration plugin="censor">
                <badwords>
                    <penalty type="warning" reasonkeyword="racist"/>
                </badwords>
                <badnames>
                    <penalty type="warning" reasonkeyword="badname"/>
                </badnames>
            </configuration>
        """)
        self.p = CensorPlugin(self.console, self.conf)
        self.p.onLoadConfig()

    def tearDown(self):
        self.timer_patcher.stop()

    def assert_name_penalized_count(self, name, count):
        self.p.penalizeClientBadname = Mock()

        mock_client = Mock()
        mock_client.connected = True
        mock_client.exactName = name

        self.p.checkBadName(mock_client)
        self.assertEquals(count, self.p.penalizeClientBadname.call_count, "name '%s' should have been penalized %s time" % (name, count))

    def assert_name_is_penalized(self, name):
        self.assert_name_penalized_count(name, 1)

    def assert_name_is_not_penalized(self, name):
        self.assert_name_penalized_count(name, 0)

    def assert_chat_is_penalized(self, text):
        self.p.penalizeClient = Mock()

        mock_client = Mock()
        mock_client.connected = True

        try:
            self.p.checkBadWord(text, mock_client)
            self.fail("text [%s] should have raised a VetoEvent" % text)
        except b3.events.VetoEvent, e:
            self.assertEquals(1, self.p.penalizeClient.call_count, "text [%s] should have been penalized" % text)
            return self.p.penalizeClient.call_args[0] if len(self.p.penalizeClient.call_args) else None
 def test_no_client_table(self, pluginCronTab_mock):
     conf = XmlConfigParser()
     conf.setXml(r"""<configuration plugin="status">
         <settings name="settings">
             <set name="interval">60</set>
             <set name="output_file">~/status.xml</set>
         </settings>
     </configuration>""")
     self.p = StatusPlugin(self.console, conf)
     self.p.onLoadConfig()
     self.assertEqual("current_clients", self.p._clientTable)
 def test_restart_with_delay():
     conf = XmlConfigParser()
     conf.setXml("""
     <configuration>
         <restart name="at restart + 7s" delay="7s">
             <rcon>say "we just restarted 7s ago"</rcon>
         </restart>
     </configuration>
     """)
     fakeConsole.gameName = 'urt41'
     p3 = SchedulerPlugin(fakeConsole, conf)
     p3.onLoadConfig()
     p3.onStartup()
 def test_no_client_table(self, pluginCronTab_mock):
     conf = XmlConfigParser()
     conf.setXml(
         r"""<configuration plugin="status">
         <settings name="settings">
             <set name="interval">60</set>
             <set name="output_file">~/status.xml</set>
         </settings>
     </configuration>"""
     )
     self.p = StatusPlugin(self.console, conf)
     self.p.onLoadConfig()
     self.assertEqual("current_clients", self.p._clientTable)
 def test_hourly():
     conf = XmlConfigParser()
     conf.setXml("""
     <configuration>
         <hourly name="hourly1" minutes="13">
             <rcon>say "^9Nightime maprotation in effect."</rcon>
             <rcon>set sv_maprotation "gametype ctf map mp_carentan gametype ctf map mp_toujane gametype ctf map mp_buhlert gametype ctf map mp_railyard gametype ctf map mp_sfrance_final gametype ctf map mp_leningrad gametype ctf map mp_farmhouse gametype ctf map mp_decoy gametype ctf map mp_carentan gametype ctf map mp_dawnville gametype ctf map mp_matmata gametype ctf map mp_breakout gametype ctf map mp_burgundy"</rcon>
         </hourly>
     </configuration>
     """)
     fakeConsole.gameName = 'urt41'
     p3 = SchedulerPlugin(fakeConsole, conf)
     p3.onLoadConfig()
     p3.onStartup()
 def test_classic_syntax():
     conf = XmlConfigParser()
     conf.setXml("""
     <configuration plugin="scheduler">
         <cron name="test0" seconds="0">
             <rcon>say "hello you"</rcon>
             <rcon>say "hello world"</rcon>
         </cron>
     </configuration>
     """)
     fakeConsole.gameName = 'urt41'
     p = SchedulerPlugin(fakeConsole, conf)
     p.onLoadConfig()
     p.onStartup()
 def test_restart_with_delay():
     conf = XmlConfigParser()
     conf.setXml(
         """
     <configuration>
         <restart name="at restart + 7s" delay="7s">
             <rcon>say "we just restarted 7s ago"</rcon>
         </restart>
     </configuration>
     """
     )
     fakeConsole.gameName = "urt41"
     p3 = SchedulerPlugin(fakeConsole, conf)
     p3.onLoadConfig()
     p3.onStartup()
Exemple #16
0
class CommandTestCase(B3TestCase):
    def setUp(self):
        B3TestCase.setUp(self)
        self.conf = XmlConfigParser()
        self.conf.setXml("""
            <configuration plugin="admin">
                <settings name="warn">
                    <set name="warn_delay">5</set>
                </settings>
            </configuration>
        """)
        self.p = AdminPlugin(b3.console, self.conf)
        self.mock_client = Mock(spec=Client, name="client")
        self.mock_client.maxLevel = 0
        self.mock_client.exactName = "MockClient"
        self.mock_command = Mock(spec=Command, name='cmd')
 def test_hourly():
     conf = XmlConfigParser()
     conf.setXml(
         """
     <configuration>
         <hourly name="hourly1" minutes="13">
             <rcon>say "^9Nightime maprotation in effect."</rcon>
             <rcon>set sv_maprotation "gametype ctf map mp_carentan gametype ctf map mp_toujane gametype ctf map mp_buhlert gametype ctf map mp_railyard gametype ctf map mp_sfrance_final gametype ctf map mp_leningrad gametype ctf map mp_farmhouse gametype ctf map mp_decoy gametype ctf map mp_carentan gametype ctf map mp_dawnville gametype ctf map mp_matmata gametype ctf map mp_breakout gametype ctf map mp_burgundy"</rcon>
         </hourly>
     </configuration>
     """
     )
     fakeConsole.gameName = "urt41"
     p3 = SchedulerPlugin(fakeConsole, conf)
     p3.onLoadConfig()
     p3.onStartup()
 def test_classic_syntax():
     conf = XmlConfigParser()
     conf.setXml(
         """
     <configuration plugin="scheduler">
         <cron name="test0" seconds="0">
             <rcon>say "hello you"</rcon>
             <rcon>say "hello world"</rcon>
         </cron>
     </configuration>
     """
     )
     fakeConsole.gameName = "urt41"
     p = SchedulerPlugin(fakeConsole, conf)
     p.onLoadConfig()
     p.onStartup()
Exemple #19
0
class CommandTestCase(B3TestCase):
    def setUp(self):
        B3TestCase.setUp(self)
        self.conf = XmlConfigParser()
        self.conf.setXml("""
            <configuration plugin="admin">
                <settings name="warn">
                    <set name="warn_delay">5</set>
                </settings>
            </configuration>
        """)
        self.p = AdminPlugin(b3.console, self.conf)
        self.mock_client = Mock(spec=Client, name="client")
        self.mock_client.maxLevel = 0
        self.mock_client.exactName = "MockClient"
        self.mock_command = Mock(spec=Command, name='cmd')
 def test_bf3():
     conf = XmlConfigParser()
     conf.setXml("""
     <configuration plugin="scheduler">
         <cron name="every3m" minutes="*/3">
             <frostbite command="yell">
                 <arg>my text</arg>
                 <arg>10</arg>
                 <arg>all</arg>
             </frostbite>
         </cron>
     </configuration>
     """)
     fakeConsole.gameName = 'bf3'
     p2 = SchedulerPlugin(fakeConsole, conf)
     p2.onLoadConfig()
     p2.onStartup()
Exemple #21
0
    def init_plugin(self, config_content=None):
        conf = None
        if config_content:
            conf = XmlConfigParser()
            conf.setXml(config_content)
        elif os.path.exists(default_plugin_file):
            conf = default_plugin_file
        else:
            unittest.skip("cannot get default plugin config file at %s" % default_plugin_file)

        self.p = AdvPlugin(self.console, conf)
        self.conf = self.p.config
        self.log.setLevel(logging.DEBUG)
        self.log.info("============================= Adv plugin: loading config ============================")
        self.p.onLoadConfig()
        self.log.info("============================= Adv plugin: starting  =================================")
        self.p.onStartup()
 def test_frostbite_syntax():
     conf = XmlConfigParser()
     conf.setXml("""
     <configuration plugin="scheduler">
         <cron name="test2" seconds="10,30">
             <frostbite command="admin.say">
                 <arg>server shuting down</arg>
                 <arg>all</arg>
             </frostbite>
             <frostbite command="admin.shutDown" />
         </cron>
     </configuration>
     """)
     fakeConsole.gameName = 'moh'
     p2 = SchedulerPlugin(fakeConsole, conf)
     p2.onLoadConfig()
     p2.onStartup()
 def test_default_values(self):
     conf = XmlConfigParser()
     conf.setXml("""
     <configuration plugin="teamspeakbf">
     	<settings name="teamspeakServer">
             <set name="host">foo_host</set>
             <set name="queryport">foo_queryport</set>
             <set name="id">1</set>
             <set name="login">foo_login</set>
             <set name="password">foo_password</set>
         </settings>
     </configuration>
     """)
     p = TeamspeakPlugin(fakeConsole, conf)
     p.readConfig()
     self.assertEqual(TeamspeakPlugin.TS3ChannelB3, p.TS3ChannelB3)
     self.assertEqual(TeamspeakPlugin.TS3ChannelTeam1, p.TS3ChannelTeam1)
     self.assertEqual(TeamspeakPlugin.TS3ChannelTeam2, p.TS3ChannelTeam2)
 def test_default_values(self):
     conf = XmlConfigParser()
     conf.setXml("""
     <configuration plugin="teamspeakbf">
     	<settings name="teamspeakServer">
             <set name="host">foo_host</set>
             <set name="queryport">foo_queryport</set>
             <set name="id">1</set>
             <set name="login">foo_login</set>
             <set name="password">foo_password</set>
         </settings>
     </configuration>
     """)
     p = TeamspeakPlugin(fakeConsole, conf)
     p.readConfig()
     self.assertEqual(TeamspeakPlugin.TS3ChannelB3, p.TS3ChannelB3)
     self.assertEqual(TeamspeakPlugin.TS3ChannelTeam1, p.TS3ChannelTeam1)
     self.assertEqual(TeamspeakPlugin.TS3ChannelTeam2, p.TS3ChannelTeam2)
    def test_daily():
        conf = XmlConfigParser()
        conf.setXml("""
        <configuration>
            <daily name="dayly1" hour="19" minutes="11">
                <rcon>say "^9Nightime maprotation in effect."</rcon>
                <rcon>set sv_maprotation "gametype ctf map mp_carentan gametype ctf map mp_toujane gametype ctf map mp_buhlert gametype ctf map mp_railyard gametype ctf map mp_sfrance_final gametype ctf map mp_leningrad gametype ctf map mp_farmhouse gametype ctf map mp_decoy gametype ctf map mp_carentan gametype ctf map mp_dawnville gametype ctf map mp_matmata gametype ctf map mp_breakout gametype ctf map mp_burgundy"</rcon>
            </daily>

            <daily name="dayly2" hour="19" minutes="12">
                <rcon>say "^9Daytime maprotation in effect."</rcon>
                <rcon>set sv_maprotation "gametype ctf map mp_carentan gametype ctf map mp_toujane gametype ctf map mp_xfireb gametype ctf map rnr_neuville gametype ctf map mp_buhlert gametype ctf map mp_railyard gametype ctf map mp_farmhouse gametype ctf map mp_decoy gametype ctf map mp_carentan gametype ctf map mp_alcazaba gametype ctf map mp_dawnville gametype ctf map mp_powcamp gametype ctf map mp_matmata gametype ctf map mp_breakout gametype ctf map mp_burgundy gametype ctf map mp_canal3 gametype ctf map mp_destroyed_village gametype ctf map mp_trainstation"</rcon>
            </daily>
        </configuration>
        """)
        fakeConsole.gameName = 'urt41'
        p3 = SchedulerPlugin(fakeConsole, conf)
        p3.onLoadConfig()
        p3.onStartup()
 def test_old_bfbc2_syntax():
     conf = XmlConfigParser()
     conf.setXml("""
     <configuration plugin="scheduler">
         <cron name="test1" seconds="5,25">
             <bfbc2 command="admin.say">
                 <arg>hello world</arg>
                 <arg>all</arg>
             </bfbc2>
             <bfbc2 command="punkBuster.pb_sv_command">
                 <arg>pb_sv_update</arg>
             </bfbc2>
         </cron>
     </configuration>
     """)
     fakeConsole.gameName = 'bfbc2'
     p1 = SchedulerPlugin(fakeConsole, conf)
     p1.onLoadConfig()
     p1.onStartup()
 def test_frostbite_syntax():
     conf = XmlConfigParser()
     conf.setXml(
         """
     <configuration plugin="scheduler">
         <cron name="test2" seconds="10,30">
             <frostbite command="admin.say">
                 <arg>server shuting down</arg>
                 <arg>all</arg>
             </frostbite>
             <frostbite command="admin.shutDown" />
         </cron>
     </configuration>
     """
     )
     fakeConsole.gameName = "moh"
     p2 = SchedulerPlugin(fakeConsole, conf)
     p2.onLoadConfig()
     p2.onStartup()
 def test_bf3():
     conf = XmlConfigParser()
     conf.setXml(
         """
     <configuration plugin="scheduler">
         <cron name="every3m" minutes="*/3">
             <frostbite command="yell">
                 <arg>my text</arg>
                 <arg>10</arg>
                 <arg>all</arg>
             </frostbite>
         </cron>
     </configuration>
     """
     )
     fakeConsole.gameName = "bf3"
     p2 = SchedulerPlugin(fakeConsole, conf)
     p2.onLoadConfig()
     p2.onStartup()
Exemple #29
0
    def init_plugin(self, config_content=None):
        conf = None
        if config_content:
            conf = XmlConfigParser()
            conf.setXml(config_content)
        elif default_plugin_content:
            conf = XmlConfigParser()
            conf.setXml(default_plugin_content)
        else:
            unittest.skip("cannot get default plugin config file at %s" % default_plugin_file)

        self.p = AdvPlugin(self.console, conf)
        self.p.save = Mock()
        self.conf = self.p.config
        self.log.setLevel(logging.DEBUG)
        self.log.info("============================= Adv plugin: loading config ============================")
        self.p.onLoadConfig()
        self.log.info("============================= Adv plugin: starting  =================================")
        self.p.onStartup()
    def init_plugin(self, config_content=None):
        conf = None
        if config_content:
            conf = XmlConfigParser()
            conf.setXml(config_content)
        elif ADV_CONFIG_CONTENT:
            conf = XmlConfigParser()
            conf.setXml(ADV_CONFIG_CONTENT)
        else:
            unittest.skip("cannot get default plugin config file at %s" % ADV_CONFIG_FILE)

        self.p = AdvPlugin(self.console, conf)
        self.p.save = Mock()
        self.conf = self.p.config
        self.log.setLevel(logging.DEBUG)
        self.log.info("============================= Adv plugin: loading config ============================")
        self.p.onLoadConfig()
        self.log.info("============================= Adv plugin: starting  =================================")
        self.p.onStartup()
Exemple #31
0
 def test_DefaultTarget_off(self):
     conf = XmlConfigParser()
     conf.setXml("""
     <configuration plugin="teamspeakbf">
     	<settings name="teamspeakServer">
             <set name="host">foo_host</set>
             <set name="queryport">foo_queryport</set>
             <set name="id">1</set>
             <set name="login">foo_login</set>
             <set name="password">foo_password</set>
         </settings>
         <settings name="teamspeakChannels">
             <set name="DefaultTarget">off</set>
         </settings>
     </configuration>
     """)
     p = TeamspeakbfPlugin(fakeConsole, conf)
     p.readConfig()
     self.assertEqual('off', p.autoswitchDefaultTarget)
 def test_plugin_tasks():
     conf = XmlConfigParser()
     conf.setXml("""
     <configuration plugin="scheduler">
         <cron name="test_plugin_enable" seconds="0,10,20,30,40,50">
             <enable_plugin plugin="admin"/>
         </cron>
         <cron name="test_plugin_disable" seconds="5,15,25,35,45,55">
             <disable_plugin plugin="admin"/>
         </cron>
         <cron name="test_plugin_fail">
             <enable_plugin plugin="foo"/>
             <disable_plugin plugin="bar"/>
         </cron>
     </configuration>
     """)
     fakeConsole.gameName = 'iourt41'
     p3 = SchedulerPlugin(fakeConsole, conf)
     p3.onLoadConfig()
     p3.onStartup()
class Test_XmlConfigParser_windows(B3TestCase):

    def setUp(self):
        B3TestCase.setUp(self)
        self.conf = XmlConfigParser()
        self.conf.setXml("""
            <configuration plugin="test">
                <settings name="settings">
                    <set name="output_file">@conf/status.xml</set>
                </settings>
            </configuration>
        """)

    def test_getpath(self):
        self.console.config.fileName = r"c:\some\where\conf\b3.xml"
        self.assertEqual(r"c:\some\where\conf\status.xml", self.conf.getpath('settings', 'output_file'))

    def test_issue_xlr8or_18(self):
        self.console.config.fileName = r"b3.xml"
        self.assertEqual(r"status.xml", self.conf.getpath('settings', 'output_file'))
class Test_XmlConfigParser_windows(B3TestCase):

    def setUp(self):
        B3TestCase.setUp(self)
        self.conf = XmlConfigParser()
        self.conf.setXml("""
            <configuration plugin="test">
                <settings name="settings">
                    <set name="output_file">@conf/status.xml</set>
                </settings>
            </configuration>
        """)

    def test_getpath(self):
        self.console.config.fileName = r"c:\some\where\conf\b3.xml"
        self.assertEqual(r"c:\some\where\conf\status.xml", self.conf.getpath('settings', 'output_file'))

    def test_issue_xlr8or_18(self):
        self.console.config.fileName = r"b3.xml"
        self.assertEqual(r"status.xml", self.conf.getpath('settings', 'output_file'))
Exemple #35
0
class Test_XmlConfigParser_outputfile(B3TestCase):

    def setUp(self):
        B3TestCase.setUp(self)
        self.conf = XmlConfigParser()
        self.conf.setXml("""
            <configuration plugin="test">
                <settings name="settings">
                    <set name="output_file">@conf/status.xml</set>
                </settings>
            </configuration>
        """)

    def test_getpath(self):
        status_file = os.path.join("tmp", "status.xml")
        self.console.config.fileName = os.path.join("tmp", "b3.xml")
        self.assertEqual(status_file, self.conf.getpath('settings', 'output_file'))

    def test_issue_xlr8or_18(self):
        self.console.config.fileName = r"b3.xml"
        self.assertEqual(r"status.xml", self.conf.getpath('settings', 'output_file'))
 def test_old_bfbc2_syntax():
     conf = XmlConfigParser()
     conf.setXml(
         """
     <configuration plugin="scheduler">
         <cron name="test1" seconds="5,25">
             <bfbc2 command="admin.say">
                 <arg>hello world</arg>
                 <arg>all</arg>
             </bfbc2>
             <bfbc2 command="punkBuster.pb_sv_command">
                 <arg>pb_sv_update</arg>
             </bfbc2>
         </cron>
     </configuration>
     """
     )
     fakeConsole.gameName = "bfbc2"
     p1 = SchedulerPlugin(fakeConsole, conf)
     p1.onLoadConfig()
     p1.onStartup()
    def test_daily():
        conf = XmlConfigParser()
        conf.setXml(
            """
        <configuration>
            <daily name="dayly1" hour="19" minutes="11">
                <rcon>say "^9Nightime maprotation in effect."</rcon>
                <rcon>set sv_maprotation "gametype ctf map mp_carentan gametype ctf map mp_toujane gametype ctf map mp_buhlert gametype ctf map mp_railyard gametype ctf map mp_sfrance_final gametype ctf map mp_leningrad gametype ctf map mp_farmhouse gametype ctf map mp_decoy gametype ctf map mp_carentan gametype ctf map mp_dawnville gametype ctf map mp_matmata gametype ctf map mp_breakout gametype ctf map mp_burgundy"</rcon>
            </daily>

            <daily name="dayly2" hour="19" minutes="12">
                <rcon>say "^9Daytime maprotation in effect."</rcon>
                <rcon>set sv_maprotation "gametype ctf map mp_carentan gametype ctf map mp_toujane gametype ctf map mp_xfireb gametype ctf map rnr_neuville gametype ctf map mp_buhlert gametype ctf map mp_railyard gametype ctf map mp_farmhouse gametype ctf map mp_decoy gametype ctf map mp_carentan gametype ctf map mp_alcazaba gametype ctf map mp_dawnville gametype ctf map mp_powcamp gametype ctf map mp_matmata gametype ctf map mp_breakout gametype ctf map mp_burgundy gametype ctf map mp_canal3 gametype ctf map mp_destroyed_village gametype ctf map mp_trainstation"</rcon>
            </daily>
        </configuration>
        """
        )
        fakeConsole.gameName = "urt41"
        p3 = SchedulerPlugin(fakeConsole, conf)
        p3.onLoadConfig()
        p3.onStartup()
Exemple #38
0
class Test_parseUserCmd(B3TestCase):
    def setUp(self):
        B3TestCase.setUp(self)
        self.conf = XmlConfigParser()
        self.conf.setXml("""
            <configuration plugin="admin">
            </configuration>
        """)
        self.p = AdminPlugin(b3.console, self.conf)

    @unittest.expectedFailure
    def test_clientinfo_bad_arg(self):
        self.assertIsNone(self.p.parseUserCmd(None))

    def test_clientinfo_empty_arg(self):
        self.assertIsNone(self.p.parseUserCmd(''))

    def test_clientinfo_only_1_arg(self):
        self.assertEqual(('someone', None), self.p.parseUserCmd('someone'))
        # see https://github.com/xlr8or/big-brother-bot/issues/54
        self.assertIsNone(self.p.parseUserCmd('someone', req=True))

    def test_clientinfo_2_args(self):
        self.assertEqual(('someone', 'param1'),
                         self.p.parseUserCmd('someone param1'))
        self.assertEqual(('someone', 'param1'),
                         self.p.parseUserCmd('someone param1', req=True))

    def test_clientinfo_3_args(self):
        self.assertEqual(('someone', 'param1 param2'),
                         self.p.parseUserCmd('someone param1 param2'))
        self.assertEqual(('someone', 'param1 param2'),
                         self.p.parseUserCmd('someone param1 param2',
                                             req=True))

    def test_clientinfo_int(self):
        self.assertEqual(('45', None), self.p.parseUserCmd('45'))
        self.assertEqual(('45', None), self.p.parseUserCmd("'45'"))
        self.assertEqual(('45', 'some param'),
                         self.p.parseUserCmd("'45' some param"))
 def test_plugin_tasks():
     conf = XmlConfigParser()
     conf.setXml(
         """
     <configuration plugin="scheduler">
         <cron name="test_plugin_enable" seconds="0,10,20,30,40,50">
             <enable_plugin plugin="admin"/>
         </cron>
         <cron name="test_plugin_disable" seconds="5,15,25,35,45,55">
             <disable_plugin plugin="admin"/>
         </cron>
         <cron name="test_plugin_fail">
             <enable_plugin plugin="foo"/>
             <disable_plugin plugin="bar"/>
         </cron>
     </configuration>
     """
     )
     fakeConsole.gameName = "iourt41"
     p3 = SchedulerPlugin(fakeConsole, conf)
     p3.onLoadConfig()
     p3.onStartup()
class LoginTestCase(B3TestCase):
    """ Ease testcases that need an working B3 console and need to control the censor plugin config """
    def setUp(self):
        self.log = logging.getLogger('output')
        self.log.propagate = False

        B3TestCase.setUp(self)

        admin_conf = XmlConfigParser()
        admin_conf.load(ADMIN_CONFIG_FILE)
        self.adminPlugin = AdminPlugin(self.console, admin_conf)
        when(self.console).getPlugin("admin").thenReturn(self.adminPlugin)
        self.adminPlugin.onLoadConfig()
        self.adminPlugin.onStartup()

        self.console.gameName = "theGame"
        self.console.startup()
        self.log.propagate = True

    def tearDown(self):
        B3TestCase.tearDown(self)

    def init_plugin(self, config_content=None):
        self.conf = XmlConfigParser()
        if config_content:
            self.conf.setXml(config_content)
        else:
            self.conf.load(default_plugin_file)
        self.p = LoginPlugin(self.console, self.conf)

        self.log.setLevel(logging.DEBUG)
        self.log.info(
            "============================= Login plugin: loading config ============================"
        )
        self.p.onLoadConfig()
        self.log.info(
            "============================= Login plugin: starting  ================================="
        )
        self.p.onStartup()
 def test_frostbite_combined_syntaxes():
     conf = XmlConfigParser()
     conf.setXml("""
     <configuration plugin="scheduler">
         <cron name="test3" seconds="15,35">
             <bfbc2 command="mycommand">
                 <arg>myArg1</arg>
                 <arg>myArg2</arg>
             </bfbc2>
         </cron>
         <cron name="test4" seconds="20,40">
             <frostbite command="mycommand">
                 <arg>myArg1</arg>
                 <arg>myArg2</arg>
             </frostbite>
         </cron>
     </configuration>
     """)
     fakeConsole.gameName = 'bfbc2'
     p3 = SchedulerPlugin(fakeConsole, conf)
     p3.onLoadConfig()
     p3.onStartup()
Exemple #42
0
class Test_getGroupLevel(B3TestCase):
    def setUp(self):
        from b3.fake import fakeConsole
        B3TestCase.setUp(self)
        self.conf = XmlConfigParser()
        self.conf.setXml("""
                <configuration plugin="admin">
                </configuration>
            """)
        self.p = AdminPlugin(fakeConsole, self.conf)

    def test_nominal(self):
        for test_data, expected in {
                'NONE': 'none',
                '0': 0,
                '1': 1,
                'guest': 0,
                'user': 1,
                'reg': 2,
                'mod': 20,
                'admin': 40,
                'fulladmin': 60,
                'senioradmin': 80,
                'superadmin': 100,
                '1-20': '1-20',
                '40-20': '40-20',
                'user-admin': '1-40',
        }.items():
            result = self.p.getGroupLevel(test_data)
            if expected != result:
                self.fail("%r, expecting %r but got %r" %
                          (test_data, expected, result))

    def test_failures(self):
        self.p.error = Mock()
        for test_data in ('foo', 'mod-foo', 'foo-mod'):
            self.assertFalse(self.p.getGroupLevel(test_data))
            assert self.p.error.called
Exemple #43
0
class Test_getGroupLevel(B3TestCase):

    def setUp(self):
        from b3.fake import fakeConsole
        B3TestCase.setUp(self)
        self.conf = XmlConfigParser()
        self.conf.setXml("""
                <configuration plugin="admin">
                </configuration>
            """)
        self.p = AdminPlugin(fakeConsole, self.conf)

    def test_nominal(self):
        for test_data, expected in {
            'NONE': 'none',
            '0': 0,
            '1': 1,
            'guest': 0,
            'user': 1,
            'reg': 2,
            'mod': 20,
            'admin': 40,
            'fulladmin': 60,
            'senioradmin': 80,
            'superadmin': 100,
            '1-20': '1-20',
            '40-20': '40-20',
            'user-admin': '1-40',
        }.items():
            result = self.p.getGroupLevel(test_data)
            if expected != result:
                self.fail("%r, expecting %r but got %r" % (test_data, expected, result))

    def test_failures(self):
        self.p.error = Mock()
        for test_data in ('foo', 'mod-foo', 'foo-mod'):
            self.assertFalse(self.p.getGroupLevel(test_data))
            assert self.p.error.called
class LoginTestCase(B3TestCase):
    """ Ease testcases that need an working B3 console and need to control the censor plugin config """

    def setUp(self):
        self.log = logging.getLogger('output')
        self.log.propagate = False

        B3TestCase.setUp(self)

        admin_conf = XmlConfigParser()
        admin_conf.load(ADMIN_CONFIG_FILE)
        self.adminPlugin = AdminPlugin(self.console, admin_conf)
        when(self.console).getPlugin("admin").thenReturn(self.adminPlugin)
        self.adminPlugin.onLoadConfig()
        self.adminPlugin.onStartup()

        self.console.gameName = "theGame"
        self.console.startup()
        self.log.propagate = True


    def tearDown(self):
        B3TestCase.tearDown(self)

    def init_plugin(self, config_content=None):
        self.conf = XmlConfigParser()
        if config_content:
            self.conf.setXml(config_content)
        else:
            self.conf.load(default_plugin_file)
        self.p = LoginPlugin(self.console, self.conf)

        self.log.setLevel(logging.DEBUG)
        self.log.info("============================= Login plugin: loading config ============================")
        self.p.onLoadConfig()
        self.log.info("============================= Login plugin: starting  =================================")
        self.p.onStartup()
 def test_frostbite_combined_syntaxes():
     conf = XmlConfigParser()
     conf.setXml(
         """
     <configuration plugin="scheduler">
         <cron name="test3" seconds="15,35">
             <bfbc2 command="mycommand">
                 <arg>myArg1</arg>
                 <arg>myArg2</arg>
             </bfbc2>
         </cron>
         <cron name="test4" seconds="20,40">
             <frostbite command="mycommand">
                 <arg>myArg1</arg>
                 <arg>myArg2</arg>
             </frostbite>
         </cron>
     </configuration>
     """
     )
     fakeConsole.gameName = "bfbc2"
     p3 = SchedulerPlugin(fakeConsole, conf)
     p3.onLoadConfig()
     p3.onStartup()
Exemple #46
0
class Test_parseUserCmd(B3TestCase):

    def setUp(self):
        B3TestCase.setUp(self)
        self.conf = XmlConfigParser()
        self.conf.setXml("""
            <configuration plugin="admin">
            </configuration>
        """)
        self.p = AdminPlugin(b3.console, self.conf)


    @unittest.expectedFailure
    def test_clientinfo_bad_arg(self):
        self.assertIsNone(self.p.parseUserCmd(None))

    def test_clientinfo_empty_arg(self):
        self.assertIsNone(self.p.parseUserCmd(''))

    def test_clientinfo_only_1_arg(self):
        self.assertEqual(('someone', None), self.p.parseUserCmd('someone'))
        # see https://github.com/xlr8or/big-brother-bot/issues/54
        self.assertIsNone(self.p.parseUserCmd('someone', req=True))

    def test_clientinfo_2_args(self):
        self.assertEqual(('someone', 'param1'), self.p.parseUserCmd('someone param1'))
        self.assertEqual(('someone', 'param1'), self.p.parseUserCmd('someone param1', req=True))

    def test_clientinfo_3_args(self):
        self.assertEqual(('someone', 'param1 param2'), self.p.parseUserCmd('someone param1 param2'))
        self.assertEqual(('someone', 'param1 param2'), self.p.parseUserCmd('someone param1 param2', req=True))

    def test_clientinfo_int(self):
        self.assertEqual(('45', None), self.p.parseUserCmd('45'))
        self.assertEqual(('45', None), self.p.parseUserCmd("'45'"))
        self.assertEqual(('45', 'some param'), self.p.parseUserCmd("'45' some param"))
Exemple #47
0
conf.setXml("""
<configuration plugin="teamspeakbf">
	<settings name="teamspeakServer">
		<!-- IP or domain where your teamspeak server is hosted -->
		<set name="host">{ts_host}</set>
		<!-- query port of your teamspeak server (default: 10011) -->
		<set name="queryport">{ts_port}</set>
		<!-- Teamspeak virtual server ID -->
		<set name="id">{ts_id}</set>
		<!-- B3 login information. You need to create a ServerQuery Login for B3. video tutorial : http://bit.ly/a5qcjp -->
		<set name="login">{ts_login}</set>
		<set name="password">{ts_password}</set>
	</settings>
	<settings name="teamspeakChannels">
		<set name="B3">B3 autoswitched channel</set>
		<set name="team1">Team 1</set>
		<set name="team2">Team 2</set>
	</settings>
    <settings name="commands">
        <!-- set here levels needed to be allowed to use commands.
            You can define a command alias adding '-' and the alias after the command name.
            Levels:
            0 : everyone
            1 : registered users
            2 : regular users
            20 : moderators
            40 : admins
            60 : full admins
            80 : senior admins
            100 : super admins
        -->

        <!-- Allow admins to reconnect/disconnect B3 to the teamspeak server -->
        <set name="tsreconnect">100</set>
        <set name="tsdisconnect">100</set>

        <!-- give the player info about the current Teamspeak server and his status -->
        <set name="teamspeak-ts">1</set>

        <!-- !tsauto allow players to change their autoswitch preferences between one
        of 'off', 'team', 'squad' -->
        <set name="tsauto">1</set>
    </settings>
</configuration>
""".format(ts_host=config.get("teamspeak_server", "host"),
           ts_port=config.get("teamspeak_server", "port"),
           ts_id=config.get("teamspeak_server", "id"),
           ts_login=config.get("teamspeak_server", "login"),
           ts_password=config.get("teamspeak_server", "password")))
        except:
            self.warning('Unable to reach B3 masterserver. unknown error')
            print sys.exc_info()


if __name__ == '__main__':
    from b3.fake import fakeConsole
    import time
    
    from b3.config import XmlConfigParser
    
    conf = XmlConfigParser()
    conf.setXml("""
    <configuration plugin="publist">
        <settings name="settings">
            <set name="url">http://test.somewhere.com/serverping.php</set>
        </settings>
    </configuration>
    """)

    
    #fakeConsole._publicIp = '127.0.0.1'
    fakeConsole._publicIp = '11.22.33.44'
    p = PublistPlugin(fakeConsole, conf)
    #p.onStartup()
    p.onLoadConfig()
    #p.update()
    
    p.sendInfo({'version': '1.3-dev', 
            'os': 'nt', 
            'database': 'unknown', 
Exemple #49
0
            for Line in f:
                crc = zlib.crc32(Line, crc)
        return crc

if __name__ == '__main__':
    from b3.fake import fakeConsole
    import time
    
    from b3.config import XmlConfigParser
    
    conf = XmlConfigParser()
    conf.setXml("""
    <configuration plugin="publist">
        <settings name="settings">
            <set name="urlsqdf">http://test.somewhere.com/serverping.php</set>
            <set name="url">http://localhost/b3publist/serverping.php</set>
            <set name="delay">30</set>
        </settings>
    </configuration>
    """)

    
    
    def test_startup():
        p._initial_heartbeat_delay = 10
        p.onStartup()
        time.sleep(5)
        print "_heartbeat_sent : %s" % p._heartbeat_sent
        time.sleep(20)
        print "_heartbeat_sent : %s" % p._heartbeat_sent
        fakeConsole.queueEvent(b3.events.Event(b3.events.EVT_STOP, None, None))
    conf.setXml("""
    <configuration plugin="weaponcontrolurt">

      <settings name="commands">
        <!-- min level required to use the weaponcontrol command
            0 : guest
            1 : user
            2 : regular
            20 : moderator
            40 : admin
            60 : fulladmin
            80 : senioradmin
            100 : superadmin
          -->
            <set name="weaponcontrol-wpctrl">60</set>
        </settings>

        <!-- put '0' below to disallow a weapon, put '1' to allow -->
        <settings name="weapons">
            <set name="Beretta 92G">0</set>
            <set name="Desert Eagle">1</set>
            <set name="SPAS-12">1</set>
            <set name="MP5K">1</set>
            <set name="UMP45">1</set>
            <set name="HK69">1</set>
            <set name="LR300ML">1</set>
            <set name="M4A1">1</set>
            <set name="G36">1</set>
            <set name="PSG-1">1</set>
            <set name="SR-8">1</set>
            <set name="AK-103">1</set>
            <set name="Negev">1</set>
            <set name="HE Grenade">1</set>
            <set name="Smoke Grenade">0</set>
            <set name="Kevlar Vest">1</set>
            <set name="Kevlar Helmet">1</set>
            <set name="Silencer">1</set>
            <set name="Laser Sight">1</set>
            <set name="Medkit">1</set>
            <set name="NVGs">1</set>
            <set name="Extra Ammo">1</set>
        </settings>
    </configuration>
    """)
Exemple #51
0
            self.warning('Unable to reach B3 masterserver. unknown error')
            print sys.exc_info()


if __name__ == '__main__':
    from b3.fake import fakeConsole
    import time
    
    from b3.config import XmlConfigParser
    
    conf = XmlConfigParser()
    conf.setXml("""
    <configuration plugin="publist">
        <settings name="settings">
            <set name="urlsqdf">http://test.somewhere.com/serverping.php</set>
            <set name="url">http://localhost/b3publist/serverping.php</set>
            <set name="delay">30</set>
        </settings>
    </configuration>
    """)

    
    
    def test_startup():
        p._initial_heartbeat_delay = 10
        p.onStartup()
        time.sleep(5)
        print "_heartbeat_sent : %s" % p._heartbeat_sent
        time.sleep(20)
        print "_heartbeat_sent : %s" % p._heartbeat_sent
        fakeConsole.queueEvent(b3.events.Event(b3.events.EVT_STOP, None, None))
class Tk_functional_test(B3TestCase):
    def setUp(self):
        B3TestCase.setUp(self)

        self.console.gameName = 'f00'

        self.adminPlugin = AdminPlugin(self.console, ADMIN_CONFIG_FILE)
        when(self.console).getPlugin("admin").thenReturn(self.adminPlugin)
        self.adminPlugin.onLoadConfig()
        self.adminPlugin.onStartup()

        self.conf = XmlConfigParser()
        self.conf.setXml(r"""
        <configuration plugin="tk">
            <settings name="settings">
                <set name="max_points">400</set>
                <set name="levels">0,1,2,20,40</set>
                <set name="round_grace">7</set>
                <set name="issue_warning">sfire</set>
                <set name="grudge_enable">True</set>
                <set name="private_messages">True</set>
            </settings>
            <settings name="messages">
                <set name="ban">^7team damage over limit</set>
                <set name="forgive">^7$vname^7 has forgiven $aname [^3$points^7]</set>
                <set name="grudged">^7$vname^7 has a ^1grudge ^7against $aname [^3$points^7]</set>
                <set name="forgive_many">^7$vname^7 has forgiven $attackers</set>
                <set name="forgive_warning">^1ALERT^7: $name^7 auto-kick if not forgiven. Type ^3!forgive $cid ^7to forgive. [^3damage: $points^7]</set>
                <set name="no_forgive">^7no one to forgive</set>
                <set name="no_punish">^7no one to punish</set>
                <set name="players">^7Forgive who? %s</set>
                <set name="forgive_info">^7$name^7 has ^3$points^7 TK points</set>
                <set name="grudge_info">^7$name^7 is ^1grudged ^3$points^7 TK points</set>
                <set name="forgive_clear">^7$name^7 cleared of ^3$points^7 TK points</set>
            </settings>
            <settings name="level_0">
                <set name="kill_multiplier">2</set>
                <set name="damage_multiplier">1</set>
                <set name="ban_length">2</set>
            </settings>
            <settings name="level_1">
                <set name="kill_multiplier">2</set>
                <set name="damage_multiplier">1</set>
                <set name="ban_length">2</set>
            </settings>
            <settings name="level_2">
                <set name="kill_multiplier">1</set>
                <set name="damage_multiplier">0.5</set>
                <set name="ban_length">1</set>
            </settings>
            <settings name="level_20">
                <set name="kill_multiplier">1</set>
                <set name="damage_multiplier">0.5</set>
                <set name="ban_length">0</set>
            </settings>
            <settings name="level_40">
                <set name="kill_multiplier">0.75</set>
                <set name="damage_multiplier">0.5</set>
                <set name="ban_length">0</set>
            </settings>
        </configuration>
        """)
        self.p = TkPlugin(self.console, self.conf)
        self.p.onLoadConfig()
        self.p.onStartup()

        self.joe = FakeClient(self.console,
                              name="Joe",
                              guid="joeguid",
                              groupBits=1,
                              team=b3.TEAM_RED)
        self.mike = FakeClient(self.console,
                               name="Mike",
                               guid="mikeguid",
                               groupBits=1,
                               team=b3.TEAM_RED)
        self.bill = FakeClient(self.console,
                               name="Bill",
                               guid="billguid",
                               groupBits=1,
                               team=b3.TEAM_RED)
        self.superadmin = FakeClient(self.console,
                                     name="superadmin",
                                     guid="superadminguid",
                                     groupBits=128,
                                     team=b3.TEAM_RED)

    def test_dammage_different_teams(self, timer_patch):
        self.joe.warn = Mock()
        self.joe.connects(0)
        self.mike.connects(1)
        self.mike.team = b3.TEAM_BLUE
        self.joe.damages(self.mike)
        self.assertEqual(0, self.joe.warn.call_count)

    def test_kill_different_teams(self, timer_patch):
        self.joe.warn = Mock()
        self.joe.connects(0)
        self.mike.connects(1)
        self.mike.team = b3.TEAM_BLUE
        self.joe.kills(self.mike)
        self.assertEqual(0, self.joe.warn.call_count)

    def test_kill_within_10s(self, timer_patch):
        self.p._round_grace = 10

        self.joe.warn = Mock()
        self.joe.connects(0)
        self.mike.connects(1)

        self.joe.kills(self.mike)
        self.assertEqual(1, self.joe.warn.call_count)

    def test_dammage(self, timer_patch):
        self.p._round_grace = 0

        self.joe.warn = Mock()
        self.joe.connects(0)
        self.mike.connects(1)

        self.joe.damages(self.mike)
        self.joe.damages(self.mike)
        self.joe.damages(self.mike)
        self.joe.damages(self.mike)
        self.joe.damages(self.mike)
        self.assertEqual(0, self.joe.warn.call_count)

    def test_kill(self, timer_patch):
        self.p._round_grace = 0

        self.joe.warn = Mock()
        self.joe.connects(0)
        self.mike.connects(1)

        self.joe.kills(self.mike)
        self.assertEqual(1, self.joe.warn.call_count)
        self.assertIsNotNone(
            self.mike.getMessageHistoryLike("^7type ^3!fp ^7 to forgive"))

    def test_multikill(self, timer_patch):
        self.p._round_grace = 0

        with patch.object(self.console, "say") as patched_say:
            self.joe.warn = Mock()
            self.joe.tempban = Mock()
            self.joe.connects(0)
            self.mike.connects(1)

            self.mike.clearMessageHistory()
            self.joe.kills(self.mike)
            self.assertEqual(1, self.joe.warn.call_count)
            self.assertEquals(
                1,
                len(
                    self.mike.getAllMessageHistoryLike(
                        "^7type ^3!fp ^7 to forgive")))

            self.joe.kills(self.mike)
            self.assertEqual(
                1,
                len([
                    call_args[0][0] for call_args in patched_say.call_args_list
                    if "auto-kick if not forgiven" in call_args[0][0]
                ]))

            self.joe.kills(self.mike)
            self.assertEqual(1, self.joe.tempban.call_count)

    def test_forgiveinfo(self, timer_patch):
        self.superadmin.connects(99)

        self.p._round_grace = 0

        self.joe.warn = Mock()
        self.joe.connects(0)
        self.mike.connects(1)
        self.bill.connects(2)

        self.joe.kills(self.mike)

        self.superadmin.clearMessageHistory()
        self.superadmin.says("!forgiveinfo joe")
        self.assertEqual(['Joe has 200 TK points, Attacked: Mike (200)'],
                         self.superadmin.message_history)

        self.joe.damages(self.bill, points=6)

        self.superadmin.clearMessageHistory()
        self.superadmin.says("!forgiveinfo joe")
        self.assertEqual(
            ['Joe has 206 TK points, Attacked: Mike (200), Bill (6)'],
            self.superadmin.message_history)

        self.mike.damages(self.joe, points=27)

        self.superadmin.clearMessageHistory()
        self.superadmin.says("!forgiveinfo joe")
        self.assertEqual([
            'Joe has 206 TK points, Attacked: Mike (200), Bill (6), Attacked By: Mike [27]'
        ], self.superadmin.message_history)

    def test_forgive(self, timer_patch):
        self.superadmin.connects(99)
        self.p._round_grace = 0

        self.joe.warn = Mock()
        self.joe.connects(0)
        self.mike.connects(1)

        self.joe.kills(self.mike)

        self.superadmin.clearMessageHistory()
        self.superadmin.says("!forgiveinfo joe")
        self.assertEqual(['Joe has 200 TK points, Attacked: Mike (200)'],
                         self.superadmin.message_history)

        self.mike.says("!forgive")

        self.superadmin.clearMessageHistory()
        self.superadmin.says("!forgiveinfo joe")
        self.assertEqual(["Joe has 0 TK points"],
                         self.superadmin.message_history)

    def test_forgiveclear(self, timer_patch):
        self.superadmin.connects(99)

        self.p._round_grace = 0

        self.joe.warn = Mock()
        self.joe.connects(0)
        self.mike.connects(1)

        self.joe.kills(self.mike)

        self.superadmin.clearMessageHistory()
        self.superadmin.says("!forgiveinfo joe")
        self.assertEqual(['Joe has 200 TK points, Attacked: Mike (200)'],
                         self.superadmin.message_history)

        self.superadmin.says("!forgiveclear joe")

        self.superadmin.clearMessageHistory()
        self.superadmin.says("!forgiveinfo joe")
        self.assertEqual(["Joe has 0 TK points"],
                         self.superadmin.message_history)

    def test_forgivelist(self, timer_patcher):
        self.p._round_grace = 0

        self.joe.connects(0)
        self.mike.connects(1)
        self.bill.connects(2)

        self.joe.clearMessageHistory()
        self.joe.says("!forgivelist")
        self.assertEqual(["no one to forgive"], self.joe.message_history)

        self.mike.damages(self.joe, points=14)
        self.joe.clearMessageHistory()
        self.joe.says("!forgivelist")
        self.assertEqual(['Forgive who? [1] Mike [14]'],
                         self.joe.message_history)

        self.bill.damages(self.joe, points=84)
        self.joe.clearMessageHistory()
        self.joe.says("!forgivelist")
        self.assertEqual(['Forgive who? [1] Mike [14], [2] Bill [84]'],
                         self.joe.message_history)

    def test_forgiveall(self, timer_patcher):
        self.p._round_grace = 0

        self.joe.connects(0)
        self.mike.connects(1)
        self.bill.connects(2)

        self.mike.damages(self.joe, points=14)
        self.bill.damages(self.joe, points=84)

        self.joe.clearMessageHistory()
        self.joe.says("!forgivelist")
        self.assertEqual(['Forgive who? [1] Mike [14], [2] Bill [84]'],
                         self.joe.message_history)

        self.joe.says("!forgiveall")
        self.joe.clearMessageHistory()
        self.joe.says("!forgivelist")
        self.assertNotIn("Mike", self.joe.message_history[0])
        self.assertNotIn("Bill", self.joe.message_history[0])

    def test_forgiveprev(self, timer_patcher):
        self.p._round_grace = 0

        self.joe.connects(0)
        self.mike.connects(1)
        self.bill.connects(2)

        self.mike.damages(self.joe, points=14)
        self.bill.damages(self.joe, points=84)

        self.joe.clearMessageHistory()
        self.joe.says("!forgivelist")
        self.assertEqual(['Forgive who? [1] Mike [14], [2] Bill [84]'],
                         self.joe.message_history)

        self.joe.says("!forgiveprev")
        self.joe.clearMessageHistory()
        self.joe.says("!forgivelist")
        self.assertEqual(['Forgive who? [1] Mike [14]'],
                         self.joe.message_history)
Exemple #53
0
class Test_misc_cmd(B3TestCase):
    def setUp(self):
        B3TestCase.setUp(self)
        self.conf = XmlConfigParser()
        self.conf.setXml("""
            <configuration plugin="admin">
            </configuration>
        """)
        self.p = AdminPlugin(b3.console, self.conf)

    def test_die(self):
        self.p.cmd_die(None, None, Mock())
        assert b3.console.die.called

    def test_restart(self):
        self.p.cmd_restart(None, None, Mock())
        assert b3.console.restart.called

    def test_reconfig(self):
        self.p.cmd_reconfig(None, None, Mock())
        assert b3.console.reloadConfigs.called

    def test_map(self):
        mock_client = Mock(spec=Client, name="client")

        # no data
        self.p.cmd_map(data=None, client=mock_client, cmd=Mock(spec=Command))
        mock_client.message.assert_called_once_with(
            '^7You must supply a map to change to.')
        assert not b3.console.changeMap.called

        # correct data
        mock_client.reset_mock()
        b3.console.reset_mock()
        b3.console.changeMap = Mock(return_value='foo')
        self.p.cmd_map(data='bar', client=mock_client, cmd=Mock(spec=Command))
        b3.console.changeMap.assert_called_once_with('bar')
        assert not mock_client.message.called

        # incorrect data
        mock_client.reset_mock()
        b3.console.reset_mock()
        b3.console.changeMap = Mock(return_value=['foo1', 'foo2', 'foo3'])
        self.p.cmd_map(data='bar', client=mock_client, cmd=Mock(spec=Command))
        b3.console.changeMap.assert_called_once_with('bar')
        assert mock_client.message.called

    def test_maprotate(self):
        self.p.cmd_maprotate(None, None, Mock(spec=Command))
        assert b3.console.rotateMap.called

    def test_b3(self):
        self.p.config = Mock(name="config")
        self.p.config.getint = Mock(return_value=10)

        mock_client = Mock(spec=Client, name="client")
        mock_command = Mock(spec=Command, name='cmd')

        mock_client.maxLevel = 0
        self.p.cmd_b3(data='', client=mock_client, cmd=mock_command)
        assert mock_command.sayLoudOrPM.called

        mock_client.maxLevel = 20
        mock_client.reset_mock()
        b3.console.reset_mock()
        self.p.cmd_b3(data='', client=mock_client, cmd=mock_command)
        assert mock_command.sayLoudOrPM.called

        for param in ('poke', 'expose', 'stare', 'stab', 'triangulate', 'bite',
                      'f**k', 'slap', 'fight', 'feed', 'throw', 'furniture',
                      'indeed', 'flog', 'sexor', 'hate', 'smoke', 'maul',
                      'procreate', 'shoot'):
            mock_client.reset_mock()
            b3.console.reset_mock()
            self.p.cmd_b3(data=param, client=mock_client, cmd=mock_command)
            if not b3.console.say.called:
                self.fail("b3.console.say was not called for %r" % param)

    def test_enable(self):
        mock_client = Mock(spec=Client, name="client")
        mock_client.maxLevel = 0
        mock_command = Mock(spec=Command, name='cmd')

        self.p.cmd_enable(data='', client=mock_client, cmd=mock_command)
        mock_client.message.assert_called_once_with(
            '^7You must supply a plugin name to enable.')

        mock_client.reset_mock()
        self.p.cmd_enable(data='admin', client=mock_client, cmd=mock_command)
        mock_client.message.assert_called_once_with(
            '^7You cannot disable/enable the admin plugin.')

        mock_client.reset_mock()
        self.p.console.getPlugin = Mock(return_value=None)
        self.p.cmd_enable(data='foo', client=mock_client, cmd=mock_command)
        mock_client.message.assert_called_once_with(
            '^7No plugin named foo loaded.')

        mock_client.reset_mock()
        mock_pluginA = Mock(spec=Plugin)
        mock_pluginA.isEnabled = Mock(return_value=True)
        self.p.console.getPlugin = Mock(return_value=mock_pluginA)
        self.p.cmd_enable(data='foo', client=mock_client, cmd=mock_command)
        mock_client.message.assert_called_once_with(
            '^7Plugin foo is already enabled.')

        mock_client.reset_mock()
        mock_pluginA = Mock(spec=Plugin)
        mock_pluginA.__class__.__name__ = "MockPlugin"
        mock_pluginA.isEnabled = Mock(return_value=False)
        self.p.console.getPlugin = Mock(return_value=mock_pluginA)
        self.p.cmd_enable(data='foo', client=mock_client, cmd=mock_command)
        self.p.console.say.assert_called_once_with('^7MockPlugin is now ^2ON')

    def test_disable(self):
        mock_client = Mock(spec=Client, name="client")
        mock_client.maxLevel = 0
        mock_command = Mock(spec=Command, name='cmd')

        self.p.cmd_disable(data='', client=mock_client, cmd=mock_command)
        mock_client.message.assert_called_once_with(
            '^7You must supply a plugin name to disable.')

        mock_client.reset_mock()
        self.p.cmd_disable(data='admin', client=mock_client, cmd=mock_command)
        mock_client.message.assert_called_once_with(
            '^7You cannot disable/enable the admin plugin.')

        mock_client.reset_mock()
        self.p.console.getPlugin = Mock(return_value=None)
        self.p.cmd_disable(data='foo', client=mock_client, cmd=mock_command)
        mock_client.message.assert_called_once_with(
            '^7No plugin named foo loaded.')

        mock_client.reset_mock()
        mock_pluginA = Mock(spec=Plugin)
        mock_pluginA.isEnabled = Mock(return_value=False)
        self.p.console.getPlugin = Mock(return_value=mock_pluginA)
        self.p.cmd_disable(data='foo', client=mock_client, cmd=mock_command)
        mock_client.message.assert_called_once_with(
            '^7Plugin foo is already disable.')

        mock_client.reset_mock()
        mock_pluginA = Mock(spec=Plugin)
        mock_pluginA.__class__.__name__ = "MockPlugin"
        mock_pluginA.isEnabled = Mock(return_value=True)
        self.p.console.getPlugin = Mock(return_value=mock_pluginA)
        self.p.cmd_disable(data='foo', client=mock_client, cmd=mock_command)
        self.p.console.say.assert_called_once_with('^7MockPlugin is now ^1OFF')

    def test_rebuild(self):
        mock_client = Mock(spec=Client, name="client")
        mock_client.maxLevel = 0
        mock_command = Mock(spec=Command, name='cmd')

        assert not self.p.console.clients.sync.called
        self.p.cmd_rebuild(data='', client=mock_client, cmd=mock_command)
        assert self.p.console.clients.sync.called
    import time
    
    from b3.config import XmlConfigParser
    
    conf = XmlConfigParser()
    conf.setXml("""
    <configuration plugin="teamspeakmoh">
   <settings name="teamspeakServer">
      <set name="host">www.cucurb.net</set>
      <set name="queryport">10011</set>
      <set name="id">1</set>
      <set name="login">b3test</set>
      <set name="password">Q3Z8icLV</set>
   </settings>
   <settings name="teamspeakChannels">
      <set name="B3">B3 autoswitched channel</set>
      <set name="team1">Team 1</set>
      <set name="team2">Team 2</set>
   </settings>
   <settings name="commands">
      <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)
conf.setXml("""
<configuration plugin="teamspeakbf">
	<settings name="teamspeakServer">
		<!-- IP or domain where your teamspeak server is hosted -->
		<set name="host">{ts_host}</set>
		<!-- query port of your teamspeak server (default: 10011) -->
		<set name="queryport">{ts_port}</set>
		<!-- Teamspeak virtual server ID -->
		<set name="id">{ts_id}</set>
		<!-- B3 login information. You need to create a ServerQuery Login for B3. video tutorial : http://bit.ly/a5qcjp -->
		<set name="login">{ts_login}</set>
		<set name="password">{ts_password}</set>
	</settings>
	<settings name="teamspeakChannels">
		<set name="B3">B3 autoswitched channel</set>
		<set name="team1">Team 1</set>
		<set name="team2">Team 2</set>
	</settings>
    <settings name="commands">
        <!-- set here levels needed to be allowed to use commands.
            You can define a command alias adding '-' and the alias after the command name.
            Levels:
            0 : everyone
            1 : registered users
            2 : regular users
            20 : moderators
            40 : admins
            60 : full admins
            80 : senior admins
            100 : super admins
        -->

        <!-- Allow admins to reconnect/disconnect B3 to the teamspeak server -->
        <set name="tsreconnect">100</set>
        <set name="tsdisconnect">100</set>

        <!-- give the player info about the current Teamspeak server and his status -->
        <set name="teamspeak-ts">1</set>

        <!-- !tsauto allow players to change their autoswitch preferences between one
        of 'off', 'team', 'squad' -->
        <set name="tsauto">1</set>
    </settings>
</configuration>
""".format(ts_host=config.get("teamspeak_server", "host"),
           ts_port=config.get("teamspeak_server", "port"),
           ts_id=config.get("teamspeak_server", "id"),
           ts_login=config.get("teamspeak_server", "login"),
           ts_password=config.get("teamspeak_server", "password")))
Exemple #56
0
    """
    from b3.fake import fakeConsole
    from b3.fake import superadmin, joe 
    import time
    
    from b3.config import XmlConfigParser
    
    conf = XmlConfigParser()
    conf.setXml("""
<configuration plugin="stats">
  <settings name="commands">
    <set name="mapstats-mystatalias">0</set>
    <set name="testscore-tscr">0</set>
    <set name="topstats-tops">2</set>
    <set name="topxp-txp">2</set>
  </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)
Exemple #57
0
    """
    from b3.fake import fakeConsole
    from b3.fake import superadmin, joe
    import time

    from b3.config import XmlConfigParser

    conf = XmlConfigParser()
    conf.setXml("""
<configuration plugin="stats">
  <settings name="commands">
    <set name="mapstats-mystatalias">0</set>
    <set name="testscore-tscr">0</set>
    <set name="topstats-tops">2</set>
    <set name="topxp-txp">2</set>
  </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")