From b21cf254cc44a71e1c6c9e83857a439edd98cd5c Mon Sep 17 00:00:00 2001 From: AleaJactaEst Date: Sun, 3 Nov 2019 13:42:13 +0100 Subject: [PATCH] fix some issue --- spykhanat.py | 19 ++++++++++++++++--- tools/CActionFactory.py | 1 + tools/CImpulseDecoder.py | 1 + tools/CStringManager.py | 2 +- 4 files changed, 19 insertions(+), 4 deletions(-) diff --git a/spykhanat.py b/spykhanat.py index b1b1b50..b7560f0 100755 --- a/spykhanat.py +++ b/spykhanat.py @@ -42,6 +42,7 @@ from tools import CImpulseDecoder from tools import CStringManager from tools import CAction import xml.etree.ElementTree as ET +from datetime import datetime LOGGER = 'SpyKhanat' @@ -86,7 +87,7 @@ class SpyPcap(): print("pkt.header:", dir(pkt.header)) print("pkt.packet:", dir(pkt.packet)) logging.getLogger(LOGGER).debug("raw: %s" % pkt.raw()) - logging.getLogger(LOGGER).debug("timestamp: %s" % pkt.timestamp) + logging.getLogger(LOGGER).debug("timestamp: %s (%s)" % (pkt.timestamp,datetime.fromtimestamp(pkt.timestamp).strftime("%Y/%m/%d %H:%M:%S"))) eth_frame = ethernet.Ethernet(pkt.raw()) logging.getLogger(LOGGER).debug("eth_frame: %s" % eth_frame) if eth_frame.type == 2048: @@ -151,6 +152,7 @@ class SpyPcap(): self.client_state.setdefault(clientid, {'CurrentReceivedNumber': 0, 'CurrentSendNumber': 0, 'LastReceivedAck': 0, + 'AckBitMask': 0, 'RegisteredAction': {}, 'world': World.World(), 'GenericMultiPartTemp': CGenericMultiPartTemp.GenericMultiPartTemp(), @@ -219,8 +221,13 @@ class SpyPcap(): self.initialize_client(clientid) self.client_state[clientid]['CurrentReceivedNumber'] = CurrentReceivedNumber if not SystemMode: + ''' + khanat-opennel-code/code/ryzom/client/src/network_connection.cpp:2029 void CNetworkConnection::sendNormalMessage() + ''' LastReceivedAck = msgin.readSint32('LastReceivedAck') self.client_state[clientid]['LastReceivedAck'] = LastReceivedAck + AckBitMask = msgin.readUint32('AckBitMask') + self.client_state[clientid]['AckBitMask'] = AckBitMask logging.getLogger(LOGGER).info("[Client -> Khanat] Normal Mode {CurrentReceivedNumber:%d, src:%s, dst:%s, LastReceivedAck:%d}" % (CurrentReceivedNumber, clientid, dst, LastReceivedAck)) #self.decode_server(msgin, _CurrentReceivedNumber, _CurrentReceivedNumber-1) self.decode_client_receive_normal_message(msgin, clientid, dst) @@ -350,7 +357,8 @@ class SpyPcap(): if not self.filter_host_service or self.filter_host_service.match("%s:%d" % (ip_packet.src.decode(), udp_packet.src_port)) or self.filter_host_service.match("%s:%d" % (ip_packet.dst.decode(), udp_packet.dst_port)): logging.getLogger(LOGGER).debug("-" * 80) if self.show_raw_packet: - logging.getLogger(LOGGER).debug("[raw packet] timestamp:%s src:%s:%d dst:%s:%d data:%s" % (pkt.timestamp, + logging.getLogger(LOGGER).debug("[raw packet] timestamp:%s [%s] src:%s:%d dst:%s:%d data:%s" % (pkt.timestamp, + datetime.fromtimestamp(pkt.timestamp).strftime("%Y/%m/%d %H:%M:%S"), ip_packet.src.decode(), udp_packet.src_port, ip_packet.dst.decode(), udp_packet.dst_port, data.decode())) @@ -358,12 +366,17 @@ class SpyPcap(): msgin.fromBytes(binascii.unhexlify(data)) src = "%s:%d" % (ip_packet.src.decode(), udp_packet.src_port) dst = "%s:%d" % (ip_packet.dst.decode(), udp_packet.dst_port) + if (self.khanat_host_service and self.khanat_host_service.match(src)) or ( not self.khanat_host_service and khanat_host == src): + _provenance = 'Khanat -> Client' + logging.getLogger(LOGGER).debug("[%s] (message received) [%s] %s" % (_provenance, datetime.fromtimestamp(pkt.timestamp).strftime("%Y/%m/%d %H:%M:%S"), msgin.showAllData())) self.decode_khanat_message(msgin, src, dst) else: + _provenance = 'Client -> Khanat' + logging.getLogger(LOGGER).debug("[%s] (message received) [%s] %s" % (_provenance, datetime.fromtimestamp(pkt.timestamp).strftime("%Y/%m/%d %H:%M:%S"), msgin.showAllData())) self.decode_client_message(msgin, src, dst) if self.show_message_decoded: - logging.getLogger(LOGGER).debug("[message decoded] %s" % msgin.showAllData()) + logging.getLogger(LOGGER).debug("[%s] %s" % (_provenance, msgin.showAllData())) for client in self.client_state: logging.getLogger(LOGGER).debug("%s [server tick:%d, client tick:%d]" %(client, self.client_state[client]['CurrentSendNumber'], self.client_state[client]['CurrentReceivedNumber'])) diff --git a/tools/CActionFactory.py b/tools/CActionFactory.py index a904cf9..867e8df 100644 --- a/tools/CActionFactory.py +++ b/tools/CActionFactory.py @@ -101,6 +101,7 @@ class CActionFactory: code = msgin.readSerial(2, 'code') else: code = msgin.readUint8('code') + logging.getLogger(LOGGER).debug("[decoded] %s" % msgin.showAllData()) action = self.create(CAction.INVALID_SLOT, code) if action: try: diff --git a/tools/CImpulseDecoder.py b/tools/CImpulseDecoder.py index af4b894..07bae89 100644 --- a/tools/CImpulseDecoder.py +++ b/tools/CImpulseDecoder.py @@ -61,6 +61,7 @@ class CImpulseDecoder: # lastAck = lAck[channel] while True: logging.getLogger(LOGGER).debug("*" * 40) + logging.getLogger(LOGGER).debug("[decoded] %s" % msgin.showAllData()) next = msgin.readBool('next:' + str(level) + ':' + str(channel)) if not next: break diff --git a/tools/CStringManager.py b/tools/CStringManager.py index 1ec8209..9ddc828 100644 --- a/tools/CStringManager.py +++ b/tools/CStringManager.py @@ -149,5 +149,5 @@ class CStringManager: self.decoded.append(ret) else: logging.getLogger(LOGGER).debug('Impossible to decode id:%d' % key) - newUnknown.append((key, data)) + newUnknown.append((key, dataRead)) self.unknown = newUnknown