plugins radiocol_tarot: do not process received messages for MUC users that are actually not playing the game + fix for testing purpose
This commit is contained in:
parent
9e6845472d
commit
8b700a6d48
1 changed files with 20 additions and 5 deletions
|
|
@ -111,7 +111,14 @@ class Radiocol(object):
|
|||
}
|
||||
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 @@ class Radiocol(object):
|
|||
#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 @@ class Radiocol(object):
|
|||
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 @@ class Radiocol(object):
|
|||
|
||||
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 @@ class Radiocol(object):
|
|||
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
|
||||
|
|
|
|||
Loading…
Reference in a new issue