Mercurial > libervia-backend
comparison src/plugins/plugin_misc_room_game.py @ 1409:3265a2639182
massive (preventive) addition of 'u' (unicode) before the strings passed to logging functions
author | souliane <souliane@mailoo.org> |
---|---|
date | Thu, 16 Apr 2015 14:57:57 +0200 |
parents | 069ad98b360d |
children | d17772b0fe22 |
comparison
equal
deleted
inserted
replaced
1408:8a7145138330 | 1409:3265a2639182 |
---|---|
203 if nick in [invited.user for invited in invitations[1]]: | 203 if nick in [invited.user for invited in invitations[1]]: |
204 auth = True | 204 auth = True |
205 break | 205 break |
206 | 206 |
207 if not auth and (verbose or _DEBUG): | 207 if not auth and (verbose or _DEBUG): |
208 log.debug(_("%(user)s not allowed to join the game %(game)s in %(room)s") % {'user': user_jid.userhost() or nick, 'game': self.name, 'room': room_jid.userhost()}) | 208 log.debug(_(u"%(user)s not allowed to join the game %(game)s in %(room)s") % {'user': user_jid.userhost() or nick, 'game': self.name, 'room': room_jid.userhost()}) |
209 return auth | 209 return auth |
210 | 210 |
211 def _updatePlayers(self, room_jid, nicks, sync, profile): | 211 def _updatePlayers(self, room_jid, nicks, sync, profile): |
212 """Update the list of players and signal to the room that some players joined the game. | 212 """Update the list of players and signal to the room that some players joined the game. |
213 If sync is True, the news players are synchronized with the game data they have missed. | 213 If sync is True, the news players are synchronized with the game data they have missed. |
339 elif self.invite_mode == self.FROM_REFEREE: | 339 elif self.invite_mode == self.FROM_REFEREE: |
340 auth = self.isReferee(room_jid, nick) | 340 auth = self.isReferee(room_jid, nick) |
341 elif self.invite_mode == self.FROM_PLAYERS: | 341 elif self.invite_mode == self.FROM_PLAYERS: |
342 auth = self.isPlayer(room_jid, nick) | 342 auth = self.isPlayer(room_jid, nick) |
343 if not auth and (verbose or _DEBUG): | 343 if not auth and (verbose or _DEBUG): |
344 log.debug(_("%(user)s not allowed to invite for the game %(game)s in %(room)s") % {'user': nick, 'game': self.name, 'room': room_jid.userhost()}) | 344 log.debug(_(u"%(user)s not allowed to invite for the game %(game)s in %(room)s") % {'user': nick, 'game': self.name, 'room': room_jid.userhost()}) |
345 return auth | 345 return auth |
346 | 346 |
347 def isReferee(self, room_jid, nick): | 347 def isReferee(self, room_jid, nick): |
348 """Checks if the player with this nick is the referee for the game in this room" | 348 """Checks if the player with this nick is the referee for the game in this room" |
349 @param room_jid (jid.JID): room JID | 349 @param room_jid (jid.JID): room JID |
385 else: | 385 else: |
386 # TODO: find a way to make it secure | 386 # TODO: find a way to make it secure |
387 (nicks, missing) = self.host.plugins["XEP-0045"].getRoomNicksOfUsers(room, other_players, secure=False) | 387 (nicks, missing) = self.host.plugins["XEP-0045"].getRoomNicksOfUsers(room, other_players, secure=False) |
388 result = (len(nicks) == len(other_players), nicks, missing) | 388 result = (len(nicks) == len(other_players), nicks, missing) |
389 if not result[0] and (verbose or _DEBUG): | 389 if not result[0] and (verbose or _DEBUG): |
390 log.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()}) | 390 log.debug(_(u"Still waiting for %(users)s before starting the game %(game)s in %(room)s") % {'users': result[2], 'game': self.name, 'room': room.occupantJID.userhost()}) |
391 return result | 391 return result |
392 | 392 |
393 def getUniqueName(self, muc_service=None, profile_key=C.PROF_KEY_NONE): | 393 def getUniqueName(self, muc_service=None, profile_key=C.PROF_KEY_NONE): |
394 """Generate unique room name | 394 """Generate unique room name |
395 | 395 |
411 | 411 |
412 @param other_players (list[JID]): list of other players JID (bare) | 412 @param other_players (list[JID]): list of other players JID (bare) |
413 @param room_jid (jid.JID): JID of the room, or None to generate a unique name | 413 @param room_jid (jid.JID): JID of the room, or None to generate a unique name |
414 @param profile_key (unicode): %(doc_profile_key)s | 414 @param profile_key (unicode): %(doc_profile_key)s |
415 """ | 415 """ |
416 log.debug(_('Preparing room for %s game') % self.name) | 416 log.debug(_(u'Preparing room for %s game') % self.name) |
417 profile = self.host.memory.getProfileName(profile_key) | 417 profile = self.host.memory.getProfileName(profile_key) |
418 if not profile: | 418 if not profile: |
419 log.error(_("Unknown profile")) | 419 log.error(_("Unknown profile")) |
420 return defer.succeed(None) | 420 return defer.succeed(None) |
421 if other_players is None: | 421 if other_players is None: |
454 return True | 454 return True |
455 if self.wait_mode == self.FOR_ALL: | 455 if self.wait_mode == self.FOR_ALL: |
456 # considering the last batch of invitations | 456 # considering the last batch of invitations |
457 batch = len(self.invitations[room_jid]) - 1 | 457 batch = len(self.invitations[room_jid]) - 1 |
458 if batch < 0: | 458 if batch < 0: |
459 log.error("Invitations from %s to play %s in %s have been lost!" % (profile_nick, self.name, room_jid.userhost())) | 459 log.error(u"Invitations from %s to play %s in %s have been lost!" % (profile_nick, self.name, room_jid.userhost())) |
460 return True | 460 return True |
461 other_players = self.invitations[room_jid][batch][1] | 461 other_players = self.invitations[room_jid][batch][1] |
462 (auth, nicks, dummy) = self._checkWaitAuth(room, other_players) | 462 (auth, nicks, dummy) = self._checkWaitAuth(room, other_players) |
463 if auth: | 463 if auth: |
464 del self.invitations[room_jid][batch] | 464 del self.invitations[room_jid][batch] |
508 - create: set to True to allow the game creation | 508 - create: set to True to allow the game creation |
509 - sync: set to True to advice a game synchronization | 509 - sync: set to True to advice a game synchronization |
510 """ | 510 """ |
511 user_nick = self.host.plugins["XEP-0045"].getRoomNick(room_jid, profile) | 511 user_nick = self.host.plugins["XEP-0045"].getRoomNick(room_jid, profile) |
512 if not user_nick: | 512 if not user_nick: |
513 log.error('Internal error: profile %s has not joined the room %s' % (profile, room_jid.userhost())) | 513 log.error(u'Internal error: profile %s has not joined the room %s' % (profile, room_jid.userhost())) |
514 return False, False | 514 return False, False |
515 if self._gameExists(room_jid): | 515 if self._gameExists(room_jid): |
516 is_referee = self.isReferee(room_jid, user_nick) | 516 is_referee = self.isReferee(room_jid, user_nick) |
517 if self._gameExists(room_jid, started=True): | 517 if self._gameExists(room_jid, started=True): |
518 log.warning(_("%(game)s game already created in room %(room)s") % {'game': self.name, 'room': room_jid.userhost()}) | 518 log.warning(_(u"%(game)s game already created in room %(room)s") % {'game': self.name, 'room': room_jid.userhost()}) |
519 return False, is_referee | 519 return False, is_referee |
520 elif not is_referee: | 520 elif not is_referee: |
521 log.warning(_("%(game)s game in room %(room)s can only be created by %(user)s") % {'game': self.name, 'room': room_jid.userhost(), 'user': user_nick}) | 521 log.warning(_(u"%(game)s game in room %(room)s can only be created by %(user)s") % {'game': self.name, 'room': room_jid.userhost(), 'user': user_nick}) |
522 return False, False | 522 return False, False |
523 else: | 523 else: |
524 self._initGame(room_jid, user_nick) | 524 self._initGame(room_jid, user_nick) |
525 return True, False | 525 return True, False |
526 | 526 |
534 but the game must not exist and all the players must be in the room already. | 534 but the game must not exist and all the players must be in the room already. |
535 @param room_jid (jid.JID): JID of the room | 535 @param room_jid (jid.JID): JID of the room |
536 @param nicks (list[unicode]): list of players nicks in the room (referee included, in first position) | 536 @param nicks (list[unicode]): list of players nicks in the room (referee included, in first position) |
537 @param profile_key (unicode): %(doc_profile_key)s | 537 @param profile_key (unicode): %(doc_profile_key)s |
538 """ | 538 """ |
539 log.debug(_("Creating %(game)s game in room %(room)s") % {'game': self.name, 'room': room_jid}) | 539 log.debug(_(u"Creating %(game)s game in room %(room)s") % {'game': self.name, 'room': room_jid}) |
540 profile = self.host.memory.getProfileName(profile_key) | 540 profile = self.host.memory.getProfileName(profile_key) |
541 if not profile: | 541 if not profile: |
542 log.error(_("profile %s is unknown") % profile_key) | 542 log.error(_(u"profile %s is unknown") % profile_key) |
543 return | 543 return |
544 (create, sync) = self._checkCreateGameAndInit(room_jid, profile) | 544 (create, sync) = self._checkCreateGameAndInit(room_jid, profile) |
545 if nicks is None: | 545 if nicks is None: |
546 nicks = [] | 546 nicks = [] |
547 if not create: | 547 if not create: |
566 @param player: the player nick in the room | 566 @param player: the player nick in the room |
567 @param referee_jid (jid.JID): JID of the referee | 567 @param referee_jid (jid.JID): JID of the referee |
568 """ | 568 """ |
569 profile = self.host.memory.getProfileName(profile_key) | 569 profile = self.host.memory.getProfileName(profile_key) |
570 if not profile: | 570 if not profile: |
571 log.error(_("profile %s is unknown") % profile_key) | 571 log.error(_(u"profile %s is unknown") % profile_key) |
572 return | 572 return |
573 log.debug('new player ready: %s' % profile) | 573 log.debug(u'new player ready: %s' % profile) |
574 # TODO: we probably need to add the game and room names in the sent message | 574 # TODO: we probably need to add the game and room names in the sent message |
575 self.send(referee_jid, 'player_ready', {'player': player_nick}, profile=profile) | 575 self.send(referee_jid, 'player_ready', {'player': player_nick}, profile=profile) |
576 | 576 |
577 def newRound(self, room_jid, data, profile): | 577 def newRound(self, room_jid, data, profile): |
578 """Launch a new round (reinit the user data) | 578 """Launch a new round (reinit the user data) |
581 @param data: a couple (common_data, msg_elts) with: | 581 @param data: a couple (common_data, msg_elts) with: |
582 - common_data: backend initialization data for the new round | 582 - common_data: backend initialization data for the new round |
583 - msg_elts: dict to map each user to his specific initialization message | 583 - msg_elts: dict to map each user to his specific initialization message |
584 @param profile | 584 @param profile |
585 """ | 585 """ |
586 log.debug(_('new round for %s game') % self.name) | 586 log.debug(_(u'new round for %s game') % self.name) |
587 game_data = self.games[room_jid] | 587 game_data = self.games[room_jid] |
588 players = game_data['players'] | 588 players = game_data['players'] |
589 players_data = game_data['players_data'] | 589 players_data = game_data['players_data'] |
590 game_data['stage'] = "init" | 590 game_data['stage'] = "init" |
591 | 591 |