decode message CONNECTION:USER_CHARS

This commit is contained in:
AleaJactaEst 2019-06-14 00:07:41 +02:00
parent 042b01b7f5
commit 0b9c136718

139
client.py
View file

@ -185,14 +185,13 @@ class BitStream():
# ------------------------------------ # ------------------------------------
def readSerial(self, nbits, name="", decode=True, typeName='', emulate=False): def readSerial(self, nbits, name="", decode=True, typeName='', emulate=False):
v1 = self._read
if nbits == 0: if nbits == 0:
return return
elif nbits > 32: elif nbits > 32:
raise "Out of range" raise "Out of range"
if self._read + nbits > self._pos: if self._read + nbits > self._pos:
raise "Stream Overflow" raise "Stream Overflow"
if decode and not emulate:
self._groupRead.append((self._read, self._read+nbits, name, typeName))
if emulate: if emulate:
oldRead = self._read oldRead = self._read
value = 0 value = 0
@ -208,10 +207,14 @@ class BitStream():
self._read += nbits self._read += nbits
if emulate: if emulate:
self._read = oldRead self._read = oldRead
if decode and not emulate:
self._groupRead.append((v1, v1+nbits, name, typeName, value))
return value return value
def readBool(self, name): def readBool(self, name):
v = self.readSerial(1, name=name, typeName='Bool') v1 = self._read
v = self.readSerial(1, name=name, decode=False, typeName='Bool')
self._groupRead.append((v1, v1+1, name, 'Bool', 'True' if v != 0 else 'False'))
if v != 0: if v != 0:
return True return True
else: else:
@ -225,8 +228,8 @@ class BitStream():
v = self.readSerial(32, name=name, decode=decode, typeName='Sint32') v = self.readSerial(32, name=name, decode=decode, typeName='Sint32')
return c_int32(v).value return c_int32(v).value
def readUint16(self, name): def readUint16(self, name, decode=True):
v = self.readSerial(16, name=name, typeName='Uint16') v = self.readSerial(16, name=name, decode=decode, typeName='Uint16')
return v return v
def readSint16(self, name): def readSint16(self, name):
@ -242,33 +245,38 @@ class BitStream():
return c_int8(v).value return c_int8(v).value
def readUint64(self, name): def readUint64(self, name):
self._groupRead.append((self._read, self._read+64, name, 'Uint64')) v1 = self._read
v = self.readSerial(32, decode=False) v = self.readSerial(32, decode=False)
v1 = self.readSerial(32, decode=False) v1 = self.readSerial(32, decode=False)
v2 = v | (v1 << 32) v2 = v | (v1 << 32)
self._groupRead.append((v1, v1+64, name, 'Uint64', v2))
return v2 return v2
def readSint64(self, name): def readSint64(self, name):
self._groupRead.append((self._read, self._read+64, name, 'Sint64')) v1 = self._read
v = self.readSerial(32, decode=False) v = self.readSerial(32, decode=False)
v1 = self.readSerial(32, decode=False) v1 = self.readSerial(32, decode=False)
v2 = v | (v1 << 32) v2 = v | (v1 << 32)
self._groupRead.append((v1, v1+64, name, 'Sint64', c_int64(v2).value))
return c_int64(v2).value return c_int64(v2).value
def readFloat(self, name): def readFloat(self, name):
v = self.readSerial(32, name=name, typeName='Float') v1 = self._read
v = self.readSerial(32, name=name, decode=False, typeName='Float')
v1 = struct.pack('I', v) v1 = struct.pack('I', v)
v2 = struct.unpack('<f',v1)[0] v2 = struct.unpack('<f',v1)[0]
self._groupRead.append((v1, v1+32, name, 'Float', v2))
return v2 return v2
def readDouble(self, name): def readDouble(self, name):
self._groupRead.append((self._read, self._read+64, name, 'Double')) v1 = self._read
v = self.readSerial(32, decode=False) v = self.readSerial(32, decode=False)
v1 = struct.pack('I', v) v1 = struct.pack('I', v)
w = self.readSerial(32, decode=False) w = self.readSerial(32, decode=False)
w1 = struct.pack('I', w) w1 = struct.pack('I', w)
x = v1 + w1 x = v1 + w1
x1 = struct.unpack('<d', x)[0] x1 = struct.unpack('<d', x)[0]
self._groupRead.append((v1, v1+64, name, 'Double', x1))
return x1 return x1
def readChar(self, name, decode=True): def readChar(self, name, decode=True):
@ -287,7 +295,22 @@ class BitStream():
if v2 > self._pos: if v2 > self._pos:
raise ValueError raise ValueError
if v1 < v2: if v1 < v2:
self._groupRead.append((v1, v2, name + ':string', 'String')) self._groupRead.append((v1, v2, name + ':string', 'String', tmp))
return tmp
def readUString(self, name):
tmp = ''
_size = self.readUint32(name + ':size', decode=True)
v1 = self._read
while _size > 0:
x = self.readUint16(name='', decode=False)
tmp += chr(x)
_size -= 1
v2 = self._read
if v2 > self._pos:
raise ValueError
if v1 < v2:
self._groupRead.append((v1, v2, name + ':ustring', 'UString', tmp))
return tmp return tmp
def readArrayUint8(self, size, name): def readArrayUint8(self, size, name):
@ -296,7 +319,7 @@ class BitStream():
for i in range(0, size): for i in range(0, size):
ret.append(self.readUint8('', decode=False)) ret.append(self.readUint8('', decode=False))
v2 = self._read v2 = self._read
self._groupRead.append((v1, v2, name, 'ArrayUint8')) self._groupRead.append((v1, v2, name, 'ArrayUint8', ''))
return ret return ret
def readBitStreamUint8(self, size, name): def readBitStreamUint8(self, size, name):
@ -305,7 +328,7 @@ class BitStream():
for i in range(0, size): for i in range(0, size):
ret.pushUint8(self.readUint8('', decode=False)) ret.pushUint8(self.readUint8('', decode=False))
v2 = self._read v2 = self._read
self._groupRead.append((v1, v2, name, 'StreamUint8')) self._groupRead.append((v1, v2, name, 'StreamUint8', ''))
return ret return ret
def readCont(self, name): def readCont(self, name):
@ -315,7 +338,7 @@ class BitStream():
for i in range(0, size): for i in range(0, size):
ret.pushBool(self.readSerial(1,name = '', decode=False)) ret.pushBool(self.readSerial(1,name = '', decode=False))
v2 = self._read v2 = self._read
self._groupRead.append((v1, v2, name + ':data', 'readCont')) self._groupRead.append((v1, v2, name + ':data', 'readCont', ''))
return size, ret return size, ret
# ------------------------------------ # ------------------------------------
@ -395,8 +418,8 @@ class BitStream():
ret2 = "" ret2 = ""
last = 0 last = 0
for x, y, name, typeName in self._groupRead: for x, y, name, typeName, value in self._groupRead:
ret2 += "[<" + str(x) + ':' + str(y-1) + "> " + str(name) + ' (' + typeName + ') = ' + ret[x:y] + "]" ret2 += "[<" + str(x) + ':' + str(y-1) + "> " + str(name) + ' (' + typeName + ') : ' + ret[x:y] + ' => ' + str(value) + "]"
last = y last = y
if last < self._pos: if last < self._pos:
ret2 += "{" + ret[last:] + "}" ret2 += "{" + ret[last:] + "}"
@ -1555,11 +1578,37 @@ class CCharacterSummary():
self.HasEditSession = msgin.readBool('HasEditSession') self.HasEditSession = msgin.readBool('HasEditSession')
self.InNewbieland = msgin.readBool('InNewbieland') self.InNewbieland = msgin.readBool('InNewbieland')
# f.serial (CharacterSlot);
# f.serial (InRingSession); class CSessionId():
# f.serial (HasEditSession); def __init__(self):
# if (serialNB) self.id = 0
# f.serial (InNewbieland); def read(self, msgin):
self.id = msgin.readUint32('id')
class CMainlandSummary():
def __init__(self):
self.Id = CSessionId()
self.Name = ""
self.Description = ""
self.LanguageCode = ""
self.Online = False
def read(self, msgin):
'''
khanat-opennel-code/code/ryzom/common/src/game_share/mainland_summary.h # void serial(NLMISC::IStream &f)
'''
self.Id.read(msgin)
self.Name = msgin.readUString('Name')
self.Description = msgin.readUString('Description')
self.LanguageCode = msgin.readString('LanguageCode')
self.Online = msgin.readBool('Online')
class CShardName():
def __init__(self, SessionId, DisplayName, ShortName):
self.SessionId = SessionId
self.DisplayName = DisplayName
self.ShortName = ShortName
class World(): class World():
@ -1570,6 +1619,10 @@ class World():
self.ServerPeopleActive = 255 self.ServerPeopleActive = 255
self.ServerCareerActive = 255 self.ServerCareerActive = 255
self.CharacterSummaries = [] self.CharacterSummaries = []
self.Mainlands = []
self.CShardNames = []
self.UserPrivileges = ''
self.FreeTrial = False
def addGenericMultiPartTemp(self, id): def addGenericMultiPartTemp(self, id):
self.GenericMultiPartTemp.setdefault(id, CGenericMultiPartTemp(self.log)) self.GenericMultiPartTemp.setdefault(id, CGenericMultiPartTemp(self.log))
@ -2263,6 +2316,20 @@ class DecodeImpulse():
self.GenericMsgHeaderMngr = {} self.GenericMsgHeaderMngr = {}
self.initializeNetwork() self.initializeNetwork()
self.world = world self.world = world
def updatePatcherPriorityBasedOnCharacters(self):
self.log.debug('Load character')
hasMainlandChar = False
for ele in self.world.CharacterSummaries:
if ele.Name == "":
continue
if not ele.InNewbieland:
hasMainlandChar = True
break
# requestDownloadThreadPriority(hasMainlandChar ? BGDownloader::ThreadPriority_Normal : BGDownloader::ThreadPriority_Low, false);
# khanat-opennel-code/code/ryzom/client/src/bg_downloader_access.cpp # void CBGDownloaderAccess::requestDownloadThreadPriority(BGDownloader::TThreadPriority newPriority, bool freezeUI)
msgout = BitStream()
self.log.debug("TODO")
def impulseDatabaseUpdatePlayer(self, msgin): def impulseDatabaseUpdatePlayer(self, msgin):
self.log.debug("TODO:%s" % msgin) self.log.debug("TODO:%s" % msgin)
@ -2284,20 +2351,38 @@ class DecodeImpulse():
''' '''
self.world.ServerPeopleActive = msgin.readUint8('ServerPeopleActive') self.world.ServerPeopleActive = msgin.readUint8('ServerPeopleActive')
self.world.ServerCareerActive = msgin.readUint8('ServerCareerActive') self.world.ServerCareerActive = msgin.readUint8('ServerCareerActive')
# impulse.serialCont (CharacterSummaries);
self.world.CharacterSummaries = [] self.world.CharacterSummaries = []
size = msgin.readUint32('CharacterSummaries:len') size = msgin.readUint32('CharacterSummaries:len')
for _ in range(0, size): for _ in range(0, size):
tmp = CCharacterSummary() tmp = CCharacterSummary()
tmp.read(msgin) tmp.read(msgin)
self.world.CharacterSummaries.append(tmp) self.world.CharacterSummaries.append(tmp)
#_, CharacterSummaries = msgin.readCont('CharacterSummaries') # impulse.serialCont (shardNames);
_, shardNames = msgin.readCont('shardNames') size = msgin.readUint32('shardNames:len')
shardNames = []
for i in range(0, size):
shardNames.append(msgin.readString('shardNames_' + str(i)))
# CShardNames::getInstance().loadShardNames(shardNames);
# int(shardNames[i*3+0]) = SessionId / shardNames[i*3+1] = DisplayName / shardNames[i*3+2] = ShortName
for i in range(0, size // 3):
tmp = CShardName(int(shardNames[i*3+0]), shardNames[i*3+1], shardNames[i*3+2])
self.world.CShardNames.append(tmp)
#_, shardNames = msgin.readCont('shardNames')
# readPrivileges(impulse); # readPrivileges(impulse);
UserPrivileges = msgin.readString('UserPrivileges') self.world.UserPrivileges = msgin.readString('UserPrivileges')
FreeTrial = msgin.readBool('FreeTrial') self.world.FreeTrial = msgin.readBool('FreeTrial')
_, Mainlands = msgin.readCont('Mainlands') self.world.FreeTrial = False # We read and ignore this param :)
self.log.debug("Mesage UserChars: %s" % msgin.showAllData())
self.log.debug("TODO") # impulse.serialCont(Mainlands);
self.Mainlands = []
size = msgin.readUint32('Mainlands:len')
for _ in range(0, size):
tmp = CMainlandSummary()
tmp.read(msgin)
self.world.Mainlands.append(tmp)
self.updatePatcherPriorityBasedOnCharacters(); # Load player config from server to client
def impulseUserChar(self, msgin): def impulseUserChar(self, msgin):
self.log.debug("TODO") self.log.debug("TODO")