1 from twisted.internet.protocol import ServerFactory
2
3 from lacewing.moo.protocol import MooProtocol
4
5 from lacewing.moo.packet import ServerPacket, ClientPacket
6
7 from lacewing.moo.packetloaders.server import *
8 from lacewing.moo.packetloaders.client import *
9
10 from lacewing.multidict import MultikeyDict
11
12 from lacewing.moo.packetloaders.message import *
13
14 from lacewing.idpool import IDPool
15
84
86 _sendPacket = ServerPacket
87 _receivePacket = ClientPacket
88
103
108
110 if isinstance(loader, SetName):
111 self.name = loader.playerName
112 self.nameSet(self.name)
113
114 elif not self.isAccepted or not self.name:
115
116
117
118
119 self.transport.loseConnection()
120
121 elif isinstance(loader, ClientMessage):
122 self.messageReceived(loader.message, loader.subchannel)
123
124 elif isinstance(loader, JoinChannel):
125 channelName = loader.channelName
126 if channelName in self.channels:
127
128
129 return
130 if not self.acceptChannelJoin(channelName):
131 return
132 self.joinChannel(channelName)
133
134 elif isinstance(loader, LeaveChannel):
135 channelId = loader.channelId
136 if not channelId in self.channels:
137
138
139
140 return
141 channel, = self.channels[channelId]
142 if not self.acceptChannelLeave(channel):
143 return
144 self.leaveChannel(channel)
145
146 elif isinstance(loader, ToChannelMessage):
147 channelId = loader.channelId
148 if not channelId in self.channels:
149
150
151
152 return
153 channel, = self.channels[channelId]
154 message = loader.message
155 subchannel = loader.subchannel
156 if not self.acceptChannelMessage(channel, message, subchannel):
157 return
158 channel.sendMessage(self, message.value, subchannel, message.type)
159 self.channelMessageReceived(channel, message, subchannel)
160
161 elif isinstance(loader, PrivateMessage):
162 channelId = loader.channelId
163 if not channelId in self.channels:
164
165
166
167 return
168 channel, = self.channels[channelId]
169 playerId = loader.playerId
170 if not playerId in channel.connections:
171
172
173 return
174 player, = channel.connections[playerId]
175 message = loader.message
176 subchannel = loader.subchannel
177 if not self.acceptPrivateMessage(channel, player, message, subchannel):
178 return
179 channel.sendMessage(self, message.value, subchannel, message.type, player)
180 self.privateMessageReceived(channel, player, message, subchannel)
181
182 elif isinstance(loader, ChangeName):
183 if not self.acceptNameChange(self.name, loader.newName):
184 return
185 self.changeName(loader.newName)
186
187 else:
188 raise NotImplementedError
189
190
191
193 """
194 Return False to stop the server from sending
195 a welcome to the client
196 """
197 return True
198
200 """
201 Return False to decline the client to change
202 it's name (after setting the inital name)
203 """
204 return True
205
207 """
208 Return False to stop the client from joining the specified
209 channel
210 """
211 return True
212
214 """
215 Return False to stop the channel message from being
216 sent to the other channel members
217 """
218 return True
219
221 """
222 Return False to stop the private message from reaching
223 the recipient
224 """
225 return True
226
228 """
229 Return False to stop the client from leaving the specified
230 channel
231 """
232 return True
233
234
235
237 """
238 Called when the connection has been accepted, and the
239 client notified.
240 """
241
243 """
244 Called after the name has been set
245 """
246
248 """
249 Called when the client has changed name
250 """
251
253 """
254 Called upon receiving a client message.
255
256 @type message: L{Message} object
257 """
258
260 """
261 Called when the client has been let into
262 a channel
263 """
264
266 """
267 Called after a channel message has been relayed.
268
269 @type message: lacewing.moo.packetloaders.message.Message object
270 """
271
273 """
274 Called after a private message has been relayed.
275
276 @type message: lacewing.moo.packetloaders.message.Message object
277 """
278
280 """
281 Called when the client has left a channel
282 """
283
285 """
286 This method returns the IP address of the connection.
287 Override if you would like to hide/edit the IP
288 """
289 return self.transport.getPeer().host
290
291
292
305
318
321
326
331
333 motd = ''
334
335 channels = None
336 connections = None
337
338 channelPool = None
339 userPool = None
340
347
358
362
364 """
365 Called when a new channel is
366 created
367 """
368
370 """
371 Called when the channel is destroyed because
372 it is now empty
373 """
374