예제 #1
0
    def setUp(self):
        self.parser_conf = MainConfig(CfgConfigParser(allow_no_value=True))
        self.parser_conf.loadFromString(dedent(r""""""))
        self.console = FakeConsole(self.parser_conf)
        self.console.gameName = 'f00'
        self.console.startup()

        with logging_disabled():
            self.adminPlugin = AdminPlugin(self.console, '@b3/conf/plugin_admin.ini')
            self.adminPlugin.onLoadConfig()
            self.adminPlugin.onStartup()

        self.evt_queue = []

        # make sure the admin plugin obtained by other plugins is our admin plugin
        when(self.console).getPlugin('admin').thenReturn(self.adminPlugin)

        with logging_disabled():
            from b3.fake import FakeClient

        # prepare a few players
        self.mike = FakeClient(self.console, name="Mike", exactName="Mike", guid="MIKEGUID", groupBits=16, ip='1.1.1.1')
        self.paul = FakeClient(self.console, name="Paul", exactName="Paul", guid="PAULGUID", groupBits=1, ip='2.2.2.2')
        self.john = FakeClient(self.console, name="John", exactName="John", guid="JOHNGUID", groupBits=0, ip='3.3.3.3')
        self.mary = FakeClient(self.console, name="Mary", exactName="Mary", guid="MARYGUID", groupBits=0, ip='4.4.4.4')

        self.conf = CfgConfigParser()
        self.p = IpbanPlugin(self.console, self.conf)

        # return some mock data
        when(self.p).getBanIps().thenReturn(['2.2.2.2', '6.6.6.6', '7.7.7.7'])
        when(self.p).getTempBanIps().thenReturn(['3.3.3.3', '8.8.8.8', '9.9.9.9'])
    def setUp(self):
        CalladminTestCase.setUp(self)
        self.conf = CfgConfigParser()
        self.conf.loadFromString(dedent(r"""
            [teamspeak]
            ip: 127.0.0.1
            port: 10011
            serverid: 1
            username: fakeusername
            password: fakepassword
            msg_groupid: -1

            [settings]
            treshold: 3600
            useirc: no

            [commands]
            calladmin: user
        """))

        self.p = CalladminPlugin(self.console, self.conf)
        self.p.onLoadConfig()
        self.p.onStartup()

        with logging_disabled():
            from b3.fake import FakeClient

        self.mike = FakeClient(console=self.console, name="Mike", guid="mikeguid", groupBits=1)
        self.bill = FakeClient(console=self.console, name="Bill", guid="billguid", groupBits=16)
 def test_existing_player(self):
     joe = FakeClient(self.console, name="Joe", guid="01230123012301230123", groupBits=1)
     joe.connects('1')
     self.assertEqual(joe, self.console.clients['1'])
     when(self.console).write("startserverdemo 1").thenReturn("startserverdemo: recording Joe to serverdemos/2012_04_22_20-16-38_Joe_642817.dm_68")
     self.moderator.says("!startserverdemo joe")
     self.assertListEqual(['startserverdemo: recording Joe to serverdemos/2012_04_22_20-16-38_Joe_642817.dm_68'], self.moderator.message_history)
예제 #4
0
    def setUp(self):
        B3TestCase.setUp(self)

        with logging_disabled():
            admin_conf = CfgConfigParser()
            admin_plugin = AdminPlugin(self.console, admin_conf)
            admin_plugin.onLoadConfig()
            admin_plugin.onStartup()
            when(self.console).getPlugin('admin').thenReturn(admin_plugin)

        conf = CfgConfigParser()
        conf.loadFromString(dedent(r"""
            [commands]
            mapstats-stats: 0
            testscore-ts: 0
            topstats-top: 0
            topxp: 0

            [settings]
            startPoints: 100
            resetscore: no
            resetxp: no
            show_awards: no
            show_awards_xp: no
        """))
        self.p = StatsPlugin(self.console, conf)
        self.p.onLoadConfig()
        self.p.onStartup()

        self.joe = FakeClient(self.console, name="Joe", guid="joeguid", groupBits=1, team=TEAM_RED)
        self.mike = FakeClient(self.console, name="Mike", guid="mikeguid", groupBits=1, team=TEAM_RED)
        self.joe.connects(1)
        self.mike.connects(2)
    def setUp(self):
        # create a B3 FakeConsole
        self.parser_conf = XmlConfigParser()
        self.parser_conf.loadFromString(r"""<configuration/>""")
        self.console = FakeConsole(self.parser_conf)
        # create our plugin instance
        self.plugin_conf = CfgConfigParser()
        self.p = Killannouncerbf3Plugin(self.console, self.plugin_conf)
        # initialise the plugin
        self.plugin_conf.loadFromString(r'''
[settings]
announce first kill: yes
[first kill alert]
us1: %(murderer)s takes first blood against %(victim)s! The battle has just began!!!
de1: %(murderer)s hat das erste Blut von %(victim)s genommen! Die Schlacht hat begonnen!!!
[kill streak alerts]
us1 #5: Killing Spree! %(murderer)s is dominating on a %(kill_streak_value)s kill streak!
us2 #10: Killing Spree! %(murderer)s is dominating on a %(kill_streak_value)s kill streak!
[end kill streak alerts]
us1: %(murderer)s has ended %(murderer)s kill streak at %(kill_streak_value)s kills!

        ''')
        # Plugin ipinfodb is required. We trick and set county property later.
        self.p.console._plugins['ipinfodb'] = ''

        self.p.onLoadConfig()
        self.p.onStartup()
        # prepare a few players
        self.joe = FakeClient(self.console, name="Joe", exactName="Joe", guid="zaerezarezar", groupBits=1, country='de',team=TEAM_RED)
        self.simon = FakeClient(self.console, name="Simon", exactName="Simon", guid="qsdfdsqfdsqf", groupBits=0, country='us',team=TEAM_BLUE)
        self.admin = FakeClient(self.console, name="Level-40-Admin", exactName="Level-40-Admin", guid="875sasda", groupBits=16, country='ch',)
        self.superadmin = FakeClient(self.console, name="God", exactName="God", guid="f4qfer654r", groupBits=128, country='fr',)

        self.joe.connects(cid='1')
        self.simon.connects(cid='2')
 def setUp(self):
     XlrstatsTestCase.setUp(self)
     self.init()
     self.p1 = FakeClient(console=self.console, name="P1", guid="P1_GUID")
     self.p1.connects("1")
     self.p2 = FakeClient(console=self.console, name="P2", guid="P2_GUID")
     self.p2.connects("2")
