1
2
3
4 from twisted.internet.protocol import ServerFactory
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
17 from lacewing.idpool import IDPool
18
87
89 _sendPacket = ServerPacket
90 _receivePacket = ClientPacket
91
106
111
113 if isinstance(loader, SetName):
114 self.name = loader.playerName
115 self.nameSet(self.name)
116
117 elif not self.isAccepted or not self.name:
118
119
120
121
122 self.transport.loseConnection()
123
124 elif isinstance(loader, ClientMessage):
125 self.messageReceived(loader.message, loader.subchannel)
126
127 elif isinstance(loader, JoinChannel):
128 channelName = loader.channelName
129 if channelName in self.channels:
130
131
132 return
133 if not self.acceptChannelJoin(channelName):
134 return
135 self.joinChannel(channelName)
136
137 elif isinstance(loader, LeaveChannel):
138 channelId = loader.channelId
139 if not channelId in self.channels:
140
141
142
143 return
144 channel, = self.channels[channelId]
145 if not self.acceptChannelLeave(channel):
146 return
147 self.leaveChannel(channel)
148
149 elif isinstance(loader, ToChannelMessage):
150 channelId = loader.channelId
151 if not channelId in self.channels:
152
153
154
155 return
156 channel, = self.channels[channelId]
157 message = loader.message
158 subchannel = loader.subchannel
159 if not self.acceptChannelMessage(channel, message, subchannel):
160 return
161 channel.sendMessage(self, message.value, subchannel, message.type)
162 self.channelMessageReceived(channel, message, subchannel)
163
164 elif isinstance(loader, PrivateMessage):
165 channelId = loader.channelId
166 if not channelId in self.channels:
167
168
169
170 return
171 channel, = self.channels[channelId]
172 playerId = loader.playerId
173 if not playerId in channel.connections:
174
175
176 return
177 player, = channel.connections[playerId]
178 message = loader.message
179 subchannel = loader.subchannel
180 if not self.acceptPrivateMessage(channel, player, message, subchannel):
181 return
182 channel.sendMessage(self, message.value, subchannel, message.type, player)
183 self.privateMessageReceived(channel, player, message, subchannel)
184
185 elif isinstance(loader, ChangeName):
186 if not self.acceptNameChange(self.name, loader.newName):
187 return
188 self.changeName(loader.newName)
189
190 else:
191 raise NotImplementedError
192
193
194
196 """
197 Return False to stop the server from sending
198 a welcome to the client
199 """
200 return True
201
203 """
204 Return False to decline the client to change
205 it's name (after setting the inital name)
206 """
207 return True
208
210 """
211 Return False to stop the client from joining the specified
212 channel
213 """
214 return True
215
217 """
218 Return False to stop the channel message from being
219 sent to the other channel members
220 """
221 return True
222
224 """
225 Return False to stop the private message from reaching
226 the recipient
227 """
228 return True
229
231 """
232 Return False to stop the client from leaving the specified
233 channel
234 """
235 return True
236
237
238
240 """
241 Called when the connection has been accepted, and the
242 client notified.
243 """
244
246 """
247 Called after the name has been set
248 """
249
251 """
252 Called when the client has changed name
253 """
254
256 """
257 Called upon receiving a client message.
258
259 @type message: L{Message} object
260 """
261
263 """
264 Called when the client has been let into
265 a channel
266 """
267
269 """
270 Called after a channel message has been relayed.
271
272 @type message: lacewing.moo.packetloaders.message.Message object
273 """
274
276 """
277 Called after a private message has been relayed.
278
279 @type message: lacewing.moo.packetloaders.message.Message object
280 """
281
283 """
284 Called when the client has left a channel
285 """
286
288 """
289 This method returns the IP address of the connection.
290 Override if you would like to hide/edit the IP
291 """
292 return self.transport.getPeer().host
293
294
295
308
321
324
329
334
336 motd = ''
337
338 channels = None
339 connections = None
340
341 channelPool = None
342 userPool = None
343
350
361
365
367 """
368 Called when a new channel is
369 created
370 """
371
373 """
374 Called when the channel is destroyed because
375 it is now empty
376 """
377