mirror of
https://port.numenaute.org/aleajactaest/clientbot.git
synced 2024-11-17 04:52:02 +00:00
99 lines
3.8 KiB
Python
99 lines
3.8 KiB
Python
#!/usr/bin/python3
|
|
# -*- coding: utf-8 -*-
|
|
#
|
|
# module CGenericMultiPartTemp
|
|
#
|
|
# Copyright (C) 2019 AleaJactaEst
|
|
#
|
|
# This program is free software: you can redistribute it and/or modify
|
|
# it under the terms of the GNU General Public License as published by
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
# (at your option) any later version.
|
|
#
|
|
# This program is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU General Public License
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
import logging
|
|
from tools import BitStream
|
|
|
|
LOGGER='CGenericMultiPartTemp'
|
|
|
|
class CGenericMultiPartTemp():
|
|
def __init__(self, autoDecompile=True):
|
|
self.NbBlock = 0xFFFFFFFF
|
|
self.MsgDecoded = None
|
|
self.FirstRead = False
|
|
self.Reference = []
|
|
self.block = {}
|
|
self.Name = None
|
|
self.AutoDecompile = autoDecompile
|
|
|
|
def getNbCurrentBlock(self):
|
|
return len(self.block)
|
|
|
|
def set(self, Number, Part, NbBlock, PartCont, decodeImpulse, world, Reference = None, Name = None):
|
|
'''
|
|
khanat-opennel-code/code/ryzom/client/src/network_connection.cpp # void CNetworkConnection::CGenericMultiPartTemp::set (CActionGenericMultiPart *agmp, CNetworkConnection *parent)
|
|
'''
|
|
logging.getLogger(LOGGER).debug("set Number:%d Part:%d NbBlock:%d" % (Number, Part, NbBlock))
|
|
ret = None
|
|
if not self.Name:
|
|
self.Name = Name
|
|
if Reference:
|
|
self.Reference.append(Reference)
|
|
if self.NbBlock == 0xFFFFFFFF:
|
|
# Initialize
|
|
self.NbBlock = NbBlock
|
|
self.block.setdefault(Part, PartCont)
|
|
self.block.setdefault(Part, None)
|
|
self.block[Part] = PartCont
|
|
logging.getLogger(LOGGER).error("CGenericMultiPartTemp : Number:%d len:%d/%d" % (Number, len(self.block), self.NbBlock))
|
|
if len(self.block) == self.NbBlock:
|
|
# reform the total action
|
|
bms = BitStream.BitStream()
|
|
|
|
self.NbBlock == 0xFFFFFFFF
|
|
for data in self.block:
|
|
logging.getLogger(LOGGER).error("CGenericMultiPartTemp : Number:%d id:%d len:%d/%d" % (Number, data, len(self.block), self.NbBlock))
|
|
bms.pushBitStream(self.block[data])
|
|
if self.AutoDecompile:
|
|
try:
|
|
ret = decodeImpulse.execute(bms, world)
|
|
except:
|
|
logging.getLogger(LOGGER).error("CGenericMultiPartTemp : Error to decode - Number:%d len:%d/%d msg:%s" % (Number, len(self.block), self.NbBlock, bms.showAllData()))
|
|
return ret
|
|
logging.getLogger(LOGGER).error("CGenericMultiPartTemp : data : %s" % bms.showAllData())
|
|
self.MsgDecoded = bms
|
|
else:
|
|
logging.getLogger(LOGGER).error("CGenericMultiPartTemp : Wait other block Number:%d [%d/%d]" % (Number, len(self.block), self.NbBlock))
|
|
return ret
|
|
|
|
def isDecoded(self):
|
|
if self.MsgDecoded:
|
|
return True
|
|
return False
|
|
|
|
def isAvailable(self):
|
|
if self.MsgDecoded and not self.FirstRead:
|
|
return True
|
|
return False
|
|
|
|
def read(self):
|
|
self.FirstRead = True
|
|
return self.MsgDecoded
|
|
|
|
|
|
class GenericMultiPartTemp():
|
|
def __init__(self):
|
|
self.data = {}
|
|
|
|
def addGenericMultiPartTemp(self, Number):
|
|
self.data.setdefault(Number, CGenericMultiPartTemp())
|
|
|
|
def setGenericMultiPartTemp(self, Number, Part, NbBlock, PartCont, decodeImpulse, world, Reference = None, Name = None):
|
|
self.data[Number].set(Number, Part, NbBlock, PartCont, decodeImpulse, world, Reference, Name)
|