1
2
3
4 from struct import unpack_from, pack
5
6 from lacewing.moo.packetloaders.common import (unpack_string, _MooLoader,
7 _ChannelMixin, _ConnectionMixin)
8
9 from lacewing.moo.packetloaders.message import Message
10
11 -class MOTD(_MooLoader):
12 motd = None
13
18
20 return pack('<I', len(self.motd)) + self.motd
21
36
37
39 playerId = None
40 channelId = None
41 masterId = None
42 playerName = None
43 playerIp = None
44
46 (self.playerId,
47 self.channelId,
48 self.masterId,
49 playerNameSize) = unpack_from('<IIII', data)
50 self.playerName = unpack_string(data, playerNameSize, 16)
51 offset = 16 + playerNameSize
52 playerIpSize, = unpack_from('<I', data, offset)
53 offset += 4
54 self.playerIp = unpack_string(data, playerIpSize, offset)
55 offset += playerIpSize
56 return offset
57
64
67
70
71 -class PlayerLeft(_MooLoader, _ChannelMixin, _ConnectionMixin):
86
88 playerId = None
89 playerName = None
90
92 (self.playerId,
93 playerNameSize) = unpack_from('<II', data)
94 self.playerName = unpack_string(data, playerNameSize, 8)
95 offset = 8 + playerNameSize
96 otherPlayerId, otherNameSize = unpack_from('<II', data, offset)
97 offset += 8
98 otherPlayerName = unpack_string(data, otherNameSize, offset)
99 offset += otherNameSize
100 if (self.playerName != otherPlayerName or
101 self.playerId != otherPlayerId):
102 raise NotImplementedError
103
104 return offset
105
111
112 -class ChannelJoined(_MooLoader, _ChannelMixin, _ConnectionMixin):
113 playerId = None
114 channelId = None
115 masterId = None
116 playerName = None
117 playerIp = None
118 channelName = None
119
121 (self.playerId,
122 self.channelId,
123 self.masterId,
124 playerNameSize) = unpack_from('<IIII', data)
125 self.playerName = unpack_string(data, playerNameSize, 16)
126 offset = 16 + playerNameSize
127 playerIpSize, = unpack_from('<I', data, offset)
128 offset += 4
129 self.playerIp = unpack_string(data, playerIpSize, offset)
130 offset += playerIpSize
131 channelSize, = unpack_from('<I', data, offset)
132 offset += 4
133 self.channelName = unpack_string(data, channelSize, offset)
134 offset += channelSize
135 return offset
136
138 return ''.join([
139 pack('<IIII', self.playerId, self.channelId, self.masterId,
140 len(self.playerName)), self.playerName, pack('<I', len(self.playerIp)),
141 self.playerIp, pack('<I', len(self.channelName)), self.channelName
142 ])
143
174
175 __all__ = ['MOTD', 'AssignedID', 'PlayerExists', 'PlayerJoined',
176 'PlayerLeft', 'PlayerChanged', 'ChannelJoined', 'FromChannelMessage']
177