mirror of
https://port.numenaute.org/aleajactaest/clientbot.git
synced 2024-11-17 04:52:02 +00:00
91 lines
3.3 KiB
Python
91 lines
3.3 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):
|
|
self.NbBlock = 0xFFFFFFFF
|
|
self.NbCurrentBlock = 0
|
|
self.TempSize = 0
|
|
self.Temp = []
|
|
self.BlockReceived = []
|
|
self.MsgDecoded = None
|
|
self.FirstRead = False
|
|
|
|
def set(self, Number, Part, NbBlock, PartCont, decodeImpulse, world):
|
|
'''
|
|
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))
|
|
if self.NbBlock == 0xFFFFFFFF:
|
|
# Initialize
|
|
self.NbBlock = NbBlock
|
|
self.NbCurrentBlock = 0
|
|
self.TempSize = 0
|
|
self.Temp = []
|
|
while len(self.Temp) < NbBlock:
|
|
self.Temp.append(None)
|
|
while len(self.BlockReceived) < NbBlock:
|
|
self.BlockReceived.append(False)
|
|
if self.BlockReceived[Part]:
|
|
logging.getLogger(LOGGER).warning('This part is already received, discard it %d' % Part)
|
|
return
|
|
self.Temp[Part] = PartCont
|
|
self.BlockReceived[Part] = True
|
|
self.NbCurrentBlock += 1
|
|
self.TempSize += len(PartCont)
|
|
|
|
logging.getLogger(LOGGER).debug("NbCurrentBlock:%d / NbBlock:%d" % (self.NbCurrentBlock, self.NbBlock))
|
|
if self.NbCurrentBlock == self.NbBlock:
|
|
# reform the total action
|
|
bms = BitStream.BitStream()
|
|
|
|
self.NbBlock == 0xFFFFFFFF
|
|
for data in self.Temp:
|
|
bms.pushBitStream(data)
|
|
decodeImpulse.execute(bms, world)
|
|
logging.getLogger(LOGGER).debug("CGenericMultiPartTemp : data : %s" % bms.showAllData())
|
|
self.MsgDecoded = bms
|
|
else:
|
|
logging.getLogger(LOGGER).debug("CGenericMultiPartTemp : Wait other block")
|
|
|
|
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):
|
|
self.data[Number].set(Number, Part, NbBlock, PartCont, decodeImpulse, world)
|