Package lacewing :: Package packetloaders :: Module channelpacket
[frames] | no frames]

Source Code for Module lacewing.packetloaders.channelpacket

 1  """ 
 2  Channel join request. 
 3  """ 
 4   
 5  from struct import unpack_from, pack 
 6   
 7  from lacewing.baseloader import _BaseLoader 
 8  from lacewing.bitdict import BitDict 
 9   
10 -class ChannelPacket(_BaseLoader):
11 """ 12 This is sent by the client if it wants to join a 13 channel by name, or to leave a channel by ID. 14 15 @ivar channel: The name of the channel to join. 16 @ivar channelId: The ID of the channel to leave. 17 @ivar flags: Flags to tell if we're leaving or to tell if the 18 channel should be hidden 19 """ 20 channel = None 21 channelId = None 22 23 flags = None 24
25 - def initialize(self):
26 self.flags = BitDict( 27 'Hidden', 28 'Leaving', 29 'AutoClose', 30 default = False 31 )
32
33 - def read(self, data):
34 self.flags.setFlags(unpack_from('<B', data)[0]) 35 if self.flags['Leaving']: 36 self.channelId, = unpack_from('<H', data, 1) 37 else: 38 self.channel = data[1:]
39
40 - def generate(self):
41 flags = self.flags.getFlags() 42 if self.flags['Leaving']: 43 return pack('<BH', flags, self.channelId) 44 else: 45 return pack('<B', flags) + self.channel
46 47 __all__ = ['ChannelPacket'] 48