Mercurial > libervia-backend
changeset 711:c9792d0be499
plugins (tools): collective games (with no opponent, like radiocol) were handled like other games
author | souliane <souliane@mailoo.org> |
---|---|
date | Sun, 17 Nov 2013 16:30:46 +0100 (2013-11-17) |
parents | 3344f1d8a232 |
children | f610864eb7a5 |
files | src/tools/plugins/games.py |
diffstat | 1 files changed, 13 insertions(+), 13 deletions(-) [+] |
line wrap: on
line diff
--- a/src/tools/plugins/games.py Sun Nov 17 16:23:29 2013 +0100 +++ b/src/tools/plugins/games.py Sun Nov 17 16:30:46 2013 +0100 @@ -30,7 +30,8 @@ def __init__(self, host, plugin_info, ns_tag, player_init_data={}, options={}): """ @param host - @param name: the name of this name + @param plugin_info: PLUGIN_INFO map of the game plugin + @ns_tag: couple (nameservice, tag) to construct the messages @param player_init_data: dictionary for initialization data, applicable to each player @param options: dictionary for game options """ @@ -38,14 +39,11 @@ self.name = plugin_info["import_name"] self.ns_tag = ns_tag self.player_init_data = player_init_data - self.collectiveGame = self.player_init_data is {} + self.collectiveGame = self.player_init_data == {} self.options = options self.games = {} self.waiting_inv = {} # Invitation waiting for people to join to launch a game - # args: room_jid, referee, players, profile - host.bridge.addSignal("%sGo" % self.name, ".plugin", signature='ssass') - def prepareRoom(self, other_players, profile_key='@NONE@'): """Prepare the room for a game: create it and invite players. @param other_players: list for other players JID userhosts @@ -62,9 +60,10 @@ players.append(_jid.userhost()) def roomJoined(room): + """@param room: instance of wokkel.muc.Room""" _room = room.occupantJID.userhostJID() if self.collectiveGame is True or other_players == [] and _jid in [user.entity for user in room.roster.values()]: - self.createGame(_room.userhost(), None if self.collectiveGame is True else players, profile_key=profile) + self.createGame(_room.userhost(), [] if self.collectiveGame is True else players, profile_key=profile) else: self.waiting_inv[_room] = (time(), players) # TODO: remove invitation waiting for too long, using the time data for player in other_players: @@ -103,9 +102,10 @@ """ _room_jid = room.occupantJID.userhostJID() if self.collectiveGame is True: - if _room_jid in self.games and self.games[_room_jid]["referee"] == room.occupantJID.full(): + room_s = _room_jid.userhost() + if room_s in self.games and self.games[room_s]["referee"] == room.occupantJID.full(): #we are in a radiocol room, let's start the party ! - mess = self.createGameElt(JID(_room_jid + '/' + user.nick)) + mess = self.createGameElt(JID(room_s + '/' + user.nick)) mess.firstChildElement().addChild(self.__create_started_elt()) self.host.profiles[profile].xmlstream.send(mess) return True @@ -131,7 +131,7 @@ self.createGame(_room_jid.userhost(), players, profile_key=profile) return True - def createGame(self, room_jid, players=None, profile_key='@NONE@'): + def createGame(self, room_jid, players=[], profile_key='@NONE@'): """Create a new game @param room_jid: jid of the room @param players: list of players nick (nick must exist in the room) @@ -142,14 +142,14 @@ if not profile: error(_("profile %s is unknown") % profile_key) return - if room in self.games: - warning(_("%s game already started in room %s") % (self.name, room)) - return room_nick = self.host.plugins["XEP-0045"].getRoomNick(room, profile) if not room_nick: error('Internal error') return referee = room + '/' + room_nick + if room in self.games: + warning(_("%s game already started in room %s") % (self.name, room)) + return self.games[room] = {'referee': referee} self.games[room].update(self.options) if self.collectiveGame is True: @@ -172,7 +172,7 @@ self.games[room].update({'players': players, 'status': status, 'players_data': players_data}) def createCollectiveGame(self, room_jid, profile_key='@NONE@'): - return self.createGame(self, room_jid, players=None, profile_key=profile_key) + return self.createGame(self, room_jid, players=[], profile_key=profile_key) def playerReady(self, player, referee, profile_key='@NONE@'): """Must be called when player is ready to start a new game"""