comparison libervia.tac @ 36:1d406077b49b

Tarot Game: first draft
author Goffi <goffi@goffi.org>
date Tue, 17 May 2011 01:33:12 +0200
parents d43d6e4b9dc8
children b306aa090438
comparison
equal deleted inserted replaced
35:d43d6e4b9dc8 36:1d406077b49b
31 from twisted.words.protocols.jabber.jid import JID 31 from twisted.words.protocols.jabber.jid import JID
32 from txjsonrpc.web import jsonrpc 32 from txjsonrpc.web import jsonrpc
33 from txjsonrpc import jsonrpclib 33 from txjsonrpc import jsonrpclib
34 from sat_frontends.bridge.DBus import DBusBridgeFrontend,BridgeExceptionNoService 34 from sat_frontends.bridge.DBus import DBusBridgeFrontend,BridgeExceptionNoService
35 import re 35 import re
36 import glob
37 import os.path
36 from server_side.blog import MicroBlog 38 from server_side.blog import MicroBlog
37 39
38 TIMEOUT = 120 #Session's time out, after that the user will be disconnected 40 TIMEOUT = 120 #Session's time out, after that the user will be disconnected
39 41 LIBERVIA_DIR = "output/"
42 CARDS_DIR = "cards/"
40 43
41 class MethodHandler(jsonrpc.JSONRPC): 44 class MethodHandler(jsonrpc.JSONRPC):
42 45
43 def __init__(self, sat_host): 46 def __init__(self, sat_host):
44 jsonrpc.JSONRPC.__init__(self) 47 jsonrpc.JSONRPC.__init__(self)
118 121
119 def jsonrpc_launchTarotGame(self, other_players): 122 def jsonrpc_launchTarotGame(self, other_players):
120 """Create a room, invite the other players and start a Tarot game""" 123 """Create a room, invite the other players and start a Tarot game"""
121 profile = self.session.sat_profile 124 profile = self.session.sat_profile
122 self.sat_host.bridge.tarotGameLaunch(other_players, profile) 125 self.sat_host.bridge.tarotGameLaunch(other_players, profile)
126
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
131
123 132
124 class Register(jsonrpc.JSONRPC): 133 class Register(jsonrpc.JSONRPC):
125 """This class manage the registration procedure with SàT 134 """This class manage the registration procedure with SàT
126 It provide an api for the browser, check password and setup the web server""" 135 It provide an api for the browser, check password and setup the web server"""
127 136
327 336
328 337
329 class Libervia(service.Service): 338 class Libervia(service.Service):
330 339
331 def __init__(self): 340 def __init__(self):
332 root = File("output/") 341 root = File(LIBERVIA_DIR)
333 self.signal_handler = SignalHandler(self) 342 self.signal_handler = SignalHandler(self)
334 _register = Register(self) 343 _register = Register(self)
335 self.signal_handler.plugRegister(_register) 344 self.signal_handler.plugRegister(_register)
336 self.sessions = {} #key = session value = user 345 self.sessions = {} #key = session value = user
337 self.prof_connected = set() #Profiles connected 346 self.prof_connected = set() #Profiles connected
342 print(u"Can't connect to SàT backend, are you sure it's launched ?") 351 print(u"Can't connect to SàT backend, are you sure it's launched ?")
343 import sys 352 import sys
344 sys.exit(1) 353 sys.exit(1)
345 self.bridge.register("connected", self.signal_handler.connected) 354 self.bridge.register("connected", self.signal_handler.connected)
346 self.bridge.register("connectionError", self.signal_handler.connectionError) 355 self.bridge.register("connectionError", self.signal_handler.connectionError)
347 for signal_name in ['presenceUpdate', 'personalEvent', 'newMessage', 'roomJoined', 'roomUserJoined', 'roomUserLeft']: 356 for signal_name in ['presenceUpdate', 'personalEvent', 'newMessage', 'roomJoined', 'roomUserJoined', 'roomUserLeft', 'tarotGameStarted']:
348 self.bridge.register(signal_name, self.signal_handler.getGenericCb(signal_name)) 357 self.bridge.register(signal_name, self.signal_handler.getGenericCb(signal_name))
349 root.putChild('json_signal_api', self.signal_handler) 358 root.putChild('json_signal_api', self.signal_handler)
350 root.putChild('json_api', MethodHandler(self)) 359 root.putChild('json_api', MethodHandler(self))
351 root.putChild('register_api', _register) 360 root.putChild('register_api', _register)
352 root.putChild('blog', MicroBlog(self)) 361 root.putChild('blog', MicroBlog(self))