# HG changeset patch # User souliane # Date 1393377209 -3600 # Node ID 386ab96af5751e1bd7091c8ed8dd3addad067c4e # Parent 65bf1bc70f6b820fd015a09343c5c61d269e7d75 plugin room_game: fix issues with data structures initialization diff -r 65bf1bc70f6b -r 386ab96af575 src/plugins/plugin_misc_room_game.py --- a/src/plugins/plugin_misc_room_game.py Tue Feb 25 22:58:42 2014 +0100 +++ b/src/plugins/plugin_misc_room_game.py Wed Feb 26 02:13:29 2014 +0100 @@ -86,7 +86,7 @@ """ self.host = host - def _init_(self, host, plugin_info, ns_tag, game_init={}, player_init={}): + def _init_(self, host, plugin_info, ns_tag, game_init=None, player_init=None): """ @param host @param plugin_info: PLUGIN_INFO map of the game plugin @@ -98,6 +98,10 @@ self.name = plugin_info["import_name"] self.ns_tag = ns_tag self.request = self.REQUEST % (self.MESSAGE, ns_tag[1], ns_tag[0]) + if game_init is None: + game_init = {} + if player_init is None: + player_init = {} self.game_init = game_init self.player_init = player_init self.games = {} @@ -257,7 +261,7 @@ for args, kwargs in sync_args: self._sendElements(*args, **kwargs) - def _getSyncData(self, room_jid_s, force_nicks=[]): + def _getSyncData(self, room_jid_s, force_nicks=None): """The synchronization data are returned for each player who has the state 'desync' or if he's been contained by force_nicks. @param room_jid_s: room userhost @@ -270,6 +274,8 @@ data = {} status = self.games[room_jid_s]['status'] nicks = [nick for nick in status if status[nick] == 'desync'] + if force_nicks is None: + force_nicks = [] for nick in force_nicks: if nick not in nicks: nicks.append(nick) @@ -385,7 +391,7 @@ room = self.host.plugins["XEP-0045"].getUniqueName(muc_service, profile_key=profile_key) return "sat_%s_%s" % (self.name.lower(), room) if room != "" else "" - def prepareRoom(self, other_players=[], room_jid_s=None, profile_key='@NONE@'): + def prepareRoom(self, other_players=None, room_jid_s=None, profile_key='@NONE@'): """Prepare the room for a game: create it if it doesn't exist and invite players. @param other_players: list for other players JID userhosts @param room_jid_s: JID userhost of the room, or None to generate a unique name @@ -396,6 +402,8 @@ if not profile: error(_("Unknown profile")) return + if other_players is None: + other_players = [] def roomJoined(room): """@param room: instance of wokkel.muc.Room""" @@ -509,7 +517,7 @@ self._initGame(room_jid_s, user_nick) return True, False - def createGame(self, room_jid_s, nicks=[], profile_key='@NONE@'): + def createGame(self, room_jid_s, nicks=None, profile_key='@NONE@'): """Create a new game - this can be called directly from a frontend and skips all the checks and invitation system, but the game must not exist and all the players must be in the room already. @@ -522,6 +530,8 @@ error(_("profile %s is unknown") % profile_key) return (create, sync) = self._checkCreateGameAndInit(room_jid_s, profile) + if nicks is None: + nicks = [] if not create: if sync: self._updatePlayers(room_jid_s, nicks, True, profile) @@ -573,7 +583,7 @@ self.send(room_jid, msg_elts, profile=profile) if common_data is not None: for player in players: - players_data[player].update(common_data) + players_data[player].update(copy.deepcopy(common_data)) def _createGameElt(self, to_jid): """Create a generic domish Element for the game messages