class Cmd_regulars(Admin_functional_test):
    def setUp(self):
        Admin_functional_test.setUp(self)
        self.init()
        self.joe.message = Mock(wraps=lambda x: sys.stdout.write("\t\t" + x + "\n"))
        self.joe.connects(0)

    def test_no_regular(self):
        # only superadmin joe is connected
        self.joe.says("!regulars")
        self.joe.message.assert_called_with("^7There are no regular players online")

    def test_one_regular(self):
        # GIVEN
        self.mike.connects(1)
        self.joe.says("!makereg mike")
        # WHEN
        self.joe.says("!regs")
        # THEN
        self.joe.message.assert_called_with("^7Regular players online: Mike^7")

    def test_two_regulars(self):
        # GIVEN
        self.mike.connects(1)
        self.joe.says("!makereg mike")
        self.jack = FakeClient(self.console, name="Jack", guid="jackguid", groupBits=1)
        self.jack.connects(2)
        self.joe.says("!makereg jack")
        # WHEN
        self.joe.says("!regs")
        # THEN
        self.joe.message.assert_called_with("^7Regular players online: Mike^7, Jack^7")
    def setUp(self):
        # create a FakeConsole parser
        parser_ini_conf = CfgConfigParser()
        parser_ini_conf.loadFromString(r'''''')
        self.parser_main_conf = MainConfig(parser_ini_conf)

        with logging_disabled():
            from b3.fake import FakeConsole
            self.console = FakeConsole(self.parser_main_conf)

        with logging_disabled():
            self.adminPlugin = AdminPlugin(self.console, '@b3/conf/plugin_admin.ini')
            self.adminPlugin._commands = {}
            self.adminPlugin.onStartup()

        # make sure the admin plugin obtained by other plugins is our admin plugin
        when(self.console).getPlugin('admin').thenReturn(self.adminPlugin)

        # simulate geolocation plugin registering events
        self.console.createEvent('EVT_CLIENT_GEOLOCATION_SUCCESS', 'Event client geolocation success')

        self.console.screen = Mock()
        self.console.time = time.time
        self.console.upTime = Mock(return_value=1000)
        self.console.cron.stop()


        self.conf = CfgConfigParser()
        self.conf.loadFromString(dedent(r"""
            [settings]
            announce: yes

            [messages]
            client_connect: ^7$name ^3from ^7$city ^3(^7$country^3) connected
            cmd_locate: ^7$name ^3is connected from ^7$city ^3(^7$country^3)
            cmd_locate_failed: ^7Could not locate ^1$name
            cmd_distance: ^7$name ^3is ^7$distance ^3km away from you
            cmd_distance_self: ^7Sorry, I'm not that smart...meh!
            cmd_distance_failed: ^7Could not compute distance with ^1$name
            cmd_isp: ^7$name ^3is using ^7$isp ^3as isp
            cmd_isp_failed: ^7Could not determine ^1$name ^7isp

            [commands]
            locate: user
            distance: user
            isp: mod
        """))

        self.p = LocationPlugin(self.console, self.conf)
        self.p.onLoadConfig()
        self.p.onStartup()

        with logging_disabled():
            from b3.fake import FakeClient

        self.mike = FakeClient(console=self.console, name="Mike", guid="MIKEGUID", groupBits=1)
        self.bill = FakeClient(console=self.console, name="Bill", guid="BILLGUID", groupBits=16)
        self.mike.location = LOCATION_MIKE
        self.bill.location = LOCATION_BILL
 def test_map_with_correct_parameters(self):
     # GIVEN
     superadmin = FakeClient(self.parser, name="superadmin", guid="guid_superadmin", groupBits=128, team=TEAM_UNKNOWN)
     superadmin.connects("1")
     # WHEN
     superadmin.says("!map market push")
     # THEN
     self.parser.output.write.assert_has_calls([call('changelevel market push')])
예제 #10
0
 def setUp(self):
     Iourt41TestCase.setUp(self)
     self.console.startup()
     self.joe = FakeClient(self.console, name="Joe", guid="000000000000000")
     self.joe.connects('0')
     self.bob = FakeClient(self.console, name="Bob", guid="111111111111111")
     self.bob.connects('1')
     self.world = self.console.clients['-1']
예제 #11
0
 def test_SUICIDE(self):  # 16
     # GIVEN
     poorguy = FakeClient(self.parser, name="attacker_name", guid='76561198070138838')
     poorguy.connects("1")
     # WHEN
     self.parser.handlePacket(Packet.decode('\x00\x10\x00\x00\x00\x08\x01\x10\x00\x01\x06\x8c\x87\xd6'))
     # THEN
     self.assert_has_event("EVT_CLIENT_SUICIDE", client=poorguy, target=poorguy, data=(100, None, None))
    def setUp(self):
        ProxyfilterTestCase.setUp(self)

        with logging_disabled():
            from b3.fake import FakeClient

        # create some fake clients
        self.mike = FakeClient(console=self.console, name="Mike", guid="mikeguid", ip="127.0.0.1", groupBits=128)
        self.bill = FakeClient(console=self.console, name="Bill", guid="billguid", ip="127.0.0.2", groupBits=1)
예제 #13
0
 def test_clantag(self):
     # GIVEN
     player = FakeClient(self.parser, name="courgette", guid="STEAM_1:0:1111111", team=TEAM_BLUE)
     player.connects("2")
     # WHEN
     self.assertFalse(hasattr(player, "clantag"))
     self.parser.parseLine('''L 08/26/2012 - 05:43:31: "courgette<2><STEAM_1:0:1111111><CT>" triggered "clantag" (value "f00")''')
     # THEN
     self.assertEqual("f00", player.clantag)
예제 #14
0
 def test_high_level_no_password_set(self):
     # GIVEN
     joe = FakeClient(self.console, name="Joe", guid="joeguid", groupBits=128)
     # WHEN
     joe.clearMessageHistory()
     joe.connects("0")
     # THEN
     self.assertEqual(['You need a password to use all your privileges: ask the administrator to set a password for you'], joe.message_history)
     self.assertEqual(2, joe.groupBits)
예제 #15
0
 def test_low_level(self):
     # GIVEN
     joe = FakeClient(self.console, name="Joe", guid="joeguid", groupBits=8)
     # WHEN
     joe.clearMessageHistory()
     joe.connects("0")
     # THEN
     self.assertEqual([], joe.message_history)
     self.assertEqual(8, joe.groupBits)
예제 #16
0
 def test_client_say(self):
     # GIVEN
     player = FakeClient(self.parser, name="<TA Crytiqal.Aero", guid="TA-Crytiqal-Aero-GUID", team=TEAM_BLUE)
     player.connects("3")
     # WHEN
     self.clear_events()
     self.parser.parseLine('21:58.44 say: <TA Crytiqal.Aero: !iamgod')
     # THEN
     self.assert_has_event("EVT_CLIENT_SAY", '!iamgod', player)
예제 #17
0
 def test_Lobby_chat(self):
     # GIVEN
     bravo17 = FakeClient(self.parser, name="Bravo17", guid="80a5885ebe2420bab5e158a310fcbc7d")
     bravo17.connects("12")
     self.clear_events()
     # WHEN
     self.parser.routeBattleyeEvent("""(Lobby) Bravo17: hello b3""")
     # THEN
     self.assert_has_event("EVT_CLIENT_SAY", client=bravo17, data='hello b3 (Lobby)')
