change message to detect player connecter and character loaded

This commit is contained in:
AleaJactaEst 2018-10-10 23:18:54 +02:00
parent aff822c534
commit fd0d717cd4
2 changed files with 45 additions and 23 deletions

View file

@ -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<UID>[\d]+)' Character '(?P<NameDomain>[^']+)' from BS stream file 'characters/([\d]+)/account_(?P<UIDBIS>[\d]+)_(?P<IDCHAR>[\d]+)_pdr.bin")
self.egs_filter_register_entity = re.compile(r".*(registerEntity).*(: EIT: Register EId )[(](?P<EId>.*)[)] EntityName '(?P<NameDomain>[^']+)' UId (?P<UID>[\d]+) UserName '(?P<UserName>[^']+)'")
self.egs_filter_active_character = re.compile(r".*(setActiveCharForPlayer).*(: set active char )(?P<IDCHAR>[\d]+)( for player )(?P<UID>[\d]+)")
self.egs_filter_sid = re.compile(r".*(Mapping UID )(?P<UID>[\d]+)( => Sid )[(](?P<SID>.*)[)]")
self.egs_filter_client_ready = re.compile(r".*(Updating IS_NEWBIE flag for character: )[(](?P<ID>.*)[)]")
self.egs_filter_disconnected = re.compile(r".*(disconnectPlayer).+[\s]+(player )(?P<UID>[\d]+)[\s]+(is disconnected)")
self.egs_filter_admin = re.compile(r"(.*)(cbClientAdmin).*(: ADMIN)(: Player )[(](?P<SID>.*)[)](?P<ACTION>.+)")
# 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

View file

@ -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")