comparison src/plugins/plugin_misc_room_game.py @ 916:1a759096ccbd

core: use of Const for profile_key + replaced '@DEFAULT@' default profile_key by '@NONE@'
author Goffi <goffi@goffi.org>
date Fri, 21 Mar 2014 16:27:09 +0100
parents 386ab96af575
children c6d8fc63b1db
comparison
equal deleted inserted replaced
915:6f96ee4d8cc0 916:1a759096ccbd
16 16
17 # You should have received a copy of the GNU Affero General Public License 17 # You should have received a copy of the GNU Affero General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. 18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 19
20 from sat.core.i18n import _ 20 from sat.core.i18n import _
21 from sat.core.constants import Const as C
21 from logging import debug, warning, error 22 from logging import debug, warning, error
22 from twisted.words.protocols.jabber.jid import JID 23 from twisted.words.protocols.jabber.jid import JID
23 from twisted.words.xish import domish 24 from twisted.words.xish import domish
24 from twisted.internet import defer 25 from twisted.internet import defer
25 from time import time 26 from time import time
380 result = (len(nicks) == len(other_players), nicks, missing) 381 result = (len(nicks) == len(other_players), nicks, missing)
381 if not result[0] and (verbose or _DEBUG): 382 if not result[0] and (verbose or _DEBUG):
382 debug(_("Still waiting for %(users)s before starting the game %(game)s in %(room)s") % {'users': result[2], 'game': self.name, 'room': room.occupantJID.userhost()}) 383 debug(_("Still waiting for %(users)s before starting the game %(game)s in %(room)s") % {'users': result[2], 'game': self.name, 'room': room.occupantJID.userhost()})
383 return result 384 return result
384 385
385 def getUniqueName(self, muc_service="", profile_key='@DEFAULT@'): 386 def getUniqueName(self, muc_service="", profile_key=C.PROF_KEY_NONE):
386 """ 387 """
387 @param muc_service: you can leave empty to autofind the muc service 388 @param muc_service: you can leave empty to autofind the muc service
388 @param profile_key 389 @param profile_key
389 @return: a unique name for a new room to be created 390 @return: a unique name for a new room to be created
390 """ 391 """
391 room = self.host.plugins["XEP-0045"].getUniqueName(muc_service, profile_key=profile_key) 392 room = self.host.plugins["XEP-0045"].getUniqueName(muc_service, profile_key=profile_key)
392 return "sat_%s_%s" % (self.name.lower(), room) if room != "" else "" 393 return "sat_%s_%s" % (self.name.lower(), room) if room != "" else ""
393 394
394 def prepareRoom(self, other_players=None, room_jid_s=None, profile_key='@NONE@'): 395 def prepareRoom(self, other_players=None, room_jid_s=None, profile_key=C.PROF_KEY_NONE):
395 """Prepare the room for a game: create it if it doesn't exist and invite players. 396 """Prepare the room for a game: create it if it doesn't exist and invite players.
396 @param other_players: list for other players JID userhosts 397 @param other_players: list for other players JID userhosts
397 @param room_jid_s: JID userhost of the room, or None to generate a unique name 398 @param room_jid_s: JID userhost of the room, or None to generate a unique name
398 @param profile_key 399 @param profile_key
399 """ 400 """
515 return False, False 516 return False, False
516 else: 517 else:
517 self._initGame(room_jid_s, user_nick) 518 self._initGame(room_jid_s, user_nick)
518 return True, False 519 return True, False
519 520
520 def createGame(self, room_jid_s, nicks=None, profile_key='@NONE@'): 521 def createGame(self, room_jid_s, nicks=None, profile_key=C.PROF_KEY_NONE):
521 """Create a new game - this can be called directly from a frontend 522 """Create a new game - this can be called directly from a frontend
522 and skips all the checks and invitation system, but the game must 523 and skips all the checks and invitation system, but the game must
523 not exist and all the players must be in the room already. 524 not exist and all the players must be in the room already.
524 @param room_jid: JID userhost of the room 525 @param room_jid: JID userhost of the room
525 @param nicks: list of players nicks in the room (referee included, in first position) 526 @param nicks: list of players nicks in the room (referee included, in first position)
543 self.games[room_jid_s].setdefault('players_data', {}) 544 self.games[room_jid_s].setdefault('players_data', {})
544 for nick in nicks: 545 for nick in nicks:
545 # The dict must be COPIED otherwise it is shared between all users 546 # The dict must be COPIED otherwise it is shared between all users
546 self.games[room_jid_s]['players_data'][nick] = copy.deepcopy(self.player_init) 547 self.games[room_jid_s]['players_data'][nick] = copy.deepcopy(self.player_init)
547 548
548 def playerReady(self, player, referee, profile_key='@NONE@'): 549 def playerReady(self, player, referee, profile_key=C.PROF_KEY_NONE):
549 """Must be called when player is ready to start a new game 550 """Must be called when player is ready to start a new game
550 @param player: the player nick in the room 551 @param player: the player nick in the room
551 @param referee: referee userhost 552 @param referee: referee userhost
552 """ 553 """
553 profile = self.host.memory.getProfileName(profile_key) 554 profile = self.host.memory.getProfileName(profile_key)