예제 #18
0
 def test_Verified_guid__with_connected_player(self):
     # GIVEN
     bravo17 = FakeClient(self.parser, name="Bravo17")
     bravo17.connects("0")
     self.clear_events()
     # WHEN
     self.parser.routeBattleyeEvent("""Verified GUID (80a5885ebe2420bab5e158a310fcbc7d) of player #0 Bravo17""")
     # THEN
     self.assert_has_event("EVT_CLIENT_AUTH", data=bravo17, client=bravo17)
예제 #19
0
 def test_player_disconnect(self):
     # GIVEN
     bravo17 = FakeClient(self.parser, name="Bravo17", guid="80a5885ebe2420bab5e158a310fcbc7d")
     bravo17.connects("12")
     self.clear_events()
     # WHEN
     self.parser.routeBattleyeEvent("""Player #12 Bravo17 disconnected""")
     # THEN
     self.assert_has_event("EVT_CLIENT_DISCONNECT", client=bravo17, data='12')
예제 #20
0
 def test_Command_chat(self):
     # GIVEN
     bravo17 = FakeClient(self.parser, name="Bravo17", guid="80a5885ebe2420bab5e158a310fcbc7d")
     bravo17.connects("12")
     self.clear_events()
     # WHEN
     self.parser.routeBattleyeEvent("""(Command) Bravo17: test command channel""")
     # THEN
     self.assert_has_event("EVT_CLIENT_SAY", client=bravo17, data='test command channel (Command)')
예제 #21
0
 def test_client_teamsay(self):
     # GIVEN
     player = FakeClient(self.parser, name="courgette", guid="STEAM_1:0:1111111", team=TEAM_BLUE)
     player.connects("2")
     # WHEN
     self.clear_events()
     self.parser.parseLine('''L 08/26/2012 - 05:04:44: "courgette<2><STEAM_1:0:1111111><CT>" say_team "team say"''')
     # THEN
     self.assert_has_event("EVT_CLIENT_TEAM_SAY", "team say", player)
예제 #22
0
 def test_bot_entered(self):
     # GIVEN
     bot22 = FakeClient(self.parser, name="Pheonix", guid="BOT_22")
     bot22.connects("22")
     # WHEN
     self.clear_events()
     self.parser.parseLine('''L 08/26/2012 - 05:29:48: "Pheonix<22><BOT><>" entered the game''')
     # THEN
     self.assert_has_event("EVT_CLIENT_JOIN", client=bot22)
예제 #23
0
 def test_client_say__no_team(self):
     # GIVEN
     player = FakeClient(self.parser, name="Spoon", guid="STEAM_1:0:10000000", team=TEAM_UNKNOWN)
     player.connects("2")
     # WHEN
     self.clear_events()
     self.parser.parseLine('''L 09/16/2012 - 04:55:17: "Spoon<2><STEAM_1:0:10000000><>" say "!h"''')
     # THEN
     self.assert_has_event("EVT_CLIENT_SAY", "!h", player)
예제 #24
0
 def test_committed_suicide(self):
     # GIVEN
     bot22 = FakeClient(self.parser, name="Pheonix", guid="BOT_22")
     bot22.connects("22")
     # WHEN
     self.clear_events()
     self.parser.parseLine('''L 08/26/2012 - 03:38:04: "Pheonix<22><BOT><TERRORIST>" committed suicide with "world"''')
     # THEN
     self.assert_has_event("EVT_CLIENT_SUICIDE", client=bot22, target=bot22, data=(100, 'world', 'body', None))
예제 #25
0
 def test_player_entered(self):
     # GIVEN
     player = FakeClient(self.parser, name="courgette", guid="STEAM_1:0:1111111")
     player.connects("2")
     # WHEN
     self.clear_events()
     self.parser.parseLine('''L 08/26/2012 - 05:38:36: "courgette<2><STEAM_1:0:1111111><>" entered the game''')
     # THEN
     self.assert_has_event("EVT_CLIENT_JOIN", client=player)
 def test_checkbadnames(self):
     # GIVEN
     p1 = FakeClient(self.console, name="all", guid="p1guid")
     p1.warn = Mock()
     p1.connects("1")
     # WHEN
     self.p.namecheck()
     # THEN
     p1.warn.assert_has_calls([call(ANY, ANY, 'badname', None, '')])
예제 #27
0
 def test_killed_but_really_is_suicide(self):
     # GIVEN
     bot22 = FakeClient(self.parser, name="Pheonix", guid="BOT_22")
     bot22.connects("22")
     # WHEN
     self.clear_events()
     self.parser.parseLine('''L 08/26/2012 - 03:46:44: "Pheonix<22><BOT><TERRORIST>" killed "Pheonix<22><BOT><TERRORIST>" with "glock"''')
     # THEN
     self.assert_has_event("EVT_CLIENT_SUICIDE", client=bot22, target=bot22, data=(100, 'glock', 'body', None))
예제 #28
0
 def test_cmd_spamins_uppercase(self):
     # GIVEN
     mike = FakeClient(self.console, name="Mike")
     mike.connects("3")
     # WHEN
     self.superadmin.clearMessageHistory()
     self.superadmin.says("!spamins MIKE")
     # THEN
     self.assertListEqual(['Mike currently has 0 spamins, peak was 0'], self.superadmin.message_history)
예제 #29
0
    def setUp(self):
        # create a Iourt42 parser
        self.parser_conf = XmlConfigParser()
        self.parser_conf.loadFromString(dedent(r"""
            <configuration>
                <settings name="server">
                    <set name="game_log"></set>
                </settings>
            </configuration>
        """))

        self.console = Iourt42Parser(self.parser_conf)

        # initialize some fixed cvars which will be used by both the plugin and the iourt42 parser
        when(self.console).getCvar('auth').thenReturn(Cvar('auth', value='0'))
        when(self.console).getCvar('fs_basepath').thenReturn(Cvar('g_maxGameClients', value='/fake/basepath'))
        when(self.console).getCvar('fs_homepath').thenReturn(Cvar('sv_maxclients', value='/fake/homepath'))
        when(self.console).getCvar('fs_game').thenReturn(Cvar('fs_game', value='q3ut4'))
        when(self.console).getCvar('gamename').thenReturn(Cvar('gamename', value='q3urt42'))

        # start the parser
        self.console.startup()

        self.admin_plugin_conf = CfgConfigParser()
        self.admin_plugin_conf.loadFromString(dedent(r"""
            [warn]
            pm_global: yes
            alert_kick_num: 3
            instant_kick_num: 5
            tempban_num: 6
            tempban_duration: 1d
            max_duration: 1d
            message: ^1WARNING^7 [^3$warnings^7]: $reason
            warn_delay: 15
            reason: ^7too many warnings: $reason
            duration_divider: 30
            alert: ^1ALERT^7: $name^7 auto-kick from warnings if not cleared [^3$warnings^7] $reason
            warn_command_abusers: no"""))

        with logging_disabled():
            self.adminPlugin = AdminPlugin(self.console, self.admin_plugin_conf)
            self.adminPlugin.onLoadConfig()
            self.adminPlugin.onStartup()

        # make sure the admin plugin obtained by other plugins is our admin plugin
        when(self.console).getPlugin('admin').thenReturn(self.adminPlugin)

        with logging_disabled():
            from b3.fake import FakeClient

        # create some clients
        self.mike = FakeClient(console=self.console, name="Mike", guid="mikeguid", team=TEAM_RED,  groupBits=1)
        self.bill = FakeClient(console=self.console, name="Bill", guid="billguid", team=TEAM_BLUE, groupBits=1)
        self.mark = FakeClient(console=self.console, name="Mark", guid="markguid", team=TEAM_BLUE, groupBits=128)

        self.conf = CfgConfigParser()
        self.p = SpawnkillPlugin(self.console, self.conf)
