1 from twisted.internet.protocol import ClientFactory
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
34
79
81 _sendPacket = ClientPacket
82 _receivePacket = ServerPacket
83
84 motd = None
85
86 playerClass = Player
87
91
93 if isinstance(loader, MOTD):
94 self.motd = loader.motd
95 self.motdReceived(loader.motd)
96
97 elif isinstance(loader, AssignedID):
98 self.id = loader.playerId
99
100 newName = SetName()
101 newName.setConnection(self)
102 self.sendLoader(newName)
103
104 self.connectionAccepted()
105
106 elif isinstance(loader, ChannelJoined):
107 channelName = loader.channelName
108 channelId = loader.channelId
109 newChannel = Channel(channelName, channelId, self)
110 newPlayer = self.playerClass(loader.playerName, loader.playerId,
111 loader.playerIp, newChannel)
112 newChannel.player = newPlayer
113 newChannel.addConnection(newPlayer)
114 newChannel.setMaster(loader.masterId)
115 self.channels[channelName, channelId] = newChannel
116 self.channelJoined(newChannel)
117
118 elif isinstance(loader, (PlayerExists, PlayerJoined)):
119 playerName = loader.playerName
120 playerId = loader.playerId
121 playerIp = loader.playerIp
122 channel, = self.channels[loader.channelId]
123 newPlayer = self.playerClass(playerName, playerId, playerIp, channel)
124 channel.addConnection(newPlayer)
125 channel.setMaster(loader.masterId)
126 if isinstance(loader, PlayerExists):
127 self.channelUserExists(channel, newPlayer)
128 elif isinstance(loader, PlayerJoined):
129 self.channelUserJoined(channel, newPlayer)
130
131 elif isinstance(loader, FromChannelMessage):
132 if loader.isServer():
133 self.messageReceived(loader.message, loader.subchannel)
134 else:
135 channel, = self.channels[loader.channelId]
136 player, = channel.connections[loader.playerId]
137 self.channelMessageReceived(channel, player, loader.message,
138 loader.subchannel)
139
140 elif isinstance(loader, PlayerChanged):
141 playerId = loader.playerId
142 playerName = loader.playerName
143 for channel in self.channels.values():
144 if playerId in channel.connections:
145 player, = channel.connections[playerId]
146 oldName = player.name
147 player.name = playerName
148 if player.isPeer():
149 self.channelUserChanged(player, oldName, player.name)
150 else:
151 self.nameChanged(channel, oldName, player.name)
152
153 elif isinstance(loader, PlayerLeft):
154 channel, = self.channels[loader.channelId]
155 player, = channel.connections[loader.playerId]
156 if player.isPeer():
157 channel.removeConnection(player)
158 channel.setMaster(loader.masterId)
159 self.channelUserLeft(channel, player)
160 else:
161 del self.channels[channel]
162 self.channelLeft(channel)
163
164 else:
165 raise NotImplementedError
166
167
168
170 """
171 Called upon receiving the MOTD
172 """
173
175 """
176 Called when the connection has been accepted, and the
177 client notified.
178 """
179
181 """
182 Called upon receiving a server message
183
184 @type message: L{Message} object
185 """
186
188 """
189 Called when a channel message has been received
190
191 @type message: lacewing.moo.packetloaders.message.Message object
192 """
193
195 """
196 Called when the server has accepted a channel join request.
197 @arg channel: The channel the client has joined.
198 """
199
201 """
202 Called when the server has accepted a channel leave request.
203 @arg channel: The channel the client has left.
204 """
205
207 """
208 Called when the server has told us we've changed
209 our name
210 """
211
213 """
214 Called when a client has joined the channel.
215 @arg channel: The channel the client has joined.
216 """
217
219 """
220 Called when a client exists in the channel.
221 @arg channel: The channel the client exists in.
222 """
223
225 """
226 Called when a client has left the channel.
227 @arg channel: The channel the client has left.
228 """
229
231 """
232 Called when a client in the channel (including has changed name.
233 """
234
235
236
241
242 - def sendMessage(self, value, subchannel, type = None):
253
256
261
266