1 from struct import unpack_from, pack
2
3 from lacewing.moo.packetloaders.common import (unpack_string, _MooLoader,
4 _ChannelMixin, _ConnectionMixin)
5
6 from lacewing.moo.packetloaders.message import Message
7
8 -class MOTD(_MooLoader):
9 motd = None
10
15
17 return pack('<I', len(self.motd)) + self.motd
18
33
34
36 playerId = None
37 channelId = None
38 masterId = None
39 playerName = None
40 playerIp = None
41
43 (self.playerId,
44 self.channelId,
45 self.masterId,
46 playerNameSize) = unpack_from('<IIII', data)
47 self.playerName = unpack_string(data, playerNameSize, 16)
48 offset = 16 + playerNameSize
49 playerIpSize, = unpack_from('<I', data, offset)
50 offset += 4
51 self.playerIp = unpack_string(data, playerIpSize, offset)
52 offset += playerIpSize
53 return offset
54
61
64
67
68 -class PlayerLeft(_MooLoader, _ChannelMixin, _ConnectionMixin):
83
85 playerId = None
86 playerName = None
87
89 (self.playerId,
90 playerNameSize) = unpack_from('<II', data)
91 self.playerName = unpack_string(data, playerNameSize, 8)
92 offset = 8 + playerNameSize
93 otherPlayerId, otherNameSize = unpack_from('<II', data, offset)
94 offset += 8
95 otherPlayerName = unpack_string(data, otherNameSize, offset)
96 offset += otherNameSize
97 if (self.playerName != otherPlayerName or
98 self.playerId != otherPlayerId):
99 raise NotImplementedError
100
101 return offset
102
108
109 -class ChannelJoined(_MooLoader, _ChannelMixin, _ConnectionMixin):
110 playerId = None
111 channelId = None
112 masterId = None
113 playerName = None
114 playerIp = None
115 channelName = None
116
118 (self.playerId,
119 self.channelId,
120 self.masterId,
121 playerNameSize) = unpack_from('<IIII', data)
122 self.playerName = unpack_string(data, playerNameSize, 16)
123 offset = 16 + playerNameSize
124 playerIpSize, = unpack_from('<I', data, offset)
125 offset += 4
126 self.playerIp = unpack_string(data, playerIpSize, offset)
127 offset += playerIpSize
128 channelSize, = unpack_from('<I', data, offset)
129 offset += 4
130 self.channelName = unpack_string(data, channelSize, offset)
131 offset += channelSize
132 return offset
133
135 return ''.join([
136 pack('<IIII', self.playerId, self.channelId, self.masterId,
137 len(self.playerName)), self.playerName, pack('<I', len(self.playerIp)),
138 self.playerIp, pack('<I', len(self.channelName)), self.channelName
139 ])
140
171
172 __all__ = ['MOTD', 'AssignedID', 'PlayerExists', 'PlayerJoined',
173 'PlayerLeft', 'PlayerChanged', 'ChannelJoined', 'FromChannelMessage']
174