Mercurial > libervia-web
annotate libervia.tac @ 37:b306aa090438
Tarot game: game launching (first hand showed), and contract selection
author | Goffi <goffi@goffi.org> |
---|---|
date | Wed, 18 May 2011 01:45:28 +0200 |
parents | 1d406077b49b |
children | 7bea2ae0c4fb |
rev | line source |
---|---|
0 | 1 #!/usr/bin/python |
2 # -*- coding: utf-8 -*- | |
3 | |
4 """ | |
5 Libervia: a Salut à Toi frontend | |
6 Copyright (C) 2011 Jérôme Poisson (goffi@goffi.org) | |
7 | |
8 This program is free software: you can redistribute it and/or modify | |
9 it under the terms of the GNU Affero General Public License as published by | |
10 the Free Software Foundation, either version 3 of the License, or | |
11 (at your option) any later version. | |
12 | |
13 This program is distributed in the hope that it will be useful, | |
14 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 GNU Affero General Public License for more details. | |
17 | |
18 You should have received a copy of the GNU Affero General Public License | |
19 along with this program. If not, see <http://www.gnu.org/licenses/>. | |
20 """ | |
21 | |
22 from twisted.application import internet, service | |
23 from twisted.internet import glib2reactor | |
24 glib2reactor.install() | |
25 from twisted.internet import reactor, defer | |
26 | |
27 from twisted.web import server | |
28 from twisted.web import error as weberror | |
29 from twisted.web.static import File | |
30 from twisted.web.resource import Resource | |
10 | 31 from twisted.words.protocols.jabber.jid import JID |
0 | 32 from txjsonrpc.web import jsonrpc |
33 from txjsonrpc import jsonrpclib | |
34 from sat_frontends.bridge.DBus import DBusBridgeFrontend,BridgeExceptionNoService | |
14
9bf8ed012adc
- Group microblog management, first draft
Goffi <goffi@goffi.org>
parents:
11
diff
changeset
|
35 import re |
36 | 36 import glob |
37 import os.path | |
10 | 38 from server_side.blog import MicroBlog |
39 | |
0 | 40 TIMEOUT = 120 #Session's time out, after that the user will be disconnected |
36 | 41 LIBERVIA_DIR = "output/" |
42 CARDS_DIR = "cards/" | |
0 | 43 |
44 class MethodHandler(jsonrpc.JSONRPC): | |
45 | |
46 def __init__(self, sat_host): | |
47 jsonrpc.JSONRPC.__init__(self) | |
48 self.sat_host=sat_host | |
49 | |
50 def render(self, request): | |
1 | 51 self.session = request.getSession() |
0 | 52 try: |
1 | 53 profile = self.session.sat_profile |
0 | 54 except AttributeError: |
55 #user is not identified, we return a jsonrpc fault | |
56 parsed = jsonrpclib.loads(request.content.read()) | |
57 fault = jsonrpclib.Fault(0, "Not allowed") #FIXME: define some standard error codes for libervia | |
58 return jsonrpc.JSONRPC._cbRender(self, fault, request, parsed.get('id'), parsed.get('jsonrpc')) | |
59 return jsonrpc.JSONRPC.render(self, request) | |
19 | 60 |
61 def jsonrpc_getProfileJid(self): | |
62 """Return the jid of the profile""" | |
63 profile = self.session.sat_profile | |
64 self.session.sat_jid = self.sat_host.bridge.getParamA("JabberID", "Connection", profile_key=profile) | |
65 return self.session.sat_jid | |
0 | 66 |
67 def jsonrpc_getContacts(self): | |
68 """Return all passed args.""" | |
1 | 69 profile = self.session.sat_profile |
70 return self.sat_host.bridge.getContacts(profile) | |
20 | 71 |
72 def jsonrpc_setStatus(self, status): | |
73 """Change the status""" | |
74 profile = self.session.sat_profile | |
75 print "new status received:", status | |
76 self.sat_host.bridge.setPresence('', '', 0, {'':status}, profile) | |
77 | |
19 | 78 |
79 def jsonrpc_sendMessage(self, to_jid, msg, subject, type): | |
80 """send message""" | |
81 profile = self.session.sat_profile | |
82 return self.sat_host.bridge.sendMessage(to_jid, msg, subject, type, profile) | |
0 | 83 |
11
331c093e4eb3
magicBox is now able to send global microblog
Goffi <goffi@goffi.org>
parents:
10
diff
changeset
|
84 def jsonrpc_sendMblog(self, raw_text): |
331c093e4eb3
magicBox is now able to send global microblog
Goffi <goffi@goffi.org>
parents:
10
diff
changeset
|
85 """Parse raw_text of the microblog box, and send message consequently""" |
331c093e4eb3
magicBox is now able to send global microblog
Goffi <goffi@goffi.org>
parents:
10
diff
changeset
|
86 profile = self.session.sat_profile |
14
9bf8ed012adc
- Group microblog management, first draft
Goffi <goffi@goffi.org>
parents:
11
diff
changeset
|
87 match = re.match(r'@(.+?): *(.*$)', raw_text) |
9bf8ed012adc
- Group microblog management, first draft
Goffi <goffi@goffi.org>
parents:
11
diff
changeset
|
88 if match: |
9bf8ed012adc
- Group microblog management, first draft
Goffi <goffi@goffi.org>
parents:
11
diff
changeset
|
89 recip = match.group(1) |
9bf8ed012adc
- Group microblog management, first draft
Goffi <goffi@goffi.org>
parents:
11
diff
changeset
|
90 text = match.group(2) |
9bf8ed012adc
- Group microblog management, first draft
Goffi <goffi@goffi.org>
parents:
11
diff
changeset
|
91 if recip == '@' and text: |
9bf8ed012adc
- Group microblog management, first draft
Goffi <goffi@goffi.org>
parents:
11
diff
changeset
|
92 #This text if for the public microblog |
9bf8ed012adc
- Group microblog management, first draft
Goffi <goffi@goffi.org>
parents:
11
diff
changeset
|
93 print "Sending message to everybody" |
11
331c093e4eb3
magicBox is now able to send global microblog
Goffi <goffi@goffi.org>
parents:
10
diff
changeset
|
94 return self.sat_host.bridge.sendPersonalEvent("MICROBLOG", {'content':text}, profile) |
14
9bf8ed012adc
- Group microblog management, first draft
Goffi <goffi@goffi.org>
parents:
11
diff
changeset
|
95 else: |
9bf8ed012adc
- Group microblog management, first draft
Goffi <goffi@goffi.org>
parents:
11
diff
changeset
|
96 return self.sat_host.bridge.sendGroupBlog([recip], text, profile) |
9bf8ed012adc
- Group microblog management, first draft
Goffi <goffi@goffi.org>
parents:
11
diff
changeset
|
97 |
20 | 98 def jsonrpc_getPresenceStatus(self): |
99 """Get Presence information for connected contacts""" | |
100 profile = self.session.sat_profile | |
101 return self.sat_host.bridge.getPresenceStatus(profile) | |
102 | |
19 | 103 def jsonrpc_getHistory(self, from_jid, to_jid, size): |
104 """Return history for the from_jid/to_jid couple""" | |
105 #FIXME: this method should definitely be asynchrone, need to fix it !!! | |
106 profile = self.session.sat_profile | |
107 try: | |
108 _jid = JID(self.session.sat_jid) | |
109 except: | |
110 error("No jid saved for this profile") | |
111 return {} | |
112 if JID(from_jid).userhost() != _jid.userhost() and JID(to_jid) != _jid.userhost(): | |
113 error("Trying to get history from a different jid, maybe a hack attempt ?") | |
114 return {} | |
24 | 115 return self.sat_host.bridge.getHistory(from_jid, to_jid, size) |
19 | 116 |
30
7684e3ceb12d
server_side: added getRoomJoined method
Goffi <goffi@goffi.org>
parents:
24
diff
changeset
|
117 def jsonrpc_getRoomJoined(self): |
7684e3ceb12d
server_side: added getRoomJoined method
Goffi <goffi@goffi.org>
parents:
24
diff
changeset
|
118 """Return list of room already joined by user""" |
7684e3ceb12d
server_side: added getRoomJoined method
Goffi <goffi@goffi.org>
parents:
24
diff
changeset
|
119 profile = self.session.sat_profile |
7684e3ceb12d
server_side: added getRoomJoined method
Goffi <goffi@goffi.org>
parents:
24
diff
changeset
|
120 return self.sat_host.bridge.getRoomJoined(profile) |
7684e3ceb12d
server_side: added getRoomJoined method
Goffi <goffi@goffi.org>
parents:
24
diff
changeset
|
121 |
24 | 122 def jsonrpc_launchTarotGame(self, other_players): |
123 """Create a room, invite the other players and start a Tarot game""" | |
124 profile = self.session.sat_profile | |
125 self.sat_host.bridge.tarotGameLaunch(other_players, profile) | |
11
331c093e4eb3
magicBox is now able to send global microblog
Goffi <goffi@goffi.org>
parents:
10
diff
changeset
|
126 |
36 | 127 def jsonrpc_getTarotCardsPaths(self): |
128 """Give the path of all the tarot cards""" | |
129 return map(lambda x: x[len(LIBERVIA_DIR):],glob.glob(os.path.join(LIBERVIA_DIR,CARDS_DIR,'*_*.png'))); | |
130 | |
37
b306aa090438
Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
131 def jsonrpc_tarotGameReady(self, player, referee): |
b306aa090438
Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
132 """Tell to the server that we are ready to start the game""" |
b306aa090438
Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
133 profile = self.session.sat_profile |
b306aa090438
Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
134 self.sat_host.bridge.tarotGameReady(player, referee) |
36 | 135 |
37
b306aa090438
Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
136 def jsonrpc_tarotGameContratChoosed(self, player_nick, referee, contrat): |
b306aa090438
Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
137 """Tell to the server that we are ready to start the game""" |
b306aa090438
Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
138 profile = self.session.sat_profile |
b306aa090438
Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
139 self.sat_host.bridge.tarotGameContratChoosed(player_nick, referee, contrat, profile) |
36 | 140 |
0 | 141 class Register(jsonrpc.JSONRPC): |
142 """This class manage the registration procedure with SàT | |
143 It provide an api for the browser, check password and setup the web server""" | |
144 | |
145 def __init__(self, sat_host): | |
146 jsonrpc.JSONRPC.__init__(self) | |
147 self.sat_host=sat_host | |
148 self.profiles_waiting={} | |
149 self.request=None | |
150 | |
151 def getWaitingRequest(self, profile): | |
152 """Tell if a profile is trying to log in""" | |
153 if self.profiles_waiting.has_key(profile): | |
154 return self.profiles_waiting[profile] | |
155 else: | |
156 return None | |
157 | |
14
9bf8ed012adc
- Group microblog management, first draft
Goffi <goffi@goffi.org>
parents:
11
diff
changeset
|
158 def _fillMblogNodes(self, result, session): |
9bf8ed012adc
- Group microblog management, first draft
Goffi <goffi@goffi.org>
parents:
11
diff
changeset
|
159 """Fill the microblog nodes association for this session""" |
9bf8ed012adc
- Group microblog management, first draft
Goffi <goffi@goffi.org>
parents:
11
diff
changeset
|
160 print "Filling session for %s with %s" % (session.sat_profile, result) |
9bf8ed012adc
- Group microblog management, first draft
Goffi <goffi@goffi.org>
parents:
11
diff
changeset
|
161 session.sat_mblog_nodes = dict(result) |
9bf8ed012adc
- Group microblog management, first draft
Goffi <goffi@goffi.org>
parents:
11
diff
changeset
|
162 |
0 | 163 def render(self, request): |
164 """ | |
165 Render method with some hacks: | |
166 - if login is requested, try to login with form data | |
167 - except login, every method is jsonrpc | |
168 - user doesn't need to be authentified for isRegistered, but must be for all other methods | |
169 """ | |
170 if request.postpath==['login']: | |
171 return self.login(request) | |
172 _session = request.getSession() | |
173 parsed = jsonrpclib.loads(request.content.read()) | |
174 if parsed.get("method")!="isRegistered": | |
175 #if we don't call login or isRegistered, we need to be identified | |
176 try: | |
177 profile = _session.sat_profile | |
178 except AttributeError: | |
179 #user is not identified, we return a jsonrpc fault | |
180 fault = jsonrpclib.Fault(0, "Not allowed") #FIXME: define some standard error codes for libervia | |
181 return jsonrpc.JSONRPC._cbRender(self, fault, request, parsed.get('id'), parsed.get('jsonrpc')) | |
182 self.request = request | |
183 return jsonrpc.JSONRPC.render(self, request) | |
184 | |
185 def login(self, request): | |
186 """ | |
187 this method is called with the POST information from the registering form | |
188 it test if the password is ok, and log in if it's the case, | |
189 else it return an error | |
190 @param request: request of the register formulaire, must have "login" and "password" as arguments | |
191 @return: A constant indicating the state: | |
192 - BAD REQUEST: something is wrong in the request (bad arguments, profile_key for login) | |
193 - AUTH ERROR: either the profile or the password is wrong | |
194 - ALREADY WAITING: a request has already be made for this profile | |
195 - server.NOT_DONE_YET: the profile is being processed, the return value will be given by self._logged or self._logginError | |
196 """ | |
197 try: | |
198 _login = request.args['login'][0] | |
199 if _login.startswith('@'): | |
200 raise Exception('No profile_key allowed') | |
201 _pass = request.args['password'][0] | |
202 except KeyError: | |
203 return "BAD REQUEST" | |
204 | |
205 _profile_check = self.sat_host.bridge.getProfileName(_login) | |
206 _profile_pass = self.sat_host.bridge.getParamA("Password", "Connection", profile_key=_login) | |
207 | |
208 if not _profile_check or _profile_check != _login or _profile_pass != _pass: | |
209 return "AUTH ERROR" | |
210 | |
211 if self.profiles_waiting.has_key(_login): | |
212 return "ALREADY WAITING" | |
213 | |
214 if self.sat_host.bridge.isConnected(_login): | |
14
9bf8ed012adc
- Group microblog management, first draft
Goffi <goffi@goffi.org>
parents:
11
diff
changeset
|
215 return self._logged(_login, request, finish=False) |
0 | 216 |
217 self.profiles_waiting[_login] = request | |
218 self.sat_host.bridge.connect(_login) | |
219 return server.NOT_DONE_YET | |
220 | |
221 def __cleanWaiting(self, login): | |
222 """Remove login from waiting queue""" | |
223 try: | |
224 del self.profiles_waiting[login] | |
225 except KeyError: | |
226 pass | |
227 | |
14
9bf8ed012adc
- Group microblog management, first draft
Goffi <goffi@goffi.org>
parents:
11
diff
changeset
|
228 def _logged(self, profile, request, finish=True): |
0 | 229 """Set everything when a user just logged |
230 and return "LOGGED" to the requester""" | |
14
9bf8ed012adc
- Group microblog management, first draft
Goffi <goffi@goffi.org>
parents:
11
diff
changeset
|
231 self.__cleanWaiting(profile) |
0 | 232 _session = request.getSession() |
14
9bf8ed012adc
- Group microblog management, first draft
Goffi <goffi@goffi.org>
parents:
11
diff
changeset
|
233 _session.sat_profile = profile |
24 | 234 self.sat_host.prof_connected.add(profile) |
14
9bf8ed012adc
- Group microblog management, first draft
Goffi <goffi@goffi.org>
parents:
11
diff
changeset
|
235 d = defer.Deferred() |
9bf8ed012adc
- Group microblog management, first draft
Goffi <goffi@goffi.org>
parents:
11
diff
changeset
|
236 self.sat_host.bridge.getMblogNodes(profile, d.callback, d.errback) |
9bf8ed012adc
- Group microblog management, first draft
Goffi <goffi@goffi.org>
parents:
11
diff
changeset
|
237 d.addCallback(self._fillMblogNodes, _session) |
9bf8ed012adc
- Group microblog management, first draft
Goffi <goffi@goffi.org>
parents:
11
diff
changeset
|
238 if finish: |
9bf8ed012adc
- Group microblog management, first draft
Goffi <goffi@goffi.org>
parents:
11
diff
changeset
|
239 request.write('LOGGED') |
9bf8ed012adc
- Group microblog management, first draft
Goffi <goffi@goffi.org>
parents:
11
diff
changeset
|
240 request.finish() |
9bf8ed012adc
- Group microblog management, first draft
Goffi <goffi@goffi.org>
parents:
11
diff
changeset
|
241 else: |
9bf8ed012adc
- Group microblog management, first draft
Goffi <goffi@goffi.org>
parents:
11
diff
changeset
|
242 return "LOGGED" |
0 | 243 |
244 def _logginError(self, login, request, error_type): | |
245 """Something went wrong during loggin, return an error""" | |
246 self.__cleanWaiting(login) | |
247 return error_type | |
248 | |
249 def jsonrpc_isConnected(self): | |
250 _session = self.request.getSession() | |
251 profile = _session.sat_profile | |
252 return self.sat_host.bridge.isConnected(profile) | |
253 | |
254 def jsonrpc_connect(self): | |
255 _session = self.request.getSession() | |
256 profile = _session.sat_profile | |
257 if self.profiles_waiting.has_key(profile): | |
258 raise jsonrpclib.Fault('1','Already waiting') #FIXME: define some standard error codes for libervia | |
259 self.profiles_waiting[profile] = self.request | |
260 self.sat_host.bridge.connect(profile) | |
261 return server.NOT_DONE_YET | |
262 | |
263 def jsonrpc_isRegistered(self): | |
264 """Tell if the user is already registered""" | |
265 _session = self.request.getSession() | |
266 try: | |
267 profile = _session.sat_profile | |
268 except AttributeError: | |
269 return False | |
270 return True | |
271 | |
272 class SignalHandler(jsonrpc.JSONRPC): | |
273 | |
274 def __init__(self, sat_host): | |
275 Resource.__init__(self) | |
276 self.register=None | |
277 self.sat_host=sat_host | |
3
154d4caa57f4
server side: proper profile management in signals generic callback
Goffi <goffi@goffi.org>
parents:
2
diff
changeset
|
278 self.signalDeferred = {} |
24 | 279 self.queue = {} #XXX: gof: don't forgot to purge queue on session end |
2
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
280 |
0 | 281 def plugRegister(self, register): |
282 self.register = register | |
2
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
283 |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
284 def jsonrpc_getSignals(self): |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
285 """Keep the connection alive until a signal is received, then send it |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
286 @return: (signal, *signal_args)""" |
3
154d4caa57f4
server side: proper profile management in signals generic callback
Goffi <goffi@goffi.org>
parents:
2
diff
changeset
|
287 _session = self.request.getSession() |
154d4caa57f4
server side: proper profile management in signals generic callback
Goffi <goffi@goffi.org>
parents:
2
diff
changeset
|
288 profile = _session.sat_profile |
24 | 289 if profile in self.queue: #if we have signals to send in queue |
290 if self.queue[profile]: | |
291 return self.queue[profile].pop(0) | |
292 else: | |
293 #the queue is empty, we delete the profile from queue | |
294 del self.queue[profile] | |
3
154d4caa57f4
server side: proper profile management in signals generic callback
Goffi <goffi@goffi.org>
parents:
2
diff
changeset
|
295 self.signalDeferred[profile] = defer.Deferred() |
154d4caa57f4
server side: proper profile management in signals generic callback
Goffi <goffi@goffi.org>
parents:
2
diff
changeset
|
296 return self.signalDeferred[profile] |
2
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
297 |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
298 def getGenericCb(self, function_name): |
3
154d4caa57f4
server side: proper profile management in signals generic callback
Goffi <goffi@goffi.org>
parents:
2
diff
changeset
|
299 """Return a generic function which send all params to signalDeferred.callback |
154d4caa57f4
server side: proper profile management in signals generic callback
Goffi <goffi@goffi.org>
parents:
2
diff
changeset
|
300 function must have profile as last argument""" |
2
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
301 def genericCb(*args): |
3
154d4caa57f4
server side: proper profile management in signals generic callback
Goffi <goffi@goffi.org>
parents:
2
diff
changeset
|
302 profile = args[-1] |
24 | 303 if not profile in self.sat_host.prof_connected: |
304 return | |
3
154d4caa57f4
server side: proper profile management in signals generic callback
Goffi <goffi@goffi.org>
parents:
2
diff
changeset
|
305 if profile in self.signalDeferred: |
154d4caa57f4
server side: proper profile management in signals generic callback
Goffi <goffi@goffi.org>
parents:
2
diff
changeset
|
306 self.signalDeferred[profile].callback((function_name,args[:-1])) |
24 | 307 del self.signalDeferred[profile] |
2
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
308 else: |
24 | 309 if not self.queue.has_key(profile): |
310 self.queue[profile] = [] | |
311 self.queue[profile].append((function_name, args[:-1])) | |
2
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
312 return genericCb |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
313 |
0 | 314 def connected(self, profile): |
315 assert(self.register) #register must be plugged | |
316 request = self.register.getWaitingRequest(profile) | |
317 if request: | |
318 self.register._logged(profile, request) | |
319 | |
320 def connectionError(self, error_type, profile): | |
321 assert(self.register) #register must be plugged | |
322 request = self.register.getWaitingRequest(profile) | |
323 if request: #The user is trying to log in | |
324 if error_type == "AUTH_ERROR": | |
325 _error_t = "AUTH ERROR" | |
326 else: | |
327 _error_t = "UNKNOWN" | |
328 self.register._logginError(profile, request, _error_t) | |
329 | |
2
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
330 def render(self, request): |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
331 """ |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
332 Render method wich reject access if user is not identified |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
333 """ |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
334 _session = request.getSession() |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
335 parsed = jsonrpclib.loads(request.content.read()) |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
336 try: |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
337 profile = _session.sat_profile |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
338 except AttributeError: |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
339 #user is not identified, we return a jsonrpc fault |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
340 fault = jsonrpclib.Fault(0, "Not allowed") #FIXME: define some standard error codes for libervia |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
341 return jsonrpc.JSONRPC._cbRender(self, fault, request, parsed.get('id'), parsed.get('jsonrpc')) |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
342 self.request = request |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
343 return jsonrpc.JSONRPC.render(self, request) |
0 | 344 |
10 | 345 |
0 | 346 class Libervia(service.Service): |
347 | |
348 def __init__(self): | |
36 | 349 root = File(LIBERVIA_DIR) |
0 | 350 self.signal_handler = SignalHandler(self) |
351 _register = Register(self) | |
352 self.signal_handler.plugRegister(_register) | |
353 self.sessions = {} #key = session value = user | |
24 | 354 self.prof_connected = set() #Profiles connected |
0 | 355 ## bridge ## |
356 try: | |
357 self.bridge=DBusBridgeFrontend() | |
358 except BridgeExceptionNoService: | |
359 print(u"Can't connect to SàT backend, are you sure it's launched ?") | |
360 import sys | |
361 sys.exit(1) | |
362 self.bridge.register("connected", self.signal_handler.connected) | |
363 self.bridge.register("connectionError", self.signal_handler.connectionError) | |
37
b306aa090438
Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
364 for signal_name in ['presenceUpdate', 'personalEvent', 'newMessage', 'roomJoined', 'roomUserJoined', 'roomUserLeft', 'tarotGameStarted', 'tarotGameNew', |
b306aa090438
Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
365 'tarotGameChooseContrat']: |
2
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
366 self.bridge.register(signal_name, self.signal_handler.getGenericCb(signal_name)) |
10 | 367 root.putChild('json_signal_api', self.signal_handler) |
368 root.putChild('json_api', MethodHandler(self)) | |
369 root.putChild('register_api', _register) | |
370 root.putChild('blog', MicroBlog(self)) | |
371 root.putChild('css', File("server_css/")) | |
372 self.site = server.Site(root) | |
0 | 373 |
374 def startService(self): | |
375 reactor.listenTCP(8080, self.site) | |
1 | 376 |
0 | 377 def run(self): |
378 reactor.run() | |
379 | |
380 def stop(self): | |
381 reactor.stop() | |
382 | |
383 | |
384 | |
385 application = service.Application('Libervia') | |
386 service = Libervia() | |
387 service.setServiceParent(application) |