Package lacewing :: Package moo :: Package packetloaders :: Module common
[frames] | no frames]

Source Code for Module lacewing.moo.packetloaders.common

 1  import struct 
 2  from struct import unpack_from, pack 
 3   
 4  from lacewing.baseloader import _BaseLoader 
 5  from lacewing.exceptions import OutOfData 
 6   
7 -def unpack_string(data, size, offset = 0):
8 newData = buffer(data, offset, size) 9 if len(newData) < size: 10 raise OutOfData 11 return str(newData)
12
13 -class _MooLoader(_BaseLoader):
14 settings = None
15 - def __init__(self, **settings):
16 self.settings = settings
17
18 - def load(self, data):
19 try: 20 return self._load(data) 21 except struct.error: 22 raise OutOfData
23
24 -class _ChannelMixin:
25 - def setChannel(self, channel):
26 if hasattr(self, 'channelId'): 27 self.channelId = channel.id 28 if hasattr(self, 'channelName'): 29 self.channelName = channel.name 30 if hasattr(self, 'masterId'): 31 self.masterId = channel.getMaster().id
32
33 -class _ConnectionMixin:
34 - def setConnection(self, connection):
35 if hasattr(self, 'playerName'): 36 self.playerName = connection.name 37 if hasattr(self, 'playerId'): 38 self.playerId = connection.id 39 if hasattr(self, 'playerIp'): 40 self.playerIp = connection.transport.getPeer().host
41