Mercurial > libervia-backend
changeset 826:71f8e996f765
plugins radiocol_tarot: do not process received messages for MUC users that are actually not playing the game + fix for testing purpose
author | souliane <souliane@mailoo.org> |
---|---|
date | Wed, 15 Jan 2014 23:09:39 +0100 |
parents | e3f4d80f987d |
children | 215a2cb15e2d |
files | src/plugins/plugin_misc_radiocol.py src/plugins/plugin_misc_tarot.py |
diffstat | 2 files changed, 20 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/src/plugins/plugin_misc_radiocol.py Wed Jan 15 23:01:23 2014 +0100 +++ b/src/plugins/plugin_misc_radiocol.py Wed Jan 15 23:09:39 2014 +0100 @@ -111,7 +111,14 @@ } radio_data = self.games[jid.JID(referee).userhost()] # FIXME: referee comes from Libervia's client side, it's unsecure radio_data['to_delete'][attrs['filename']] = song_path # FIXME: works only because of the same host trick, see the note under the docstring - return threads.deferToThread(self.send, jid.JID(referee), ('', 'song_added'), attrs, profile=profile) + + # XXX: avoid deferToThread which is causing testing troubles. When using deferToThread, + # the callbacks that are added (by the test) to the Deferred instance returned by this + # method are not run. And if you run d.callback again, you get a AlreadyCalledError. + d = defer.Deferred() + d.addCallback(self.send, ('', 'song_added'), attrs, profile=profile) + d.callback(jid.JID(referee)) + return d def playNext(self, room_jid, profile): """"Play next song in queue if exists, and put a timer @@ -130,7 +137,6 @@ #nothing left to play, we need to wait for uploads radio_data['playing'] = False return - song = queue.pop(0) filename, length = song['filename'], float(song['length']) self.send(room_jid, ('', 'play'), {'filename': filename}, profile=profile) @@ -169,6 +175,8 @@ def room_game_cmd(self, mess_elt, profile): from_jid = jid.JID(mess_elt['from']) room_jid = jid.JID(from_jid.userhost()) + nick = self.host.plugins["XEP-0045"].getRoomNick(room_jid.userhost(), profile) + radio_elt = mess_elt.firstChildElement() radio_data = self.games[room_jid.userhost()] if 'queue' in radio_data: @@ -176,11 +184,14 @@ from_referee = self.isReferee(room_jid.userhost(), from_jid.resource) to_referee = self.isReferee(room_jid.userhost(), jid.JID(mess_elt['to']).user) + is_player = self.isPlayer(room_jid.userhost(), nick) for elt in radio_elt.elements(): if not from_referee and not (to_referee and elt.name == 'song_added'): continue # sender must be referee, expect when a song is submitted + if not is_player and (elt.name not in ('started', 'players')): + continue # user is in the room but not playing - if elt.name == 'started' or elt.name == 'players': # new game created + if elt.name in ('started', 'players'): # new game created and/or players list updated players = [] for player in elt.elements(): players.append(unicode(player)) @@ -199,7 +210,6 @@ elif elt.name == 'song_added': # a song has been added #FIXME: we are KISS for the proof of concept: every song is added, to a limit of 3 in queue. # Need to manage some sort of rules to allow peoples to send songs - if len(queue) >= QUEUE_LIMIT: #there are already too many songs in queue, we reject this one #FIXME: add an error code
--- a/src/plugins/plugin_misc_tarot.py Wed Jan 15 23:01:23 2014 +0100 +++ b/src/plugins/plugin_misc_tarot.py Wed Jan 15 23:09:39 2014 +0100 @@ -447,14 +447,19 @@ """ from_jid = jid.JID(mess_elt['from']) room_jid = jid.JID(from_jid.userhost()) + nick = self.host.plugins["XEP-0045"].getRoomNick(room_jid.userhost(), profile) + game_elt = mess_elt.firstChildElement() game_data = self.games[room_jid.userhost()] + is_player = self.isPlayer(room_jid.userhost(), nick) if 'players_data' in game_data: players_data = game_data['players_data'] for elt in game_elt.elements(): + if not is_player and (elt.name not in ('started', 'players')): + continue # user is in the room but not playing - if elt.name == 'started' or elt.name == 'players': # new game created + if elt.name in ('started', 'players'): # new game created and/or players list updated players = [] for player in elt.elements(): players.append(unicode(player))