def __init__(self):
        MultiService.__init__(self)
        self.clear_shared_storage()

        # Place to store some of server confs values --------------------------
        self.confs = {}

        # Init pilots service -------------------------------------------------
        from commander.service.pilots import PilotsService
        pilots = PilotsService()
        pilots.setServiceParent(self)

        # Init objects service ------------------------------------------------
        from commander.service.objects import ObjectsService
        objects = ObjectsService()
        objects.setServiceParent(self)

        # Init missions service with log watcher ------------------------------
        from commander.service.missions import MissionsService
        log_watcher = LogWatchingService(settings.IL2_EVENTS_LOG_PATH)
        missions = MissionsService(log_watcher)
        log_parser = EventLogParser((pilots, objects, missions, ))
        log_watcher.set_parser(log_parser)
        missions.setServiceParent(self)

        # Init console and DeviceLink parsers ---------------------------------
        console_parser = ConsoleParser((pilots, missions, ))
        device_link_parser = DeviceLinkParser()

        # Group parsers and services ------------------------------------------
        self.parsers = namedtuple('commander_parsers',
            field_names=['console', 'device_link', 'log'])(
            console_parser, device_link_parser, log_parser)
        self.services = namedtuple('commander_services',
            field_names=['pilots', 'objects', 'missions'])(
            pilots, objects, missions)
Exemplo n.º 2
0
 def setUp(self):
     self.pilot_srvc = PilotService()
     self.obj_srvc = ObjectsService()
     self.parser = EventLogParser((self.pilot_srvc, self.obj_srvc))
     self.pilot_srvc.startService()
Exemplo n.º 3
0
class EventLogParserTestCase(TestCase):

    def setUp(self):
        self.pilot_srvc = PilotService()
        self.obj_srvc = ObjectsService()
        self.parser = EventLogParser((self.pilot_srvc, self.obj_srvc))
        self.pilot_srvc.startService()

    def tearDown(self):
        self.pilot_srvc.stopService()
        self.obj_srvc.stopService()

    def test_occupied_seat(self):
        data = "user0:A6M2-21(0) seat occupied by user0 at 100.99 200.99"
        self.parser.parse_line(data)

        self.assertEqual(len(self.pilot_srvc.occupied), 1)
        result = self.pilot_srvc.occupied[0]

        self.assertIsInstance(result, dict)
        self.assertEqual(result.get('callsign'), "user0")
        self.assertEqual(result.get('seat'), 0)
        self.assertEqual(result.get('aircraft'), "A6M2-21")
        self.assertIsInstance(result.get('pos'), dict)
        self.assertEqual(result['pos'].get('x'), 100.99)
        self.assertEqual(result['pos'].get('y'), 200.99)

    def test_weapons_loaded(self):
        data = "user0:A6M2-21 loaded weapons '1xdt' fuel 100%"
        self.parser.parse_line(data)

        self.assertEqual(len(self.pilot_srvc.weapons), 1)
        result = self.pilot_srvc.weapons[0]

        self.assertIsInstance(result, dict)
        self.assertEqual(result.get('callsign'), "user0")
        self.assertEqual(result.get('aircraft'), "A6M2-21")
        self.assertEqual(result.get('weapons'), "1xdt")
        self.assertEqual(result.get('fuel'), 100)

    def test_was_killed(self):
        data = "user0:A6M2-21(0) was killed at 100.99 200.99"
        self.parser.parse_line(data)

        self.assertEqual(len(self.pilot_srvc.killed), 1)
        result = self.pilot_srvc.killed[0]

        self.assertIsInstance(result, dict)
        self.assertEqual(result.get('callsign'), "user0")
        self.assertEqual(result.get('seat'), 0)
        self.assertEqual(result.get('aircraft'), "A6M2-21")
        self.assertIsInstance(result.get('pos'), dict)
        self.assertEqual(result['pos'].get('x'), 100.99)
        self.assertEqual(result['pos'].get('y'), 200.99)

    def test_was_shot_down(self):
        data = "user0:A6M2-21 shot down by user1:B5N2 at 100.99 200.99"
        self.parser.parse_line(data)

        self.assertEqual(len(self.pilot_srvc.shot_down), 1)
        result = self.pilot_srvc.shot_down[0]

        self.assertIsInstance(result, dict)
        self.assertIsInstance(result.get('victim'), dict)
        self.assertEqual(result['victim'].get('callsign'), "user0")
        self.assertEqual(result['victim'].get('aircraft'), "A6M2-21")
        self.assertIsInstance(result.get('attacker'), dict)
        self.assertEqual(result['attacker'].get('callsign'), "user1")
        self.assertEqual(result['attacker'].get('aircraft'), "B5N2")
        self.assertIsInstance(result.get('pos'), dict)
        self.assertEqual(result['pos'].get('x'), 100.99)
        self.assertEqual(result['pos'].get('y'), 200.99)

    def test_selected_army(self):
        data = "user0 selected army Red at 100.99 200.99"
        self.parser.parse_line(data)

        self.assertEqual(len(self.pilot_srvc.army_select), 1)
        result = self.pilot_srvc.army_select[0]

        self.assertIsInstance(result, dict)
        self.assertEqual(result.get('callsign'), "user0")
        self.assertEqual(result.get('army'), 'Red')
        self.assertIsInstance(result.get('pos'), dict)
        self.assertEqual(result['pos'].get('x'), 100.99)
        self.assertEqual(result['pos'].get('y'), 200.99)

    def test_went_to_menu(self):
        data = "user0 entered refly menu"
        self.parser.parse_line(data)

        self.assertEqual(len(self.pilot_srvc.to_menu), 1)
        result = self.pilot_srvc.to_menu[0]

        self.assertIsInstance(result, dict)
        self.assertEqual(result.get('callsign'), "user0")

    def test_was_destroyed(self):
        data = "0_Static destroyed by landscape at 100.99 200.99"
        self.parser.parse_line(data)

        self.assertEqual(len(self.obj_srvc.destroyed), 1)
        result = self.obj_srvc.destroyed[0]

        self.assertIsInstance(result, dict)
        self.assertEqual(result.get('victim'), "0_Static")
        self.assertEqual(result.get('attacker'), "landscape")
        self.assertIsInstance(result.get('pos'), dict)
        self.assertEqual(result['pos'].get('x'), 100.99)
        self.assertEqual(result['pos'].get('y'), 200.99)