예제 #30
0
 def test_TEAM_CHANGED_1(self):  # 13
     # GIVEN
     player = FakeClient(self.parser, name="Pheonix", guid="76561198070138838")
     player.connects("1")
     self.assertEqual(TEAM_UNKNOWN, player.team)
     # WHEN
     self.parser.handlePacket(Packet.decode('\x00\r\x00\x00\x00\x0c\x01\x10\x00\x01\x06\x8c\x87\xd6\x00\x00\x00\x01'))
     # THEN
     self.assertEqual(1, player.team)
예제 #31
0
 def test_cmd_plugin_disable_mixed_multiple(self):
     # GIVEN
     mock_pluginA = Mock(spec=Plugin)
     mock_pluginA.isEnabled = Mock(return_value=True)
     when(self.console).getPlugin("mock").thenReturn(mock_pluginA)
     superadmin = FakeClient(self.console,
                             name="superadmin",
                             guid="superadminguid",
                             groupBits=128)
     superadmin.connects("1")
     # WHEN
     superadmin.clearMessageHistory()
     superadmin.says("!plugin disable mock fake")
     # THEN
     self.assertListEqual(
         ['Plugin mock is now disabled', 'Plugin fake is not loaded'],
         superadmin.message_history)
예제 #32
0
 def test_kill_teammate(self):
     # GIVEN
     p1 = FakeClient(self.parser, guid="11111111111111")
     p1.connects("11111111111111")
     p2 = FakeClient(self.parser, guid="2222222222222")
     p2.connects("2222222222222")
     self.queueEvent_mock.reset_mock()
     self.clear_events()
     # WHEN
     self.parser.route_game_event(
         '''"Name1<11111111111111><0>" killed "Name2<2222222222222><0>" with "the_weapon"'''
     )
     # THEN
     self.assert_has_event('EVT_CLIENT_KILL_TEAM',
                           data=(100, "the_weapon", 'body'),
                           client=p1,
                           target=p2)
예제 #33
0
 def setUp(self):
     BFHTestCase.setUp(self)
     with logging_disabled():
         self.conf = CfgConfigParser()
         self.conf.loadFromString("""[configuration]""")
         self.parser = BfhParser(self.conf)
         adminPlugin_conf = CfgConfigParser()
         adminPlugin_conf.loadFromString(
             dedent(r"""
             [commands]
             map: 20
         """))
         adminPlugin = AdminPlugin(self.parser, adminPlugin_conf)
         adminPlugin.onLoadConfig()
         adminPlugin.onStartup()
         when(self.parser).getPlugin('admin').thenReturn(adminPlugin)
         self.parser.patch_b3_admin_plugin()
         self.joe = FakeClient(self.parser,
                               name="Joe",
                               guid="joeguid",
                               groupBits=128)
         self.joe.connects(cid="joe")
         self.parser.game.gameType = "TurfWarSmall0"
         self.parser.game.serverinfo = {'roundsTotal': 2}
    def setUp(self):
        SpamcontrolTestCase.setUp(self)

        self.adminPlugin = AdminPlugin(self.console,
                                       '@b3/conf/plugin_admin.ini')
        when(self.console).getPlugin("admin").thenReturn(self.adminPlugin)
        self.adminPlugin.onLoadConfig()
        self.adminPlugin.onStartup()

        with open(b3.getAbsolutePath(
                '@b3/conf/plugin_spamcontrol.ini')) as default_conf:
            self.init_plugin(default_conf.read())

        self.joe = FakeClient(self.console,
                              name="Joe",
                              guid="zaerezarezar",
                              groupBits=1)
        self.joe.connects("1")

        self.superadmin = FakeClient(self.console,
                                     name="Superadmin",
                                     guid="superadmin_guid",
                                     groupBits=128)
        self.superadmin.connects("2")
    def test_say_after_player_changed_name(self):
        def assert_new_name_and_text_does_not_break_auth(new_name, text="!help"):
            # WHEN the player renames himself
            self.console.parseLine(r'''777:16 ClientUserinfoChanged: 2 n\%s\t\3\r\1\tl\0\f0\\f1\\f2\\a0\0\a1\255\a2\0''' % new_name)
            self.console.parseLine(r'''777:16 AccountValidated: 2 - louk - 6 - "basic"''')
            self.console.parseLine(r'''777:16 ClientUserinfo: 2 \name\%s\ip\49.111.22.33:27960\password\xxxxxx\racered\0\raceblue\0\rate\16000\ut_timenudge\0\cg_rgb\0 255 0\funred\ninja,caprd,bartsor\funblue\ninja,gasmask,capbl\cg_physics\1\snaps\20\color1\4\color2\5\handicap\100\sex\male\cg_autoPickup\-1\cg_ghost\0\cl_time\n34|0610q5qH=t<a\racefree\1\gear\GZAAVWT\authc\2708\cl_guid\AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\weapmodes\01000110220000020002000''' % new_name)
            self.console.parseLine(r'''777:16 ClientUserinfoChanged: 2 n\%s\t\3\r\1\tl\0\f0\\f1\\f2\\a0\0\a1\255\a2\0''' % new_name)
            # THEN the next chat line should work
            self.assertEvent(r'''777:18 say: 2 %s: %s''' % (new_name, text),
                event_type='EVT_CLIENT_SAY',
                event_client=player,
                event_data=text.lstrip())

        # GIVEN a known player with cl_guid "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" that will connect on slot 2
        player = FakeClient(console=self.console, name="Chucky", guid="AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA")
        player.connects("2")

        # THEN
        assert_new_name_and_text_does_not_break_auth("joe")
        assert_new_name_and_text_does_not_break_auth("joe:")
        assert_new_name_and_text_does_not_break_auth("jo:e")
        assert_new_name_and_text_does_not_break_auth("j:oe")
        assert_new_name_and_text_does_not_break_auth(":joe")
        assert_new_name_and_text_does_not_break_auth("joe:")
        assert_new_name_and_text_does_not_break_auth("joe:foo")
        assert_new_name_and_text_does_not_break_auth("joe", "what does the fox say: Ring-ding-ding-ding-dingeringeding!")
        assert_new_name_and_text_does_not_break_auth("joe:", "what does the fox say: Ring-ding-ding-ding-dingeringeding!")
        assert_new_name_and_text_does_not_break_auth("jo:e", "what does the fox say: Ring-ding-ding-ding-dingeringeding!")
        assert_new_name_and_text_does_not_break_auth("j:oe", "what does the fox say: Ring-ding-ding-ding-dingeringeding!")
        assert_new_name_and_text_does_not_break_auth(":joe", "what does the fox say: Ring-ding-ding-ding-dingeringeding!")
        assert_new_name_and_text_does_not_break_auth("joe:", "what does the fox say: Ring-ding-ding-ding-dingeringeding!")
        assert_new_name_and_text_does_not_break_auth("joe:foo", "what does the fox say: Ring-ding-ding-ding-dingeringeding!")
        assert_new_name_and_text_does_not_break_auth("j:oe", ":")
        assert_new_name_and_text_does_not_break_auth("j:oe", " :")
        assert_new_name_and_text_does_not_break_auth("j:oe", " : ")
        assert_new_name_and_text_does_not_break_auth("j:oe", ": ")
