mirror of
https://port.numenaute.org/aleajactaest/clientbot.git
synced 2024-11-25 00:26:33 +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 xml.etree.ElementTree as ET
|
||||
import hashlib
|
||||
import time
|
||||
|
||||
|
||||
class BitStream():
|
||||
|
@ -1481,7 +1482,8 @@ class ClientNetworkConnection:
|
|||
def __init__(self,
|
||||
khanat_host,
|
||||
khanat_port_frontend,
|
||||
LanguageCode="fr"):
|
||||
LanguageCode="fr",
|
||||
checkMessageNumber = True):
|
||||
self.log = logging.getLogger('myLogger')
|
||||
self._CurrentSendNumber = 0
|
||||
self.LanguageCode = LanguageCode
|
||||
|
@ -1501,6 +1503,22 @@ class ClientNetworkConnection:
|
|||
self._DatabaseXmlMD5 = None
|
||||
self.msgXml = 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):
|
||||
self.UserAddr = UserAddr
|
||||
|
@ -1550,9 +1568,10 @@ class ClientNetworkConnection:
|
|||
msg.pushUint8(2) # SYSTEM_ACK_SYNC_CODE
|
||||
msg.pushSint32(self._LastReceivedNumber)
|
||||
msg.pushSint32(self._LastAckInLongAck)
|
||||
# msg.pushSint32(self._LongAckBitField) #
|
||||
# msg.pushSint32(self._LatestSync)
|
||||
msg.pushSint32(self._LongAckBitField) # Signale le nombre de packet perdu
|
||||
msg.pushSint32(self._LatestSync)
|
||||
self.log.error("TODO")
|
||||
# self._sock.sendto(msg.toBytes(), self.frontend)
|
||||
|
||||
def readDelta(self, msg):
|
||||
propertyCount = msg.readUint16()
|
||||
|
@ -1574,12 +1593,49 @@ class ClientNetworkConnection:
|
|||
return data, addr
|
||||
|
||||
def decodeHeader(self, msg):
|
||||
self._TotalMessages += 1
|
||||
self._LastReceivedTime = self._UpdateTime
|
||||
self._CurrentReceivedNumber = msg.readSint32()
|
||||
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();
|
||||
|
||||
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.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):
|
||||
self._LatestProbe = msg.readSint32()
|
||||
|
@ -1589,10 +1645,10 @@ class ClientNetworkConnection:
|
|||
self.log.debug("received STALLED")
|
||||
|
||||
def receiveSystemSync(self, msg):
|
||||
_Synchronize = msg.readUint32()
|
||||
self._Synchronize = msg.readUint32()
|
||||
stime = msg.readSint64()
|
||||
_LatestSync = msg.readUint32()
|
||||
self.log.debug("%d %d %d" %(_Synchronize, stime, _LatestSync))
|
||||
self._LatestSync = msg.readUint32()
|
||||
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)
|
||||
MsgData = msg.readArrayUint8(16)
|
||||
DatabaseData = msg.readArrayUint8(16)
|
||||
|
@ -1608,12 +1664,21 @@ class ClientNetworkConnection:
|
|||
self.log.info("Check MD5 database.xml : OK")
|
||||
else:
|
||||
self.log.error("Check MD5 database.xml : KO")
|
||||
self.log.error("TODO")
|
||||
#self.sendSystemAckSync()
|
||||
self._MsPerTick = 100
|
||||
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):
|
||||
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):
|
||||
self.msgXml = ET.fromstring(msgRawXml)
|
||||
#ET.dump(msgXml)
|
||||
|
@ -1628,6 +1693,7 @@ class ClientNetworkConnection:
|
|||
|
||||
self.log.info("Receive Message")
|
||||
for _ in range(0, 20): # while True:
|
||||
self.update()
|
||||
data, addr = self.buildStream()
|
||||
self.log.debug("received message: %s" % data)
|
||||
msg = BitStream()
|
||||
|
|
Loading…
Reference in a new issue