Exemplo n.º 4
0
 def setUp(self):
     self.pilot_srvc = PilotService()
     self.obj_srvc = ObjectsService()
     self.parser = EventLogParser((self.pilot_srvc, self.obj_srvc))
     self.pilot_srvc.startService()
Exemplo n.º 5
0
class EventLogParserTestCase(TestCase):
    def setUp(self):
        self.pilot_srvc = PilotService()
        self.obj_srvc = ObjectsService()
        self.parser = EventLogParser((self.pilot_srvc, self.obj_srvc))
        self.pilot_srvc.startService()

    def tearDown(self):
        self.pilot_srvc.stopService()
        self.obj_srvc.stopService()

    def test_occupied_seat(self):
        data = "user0:A6M2-21(0) seat occupied by user0 at 100.99 200.99"
        self.parser.parse_line(data)

        self.assertEqual(len(self.pilot_srvc.occupied), 1)
        result = self.pilot_srvc.occupied[0]

        self.assertIsInstance(result, dict)
        self.assertEqual(result.get('callsign'), "user0")
        self.assertEqual(result.get('seat'), 0)
        self.assertEqual(result.get('aircraft'), "A6M2-21")
        self.assertIsInstance(result.get('pos'), dict)
        self.assertEqual(result['pos'].get('x'), 100.99)
        self.assertEqual(result['pos'].get('y'), 200.99)

    def test_weapons_loaded(self):
        data = "user0:A6M2-21 loaded weapons '1xdt' fuel 100%"
        self.parser.parse_line(data)

        self.assertEqual(len(self.pilot_srvc.weapons), 1)
        result = self.pilot_srvc.weapons[0]

        self.assertIsInstance(result, dict)
        self.assertEqual(result.get('callsign'), "user0")
        self.assertEqual(result.get('aircraft'), "A6M2-21")
        self.assertEqual(result.get('weapons'), "1xdt")
        self.assertEqual(result.get('fuel'), 100)

    def test_was_killed(self):
        data = "user0:A6M2-21(0) was killed at 100.99 200.99"
        self.parser.parse_line(data)

        self.assertEqual(len(self.pilot_srvc.killed), 1)
        result = self.pilot_srvc.killed[0]

        self.assertIsInstance(result, dict)
        self.assertEqual(result.get('callsign'), "user0")
        self.assertEqual(result.get('seat'), 0)
        self.assertEqual(result.get('aircraft'), "A6M2-21")
        self.assertIsInstance(result.get('pos'), dict)
        self.assertEqual(result['pos'].get('x'), 100.99)
        self.assertEqual(result['pos'].get('y'), 200.99)

    def test_was_shot_down(self):
        data = "user0:A6M2-21 shot down by user1:B5N2 at 100.99 200.99"
        self.parser.parse_line(data)

        self.assertEqual(len(self.pilot_srvc.shot_down), 1)
        result = self.pilot_srvc.shot_down[0]

        self.assertIsInstance(result, dict)
        self.assertIsInstance(result.get('victim'), dict)
        self.assertEqual(result['victim'].get('callsign'), "user0")
        self.assertEqual(result['victim'].get('aircraft'), "A6M2-21")
        self.assertIsInstance(result.get('attacker'), dict)
        self.assertEqual(result['attacker'].get('callsign'), "user1")
        self.assertEqual(result['attacker'].get('aircraft'), "B5N2")
        self.assertIsInstance(result.get('pos'), dict)
        self.assertEqual(result['pos'].get('x'), 100.99)
        self.assertEqual(result['pos'].get('y'), 200.99)

    def test_selected_army(self):
        data = "user0 selected army Red at 100.99 200.99"
        self.parser.parse_line(data)

        self.assertEqual(len(self.pilot_srvc.army_select), 1)
        result = self.pilot_srvc.army_select[0]

        self.assertIsInstance(result, dict)
        self.assertEqual(result.get('callsign'), "user0")
        self.assertEqual(result.get('army'), 'Red')
        self.assertIsInstance(result.get('pos'), dict)
        self.assertEqual(result['pos'].get('x'), 100.99)
        self.assertEqual(result['pos'].get('y'), 200.99)

    def test_went_to_menu(self):
        data = "user0 entered refly menu"
        self.parser.parse_line(data)

        self.assertEqual(len(self.pilot_srvc.to_menu), 1)
        result = self.pilot_srvc.to_menu[0]

        self.assertIsInstance(result, dict)
        self.assertEqual(result.get('callsign'), "user0")

    def test_was_destroyed(self):
        data = "0_Static destroyed by landscape at 100.99 200.99"
        self.parser.parse_line(data)

        self.assertEqual(len(self.obj_srvc.destroyed), 1)
        result = self.obj_srvc.destroyed[0]

        self.assertIsInstance(result, dict)
        self.assertEqual(result.get('victim'), "0_Static")
        self.assertEqual(result.get('attacker'), "landscape")
        self.assertIsInstance(result.get('pos'), dict)
        self.assertEqual(result['pos'].get('x'), 100.99)
        self.assertEqual(result['pos'].get('y'), 200.99)