annotate libervia.tac @ 39:305e81c7a32c

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