plugin room_game: fix issues with data structures initialization

This commit is contained in:
souliane 2014-02-26 02:13:29 +01:00
commit e8f6c14436

View file

@ -86,7 +86,7 @@ class RoomGame(object):
"""
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 @@ class RoomGame(object):
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 @@ class RoomGame(object):
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 @@ class RoomGame(object):
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 @@ class RoomGame(object):
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 @@ class RoomGame(object):
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 @@ class RoomGame(object):
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 @@ class RoomGame(object):
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 @@ class RoomGame(object):
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