예제 #36
0
 def test_kill_enemy_2(self):
     # GIVEN
     p1 = FakeClient(self.parser, guid="76561000000000000")
     p1.connects("76561000000000000")
     p2 = FakeClient(self.parser, guid="70000000000000005")
     p2.connects("70000000000000005")
     self.queueEvent_mock.reset_mock()
     self.clear_events()
     # WHEN
     self.parser.route_game_event(
         '''"txsniper<76561000000000000><1>" killed "Killer Badger<70000000000000005><0>" with R_DmgType_SniperPrimary'''
     )
     # THEN
     self.assert_has_event('EVT_CLIENT_KILL',
                           data=(100, "R_DmgType_SniperPrimary", 'body'),
                           client=p1,
                           target=p2)
예제 #37
0
 def test_cmd_plugin_unload_with_enabled_plugin(self):
     # GIVEN
     mock_plugin = Mock(spec=Plugin)
     mock_plugin.isEnabled = Mock(return_value=True)
     when(self.console).getPlugin("mock").thenReturn(mock_plugin)
     superadmin = FakeClient(self.console,
                             name="superadmin",
                             guid="superadminguid",
                             groupBits=128)
     superadmin.connects("1")
     # WHEN
     superadmin.clearMessageHistory()
     superadmin.says("!plugin unload mock")
     # THEN
     self.assertListEqual(
         ['Plugin mock is currently enabled: disable it first'],
         superadmin.message_history)
예제 #38
0
    def test_known_client_with_unverified_guid_and_different_ip_is_not_auth(
            self):
        # GIVEN a known client Bob
        bob = FakeClient(self.parser,
                         name="bob",
                         guid="80a50000000000000000000000fcbc7d",
                         ip="1.2.3.4")
        bob.save()
        # WHEN
        when(self.parser.output).write('players').thenReturn('''\
Players on server:
[#] [IP Address]:[Port] [Ping] [GUID] [Name]
--------------------------------------------------
2   4.6.8.10:2316       47   80a50000000000000000000000fcbc7d(?)  bob
(1 players in total)
''')
        rv = self.parser.sync()
        # THEN
        self.assertIn('2', rv)
        client = rv["2"]
        self.assertEqual("bob", client.name)
        self.assertEqual("4.6.8.10", client.ip)
        self.assertEqual('', client.guid)
        self.assertFalse(client.authed)
예제 #39
0
 def test_cmd_plugin_info_with_valid_plugin_name_and_email_escape(self):
     # GIVEN
     mock_module = Mock()
     mock_module.__setattr__('__author__', 'Mocker - [email protected]')
     mock_module.__setattr__('__version__', '1.1')
     when(self.console).pluginImport('mock').thenReturn(mock_module)
     superadmin = FakeClient(self.console,
                             name="superadmin",
                             guid="superadminguid",
                             groupBits=128)
     superadmin.connects("1")
     # WHEN
     superadmin.clearMessageHistory()
     superadmin.says("!plugin info mock")
     # THEN
     self.assertListEqual(['You are running plugin mock v1.1 by Mocker'],
                          superadmin.message_history)
예제 #40
0
 def setUp(self):
     with logging_disabled():
         CustomcommandsTestCase.setUp(self)
         self.conf = CfgConfigParser()
         self.p = CustomcommandsPlugin(self.console, self.conf)
         self.guest = FakeClient(console=self.console, name="Guest", guid="GuestGUID", pbid="GuestPBID", group_bits=0)
         self.player1 = FakeClient(console=self.console, name="player1", guid="player1GUID", pbid="player1PBID", group_bits=1)
         self.player1.connects(cid="CID1")
         self.player2 = FakeClient(console=self.console, name="player2", guid="player2GUID", pbid="player2PBID", group_bits=1)
         self.player2.connects(cid="CID2")
         self.guest.connects(cid="guestCID")
예제 #41
0
    def test_cmd_plugin_unload_successful(self):
        # GIVEN

        ###### MOCK PLUGIN
        mock_plugin = Mock(spec=Plugin)
        mock_plugin.console = self.console
        mock_plugin.isEnabled = Mock(return_value=False)
        when(self.console).getPlugin("mock").thenReturn(mock_plugin)
        self.console._plugins['mock'] = mock_plugin
        ###### MOCK COMMAND
        mock_func = Mock()
        mock_func.__name__ = 'cmd_mockfunc'
        self.adminPlugin._commands['mockcommand'] = Command(plugin=mock_plugin,
                                                            cmd='mockcommand',
                                                            level=100,
                                                            func=mock_func)
        ###### MOCK EVENT
        mock_plugin.onSay = Mock()
        mock_plugin.registerEvent('EVT_CLIENT_SAY', mock_plugin.onSay)
        ###### MOCK CRON
        mock_plugin.mockCronjob = Mock()
        mock_plugin.mockCrontab = b3.cron.PluginCronTab(
            mock_plugin, mock_plugin.mockCronjob, minute='*', second='*/60')
        self.console.cron.add(mock_plugin.mockCrontab)
        self.assertIn(id(mock_plugin.mockCrontab), self.console.cron._tabs)

        superadmin = FakeClient(self.console,
                                name="superadmin",
                                guid="superadminguid",
                                groupBits=128)
        superadmin.connects("1")
        # WHEN
        superadmin.clearMessageHistory()
        superadmin.says("!plugin unload mock")
        # THEN
        self.assertNotIn('mockcommand', self.adminPlugin._commands)
        self.assertIn(self.console.getEventID('EVT_CLIENT_SAY'),
                      self.console._handlers)
        self.assertNotIn(
            mock_plugin,
            self.console._handlers[self.console.getEventID('EVT_CLIENT_SAY')])
        self.assertNotIn(id(mock_plugin.mockCrontab), self.console.cron._tabs)
        self.assertListEqual(['Plugin mock has been unloaded'],
                             superadmin.message_history)
예제 #42
0
    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)
