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

Source Code for Module lacewing.packetloaders.clientevent

 1  """ 
 2  Channel user event notification. 
 3  """ 
 4   
 5  from struct import unpack_from, pack, calcsize 
 6  import traceback 
 7   
 8  from lacewing.baseloader import _BaseLoader 
 9  from lacewing.bitdict import BitDict 
10   
11 -class ClientEvent(_BaseLoader):
12 """ 13 This is sent by the server to notify about a client 14 either joining or leaving a channel. 15 @ivar id: The ID of the client 16 @ivar channelId: The channel ID. 17 @ivar name: The name of the client. 18 19 @ivar flags: Flags that states whether the client just joined, 20 etc. 21 """ 22 23 id = None 24 channelId = None 25 name = None 26 27 flags = None 28
29 - def initialize(self):
30 self.flags = BitDict( 31 'ConnectedNow', 32 'Last', 33 'Connected', 34 'ChannelMaster', 35 default = False 36 )
37
38 - def read(self, data):
39 # unpack the variables 40 (self.channelId, 41 flags, 42 self.id) = unpack_from('<HBH', data) 43 44 # set the flags from the flagbyte 45 self.flags.setFlags(flags) 46 47 # read the rest of the data into name, as it is the last variable 48 self.name = str(buffer(data, 5))
49
50 - def generate(self):
51 flags = self.flags.getFlags() 52 data = pack('<HBH', self.channelId, flags, self.id) 53 return data + (self.name or '')
54 55 __all__ = ['ClientEvent'] 56