def OnVote(self, action, data, match=None): cid = match.group('cid') value = match.group('value') client = self.getByCidOrJoinPlayer(cid) if not client: self.debug('No client found') return None return Event(self.EVT_CLIENT_VOTE, client=client, data=value)
def OnCallvote(self, action, data, match=None): cid = match.group('cid') vote_string = match.group('vote_string') client = self.getByCidOrJoinPlayer(cid) if not client: self.debug('No client found') return None return Event(self.EVT_CLIENT_CALLVOTE, client=client, data=vote_string)
def test_parse_registered_event_with_no_hook_registered(self): # GIVEN k = self.console.getEventID('EVT_CLIENT_SAY') p = MyPlugin(self.console, self.conf) # WHEN self.console.queueEvent(Event(k, None)) # THEN self.assertEqual(0, p.onEvent_call_count) self.assertEqual(0, p.stub_method_call_count) self.assertEqual(0, p.stub_method2_call_count)
def test_3_consecutive_deaths_with_some_activity(plugin, joe, jack): """ player is killed 3 times in a row but shown some activity """ # GIVEN plugin.check_client = Mock() joe.connects(1) jack.connects(2) # WHEN plugin.on_client_activity(Event("", None, client=jack)) # some activity joe.kills(jack) # 1st death joe.kills(jack) # 2nd death plugin.on_client_activity(Event("", None, client=jack)) # some activity # THEN jack is not yet checked assert not plugin.check_client.called # WHEN joe.kills(jack) # 3rd death but with activity in between # THEN jack is still not checked assert not plugin.check_client.called
def test_parse_registered_event_with_multiple_valid_hooks_and_old_fashion_way(self): # GIVEN k = self.console.getEventID('EVT_CLIENT_SAY') p = MyPlugin(self.console, self.conf) p.registerEvent(k) # old fashion p.registerEvent(k, p.stub_method) # WHEN self.console.queueEvent(Event(k, None)) # THEN self.assertEqual(1, p.onEvent_call_count) self.assertEqual(1, p.stub_method_call_count) self.assertEqual(0, p.stub_method2_call_count)
def test_parse_registered_event_with_multiple_valid_hooks(self): # GIVEN k = self.console.getEventID('EVT_CLIENT_SAY') p = MyPlugin(self.console, self.conf) p.registerEvent(k, p.stub_method) # register the first hook p.registerEvent(k, p.stub_method2) # register the second hook # WHEN self.console.queueEvent(Event(k, None)) # THEN self.assertEqual(0, p.onEvent_call_count) self.assertEqual(1, p.stub_method_call_count) self.assertEqual(1, p.stub_method2_call_count)
def test_register_event_same_hook_registered_multiple_times(self): # GIVEN k = self.console.getEventID('EVT_CLIENT_SAY') p = MyPlugin(self.console, self.conf) p.registerEvent(k, p.stub_method) p.registerEvent(k, p.stub_method) p.registerEvent(k, p.stub_method) # WHEN self.console.queueEvent(Event(k, None)) # THEN self.assertEqual(0, p.onEvent_call_count) self.assertEqual(1, p.stub_method_call_count) self.assertEqual(0, p.stub_method2_call_count)
def test_active_recently(plugin, joe): """ check a player who was active 20s ago """ # GIVEN now = time() joe.connects(1) plugin.on_client_activity(Event("", None, client=joe), now=(now - 20)) # some activity 20s ago # WHEN plugin.check_client(joe) # THEN joe is not asked if AFK assert not plugin.ask_client.called
def test_not_active_recently(plugin, joe): """ check a player who was active 50s ago """ # GIVEN now = time() joe.connects(1) plugin.on_client_activity(Event("", None, client=joe), now=(now - 50)) # some activity 50s ago # WHEN plugin.check_client(joe) # THEN joe is asked if AFK assert [call(joe)] == plugin.ask_client.mock_calls
def test_not_active_recently_but_superadmin(plugin, superadmin): """ check an immune player who was active 50s ago """ # GIVEN now = time() superadmin.connects(1) plugin.on_client_activity(Event("", None, client=superadmin), now=(now - 50)) # some activity 50s ago # WHEN plugin.check_client(superadmin) # THEN joe is not asked if AFK assert not plugin.ask_client.called
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 OnSurvivorwinner(self, action, data, match=None): #SurvivorWinner: Blue #SurvivorWinner: Red #SurvivorWinner: 0 if data in ('Blue', 'Red'): return b3.events.Event(b3.events.EVT_SURVIVOR_WIN, data) else: client = self.getByCidOrJoinPlayer(data) if not client: self.debug('No client found') return None return Event(self.EVT_CLIENT_SURVIVOR_WINNER, client=client, data=None)
def OnClientjumptimerstarted(self, action, data, match=None): cid = match.group('cid') way_id = match.group('way_id') way_label = match.group('way_label') client = self.getByCidOrJoinPlayer(cid) if not client: self.debug('No client found') return None return Event(self.EVT_CLIENT_JUMP_TIMER_START, client=client, data={ 'way_id': way_id, 'way_label': way_label })
def test_not_active_recently_but_bot(plugin, bot): """ check a bot who was active 50s ago """ # GIVEN now = time() bot.connects(1) bot.bot = True plugin.on_client_activity(Event("", None, client=bot), now=(now - 50)) # some activity 50s ago # WHEN plugin.check_client(bot) # THEN bot is not asked if AFK assert not plugin.ask_client.called
def OnClientloadposition(self, action, data, match=None): cid = match.group('cid') position = float(match.group('x')), float(match.group('y')), float( match.group('z')) name = match.group('name') client = self.getByCidOrJoinPlayer(cid) if not client: self.debug('No client found') return None return Event(self.EVT_CLIENT_POS_LOAD, client=client, data={ 'position': position, 'name': name })
def test_register_event_with_not_valid_hook(self): # GIVEN k = self.console.getEventID('EVT_CLIENT_SAY') p = MyPlugin(self.console, self.conf) p.registerEvent(k, p.stub_not_callable) # THEN self.assertIn(k, self.console._handlers.keys()) self.assertIn(p, self.console._handlers[k]) self.assertNotIn(k, p.eventmap.keys()) # WHEN self.console.queueEvent(Event(k, None)) # THEN self.assertEqual(0, p.onEvent_call_count) self.assertEqual(0, p.stub_method_call_count) self.assertEqual(0, p.stub_method2_call_count)
def test_register_event_by_name_with_valid_hook(self): # GIVEN evt_name = 'EVT_CLIENT_SAY' k = self.console.getEventID(evt_name) p = MyPlugin(self.console, self.conf) p.registerEvent(evt_name, p.stub_method) # THEN self.assertIn(k, self.console._handlers.keys()) self.assertIn(p, self.console._handlers[k]) self.assertIn(k, p.eventmap.keys()) self.assertIn(p.stub_method, p.eventmap[k]) # WHEN self.console.queueEvent(Event(k, None)) # THEN self.assertEqual(0, p.onEvent_call_count) self.assertEqual(1, p.stub_method_call_count) self.assertEqual(0, p.stub_method2_call_count)
def test_event_EVT_1337_PORT(self): # GIVEN self.p._haxbusterurt_demo_duration = (1.0 / 60) / 8 # will make the auto-stop timer end after 125ms self.p.start_recording_player = Mock() self.p.stop_recording_player = Mock() joe = FakeClient(console=self.console, name="Joe", guid="JOE_GUID") joe.connects("2") # WHEN the haxbusterurt plugin detects that Joe has a contestable guid self.console.queueEvent(Event(self.console.getEventID('EVT_1337_PORT'), data=joe.guid, client=joe)) # THEN sleep(.5) # sleep so the thread has time of doing its job self.p.start_recording_player.assert_called_with(joe, None) # WHEN sleep(.5) # sleep so the thread has time of doing its job self.p.stop_recording_player.assert_called_with(joe)
def test_3_consecutive_deaths_with_no_activity(plugin, joe, jack): """ player is killed 3 times in a row but shown some activity """ # GIVEN plugin.check_client = Mock() joe.connects(1) jack.connects(2) # WHEN plugin.on_client_activity(Event("", None, client=jack)) # some activity joe.kills(jack) # 1st death joe.kills(jack) # 2nd death # THEN jack is not yet checked assert not plugin.check_client.called # WHEN joe.kills(jack) # 3rd consecutive death with no activity # THEN jack is checked for inactivity assert [call(jack)] == plugin.check_client.mock_calls
def OnRadio(self, action, data, match=None): cid = match.group('cid') msg_group = match.group('msg_group') msg_id = match.group('msg_id') location = match.group('location') text = match.group('text') client = self.getByCidOrJoinPlayer(cid) if not client: self.debug('No client found') return None return Event(self.EVT_CLIENT_RADIO, client=client, data={ 'msg_group': msg_group, 'msg_id': msg_id, 'location': location, 'text': text })
def test_event_EVT_FOLLOW_CONNECTED(self): # GIVEN self.p._follow_demo_duration = ( 1.0 / 60) / 8 # will make the auto-stop timer end after 125ms self.p.start_recording_player = Mock() self.p.stop_recording_player = Mock() joe = FakeClient(console=self.console, name="Joe", guid="JOE_GUID") joe.connects("2") self.console.queueEvent( Event(EVT_FOLLOW_CONNECTED, data=None, client=joe)) # THEN self.p.start_recording_player.assert_called_with(joe, None) # WHEN sleep(.2) # THEN self.p.stop_recording_player.assert_called_with(joe)
def testd_3_consecutive_deaths_with_no_activity_but_not_enough_players( plugin, joe, jack, bot): """ player is killed 3 times in a row but shown some activity but he's the last player on the server """ # GIVEN plugin.MIN_INGAME_PLAYERS = 1 plugin.check_client = Mock() joe.connects(1) jack.connects(2) jack.team = TEAM_SPEC bot.connects(2) # WHEN plugin.on_client_activity(Event("", None, client=joe)) # some activity bot.kills(joe) # 1st death bot.kills(joe) # 2nd death # THEN jack is not yet checked assert not plugin.check_client.called # WHEN bot.kills(joe) # 3rd consecutive death with no activity # THEN joe is not checked for inactivity as he is the last remaining human on the server (excluding spectators) assert not plugin.check_client.called
def OnRotu_stats_player(self, action, data, match=None): return Event(EVT_ROTU_STATS_PLAYER, data=match)
def OnRotu_stats_done(self, action, data, match=None): return Event(EVT_ROTU_STATS_DONE, data=None)
def onRadio(this, event): new_event = Event(type=event.type, client=event.client, target=event.target, data=event.data['text']) this.onChat(new_event)
def onRadio(event): new_event = Event(type=event.type, client=event.client, target=event.target, data=event.data['text']) self.p.onChat(new_event)
def radios(me, text): me.console.queueEvent( Event(type=EVT_CLIENT_RADIO, client=me, data={'text': text}))
def onRadio(this, event): new_event = Event(type=event.type, client=event.client, target=event.target, data=repr(event.data)) this.onChat(new_event)
def _set_mapName(self, newmap): if self._mapName != newmap: self.console.queueEvent(Event(EVT_GAME_MAP_CHANGE, {'old': self._mapName, 'new': newmap})) self._mapName = newmap
def OnRotu_stats_game(self, action, data, match=None): return Event(EVT_ROTU_STATS_GAME, data=match)