예제 #43
0
class NickregTestCase(unittest2.TestCase):
    def setUp(self):
        # create a FakeConsole parser
        self.parser_conf = XmlConfigParser()
        self.parser_conf.loadFromString(r"""<configuration/>""")
        with logging_disabled():
            from b3.fake import FakeConsole
            self.console = FakeConsole(self.parser_conf)

        with logging_disabled():
            self.adminPlugin = AdminPlugin(self.console,
                                           '@b3/conf/plugin_admin.ini')
            self.adminPlugin._commands = {}
            self.adminPlugin.onStartup()

        # make sure the admin plugin obtained by other plugins is our admin plugin
        when(self.console).getPlugin('admin').thenReturn(self.adminPlugin)

        self.conf = CfgConfigParser()
        self.conf.loadFromString(
            dedent("""
            [settings]
            min_level: mod
            min_level_global_manage: admin
            max_nicks: 3
            interval: 30
        """))

        self.p = NickregPlugin(self.console, self.conf)
        self.p.onLoadConfig()
        self.p.onStartup()

        with logging_disabled():
            from b3.fake import FakeClient
            self.senioradmin = FakeClient(console=self.console,
                                          name="SeniorAdmin",
                                          guid="SENIORADMIN",
                                          groupBits=64)
            self.admin = FakeClient(console=self.console,
                                    name="Admin",
                                    guid="ADMIN",
                                    groupBits=16)
            self.guest = FakeClient(console=self.console,
                                    name="Guest",
                                    guid="GUEST",
                                    groupBits=0)

        self.admin.connects("1")
        self.guest.connects("2")
        self.senioradmin.connects("3")

    def tearDown(self):
        pass
예제 #44
0
    def setUp(self):
        # create a Iourt42 parser
        parser_conf = XmlConfigParser()
        parser_conf.loadFromString(dedent(r"""
            <configuration>
                <settings name="server">
                    <set name="game_log"></set>
                </settings>
            </configuration>
        """))

        self.parser_conf = MainConfig(parser_conf)
        self.console = Iourt42Parser(self.parser_conf)

        # initialize some fixed cvars which will be used by both the plugin and the iourt42 parser
        when(self.console).getCvar('auth').thenReturn(Cvar('auth', value='0'))
        when(self.console).getCvar('fs_basepath').thenReturn(Cvar('fs_basepath', value='/fake/basepath'))
        when(self.console).getCvar('fs_homepath').thenReturn(Cvar('fs_homepath', value='/fake/homepath'))
        when(self.console).getCvar('fs_game').thenReturn(Cvar('fs_game', value='q3ut4'))
        when(self.console).getCvar('gamename').thenReturn(Cvar('gamename', value='q3urt42'))

        # start the parser
        self.console.startup()

        with logging_disabled():
            self.adminPlugin = AdminPlugin(self.console, '@b3/conf/plugin_admin.ini')
            self.adminPlugin.onLoadConfig()
            self.adminPlugin.onStartup()

        # make sure the admin plugin obtained by other plugins is our admin plugin
        when(self.console).getPlugin('admin').thenReturn(self.adminPlugin)

        with logging_disabled():
            from b3.fake import FakeClient

        # create some clients
        self.mike = FakeClient(console=self.console, name="Mike", guid="mikeguid", team=TEAM_RED,  groupBits=128)
        self.bill = FakeClient(console=self.console, name="Bill", guid="billguid", team=TEAM_BLUE, groupBits=16)
        self.mark = FakeClient(console=self.console, name="Mark", guid="markguid", team=TEAM_RED,  groupBits=2)
        self.sara = FakeClient(console=self.console, name="Sara", guid="saraguid", team=TEAM_SPEC, groupBits=1)

        self.conf = CfgConfigParser()
        self.p = CallvotePlugin(self.console, self.conf)
예제 #45
0
 def test_cmd_plugin_enable_succeed_multiple(self):
     # GIVEN
     mock_pluginA = Mock(spec=Plugin)
     mock_pluginA.isEnabled = Mock(return_value=False)
     when(self.console).getPlugin("mocka").thenReturn(mock_pluginA)
     mock_pluginB = Mock(spec=Plugin)
     mock_pluginB.isEnabled = Mock(return_value=False)
     when(self.console).getPlugin("mockb").thenReturn(mock_pluginB)
     superadmin = FakeClient(self.console,
                             name="superadmin",
                             guid="superadminguid",
                             groupBits=128)
     superadmin.connects("1")
     # WHEN
     superadmin.clearMessageHistory()
     superadmin.says("!plugin enable mocka mockb")
     # THEN
     self.assertListEqual(
         ['Plugin mocka is now enabled', 'Plugin mockb is now enabled'],
         superadmin.message_history)
예제 #46
0
 def test_KILL(self):  # 15
     # GIVEN
     attacker = FakeClient(self.parser,
                           name="attacker_name",
                           guid='76561198036015889')
     attacker.connects("1")
     victim = FakeClient(self.parser,
                         name="victim_name",
                         guid='76561198021620061')
     victim.connects("2")
     # WHEN
     self.parser.handlePacket(
         Packet.decode(
             '\x00\x0f\x00\x00\x00\x1e\x01\x10\x00\x01\x04\x83\xdb\x11\x01\x10\x00\x01\x03\xa81]\x00\x00\x00\nTekko Kagi'
         ))
     # THEN
     self.assert_has_event("EVT_CLIENT_KILL",
                           client=attacker,
                           target=victim,
                           data=(100, u'Tekko Kagi', 'body'))
예제 #47
0
 def test_map_with_correct_parameters(self):
     # GIVEN
     superadmin = FakeClient(self.parser,
                             name="superadmin",
                             guid="guid_superadmin",
                             groupBits=128,
                             team=TEAM_UNKNOWN)
     superadmin.connects("1")
     # WHEN
     superadmin.says("!map market push")
     # THEN
     self.parser.output.write.assert_has_calls(
         [call('changelevel market push')])
예제 #48
0
    def setUp(self):
        # less logging
        self.logger = logging.getLogger('output')
        self.logger.setLevel(logging.ERROR)
        self.logger.propagate = False

        from b3.fake import FakeConsole, FakeClient

        # create a Fake parser
        self.parser_conf = XmlConfigParser()
        self.parser_conf.loadFromString(
            """<configuration><settings name="server"><set name="game_log"></set></settings></configuration>"""
        )
        self.console = FakeConsole(self.parser_conf)
        self.console.startup()

        # load the admin plugin
        # load the admin plugin
        if B3version(b3_version) >= B3version("1.10dev"):
            admin_plugin_conf_file = '@b3/conf/plugin_admin.ini'
        else:
            admin_plugin_conf_file = '@b3/conf/plugin_admin.xml'
        with logging_disabled():
            self.adminPlugin = AdminPlugin(self.console,
                                           admin_plugin_conf_file)
            self.adminPlugin.onLoadConfig()
            self.adminPlugin._commands = {
            }  # work around known bug in the Admin plugin which makes the _command property shared between all instances
            self.adminPlugin.onStartup()

        # make sure the admin plugin obtained by other plugins is our admin plugin
        when(self.console).getPlugin('admin').thenReturn(self.adminPlugin)

        # load our plugin
        self.conf = CfgConfigParser()
        self.p = ServermonitorPlugin(self.console, self.conf)

        self.superadmin = FakeClient(self.console,
                                     name="Superadmin",
                                     guid="Superadmin_guid",
                                     groupBits=128)

        self.logger.propagate = True
