plugins (games): more factorization and flexibility for launching and joining games:

- "MUC user joined", "MUC user left" and class XMPPHandler are managed directly in RoomGame
- renamed __init__ parameters 'player_init_data' to 'player_init' and 'options' to 'game_init'
- pass the players list in radiocol method 'createGame' and signal 'radiocolStarted' (needed for invitation system and for UI players identification)
- added some parameters to manage who can invite, who can join, who to wait for... managed with check***Auth methods
- joining a game that is already launched may be possible, regarding these parameters and the invitation list
- leave and join a game again is partly managed: new tarot round is launched, we should keep playing the same round instead
This commit is contained in:
souliane 2013-11-21 15:49:53 +01:00
commit ea67ed7a61

View file

@ -25,23 +25,15 @@ from twisted.words.protocols.jabber import error as jab_error
from twisted.words.protocols.jabber.xmlstream import IQ
import random
from zope.interface import implements
from wokkel import disco, iwokkel, data_form
from wokkel import data_form
from sat.tools.xml_tools import dataForm2XML
from sat.tools.frontends.games import TarotCard
from sat.tools.plugins.games import RoomGame
from time import time
try:
from twisted.words.protocols.xmlstream import XMPPHandler
except ImportError:
from wokkel.subprotocols import XMPPHandler
MESSAGE = '/message'
NS_QG = 'http://www.goffi.org/protocol/quiz'
QG_TAG = 'quiz'
QG_REQUEST = MESSAGE + '/' + QG_TAG + '[@xmlns="' + NS_QG + '"]'
PLUGIN_INFO = {
"name": "Quiz game plugin",
@ -59,8 +51,7 @@ class Quiz(RoomGame):
def __init__(self, host):
info(_("Plugin Quiz initialization"))
RoomGame.__init__(self, host, PLUGIN_INFO, (NS_QG, QG_TAG), player_init_data={'score': 0},
options={'stage': None})
RoomGame.__init__(self, host, PLUGIN_INFO, (NS_QG, QG_TAG), game_init={'stage': None}, player_init={'score': 0})
host.bridge.addMethod("quizGameLaunch", ".plugin", in_sign='asss', out_sign='', method=self.prepareRoom) # args: players, room_jid, profile
host.bridge.addMethod("quizGameCreate", ".plugin", in_sign='sass', out_sign='', method=self.createGame) # args: room_jid, players, profile
host.bridge.addMethod("quizGameReady", ".plugin", in_sign='sss', out_sign='', method=self.playerReady) # args: player, referee, profile
@ -114,7 +105,6 @@ class Quiz(RoomGame):
'param_0': "room_jid: jid of game's room",
'param_1': "time_left: time left before timer expiration",
'param_2': '%(doc_profile)s'})
host.trigger.add("MUC user joined", self.userJoinedTrigger)
def __game_data_to_xml(self, game_data):
"""Convert a game data dict to domish element"""
@ -264,12 +254,13 @@ Attention, tu es prêt ?""")}
RoomGame.newRound(self, room_jid, (common_data, msg_elts), profile)
reactor.callLater(10, self.askQuestion, room_jid, profile)
def quiz_game_cmd(self, mess_elt, profile):
def room_game_cmd(self, mess_elt, profile):
from_jid = jid.JID(mess_elt['from'])
room_jid = jid.JID(from_jid.userhost())
game_elt = mess_elt.firstChildElement()
game_data = self.games[room_jid.userhost()]
players_data = game_data['players_data']
if 'players_data' in game_data:
players_data = game_data['players_data']
for elt in game_elt.elements():
@ -333,23 +324,3 @@ Attention, tu es prêt ?""")}
else:
error(_('Unmanaged game element: %s') % elt.name)
def getHandler(self, profile):
return QuizGameHandler(self)
class QuizGameHandler (XMPPHandler):
implements(iwokkel.IDisco)
def __init__(self, plugin_parent):
self.plugin_parent = plugin_parent
self.host = plugin_parent.host
def connectionInitialized(self):
self.xmlstream.addObserver(QG_REQUEST, self.plugin_parent.quiz_game_cmd, profile=self.parent.profile)
def getDiscoInfo(self, requestor, target, nodeIdentifier=''):
return [disco.DiscoFeature(NS_QG)]
def getDiscoItems(self, requestor, target, nodeIdentifier=''):
return []