1
2
3
4 from twisted.internet.protocol import ClientFactory
5
6 from lacewing.moo.protocol import MooProtocol
7
8 from lacewing.moo.packet import ServerPacket, ClientPacket
9
10 from lacewing.moo.packetloaders.server import *
11 from lacewing.moo.packetloaders.client import *
12
13 from lacewing.multidict import MultikeyDict
14
15 from lacewing.moo.packetloaders.message import *
16
37
82
84 _sendPacket = ClientPacket
85 _receivePacket = ServerPacket
86
87 motd = None
88
89 playerClass = Player
90
94
96 if isinstance(loader, MOTD):
97 self.motd = loader.motd
98 self.motdReceived(loader.motd)
99
100 elif isinstance(loader, AssignedID):
101 self.id = loader.playerId
102
103 newName = SetName()
104 newName.setConnection(self)
105 self.sendLoader(newName)
106
107 self.connectionAccepted()
108
109 elif isinstance(loader, ChannelJoined):
110 channelName = loader.channelName
111 channelId = loader.channelId
112 newChannel = Channel(channelName, channelId, self)
113 newPlayer = self.playerClass(loader.playerName, loader.playerId,
114 loader.playerIp, newChannel)
115 newChannel.player = newPlayer
116 newChannel.addConnection(newPlayer)
117 newChannel.setMaster(loader.masterId)
118 self.channels[channelName, channelId] = newChannel
119 self.channelJoined(newChannel)
120
121 elif isinstance(loader, (PlayerExists, PlayerJoined)):
122 playerName = loader.playerName
123 playerId = loader.playerId
124 playerIp = loader.playerIp
125 channel, = self.channels[loader.channelId]
126 newPlayer = self.playerClass(playerName, playerId, playerIp, channel)
127 channel.addConnection(newPlayer)
128 channel.setMaster(loader.masterId)
129 if isinstance(loader, PlayerExists):
130 self.channelUserExists(channel, newPlayer)
131 elif isinstance(loader, PlayerJoined):
132 self.channelUserJoined(channel, newPlayer)
133
134 elif isinstance(loader, FromChannelMessage):
135 if loader.isServer():
136 self.messageReceived(loader.message, loader.subchannel)
137 else:
138 channel, = self.channels[loader.channelId]
139 player, = channel.connections[loader.playerId]
140 self.channelMessageReceived(channel, player, loader.message,
141 loader.subchannel)
142
143 elif isinstance(loader, PlayerChanged):
144 playerId = loader.playerId
145 playerName = loader.playerName
146 for channel in self.channels.values():
147 if playerId in channel.connections:
148 player, = channel.connections[playerId]
149 oldName = player.name
150 player.name = playerName
151 if player.isPeer():
152 self.channelUserChanged(player, oldName, player.name)
153 else:
154 self.nameChanged(channel, oldName, player.name)
155
156 elif isinstance(loader, PlayerLeft):
157 channel, = self.channels[loader.channelId]
158 player, = channel.connections[loader.playerId]
159 if player.isPeer():
160 channel.removeConnection(player)
161 channel.setMaster(loader.masterId)
162 self.channelUserLeft(channel, player)
163 else:
164 del self.channels[channel]
165 self.channelLeft(channel)
166
167 else:
168 raise NotImplementedError
169
170
171
173 """
174 Called upon receiving the MOTD
175 """
176
178 """
179 Called when the connection has been accepted, and the
180 client notified.
181 """
182
184 """
185 Called upon receiving a server message
186
187 @type message: L{Message} object
188 """
189
191 """
192 Called when a channel message has been received
193
194 @type message: lacewing.moo.packetloaders.message.Message object
195 """
196
198 """
199 Called when the server has accepted a channel join request.
200 @arg channel: The channel the client has joined.
201 """
202
204 """
205 Called when the server has accepted a channel leave request.
206 @arg channel: The channel the client has left.
207 """
208
210 """
211 Called when the server has told us we've changed
212 our name
213 """
214
216 """
217 Called when a client has joined the channel.
218 @arg channel: The channel the client has joined.
219 """
220
222 """
223 Called when a client exists in the channel.
224 @arg channel: The channel the client exists in.
225 """
226
228 """
229 Called when a client has left the channel.
230 @arg channel: The channel the client has left.
231 """
232
234 """
235 Called when a client in the channel (including has changed name.
236 """
237
238
239
244
245 - def sendMessage(self, value, subchannel, type = None):
256
259
264
269