annotate src/plugins/plugin_misc_radiocol.py @ 452:fd455b3ca6d4

plugin XEP-0045: room unlocking fix
author Goffi <goffi@goffi.org>
date Sun, 22 Jan 2012 19:40:04 +0100
parents afe9cfd2ddbb
children 5731b038fc7f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
450
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
1 #!/usr/bin/python
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
2 # -*- coding: utf-8 -*-
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
3
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
4 """
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
5 SAT plugin for managing Radiocol
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
6 Copyright (C) 2009, 2010, 2011 Jérôme Poisson (goffi@goffi.org)
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
7
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
8 This program is free software: you can redistribute it and/or modify
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
9 it under the terms of the GNU General Public License as published by
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
10 the Free Software Foundation, either version 3 of the License, or
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
11 (at your option) any later version.
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
12
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
13 This program is distributed in the hope that it will be useful,
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
16 GNU General Public License for more details.
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
17
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
18 You should have received a copy of the GNU General Public License
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
20 """
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
21
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
22 from logging import debug, info, warning, error
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
23 from twisted.words.xish import domish
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
24 from twisted.internet import protocol, defer, threads, reactor
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
25 from twisted.words.protocols.jabber import client, jid, xmlstream
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
26 from twisted.words.protocols.jabber import error as jab_error
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
27 from twisted.words.protocols.jabber.xmlstream import IQ
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
28 import random
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
29
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
30 from zope.interface import implements
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
31
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
32 from wokkel import disco, iwokkel, data_form
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
33 from sat.tools.xml_tools import dataForm2xml
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
34 from sat.tools.games import TarotCard
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
35
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
36 from time import time
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
37
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
38 try:
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
39 from twisted.words.protocols.xmlstream import XMPPHandler
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
40 except ImportError:
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
41 from wokkel.subprotocols import XMPPHandler
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
42
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
43 MESSAGE = '/message'
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
44 NC_RADIOCOL = 'http://www.goffi.org/protocol/radiocol'
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
45 RADIOC_TAG = 'radiocol'
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
46 RADIOC_REQUEST = MESSAGE + '/' + RADIOC_TAG + '[@xmlns="' + NC_RADIOCOL + '"]'
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
47
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
48 PLUGIN_INFO = {
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
49 "name": "Radio collective plugin",
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
50 "import_name": "Radiocol",
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
51 "type": "Exp",
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
52 "protocols": [],
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
53 "dependencies": ["XEP-0045", "XEP-0249"],
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
54 "main": "Radiocol",
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
55 "handler": "yes",
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
56 "description": _("""Implementation of radio collective""")
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
57 }
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
58
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
59
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
60 class Radiocol():
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
61
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
62 def __init__(self, host):
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
63 info(_("Radio collective initialization"))
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
64 self.host = host
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
65 self.radios={}
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
66 host.bridge.addMethod("radiocolLaunch", ".plugin", in_sign='ass', out_sign='', method=self.radiocolLaunch) #args: occupants, profile
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
67 host.bridge.addMethod("radiocolCreate", ".plugin", in_sign='ss', out_sign='', method=self.radiocolCreate) #args: room_jid, profile
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
68 host.bridge.addSignal("radiocolStarted", ".plugin", signature='ssass') #args: room_jid, referee, occupants, profile
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
69 host.trigger.add("MUC user joined", self.userJoinedTrigger)
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
70
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
71 def createRadiocolElt(self, to_jid, type="normal"):
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
72 type = "normal" if to_jid.resource else "groupchat"
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
73 elt = domish.Element(('jabber:client','message'))
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
74 elt["to"] = to_jid.full()
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
75 elt["type"] = type
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
76 elt.addElement((NC_RADIOCOL, RADIOC_TAG))
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
77 return elt
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
78
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
79 def __create_started_elt(self):
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
80 """Create a game_started domish element"""
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
81 started_elt = domish.Element(('','started'))
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
82 return started_elt
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
83
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
84 def userJoinedTrigger(self, room, user, profile):
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
85 """This trigger is used to check if we are waiting people in this room,
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
86 and to create a game if everybody is here"""
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
87 room_jid = room.occupantJID.userhostJID()
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
88 if self.radios.has_key(room_jid):
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
89 #we are in a radiocol room, let's start the party !
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
90 mess = self.createRadiocolElt(jid.JID(room_jid.userhost()+'/'+occupant))
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
91 mess.firstChildElement().addChild(self.__create_started_elt())
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
92 self.host.profiles[profile].xmlstream.send(mess)
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
93 return True
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
94
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
95 def radiocolLaunch(self, occupants, profile_key='@DEFAULT@'):
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
96 """Launch a game: helper method to create a room, invite occupants, and create the radiocol
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
97 @param occupants: list for occupants jid"""
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
98 debug(_('Launching radiocol'))
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
99 profile = self.host.memory.getProfileName(profile_key)
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
100 if not profile:
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
101 error(_("Unknown profile"))
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
102 return
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
103
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
104 def radiocolRoomJoined(room):
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
105 print "radiocolRoomJoined"
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
106 _room_jid = room.occupantJID.userhostJID()
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
107 for occupant in occupants:
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
108 self.host.plugins["XEP-0249"].invite(jid.JID(occupant), room.occupantJID.userhostJID(), {"game":"Radiocol"}, profile)
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
109 self.radiocolCreate(_room_jid.userhost(), profile_key=profile)
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
110
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
111 def after_init(ignore):
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
112 room_name = "sat_radiocol_%s" % self.host.plugins["XEP-0045"].getUniqueName(profile_key)
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
113 print "\n\n===> room_name:", room_name
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
114 muc_service = None
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
115 for service in self.host.memory.getServerServiceEntities("conference", "text", profile):
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
116 if not ".irc." in service.userhost():
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
117 #FIXME:
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
118 #This awfull ugly hack is here to avoid an issue with openfire: the irc gateway
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
119 #use "conference/text" identity (instead of "conference/irc"), there is certainly a better way
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
120 #to manage this, but this hack fill do it for test purpose
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
121 muc_service = service
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
122 break
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
123 if not muc_service:
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
124 error(_("Can't find a MUC service"))
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
125 return
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
126
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
127 _jid, xmlstream = self.host.getJidNStream(profile)
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
128 d = self.host.plugins["XEP-0045"].join(jid.JID("%s@%s" % (room_name, muc_service.userhost())), _jid.user, {}, profile)
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
129 d.addCallback(radiocolRoomJoined)
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
130
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
131 client = self.host.getClient(profile)
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
132 if not client:
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
133 error(_('No client for this profile key: %s') % profile_key)
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
134 return
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
135 client.client_initialized.addCallback(after_init)
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
136
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
137 def radiocolCreate(self, room_jid_param, profile_key='@DEFAULT@'):
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
138 """Create a new game
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
139 @param room_jid_param: jid of the room
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
140 @param profile_key: %(doc_profile_key)s"""
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
141 debug (_("Creating Radiocol"))
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
142 room_jid = jid.JID(room_jid_param)
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
143 profile = self.host.memory.getProfileName(profile_key)
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
144 if not profile:
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
145 error (_("profile %s is unknown") % profile_key)
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
146 return
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
147 if self.radios.has_key(room_jid):
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
148 warning (_("Radiocol already started in room %s") % room_jid.userhost())
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
149 else:
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
150 room_nick = self.host.plugins["XEP-0045"].getRoomNick(room_jid.userhost(), profile)
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
151 if not room_nick:
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
152 error ('Internal error')
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
153 return
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
154 referee = room_jid.userhost() + '/' + room_nick
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
155 status = {}
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
156 occupants_data = {}
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
157 self.radios[room_jid.userhost()] = {'referee':referee, 'occupants_data':occupants_data}
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
158 mess = self.createRadiocolElt(jid.JID(room_jid.userhost()))
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
159 mess.firstChildElement().addChild(self.__create_started_elt())
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
160 self.host.profiles[profile].xmlstream.send(mess)
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
161
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
162 def radiocol_game_cmd(self, mess_elt, profile):
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
163 from_jid = jid.JID(mess_elt['from'])
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
164 room_jid = jid.JID(from_jid.userhost())
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
165 radio_elt = mess_elt.firstChildElement()
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
166 radio_data = self.radios[room_jid.userhost()]
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
167 occupants_data = radio_data['occupants_data']
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
168
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
169 for elt in radio_elt.elements():
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
170
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
171 if elt.name == 'started': #new game created
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
172 self.host.bridge.radiocolStarted(room_jid.userhost(), from_jid.full(), [], profile) #FIXME: add occupants list here ?
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
173 else:
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
174 error (_('Unmanaged game element: %s') % elt.name)
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
175
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
176 def getHandler(self, profile):
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
177 return RadiocolHandler(self)
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
178
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
179 class RadiocolHandler (XMPPHandler):
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
180 implements(iwokkel.IDisco)
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
181
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
182 def __init__(self, plugin_parent):
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
183 self.plugin_parent = plugin_parent
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
184 self.host = plugin_parent.host
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
185
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
186 def connectionInitialized(self):
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
187 self.xmlstream.addObserver(RADIOC_REQUEST, self.plugin_parent.radiocol_game_cmd, profile = self.parent.profile)
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
188
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
189 def getDiscoInfo(self, requestor, target, nodeIdentifier=''):
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
190 return [disco.DiscoFeature(NC_RADIOCOL)]
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
191
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
192 def getDiscoItems(self, requestor, target, nodeIdentifier=''):
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
193 return []
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
194