예제 #49
0
 def test_high_level_no_password_set(self):
     # GIVEN
     joe = FakeClient(self.console,
                      name="Joe",
                      guid="joeguid",
                      groupBits=128)
     # WHEN
     joe.clearMessageHistory()
     joe.connects("0")
     # THEN
     self.assertEqual([
         'You need a password to use all your privileges: ask the administrator to set a password for you'
     ], joe.message_history)
     self.assertEqual(2, joe.groupBits)
    def setUp(self):
        self.log = logging.getLogger('output')
        self.log.propagate = False

        B3TestCase.setUp(self)

        self.console.screen = Mock()
        self.console.time = time.time
        self.console.upTime = Mock(return_value=3)

        self.p = GeolocationPlugin(self.console)
        self.p.onLoadConfig()
        self.p.onStartup()

        self.log.propagate = True

        self.mike = FakeClient(console=self.console,
                               name="Mike",
                               guid="MIKEGUID",
                               groupBits=1)
예제 #51
0
 def test_map_with_invalid_map_name(self):
     # GIVEN
     superadmin = FakeClient(self.parser,
                             name="superadmin",
                             guid="guid_superadmin",
                             groupBits=128,
                             team=TEAM_UNKNOWN)
     superadmin.connects("1")
     # WHEN
     superadmin.says("!map blargh blub")
     # THEN
     self.assertListEqual([
         "do you mean : buhriz, district, sinjar, siege, uprising, ministry, revolt, heights, "
         "contact, peak, panj, market ?"
     ], superadmin.message_history)
예제 #52
0
class Test_player_connect_event(PluginTestCase):
    CONF = """\
[commands]
startserverdemo = 20
stopserverdemo = 20
"""

    def setUp(self):
        PluginTestCase.setUp(self)
        self.p.onStartup()

        self.joe = FakeClient(self.console,
                              name="Joe",
                              guid="01230123012301230123",
                              groupBits=1)
        self.joe.clearMessageHistory()

        self.p.start_recording_player = Mock(
            return_value="startserverdemo: recording ")
        self.p.start_recording_player.reset_mock()

    def test_auto_start_demo_of_connecting_players(self):
        # GIVEN
        self.p._recording_all_players = True

        # WHEN
        self.joe.connects("2")
        self.console.queueEvent(
            Event(self.console.getEventID('EVT_CLIENT_JOIN'), self.joe,
                  self.joe))

        # THEN
        sleep(.5)  # sleep so the thread has time of doing its job
        self.assertTrue(self.p.start_recording_player.called)
        self.p.start_recording_player.assert_called_with(self.joe, None)

    def test_do_not_auto_start_demo_of_connecting_players(self):
        # GIVEN
        self.p._recording_all_players = False

        # WHEN
        self.joe.connects("2")

        # THEN
        sleep(.5)  # sleep so the thread has time of doing its job
        self.assertFalse(self.p.start_recording_player.called)
예제 #53
0
    def setUp(self):
        JumperTestCase.setUp(self)
        with logging_disabled():
            from b3.fake import FakeClient

        # create some clients
        self.mike = FakeClient(console=self.console, name="Mike", guid="mikeguid", team=TEAM_FREE, groupBits=128)
        self.bill = FakeClient(console=self.console, name="Bill", guid="billguid", team=TEAM_FREE, groupBits=1)
        self.mark = FakeClient(console=self.console, name="Mark", guid="markguid", team=TEAM_FREE, groupBits=1)
        self.mike.connects("1")
        self.bill.connects("2")
        self.mark.connects("3")

        self.console.game.mapName = 'ut42_bstjumps_u2'
        self.console.parseLine('''ClientJumpRunStarted: 1 - way: 1''')
        self.console.parseLine('''ClientJumpRunStopped: 1 - way: 1 - time: 537000''')
        self.console.parseLine('''ClientJumpRunStarted: 2 - way: 1''')
        self.console.parseLine('''ClientJumpRunStopped: 2 - way: 1 - time: 349000''')
        self.console.parseLine('''ClientJumpRunStarted: 3 - way: 1''')
        self.console.parseLine('''ClientJumpRunStopped: 3 - way: 1 - time: 122000''')
        self.console.parseLine('''ClientJumpRunStarted: 1 - way: 2''')
        self.console.parseLine('''ClientJumpRunStopped: 1 - way: 2 - time: 84000''')
        self.console.parseLine('''ClientJumpRunStarted: 2 - way: 2''')
        self.console.parseLine('''ClientJumpRunStopped: 2 - way: 2 - time: 91000''')
        self.console.parseLine('''ClientJumpRunStarted: 3 - way: 2''')
        self.console.parseLine('''ClientJumpRunStopped: 3 - way: 2 - time: 177000''')

        self.console.game.mapName = 'ut42_jupiter'
        self.console.parseLine('''ClientJumpRunStarted: 1 - way: 1''')
        self.console.parseLine('''ClientJumpRunStopped: 1 - way: 1 - time: 123000''')
        self.console.parseLine('''ClientJumpRunStarted: 2 - way: 1''')
        self.console.parseLine('''ClientJumpRunStopped: 2 - way: 1 - time: 543000''')
        self.console.parseLine('''ClientJumpRunStarted: 1 - way: 2''')
        self.console.parseLine('''ClientJumpRunStopped: 1 - way: 2 - time: 79000''')

        when(self.console).getMaps().thenReturn(['ut4_abbey', 'ut4_abbeyctf', 'ut4_algiers', 'ut4_ambush',
            'ut4_austria', 'ut42_bstjumps_u2', 'ut4_bohemia', 'ut4_casa', 'ut4_cascade', 'ut4_commune',
            'ut4_company', 'ut4_crossing', 'ut4_docks', 'ut4_dressingroom', 'ut4_eagle', 'ut4_elgin',
            'ut4_firingrange', 'ut4_ghosttown_rc4', 'ut4_harbortown', 'ut4_herring', 'ut4_horror', 'ut42_jupiter',
            'ut4_kingdom', 'ut4_kingpin', 'ut4_mandolin', 'ut4_mars_b1', 'ut4_maya', 'ut4_oildepot', 'ut4_prague',
            'ut4_prague_v2', 'ut4_raiders', 'ut4_ramelle', 'ut4_ricochet', 'ut4_riyadh', 'ut4_sanc', 'ut4_snoppis',
            'ut4_suburbs', 'ut4_subway', 'ut4_swim', 'ut4_thingley', 'ut4_tombs', 'ut4_toxic',
            'ut4_tunis', 'ut4_turnpike', 'ut4_uptown'])
