From fd0d717cd452c273bd1948b81761eec17159482d Mon Sep 17 00:00:00 2001 From: AleaJactaEst Date: Wed, 10 Oct 2018 23:18:54 +0200 Subject: [PATCH] change message to detect player connecter and character loaded --- pymanager/manager.py | 47 +++++++++++++++++++++++++++---------------- tests/test_manager.py | 21 +++++++++++++------ 2 files changed, 45 insertions(+), 23 deletions(-) diff --git a/pymanager/manager.py b/pymanager/manager.py index 5b0c3cf..f6b33d9 100755 --- a/pymanager/manager.py +++ b/pymanager/manager.py @@ -635,14 +635,13 @@ class ManageCommand(): self.restart_delay = restart_delay self.threadRestart = None self.egs_filter = egs_filter - self.egs_filter_load_character = re.compile(r".*(egs_plinfo).*(: LOADED User )'(?P[\d]+)' Character '(?P[^']+)' from BS stream file 'characters/([\d]+)/account_(?P[\d]+)_(?P[\d]+)_pdr.bin") + self.egs_filter_register_entity = re.compile(r".*(registerEntity).*(: EIT: Register EId )[(](?P.*)[)] EntityName '(?P[^']+)' UId (?P[\d]+) UserName '(?P[^']+)'") self.egs_filter_active_character = re.compile(r".*(setActiveCharForPlayer).*(: set active char )(?P[\d]+)( for player )(?P[\d]+)") self.egs_filter_sid = re.compile(r".*(Mapping UID )(?P[\d]+)( => Sid )[(](?P.*)[)]") self.egs_filter_client_ready = re.compile(r".*(Updating IS_NEWBIE flag for character: )[(](?P.*)[)]") self.egs_filter_disconnected = re.compile(r".*(disconnectPlayer).+[\s]+(player )(?P[\d]+)[\s]+(is disconnected)") self.egs_filter_admin = re.compile(r"(.*)(cbClientAdmin).*(: ADMIN)(: Player )[(](?P.*)[)](?P.+)") - # cbClientAdmin EGS-133 : ADMIN: Player (0x0000000021:00:00:86) tried to execute a no valid client admin command 'info' - self.filter_load_character = {} + self.filter_register_entity = {} self.filter_active_character = {} self.filter_admin = {} self.number_start = 0 @@ -685,33 +684,43 @@ class ManageCommand(): logging.debug("del1 del_filter found [%s][%s][%s]" % (str(key), str(dico[key]), str(self.filter[key]))) del self.filter[key][dico[key]] if self.egs_filter: - res = self.egs_filter_load_character.match(msg) + res = self.egs_filter_register_entity.match(msg) if res: - logging.debug("egs_filter_load_character found") - if len(self.filter_load_character) < self.size_max_filter: - logging.debug("include add_filter found") + logging.debug("egs_filter_register_entity found") + if len(self.filter_register_entity) < self.size_max_filter: + logging.debug("include filter_register_entity found") dico = res.groupdict() try: - self.filter_load_character.setdefault(dico['UID'], {}) - self.filter_load_character[dico['UID']].setdefault(dico['IDCHAR'], {'NameDomain': dico['NameDomain'], 'UID': dico['UIDBIS'], 'when': now}) + self.filter_register_entity.setdefault(dico['UID'], {}) + IDCHAR = len(self.filter_register_entity[dico['UID']]) + if IDCHAR > 0: + # check UserName + if dico['UserName'] != self.filter_register_entity[dico['UID']][0]['UserName']: + logging.info("Remove old player %s by %s (UID:%d)" % (self.filter_register_entity[dico['UID']][IDCHAR]['UserName'], dico['UserName'], dico['UID'])) + del self.filter_register_entity[dico['UID']] + logging.debug("add filter_register_entity (uid:%s char:%d)" % (dico['UID'], IDCHAR)) + self.filter_register_entity[dico['UID']].setdefault(IDCHAR, {'NameDomain': dico['NameDomain'], 'UserName': dico['UserName'], 'UID': dico['UID'], "EId": dico['EId'], 'When': now, 'CHAR': IDCHAR}) except KeyError as e: - logging.error('Missing key when read "load_character" (%s)' % e) + logging.error('Missing key when read "register_entity" (%s)' % e) else: - logging.warning("impossible to add param 'load_character' (size too high)") + logging.warning("impossible to add param 'register_entity' (size too high)") return res = self.egs_filter_active_character.match(msg) if res: logging.debug("egs_filter_active_character found") + dico = res.groupdict() if len(self.filter_active_character) < self.size_max_filter: - dico = res.groupdict() try: self.filter_active_character.setdefault(dico['UID'], {}) - self.filter_active_character[dico['UID']] = self.filter_load_character[dico['UID']][dico['IDCHAR']] - del self.filter_load_character[dico['UID']] + self.filter_active_character[dico['UID']] = self.filter_register_entity[dico['UID']][int(dico['IDCHAR'])] except KeyError as e: logging.error('Missing key when read "active_character" (%s)' % e) else: logging.warning("impossible to add param 'active_character' (size too high)") +# try: +# del self.filter_register_entity[dico['UID']] +# except KeyError as e: +# logging.error('Missing key when delete "active_character" (%s)' % e) return res = self.egs_filter_sid.match(msg) if res: @@ -720,6 +729,7 @@ class ManageCommand(): try: if dico['UID'] in self.filter_active_character: self.filter_active_character[dico['UID']].setdefault("SID", dico['SID']) + self.filter_active_character[dico['UID']].setdefault("When", now) else: logging.error('Impossible to add SID on player %s (Player not found)' % dico['UID']) except KeyError as e: @@ -745,15 +755,18 @@ class ManageCommand(): del self.filter_admin[self.pos_admin - self.maxlog] try: dico = res.groupdict() - username = '' + UserName = '' + NameDomain = '' try: for key in self.filter_active_character: if self.filter_active_character[key]['SID'] == dico['SID']: - username = self.filter_active_character[key]['NameDomain'] + NameDomain = self.filter_active_character[key]['NameDomain'] + UserName = self.filter_active_character[key]['UserName'] + EId = self.filter_active_character[key]['EId'] break except KeyError: pass - self.filter_admin.setdefault(self.pos_admin, {'when': now, 'SID': dico['SID'], 'ACTION': dico['ACTION'], 'USER': username}) + self.filter_admin.setdefault(self.pos_admin, {'When': now, 'SID': dico['SID'], "EId": EId, 'ACTION': dico['ACTION'], 'NameDomain': NameDomain, 'UserName': UserName}) except KeyError as e: logging.error('Missing key when admin player (%s)' % e) self.pos_admin = self.pos_admin + 1 diff --git a/tests/test_manager.py b/tests/test_manager.py index 3bf0cd5..ea9abdc 100644 --- a/tests/test_manager.py +++ b/tests/test_manager.py @@ -273,12 +273,21 @@ class TestManager(unittest.TestCase): self.assertTrue(False, "LOADED - Missing player 2") if '0' not in manage.filter_load_character['2']: self.assertTrue(False, "LOADED - Missing charactere 0 for player 2") - manage._analyze_line("alpha egs_plinfo EGS-132 : LOADED User '2' Character 'Puskle(Lirria)' from BS stream file 'characters/002/account_2_1_pdr.bin'") - if '1' not in manage.filter_load_character['2']: - self.assertTrue(False, "LOADED - Missing charactere 1 for player 2") - manage._analyze_line("alpha egs_plinfo EGS-132 : LOADED User '3' Character 'Puskle(Lirria)' from BS stream file 'characters/003/account_3_4_pdr.bin'") - if '3' not in manage.filter_load_character: - self.assertTrue(False, "LOADED - Missing player 2") + manage._analyze_line("alpha egs_plinfo EGS-132 : registerEntity EGS-134 : EIT: Register EId (0x0000000020:00:00:00) EntityName 'Nin(lirria)' UId 2 UserName 'tester'") + if '0' not in manage.filter_register_entity['2']: + self.assertTrue(False, "registerEntity - Missing player 2 (1st char)") + manage._analyze_line("alpha egs_plinfo EGS-132 : registerEntity EGS-134 : EIT: Register EId (0x0000000020:00:00:00) EntityName 'Nin(lirria)' UId 2 UserName 'tester'") + if '1' not in manage.filter_register_entity['2']: + self.assertTrue(False, "registerEntity - Missing player 2 (2nd char)") + manage._analyze_line("alpha egs_plinfo EGS-132 : registerEntity EGS-134 : EIT: Register EId (0x0000000020:00:00:00) EntityName 'Nin(lirria)' UId 3 UserName 'tester'") + if '0' not in manage.filter_register_entity['3']: + self.assertTrue(False, "registerEntity - Missing player 3 (1st char)") + #manage._analyze_line("alpha egs_plinfo EGS-132 : LOADED User '2' Character 'Puskle(Lirria)' from BS stream file 'characters/002/account_2_1_pdr.bin'") + #if '1' not in manage.filter_load_character['2']: + # self.assertTrue(False, "LOADED - Missing charactere 1 for player 2") + #manage._analyze_line("alpha egs_plinfo EGS-132 : LOADED User '3' Character 'Puskle(Lirria)' from BS stream file 'characters/003/account_3_4_pdr.bin'") + #if '3' not in manage.filter_load_character: + # self.assertTrue(False, "LOADED - Missing player 2") manage._analyze_line("alpha egs_ecinfo EGS-132 : setActiveCharForPlayer EGS-132 : set active char 1 for player 2") if '2' not in manage.filter_active_character: self.assertTrue(False, "setActiveCharForPlayer - Missing player 2")