annotate plugins/plugin_misc_tarot.py @ 90:4020931569b8

Tarot Game: session initialization
author Goffi <goffi@goffi.org>
date Sun, 23 May 2010 16:39:05 +0930
parents 23caf1051099
children 39c672544593
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
88
Goffi <goffi@goffi.org>
parents:
diff changeset
1 #!/usr/bin/python
Goffi <goffi@goffi.org>
parents:
diff changeset
2 # -*- coding: utf-8 -*-
Goffi <goffi@goffi.org>
parents:
diff changeset
3
Goffi <goffi@goffi.org>
parents:
diff changeset
4 """
Goffi <goffi@goffi.org>
parents:
diff changeset
5 SAT plugin for managing xep-0045
Goffi <goffi@goffi.org>
parents:
diff changeset
6 Copyright (C) 2009, 2010 Jérôme Poisson (goffi@goffi.org)
Goffi <goffi@goffi.org>
parents:
diff changeset
7
Goffi <goffi@goffi.org>
parents:
diff changeset
8 This program is free software: you can redistribute it and/or modify
Goffi <goffi@goffi.org>
parents:
diff changeset
9 it under the terms of the GNU General Public License as published by
Goffi <goffi@goffi.org>
parents:
diff changeset
10 the Free Software Foundation, either version 3 of the License, or
Goffi <goffi@goffi.org>
parents:
diff changeset
11 (at your option) any later version.
Goffi <goffi@goffi.org>
parents:
diff changeset
12
Goffi <goffi@goffi.org>
parents:
diff changeset
13 This program is distributed in the hope that it will be useful,
Goffi <goffi@goffi.org>
parents:
diff changeset
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
Goffi <goffi@goffi.org>
parents:
diff changeset
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Goffi <goffi@goffi.org>
parents:
diff changeset
16 GNU General Public License for more details.
Goffi <goffi@goffi.org>
parents:
diff changeset
17
Goffi <goffi@goffi.org>
parents:
diff changeset
18 You should have received a copy of the GNU General Public License
Goffi <goffi@goffi.org>
parents:
diff changeset
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
Goffi <goffi@goffi.org>
parents:
diff changeset
20 """
Goffi <goffi@goffi.org>
parents:
diff changeset
21
Goffi <goffi@goffi.org>
parents:
diff changeset
22 from logging import debug, info, warning, error
Goffi <goffi@goffi.org>
parents:
diff changeset
23 from twisted.words.xish import domish
Goffi <goffi@goffi.org>
parents:
diff changeset
24 from twisted.internet import protocol, defer, threads, reactor
Goffi <goffi@goffi.org>
parents:
diff changeset
25 from twisted.words.protocols.jabber import client, jid, xmlstream
Goffi <goffi@goffi.org>
parents:
diff changeset
26 from twisted.words.protocols.jabber import error as jab_error
Goffi <goffi@goffi.org>
parents:
diff changeset
27 from twisted.words.protocols.jabber.xmlstream import IQ
Goffi <goffi@goffi.org>
parents:
diff changeset
28 import os.path
Goffi <goffi@goffi.org>
parents:
diff changeset
29 import pdb
Goffi <goffi@goffi.org>
parents:
diff changeset
30 import random
Goffi <goffi@goffi.org>
parents:
diff changeset
31
Goffi <goffi@goffi.org>
parents:
diff changeset
32 from zope.interface import implements
Goffi <goffi@goffi.org>
parents:
diff changeset
33
Goffi <goffi@goffi.org>
parents:
diff changeset
34 from wokkel import disco, iwokkel, muc
Goffi <goffi@goffi.org>
parents:
diff changeset
35
Goffi <goffi@goffi.org>
parents:
diff changeset
36 from base64 import b64decode
Goffi <goffi@goffi.org>
parents:
diff changeset
37 from hashlib import sha1
Goffi <goffi@goffi.org>
parents:
diff changeset
38 from time import sleep
Goffi <goffi@goffi.org>
parents:
diff changeset
39
Goffi <goffi@goffi.org>
parents:
diff changeset
40 try:
Goffi <goffi@goffi.org>
parents:
diff changeset
41 from twisted.words.protocols.xmlstream import XMPPHandler
Goffi <goffi@goffi.org>
parents:
diff changeset
42 except ImportError:
Goffi <goffi@goffi.org>
parents:
diff changeset
43 from wokkel.subprotocols import XMPPHandler
Goffi <goffi@goffi.org>
parents:
diff changeset
44
90
4020931569b8 Tarot Game: session initialization
Goffi <goffi@goffi.org>
parents: 89
diff changeset
45 MESSAGE = '/message'
4020931569b8 Tarot Game: session initialization
Goffi <goffi@goffi.org>
parents: 89
diff changeset
46 NS_CG = 'http://www.goffi.org/protocol/card_game'
4020931569b8 Tarot Game: session initialization
Goffi <goffi@goffi.org>
parents: 89
diff changeset
47 CG_TAG = 'card_game'
4020931569b8 Tarot Game: session initialization
Goffi <goffi@goffi.org>
parents: 89
diff changeset
48 CG_REQUEST = MESSAGE + '/' + CG_TAG + '[@xmlns="' + NS_CG + '"]'
88
Goffi <goffi@goffi.org>
parents:
diff changeset
49
Goffi <goffi@goffi.org>
parents:
diff changeset
50 PLUGIN_INFO = {
Goffi <goffi@goffi.org>
parents:
diff changeset
51 "name": "Tarot cards plugin",
Goffi <goffi@goffi.org>
parents:
diff changeset
52 "import_name": "Tarot",
Goffi <goffi@goffi.org>
parents:
diff changeset
53 "type": "Misc",
Goffi <goffi@goffi.org>
parents:
diff changeset
54 "protocols": [],
Goffi <goffi@goffi.org>
parents:
diff changeset
55 "dependencies": ["XEP_0045"],
Goffi <goffi@goffi.org>
parents:
diff changeset
56 "main": "Tarot",
90
4020931569b8 Tarot Game: session initialization
Goffi <goffi@goffi.org>
parents: 89
diff changeset
57 "handler": "yes",
88
Goffi <goffi@goffi.org>
parents:
diff changeset
58 "description": _("""Implementation of Tarot card game""")
Goffi <goffi@goffi.org>
parents:
diff changeset
59 }
Goffi <goffi@goffi.org>
parents:
diff changeset
60
Goffi <goffi@goffi.org>
parents:
diff changeset
61 class Tarot():
Goffi <goffi@goffi.org>
parents:
diff changeset
62
Goffi <goffi@goffi.org>
parents:
diff changeset
63 def __init__(self, host):
Goffi <goffi@goffi.org>
parents:
diff changeset
64 info(_("Plugin Tarot initialization"))
Goffi <goffi@goffi.org>
parents:
diff changeset
65 self.host = host
Goffi <goffi@goffi.org>
parents:
diff changeset
66 self.games={}
90
4020931569b8 Tarot Game: session initialization
Goffi <goffi@goffi.org>
parents: 89
diff changeset
67 host.bridge.addMethod("tarotGameCreate", ".communication", in_sign='sass', out_sign='', method=self.createGame) #args: room_jid, players, profile
4020931569b8 Tarot Game: session initialization
Goffi <goffi@goffi.org>
parents: 89
diff changeset
68 host.bridge.addMethod("tarotGameReady", ".communication", in_sign='sss', out_sign='', method=self.newPlayerReady) #args: user, referee, profile
4020931569b8 Tarot Game: session initialization
Goffi <goffi@goffi.org>
parents: 89
diff changeset
69 host.bridge.addSignal("tarotGameStarted", ".communication", signature='ssass') #args: room_jid, referee, players, profile
4020931569b8 Tarot Game: session initialization
Goffi <goffi@goffi.org>
parents: 89
diff changeset
70 host.bridge.addSignal("tarotGameNew", ".communication", signature='sa(ss)s') #args: room_jid, hand, profile
88
Goffi <goffi@goffi.org>
parents:
diff changeset
71 self.deck_ordered = []
Goffi <goffi@goffi.org>
parents:
diff changeset
72 for value in map(str,range(1,22))+['excuse']:
Goffi <goffi@goffi.org>
parents:
diff changeset
73 self.deck_ordered.append(("atout",value))
Goffi <goffi@goffi.org>
parents:
diff changeset
74 for family in ["pique", "coeur", "carreau", "trefle"]:
Goffi <goffi@goffi.org>
parents:
diff changeset
75 for value in map(str,range(1,11))+["valet","cavalier","dame","roi"]:
Goffi <goffi@goffi.org>
parents:
diff changeset
76 self.deck_ordered.append((family, value))
Goffi <goffi@goffi.org>
parents:
diff changeset
77
90
4020931569b8 Tarot Game: session initialization
Goffi <goffi@goffi.org>
parents: 89
diff changeset
78 def createGameElt(self, to_jid):
4020931569b8 Tarot Game: session initialization
Goffi <goffi@goffi.org>
parents: 89
diff changeset
79 elt = domish.Element(('jabber:client','message'))
4020931569b8 Tarot Game: session initialization
Goffi <goffi@goffi.org>
parents: 89
diff changeset
80 elt["to"] = to_jid.full()
4020931569b8 Tarot Game: session initialization
Goffi <goffi@goffi.org>
parents: 89
diff changeset
81 elt.addElement((NS_CG, CG_TAG))
4020931569b8 Tarot Game: session initialization
Goffi <goffi@goffi.org>
parents: 89
diff changeset
82 return elt
4020931569b8 Tarot Game: session initialization
Goffi <goffi@goffi.org>
parents: 89
diff changeset
83
4020931569b8 Tarot Game: session initialization
Goffi <goffi@goffi.org>
parents: 89
diff changeset
84 def __hand_to_xml(self, hand):
4020931569b8 Tarot Game: session initialization
Goffi <goffi@goffi.org>
parents: 89
diff changeset
85 """Convert a hand (list of tuples) to domish element"""
4020931569b8 Tarot Game: session initialization
Goffi <goffi@goffi.org>
parents: 89
diff changeset
86 hand_elt = domish.Element(('','hand'))
4020931569b8 Tarot Game: session initialization
Goffi <goffi@goffi.org>
parents: 89
diff changeset
87 for family, value in hand:
4020931569b8 Tarot Game: session initialization
Goffi <goffi@goffi.org>
parents: 89
diff changeset
88 card_elt = domish.Element(('','card'))
4020931569b8 Tarot Game: session initialization
Goffi <goffi@goffi.org>
parents: 89
diff changeset
89 card_elt['family'] = family
4020931569b8 Tarot Game: session initialization
Goffi <goffi@goffi.org>
parents: 89
diff changeset
90 card_elt['value'] = value
4020931569b8 Tarot Game: session initialization
Goffi <goffi@goffi.org>
parents: 89
diff changeset
91 hand_elt.addChild(card_elt)
4020931569b8 Tarot Game: session initialization
Goffi <goffi@goffi.org>
parents: 89
diff changeset
92 return hand_elt
4020931569b8 Tarot Game: session initialization
Goffi <goffi@goffi.org>
parents: 89
diff changeset
93
4020931569b8 Tarot Game: session initialization
Goffi <goffi@goffi.org>
parents: 89
diff changeset
94 def __xml_to_hand(self, hand_elt):
4020931569b8 Tarot Game: session initialization
Goffi <goffi@goffi.org>
parents: 89
diff changeset
95 """Convert a hand domish element to a list of tuples"""
4020931569b8 Tarot Game: session initialization
Goffi <goffi@goffi.org>
parents: 89
diff changeset
96 hand = []
4020931569b8 Tarot Game: session initialization
Goffi <goffi@goffi.org>
parents: 89
diff changeset
97 assert (hand_elt.name == 'hand')
4020931569b8 Tarot Game: session initialization
Goffi <goffi@goffi.org>
parents: 89
diff changeset
98 for card in hand_elt.elements():
4020931569b8 Tarot Game: session initialization
Goffi <goffi@goffi.org>
parents: 89
diff changeset
99 hand.append((card['family'], card['value']))
4020931569b8 Tarot Game: session initialization
Goffi <goffi@goffi.org>
parents: 89
diff changeset
100 return hand
4020931569b8 Tarot Game: session initialization
Goffi <goffi@goffi.org>
parents: 89
diff changeset
101
4020931569b8 Tarot Game: session initialization
Goffi <goffi@goffi.org>
parents: 89
diff changeset
102 def __create_started_elt(self, players):
4020931569b8 Tarot Game: session initialization
Goffi <goffi@goffi.org>
parents: 89
diff changeset
103 """Create a game_started domish element"""
4020931569b8 Tarot Game: session initialization
Goffi <goffi@goffi.org>
parents: 89
diff changeset
104 started_elt = domish.Element(('','started'))
4020931569b8 Tarot Game: session initialization
Goffi <goffi@goffi.org>
parents: 89
diff changeset
105 idx = 0
4020931569b8 Tarot Game: session initialization
Goffi <goffi@goffi.org>
parents: 89
diff changeset
106 for player in players:
4020931569b8 Tarot Game: session initialization
Goffi <goffi@goffi.org>
parents: 89
diff changeset
107 player_elt = domish.Element(('','player'))
4020931569b8 Tarot Game: session initialization
Goffi <goffi@goffi.org>
parents: 89
diff changeset
108 player_elt.addContent(player)
4020931569b8 Tarot Game: session initialization
Goffi <goffi@goffi.org>
parents: 89
diff changeset
109 player_elt['index'] = str(idx)
4020931569b8 Tarot Game: session initialization
Goffi <goffi@goffi.org>
parents: 89
diff changeset
110 idx+=1
4020931569b8 Tarot Game: session initialization
Goffi <goffi@goffi.org>
parents: 89
diff changeset
111 started_elt.addChild(player_elt)
4020931569b8 Tarot Game: session initialization
Goffi <goffi@goffi.org>
parents: 89
diff changeset
112 return started_elt
4020931569b8 Tarot Game: session initialization
Goffi <goffi@goffi.org>
parents: 89
diff changeset
113
4020931569b8 Tarot Game: session initialization
Goffi <goffi@goffi.org>
parents: 89
diff changeset
114 def createGame(self, room_jid_param, players, profile_key='@DEFAULT@'):
88
Goffi <goffi@goffi.org>
parents:
diff changeset
115 """Create a new game"""
Goffi <goffi@goffi.org>
parents:
diff changeset
116 debug (_("Creating Tarot game"))
90
4020931569b8 Tarot Game: session initialization
Goffi <goffi@goffi.org>
parents: 89
diff changeset
117 room_jid = jid.JID(room_jid_param)
88
Goffi <goffi@goffi.org>
parents:
diff changeset
118 profile = self.host.memory.getProfileName(profile_key)
Goffi <goffi@goffi.org>
parents:
diff changeset
119 if not profile:
Goffi <goffi@goffi.org>
parents:
diff changeset
120 error (_("profile %s is unknown") % profile_key)
Goffi <goffi@goffi.org>
parents:
diff changeset
121 return
Goffi <goffi@goffi.org>
parents:
diff changeset
122 if False: #gof: self.games.has_key(room_jid):
90
4020931569b8 Tarot Game: session initialization
Goffi <goffi@goffi.org>
parents: 89
diff changeset
123 warning (_("Tarot game already started in room %s") % room_jid.userhost())
88
Goffi <goffi@goffi.org>
parents:
diff changeset
124 else:
90
4020931569b8 Tarot Game: session initialization
Goffi <goffi@goffi.org>
parents: 89
diff changeset
125 status = {}
4020931569b8 Tarot Game: session initialization
Goffi <goffi@goffi.org>
parents: 89
diff changeset
126 for player in players:
4020931569b8 Tarot Game: session initialization
Goffi <goffi@goffi.org>
parents: 89
diff changeset
127 status[player] = "init"
4020931569b8 Tarot Game: session initialization
Goffi <goffi@goffi.org>
parents: 89
diff changeset
128 self.games[room_jid.userhost()] = {'players':players, 'status':status, 'profile':profile, 'hand_size':18, 'player_start':0}
4020931569b8 Tarot Game: session initialization
Goffi <goffi@goffi.org>
parents: 89
diff changeset
129 for player in players:
4020931569b8 Tarot Game: session initialization
Goffi <goffi@goffi.org>
parents: 89
diff changeset
130 mess = self.createGameElt(jid.JID(room_jid.userhost()+'/'+player))
4020931569b8 Tarot Game: session initialization
Goffi <goffi@goffi.org>
parents: 89
diff changeset
131 mess.firstChildElement().addChild(self.__create_started_elt(players))
4020931569b8 Tarot Game: session initialization
Goffi <goffi@goffi.org>
parents: 89
diff changeset
132 self.host.profiles[profile].xmlstream.send(mess)
4020931569b8 Tarot Game: session initialization
Goffi <goffi@goffi.org>
parents: 89
diff changeset
133
4020931569b8 Tarot Game: session initialization
Goffi <goffi@goffi.org>
parents: 89
diff changeset
134 def newPlayerReady(self, user, referee, profile_key='@DEFAULT@'):
4020931569b8 Tarot Game: session initialization
Goffi <goffi@goffi.org>
parents: 89
diff changeset
135 """Must be called when player is ready to start a new game"""
4020931569b8 Tarot Game: session initialization
Goffi <goffi@goffi.org>
parents: 89
diff changeset
136 profile = self.host.memory.getProfileName(profile_key)
4020931569b8 Tarot Game: session initialization
Goffi <goffi@goffi.org>
parents: 89
diff changeset
137 if not profile:
4020931569b8 Tarot Game: session initialization
Goffi <goffi@goffi.org>
parents: 89
diff changeset
138 error (_("profile %s is unknown") % profile_key)
4020931569b8 Tarot Game: session initialization
Goffi <goffi@goffi.org>
parents: 89
diff changeset
139 return
4020931569b8 Tarot Game: session initialization
Goffi <goffi@goffi.org>
parents: 89
diff changeset
140 debug ('new player ready: %s' % profile)
4020931569b8 Tarot Game: session initialization
Goffi <goffi@goffi.org>
parents: 89
diff changeset
141 mess = self.createGameElt(jid.JID(referee))
4020931569b8 Tarot Game: session initialization
Goffi <goffi@goffi.org>
parents: 89
diff changeset
142 mess.firstChildElement().addElement('player_ready', content=user)
4020931569b8 Tarot Game: session initialization
Goffi <goffi@goffi.org>
parents: 89
diff changeset
143 self.host.profiles[profile].xmlstream.send(mess)
88
Goffi <goffi@goffi.org>
parents:
diff changeset
144
Goffi <goffi@goffi.org>
parents:
diff changeset
145
Goffi <goffi@goffi.org>
parents:
diff changeset
146 def newGame(self, room_jid):
Goffi <goffi@goffi.org>
parents:
diff changeset
147 """Launch a new round"""
Goffi <goffi@goffi.org>
parents:
diff changeset
148 debug (_('new Tarot game'))
Goffi <goffi@goffi.org>
parents:
diff changeset
149 deck = self.deck_ordered[:]
Goffi <goffi@goffi.org>
parents:
diff changeset
150 random.shuffle(deck)
90
4020931569b8 Tarot Game: session initialization
Goffi <goffi@goffi.org>
parents: 89
diff changeset
151 profile = self.games[room_jid.userhost()]['profile']
4020931569b8 Tarot Game: session initialization
Goffi <goffi@goffi.org>
parents: 89
diff changeset
152 players = self.games[room_jid.userhost()]['players']
4020931569b8 Tarot Game: session initialization
Goffi <goffi@goffi.org>
parents: 89
diff changeset
153 hand = self.games[room_jid.userhost()]['hand'] = {}
4020931569b8 Tarot Game: session initialization
Goffi <goffi@goffi.org>
parents: 89
diff changeset
154 hand_size = self.games[room_jid.userhost()]['hand_size']
4020931569b8 Tarot Game: session initialization
Goffi <goffi@goffi.org>
parents: 89
diff changeset
155 chien = self.games[room_jid.userhost()]['chien'] = []
88
Goffi <goffi@goffi.org>
parents:
diff changeset
156 for i in range(4): #TODO: distribute according to real Tarot rules (3 by 3 counter-clockwise, 1 card at once to chien)
Goffi <goffi@goffi.org>
parents:
diff changeset
157 hand[players[i]] = deck[0:hand_size]
Goffi <goffi@goffi.org>
parents:
diff changeset
158 del deck[0:hand_size]
Goffi <goffi@goffi.org>
parents:
diff changeset
159 chien = deck[:]
Goffi <goffi@goffi.org>
parents:
diff changeset
160 del(deck[:])
Goffi <goffi@goffi.org>
parents:
diff changeset
161
Goffi <goffi@goffi.org>
parents:
diff changeset
162 for player in players:
90
4020931569b8 Tarot Game: session initialization
Goffi <goffi@goffi.org>
parents: 89
diff changeset
163 to_jid = jid.JID(room_jid.userhost()+"/"+player) #FIXME: gof:
4020931569b8 Tarot Game: session initialization
Goffi <goffi@goffi.org>
parents: 89
diff changeset
164 mess = self.createGameElt(to_jid)
4020931569b8 Tarot Game: session initialization
Goffi <goffi@goffi.org>
parents: 89
diff changeset
165 mess.firstChildElement().addChild(self.__hand_to_xml(hand[player]))
4020931569b8 Tarot Game: session initialization
Goffi <goffi@goffi.org>
parents: 89
diff changeset
166 self.host.profiles[profile].xmlstream.send(mess)
4020931569b8 Tarot Game: session initialization
Goffi <goffi@goffi.org>
parents: 89
diff changeset
167
4020931569b8 Tarot Game: session initialization
Goffi <goffi@goffi.org>
parents: 89
diff changeset
168
4020931569b8 Tarot Game: session initialization
Goffi <goffi@goffi.org>
parents: 89
diff changeset
169 def card_game_cmd(self, mess_elt, profile):
4020931569b8 Tarot Game: session initialization
Goffi <goffi@goffi.org>
parents: 89
diff changeset
170 print "\n\nCARD GAME command received (profile=%s): %s" % (profile, mess_elt.toXml())
4020931569b8 Tarot Game: session initialization
Goffi <goffi@goffi.org>
parents: 89
diff changeset
171 room_jid = jid.JID(mess_elt['from'])
4020931569b8 Tarot Game: session initialization
Goffi <goffi@goffi.org>
parents: 89
diff changeset
172 game_elt = mess_elt.firstChildElement()
4020931569b8 Tarot Game: session initialization
Goffi <goffi@goffi.org>
parents: 89
diff changeset
173 for elt in game_elt.elements(): #new game created
4020931569b8 Tarot Game: session initialization
Goffi <goffi@goffi.org>
parents: 89
diff changeset
174 if elt.name == 'started':
4020931569b8 Tarot Game: session initialization
Goffi <goffi@goffi.org>
parents: 89
diff changeset
175 players = []
4020931569b8 Tarot Game: session initialization
Goffi <goffi@goffi.org>
parents: 89
diff changeset
176 for player in elt.elements():
4020931569b8 Tarot Game: session initialization
Goffi <goffi@goffi.org>
parents: 89
diff changeset
177 players.append(unicode(player))
4020931569b8 Tarot Game: session initialization
Goffi <goffi@goffi.org>
parents: 89
diff changeset
178 self.host.bridge.tarotGameStarted(room_jid.userhost(), room_jid.full(), players, profile)
4020931569b8 Tarot Game: session initialization
Goffi <goffi@goffi.org>
parents: 89
diff changeset
179 elif elt.name == 'player_ready':
4020931569b8 Tarot Game: session initialization
Goffi <goffi@goffi.org>
parents: 89
diff changeset
180 player = unicode(elt)
4020931569b8 Tarot Game: session initialization
Goffi <goffi@goffi.org>
parents: 89
diff changeset
181 status = self.games[room_jid.userhost()]['status']
4020931569b8 Tarot Game: session initialization
Goffi <goffi@goffi.org>
parents: 89
diff changeset
182 nb_players = len(self.games[room_jid.userhost()]['players'])
4020931569b8 Tarot Game: session initialization
Goffi <goffi@goffi.org>
parents: 89
diff changeset
183 status[player] = 'ready'
4020931569b8 Tarot Game: session initialization
Goffi <goffi@goffi.org>
parents: 89
diff changeset
184 debug (_('Player %(player)s is ready to start [status: %(status)s]') % {'player':player, 'status':status})
4020931569b8 Tarot Game: session initialization
Goffi <goffi@goffi.org>
parents: 89
diff changeset
185 if status.values().count('ready') == 2: #gof: nb_players: #everybody is ready, we can start the game
4020931569b8 Tarot Game: session initialization
Goffi <goffi@goffi.org>
parents: 89
diff changeset
186 self.newGame(room_jid)
88
Goffi <goffi@goffi.org>
parents:
diff changeset
187
90
4020931569b8 Tarot Game: session initialization
Goffi <goffi@goffi.org>
parents: 89
diff changeset
188 elif elt.name == 'hand': #a new hand has been received
4020931569b8 Tarot Game: session initialization
Goffi <goffi@goffi.org>
parents: 89
diff changeset
189 self.host.bridge.tarotGameNew(room_jid.userhost(), self.__xml_to_hand(elt), profile)
4020931569b8 Tarot Game: session initialization
Goffi <goffi@goffi.org>
parents: 89
diff changeset
190
4020931569b8 Tarot Game: session initialization
Goffi <goffi@goffi.org>
parents: 89
diff changeset
191
4020931569b8 Tarot Game: session initialization
Goffi <goffi@goffi.org>
parents: 89
diff changeset
192 def getHandler(self, profile):
4020931569b8 Tarot Game: session initialization
Goffi <goffi@goffi.org>
parents: 89
diff changeset
193 return CardGameHandler(self)
4020931569b8 Tarot Game: session initialization
Goffi <goffi@goffi.org>
parents: 89
diff changeset
194
4020931569b8 Tarot Game: session initialization
Goffi <goffi@goffi.org>
parents: 89
diff changeset
195
88
Goffi <goffi@goffi.org>
parents:
diff changeset
196
90
4020931569b8 Tarot Game: session initialization
Goffi <goffi@goffi.org>
parents: 89
diff changeset
197 class CardGameHandler (XMPPHandler):
4020931569b8 Tarot Game: session initialization
Goffi <goffi@goffi.org>
parents: 89
diff changeset
198 implements(iwokkel.IDisco)
4020931569b8 Tarot Game: session initialization
Goffi <goffi@goffi.org>
parents: 89
diff changeset
199
4020931569b8 Tarot Game: session initialization
Goffi <goffi@goffi.org>
parents: 89
diff changeset
200 def __init__(self, plugin_parent):
4020931569b8 Tarot Game: session initialization
Goffi <goffi@goffi.org>
parents: 89
diff changeset
201 self.plugin_parent = plugin_parent
4020931569b8 Tarot Game: session initialization
Goffi <goffi@goffi.org>
parents: 89
diff changeset
202 self.host = plugin_parent.host
4020931569b8 Tarot Game: session initialization
Goffi <goffi@goffi.org>
parents: 89
diff changeset
203
4020931569b8 Tarot Game: session initialization
Goffi <goffi@goffi.org>
parents: 89
diff changeset
204 def connectionInitialized(self):
4020931569b8 Tarot Game: session initialization
Goffi <goffi@goffi.org>
parents: 89
diff changeset
205 print "gof: ajout d'observer", CG_REQUEST
4020931569b8 Tarot Game: session initialization
Goffi <goffi@goffi.org>
parents: 89
diff changeset
206 self.xmlstream.addObserver(CG_REQUEST, self.plugin_parent.card_game_cmd, profile = self.parent.profile)
4020931569b8 Tarot Game: session initialization
Goffi <goffi@goffi.org>
parents: 89
diff changeset
207
4020931569b8 Tarot Game: session initialization
Goffi <goffi@goffi.org>
parents: 89
diff changeset
208 def getDiscoInfo(self, requestor, target, nodeIdentifier=''):
4020931569b8 Tarot Game: session initialization
Goffi <goffi@goffi.org>
parents: 89
diff changeset
209 return [disco.DiscoFeature(NS_CB)]
4020931569b8 Tarot Game: session initialization
Goffi <goffi@goffi.org>
parents: 89
diff changeset
210
4020931569b8 Tarot Game: session initialization
Goffi <goffi@goffi.org>
parents: 89
diff changeset
211 def getDiscoItems(self, requestor, target, nodeIdentifier=''):
4020931569b8 Tarot Game: session initialization
Goffi <goffi@goffi.org>
parents: 89
diff changeset
212 return []
4020931569b8 Tarot Game: session initialization
Goffi <goffi@goffi.org>
parents: 89
diff changeset
213