mirror of
https://port.numenaute.org/aleajactaest/clientbot.git
synced 2024-11-09 16:59:03 +00:00
update decodeHeader - decode number message received
This commit is contained in:
parent
3478c16243
commit
bc4a1cbd09
1 changed files with 77 additions and 11 deletions
86
client.py
86
client.py
|
@ -42,6 +42,7 @@ import socket
|
||||||
import struct
|
import struct
|
||||||
import xml.etree.ElementTree as ET
|
import xml.etree.ElementTree as ET
|
||||||
import hashlib
|
import hashlib
|
||||||
|
import time
|
||||||
|
|
||||||
|
|
||||||
class BitStream():
|
class BitStream():
|
||||||
|
@ -1481,7 +1482,8 @@ class ClientNetworkConnection:
|
||||||
def __init__(self,
|
def __init__(self,
|
||||||
khanat_host,
|
khanat_host,
|
||||||
khanat_port_frontend,
|
khanat_port_frontend,
|
||||||
LanguageCode="fr"):
|
LanguageCode="fr",
|
||||||
|
checkMessageNumber = True):
|
||||||
self.log = logging.getLogger('myLogger')
|
self.log = logging.getLogger('myLogger')
|
||||||
self._CurrentSendNumber = 0
|
self._CurrentSendNumber = 0
|
||||||
self.LanguageCode = LanguageCode
|
self.LanguageCode = LanguageCode
|
||||||
|
@ -1501,6 +1503,22 @@ class ClientNetworkConnection:
|
||||||
self._DatabaseXmlMD5 = None
|
self._DatabaseXmlMD5 = None
|
||||||
self.msgXml = None
|
self.msgXml = None
|
||||||
self.databaseXml = None
|
self.databaseXml = None
|
||||||
|
self._Synchronize = 0
|
||||||
|
self._LatestSync = 0
|
||||||
|
self._CurrentServerTick = 0
|
||||||
|
self._MsPerTick = 0
|
||||||
|
self._LCT = 100
|
||||||
|
self._UpdateTime = 0
|
||||||
|
#self._UpdateTicks = 0
|
||||||
|
self._ReceivedSync = False
|
||||||
|
self._LastReceivedTime = 0
|
||||||
|
self._LastReceivedPacketInBothModes = 0
|
||||||
|
self._TotalMessages = 0
|
||||||
|
self._TotalLostPackets = 0
|
||||||
|
self.checkMessageNumber = checkMessageNumber
|
||||||
|
self._LastAckBit = 0
|
||||||
|
self._AckBitMask = 0
|
||||||
|
self._LongAckBitField = 0
|
||||||
|
|
||||||
def cookiesInit(self, UserAddr, UserKey, UserId):
|
def cookiesInit(self, UserAddr, UserKey, UserId):
|
||||||
self.UserAddr = UserAddr
|
self.UserAddr = UserAddr
|
||||||
|
@ -1550,9 +1568,10 @@ class ClientNetworkConnection:
|
||||||
msg.pushUint8(2) # SYSTEM_ACK_SYNC_CODE
|
msg.pushUint8(2) # SYSTEM_ACK_SYNC_CODE
|
||||||
msg.pushSint32(self._LastReceivedNumber)
|
msg.pushSint32(self._LastReceivedNumber)
|
||||||
msg.pushSint32(self._LastAckInLongAck)
|
msg.pushSint32(self._LastAckInLongAck)
|
||||||
# msg.pushSint32(self._LongAckBitField) #
|
msg.pushSint32(self._LongAckBitField) # Signale le nombre de packet perdu
|
||||||
# msg.pushSint32(self._LatestSync)
|
msg.pushSint32(self._LatestSync)
|
||||||
self.log.error("TODO")
|
self.log.error("TODO")
|
||||||
|
# self._sock.sendto(msg.toBytes(), self.frontend)
|
||||||
|
|
||||||
def readDelta(self, msg):
|
def readDelta(self, msg):
|
||||||
propertyCount = msg.readUint16()
|
propertyCount = msg.readUint16()
|
||||||
|
@ -1574,12 +1593,49 @@ class ClientNetworkConnection:
|
||||||
return data, addr
|
return data, addr
|
||||||
|
|
||||||
def decodeHeader(self, msg):
|
def decodeHeader(self, msg):
|
||||||
|
self._TotalMessages += 1
|
||||||
|
self._LastReceivedTime = self._UpdateTime
|
||||||
self._CurrentReceivedNumber = msg.readSint32()
|
self._CurrentReceivedNumber = msg.readSint32()
|
||||||
self._SystemMode = msg.readBool()
|
self._SystemMode = msg.readBool()
|
||||||
if self._SystemMode:
|
|
||||||
return
|
if self.checkMessageNumber and self._CurrentReceivedNumber > self._LastReceivedPacketInBothModes:
|
||||||
|
self._TotalLostPackets += self._CurrentReceivedNumber - self._LastReceivedPacketInBothModes - 1
|
||||||
|
self._LastReceivedPacketInBothModes = self._CurrentReceivedNumber
|
||||||
|
else:
|
||||||
|
self._LastReceivedPacketInBothModes = self._CurrentReceivedNumber - 1
|
||||||
|
|
||||||
|
if not self._SystemMode:
|
||||||
self._LastReceivedAck = msg.readSint32();
|
self._LastReceivedAck = msg.readSint32();
|
||||||
|
|
||||||
|
if self._CurrentReceivedNumber > self._LastReceivedNumber+1:
|
||||||
|
self.log.debug("lost messages server->client [%d; %d]" %(self._LastReceivedPacketInBothModes + 1, self._CurrentReceivedNumber - 1))
|
||||||
|
elif self._CurrentReceivedNumber == self._LastReceivedNumber:
|
||||||
|
self.log.debug("awaiting packet %d, received packet %d" %(self._LastReceivedPacketInBothModes + 1, self._CurrentReceivedNumber))
|
||||||
|
return False
|
||||||
|
elif self._CurrentReceivedNumber < self._LastReceivedNumber:
|
||||||
|
self.log.debug("received an old message, awaiting packet %d, received packet %d" %(self._LastReceivedPacketInBothModes + 1, self._CurrentReceivedNumber))
|
||||||
|
return false
|
||||||
|
ackBool = ( not self._SystemMode ) and (self._ConnectionState == TConnectionState.Connected or self._ConnectionState == TConnectionState.Synchronize)
|
||||||
|
if ackBool:
|
||||||
|
ackBit = 1
|
||||||
|
else:
|
||||||
|
ackBit = 0
|
||||||
|
if self._CurrentReceivedNumber - self._LastReceivedNumber < 32:
|
||||||
|
self._AckBitMask <<= self._CurrentReceivedNumber - self._LastReceivedNumber;
|
||||||
|
elif (self_CurrentReceivedNumber - self_LastReceivedNumber) == 32 and self._LastAckBit != 0:
|
||||||
|
self._AckBitMask = 0x80000000
|
||||||
|
else:
|
||||||
|
self._AckBitMask = 0x00000000
|
||||||
|
self._LastAckBit = ackBit;
|
||||||
|
for i in range(self._LastReceivedNumber+1, self._CurrentReceivedNumber+1):
|
||||||
|
if self._LongAckBitField & (i & (512-1)) > 1:
|
||||||
|
self._LongAckBitField = self._LongAckBitField ^ (i & (512-1))
|
||||||
|
if ackBool:
|
||||||
|
self._LongAckBitField = self._LongAckBitField | (self._CurrentReceivedNumber & (512 - 1))
|
||||||
|
self._LongAckBitField %= 512
|
||||||
self._LastReceivedNumber = self._CurrentReceivedNumber
|
self._LastReceivedNumber = self._CurrentReceivedNumber
|
||||||
|
self.log.debug("_CurrentReceivedNumber:%d, _LastReceivedNumber:%d, ackBit:%d, _AckBitMask:%d _LongAckBitField:%d" % (self._CurrentReceivedNumber, self._LastReceivedNumber, ackBit, self._AckBitMask, self._LongAckBitField))
|
||||||
|
return True
|
||||||
|
|
||||||
def receiveSystemProbe(self, msg):
|
def receiveSystemProbe(self, msg):
|
||||||
self._LatestProbe = msg.readSint32()
|
self._LatestProbe = msg.readSint32()
|
||||||
|
@ -1589,10 +1645,10 @@ class ClientNetworkConnection:
|
||||||
self.log.debug("received STALLED")
|
self.log.debug("received STALLED")
|
||||||
|
|
||||||
def receiveSystemSync(self, msg):
|
def receiveSystemSync(self, msg):
|
||||||
_Synchronize = msg.readUint32()
|
self._Synchronize = msg.readUint32()
|
||||||
stime = msg.readSint64()
|
stime = msg.readSint64()
|
||||||
_LatestSync = msg.readUint32()
|
self._LatestSync = msg.readUint32()
|
||||||
self.log.debug("%d %d %d" %(_Synchronize, stime, _LatestSync))
|
self.log.debug("%d %d %d" %(self._Synchronize, stime, self._LatestSync))
|
||||||
# khanat-opennel-code/code/ryzom/client/src/network_connection.cpp : void CNetworkConnection::receiveSystemSync(CBitMemStream &msgin)
|
# khanat-opennel-code/code/ryzom/client/src/network_connection.cpp : void CNetworkConnection::receiveSystemSync(CBitMemStream &msgin)
|
||||||
MsgData = msg.readArrayUint8(16)
|
MsgData = msg.readArrayUint8(16)
|
||||||
DatabaseData = msg.readArrayUint8(16)
|
DatabaseData = msg.readArrayUint8(16)
|
||||||
|
@ -1608,12 +1664,21 @@ class ClientNetworkConnection:
|
||||||
self.log.info("Check MD5 database.xml : OK")
|
self.log.info("Check MD5 database.xml : OK")
|
||||||
else:
|
else:
|
||||||
self.log.error("Check MD5 database.xml : KO")
|
self.log.error("Check MD5 database.xml : KO")
|
||||||
self.log.error("TODO")
|
self._MsPerTick = 100
|
||||||
#self.sendSystemAckSync()
|
self._CurrentServerTick = self._Synchronize + self._CurrentReceivedNumber + 2
|
||||||
|
self._CurrentClientTick = self._CurrentServerTick - ( self._LCT + self._MsPerTick ) / self._MsPerTick
|
||||||
|
self._CurrentClientTime = self._UpdateTime - (self._LCT + self._MsPerTick)
|
||||||
|
self.sendSystemAckSync()
|
||||||
|
|
||||||
def disconnect(self):
|
def disconnect(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def update(self):
|
||||||
|
# khanat-opennel-code/code/ryzom/client/src/network_connection.cpp # bool CNetworkConnection::update()
|
||||||
|
self._UpdateTime = int(time.clock_gettime(1)*1000)
|
||||||
|
#self._UpdateTicks = 0
|
||||||
|
self._ReceivedSync = False
|
||||||
|
|
||||||
def EmulateFirst(self, msgRawXml, databaseRawXml):
|
def EmulateFirst(self, msgRawXml, databaseRawXml):
|
||||||
self.msgXml = ET.fromstring(msgRawXml)
|
self.msgXml = ET.fromstring(msgRawXml)
|
||||||
#ET.dump(msgXml)
|
#ET.dump(msgXml)
|
||||||
|
@ -1628,6 +1693,7 @@ class ClientNetworkConnection:
|
||||||
|
|
||||||
self.log.info("Receive Message")
|
self.log.info("Receive Message")
|
||||||
for _ in range(0, 20): # while True:
|
for _ in range(0, 20): # while True:
|
||||||
|
self.update()
|
||||||
data, addr = self.buildStream()
|
data, addr = self.buildStream()
|
||||||
self.log.debug("received message: %s" % data)
|
self.log.debug("received message: %s" % data)
|
||||||
msg = BitStream()
|
msg = BitStream()
|
||||||
|
|
Loading…
Reference in a new issue