예제 #54
0
    def setUp(self):
        # create a BF4 parser
        self.parser_conf = XmlConfigParser()
        self.parser_conf.loadFromString("""<configuration />""")
        with logging_disabled():
            self.console = Bf4Parser(self.parser_conf)

        # alter a few settings to speed up the tests
        self.console.sayqueue_get_timeout = 0
        self.console._settings['message_delay'] = 0

        with logging_disabled():
            self.console.startup()

        # load the admin plugin
        if B3version(b3_version) >= B3version("1.10dev"):
            admin_plugin_conf_file = '@b3/conf/plugin_admin.ini'
        else:
            admin_plugin_conf_file = '@b3/conf/plugin_admin.xml'
        with logging_disabled():
            self.adminPlugin = AdminPlugin(self.console, admin_plugin_conf_file)
            self.adminPlugin.onStartup()

        # make sure the admin plugin obtained by other plugins is our admin plugin
        def getPlugin(name):
            if name == 'admin':
                return self.adminPlugin
            else:
                return self.console.getPlugin(name)
        self.console.getPlugin = getPlugin

        self.console.patch_b3_admin_plugin()

        # prepare a few players
        with logging_disabled():
            from b3.fake import FakeClient
            self.joe = FakeClient(self.console, name="Joe", exactName="Joe", guid="zaerezarezar", groupBits=1, team=TEAM_UNKNOWN, teamId=0, squad=0)
            self.simon = FakeClient(self.console, name="Simon", exactName="Simon", guid="qsdfdsqfdsqf", groupBits=0, team=TEAM_UNKNOWN, teamId=0, squad=0)
            self.reg = FakeClient(self.console, name="Reg", exactName="Reg", guid="qsdfdsqfdsqf33", groupBits=4, team=TEAM_UNKNOWN, teamId=0, squad=0)
            self.moderator = FakeClient(self.console, name="Moderator", exactName="Moderator", guid="sdf455ezr", groupBits=8, team=TEAM_UNKNOWN, teamId=0, squad=0)
            self.admin = FakeClient(self.console, name="Level-40-Admin", exactName="Level-40-Admin", guid="875sasda", groupBits=16, team=TEAM_UNKNOWN, teamId=0, squad=0)
            self.superadmin = FakeClient(self.console, name="God", exactName="God", guid="f4qfer654r", groupBits=128, team=TEAM_UNKNOWN, teamId=0, squad=0)
예제 #55
0
class Test_cmd_xlrid(XlrstatsTestCase):

    def setUp(self):
        XlrstatsTestCase.setUp(self)
        self.init()
        self.p1 = FakeClient(console=self.console, name="P1", guid="P1_GUID", groupBits=1)
        self.p1.connects("1")

    def test_no_parameters(self):
        # WHEN
        self.p1.says("!xlrid")
        # THEN
        self.assertEqual(['Invalid/missing data, try !help xlrid'], self.p1.message_history)

    def test_with_parameters(self):
        # WHEN
        self.p1.says("!xlrid 12345")
        pstats = self.p.get_PlayerStats(self.p1)
        # THEN
        self.assertEqual('12345', pstats.id_token)
        self.assertEqual(['Token saved!'], self.p1.message_history)
예제 #56
0
 def test_client_with_password_gamepassword(self):
     """
     Case where a player saved the password to join the game in its UrT config. As a result, we find a 'password'
     field in the clientuserinfo line.
     This value must not overwrite the 'password' property of the Client object.
     """
     # GIVEN a known client
     c = FakeClient(console=self.console, name="Zesco", guid="58D4069246865BB5A85F20FB60ED6F65", login="******", password="******")
     c.save()
     c.connects('15')
     self.assertEqual('password_in_database', c.password)
     # WHEN
     infoline = r"15 \ip\1.2.3.4:27960\name\Zesco\password\some_password_here\racered\2\raceblue\3\rate\8000\ut_timenudge\0\cg_rgb\128 128 128\cg_predictitems\0\cg_physics\1\snaps\20\model\sarge\headmodel\sarge\team_model\james\team_headmodel\*james\color1\4\color2\5\handicap\100\sex\male\cl_anonymous\0\gear\GMIORAA\teamtask\0\cl_guid\58D4069246865BB5A85F20FB60ED6F65\weapmodes\00000110120000020002"
     self.assertTrue('15' in self.console.clients)
     self.console.OnClientuserinfo(action=None, data=infoline)
     # THEN
     client = self.console.clients['15']
     self.assertEqual('1.2.3.4', client.ip)
     self.assertEqual('Zesco^7', client.exactName)
     self.assertEqual('Zesco', client.name)
     self.assertEqual('58D4069246865BB5A85F20FB60ED6F65', client.guid)
     self.assertEqual('password_in_database', client.password)
예제 #57
0
    def test_map(self):
        # GIVEN
        when(self.parser.output).write("getmaplist false").thenReturn(u"""0 CTR_Bridge
1 CTR_Canyon
2 CTR_Derelict
3 CTR_IceBreaker
4 CTR_Liberty
5 CTR_Rooftop
6 Thrust_Bridge
7 Thrust_Canyon
8 Thrust_Chasm
9 Thrust_IceBreaker
10 Thrust_Liberty
11 Thrust_Oilrig
12 Thrust_Rooftop
""".encode('UTF-8'))
        admin = FakeClient(console=self.parser, name="admin", guid="guid_admin", groupBits=128)
        admin.connects("guid_admin")
        # WHEN
        with patch.object(self.parser.output, 'write', wraps=self.parser.output.write) as write_mock:
            admin.says("!map chasm")
        # THEN
        write_mock.assert_has_calls([call("addmap Thrust_Chasm 1"), call("nextmap")])
예제 #58
0
 def test_permban(self):
     # GIVEN
     superadmin = FakeClient(self.parser,
                             name="superadmin",
                             guid="guid_superadmin",
                             groupBits=128,
                             team=TEAM_UNKNOWN)
     superadmin.connects("1")
     bill = FakeClient(self.parser,
                       name="bill",
                       guid="guid_bill",
                       team=TEAM_UNKNOWN)
     bill.connects("2")
     # WHEN
     superadmin.says("!permban bill rule1")
     # THEN
     superadmin.says('!baninfo @%s' % bill.id)
     self.assertListEqual([
         'Banned: bill (@3) has been added to banlist',
         'bill has 1 active bans',
     ], superadmin.message_history)
예제 #59
0
           ts_login=config.get("teamspeak_server", "login"),
           ts_password=config.get("teamspeak_server", "password")))

p = TeamspeakbfPlugin(fakeConsole, conf)
p.onLoadConfig()
p.onStartup()


def instruct(instructions):
    print "\n\n> %s" % instructions
    raw_input("type ENTER when ready")


me = FakeClient(fakeConsole,
                name="me",
                guid="zaerazerazerzaer",
                groupBits=128,
                team=TEAM_UNKNOWN,
                ip=config.get("me", "ip"))

# force me to the managed channel
tsclient = p.tsGetClient(me)
while not tsclient:
    instruct("connect to the teamspeak server")
    tsclient = p.tsGetClient(me)

me.connects(0)

if not p.tsIsClientInB3Channel(tsclient):
    p.tsMoveTsclientToChannelId(tsclient, p.tsChannelIdB3)

time.sleep(.5)
예제 #60
0
def joe(console):
    with logging_disabled():
        from b3.fake import FakeClient
    joe = FakeClient(console, name="Joe", guid="joe_guid", groupBits=1, team=TEAM_UNKNOWN)
    joe.clearMessageHistory()
    return joe