Exemplo n.º 1
0
 def cmd_newgame_player(self, tag, args):
     if len(args) < 2:
         raise IllegalCommand(_("Insufficient arguments."))
     else:
         name = args[0]
         if GameRegistry.registry.hasGame(name):
             raise DeniedCommand(_("That game name is already in use."))
         else:
             try:
                 g = Game(name, args[1])
                 self.sendOk(tag)
                 g.addPlayer(self._username)
                 GameRegistry.registry.addGame(g)
                 self._state = "joined"
                 GameRegistry.registry.removeUnjoinedUser(self._username)
                 log.msg(
                     util.printable(
                         _("New game \"%(gamename)s\" created by player \"%(playername)s\""
                           ) % {
                               "gamename": name,
                               "playername": self._username
                           }))
                 for p in GameRegistry.registry.getUnjoinedUsers():
                     GameRegistry.registry.getClient(p).sendUntagged(
                         "gameinfo", g.getName(), g.getStatus(),
                         g.getType(), str(g.getNumPlayers()))
             except GameError as e:
                 raise DeniedCommand(_(e.ustr()))
Exemplo n.º 2
0
 def removeGame(self, game):
     if game.getName() in self._games:
         del self._games[game.getName()]
         log.msg(
             util.printable(
                 _("Removed game \"%(gamename)s\"") %
                 {"gamename": game.getName()}))
Exemplo n.º 3
0
 def purgeExpiredGames(self):
     if self._expiration != None:
         log.msg(util.printable(_("Purging expired games")))
         games = list(self._games.values())
         for game in games:
             if (time.time() - game._startTime) / 3600 > self._expiration:
                 self.purgeGame(game)
Exemplo n.º 4
0
 def purgeBotGames(self):
     # purge any games that have bots
     log.msg(util.printable(_("Purging games involving AI clients")))
     games = list(self._games.values())
     for game in games:
         for player in game.getPlayers():
             if player[-5:] == '[bot]':
                 self.purgeGame(game)
                 break
Exemplo n.º 5
0
 def connectionLost(self, reason):
     if self._game is not None:
         self._game.removePlayer(self._username)
         # number of players in this game needs to be updated
         for p in GameRegistry.registry.getUnjoinedUsers():
             GameRegistry.registry.getClient(p).sendUntagged(
                 "gameinfo", self._game.getName(), self._game.getStatus(),
                 self._game.getType(), str(self._game.getNumPlayers()))
         # kill the game if this was the last player
         self.testRemoveGame(self._game)
     if self._username is not None:
         GameRegistry.registry.removeClient(self)
         GameRegistry.registry.removeUnjoinedUser(self._username)
         log.msg(
             util.printable(
                 _("Connection lost to player \"%(playername)s\"") %
                 {"playername": self._username}))
Exemplo n.º 6
0
 def cmd_requestai_joined(self, tag, args):
     if len(args) > 0:
         requestedAlgorithm = args[0].decode("utf-8")
         launchScript = None
         for algorithm, launcher in ai_list.X_ALGORITHMS + ai_list.DETECTIVE_ALGORITHMS:
             if algorithm == requestedAlgorithm:
                 aidir = os.path.dirname(ai_list.__file__)
                 launchScript = os.path.normpath(
                     os.path.join(aidir, launcher))
                 break
         if launchScript != None:
             self.sendOk(tag)
         log.msg(
             util.printable(
                 _("Launching AI algorithm \"%(algorithm)s\" using script \"%(script)s\""
                   % {
                       "algorithm": requestedAlgorithm,
                       "script": launchScript
                   })))
         os.spawnl(os.P_NOWAIT, sys.executable,
                   sys.executable, launchScript, self.generateBotName(),
                   self._game.getName())
     else:
         raise IllegalCommand(_("Insufficient arguments."))
Exemplo n.º 7
0
 def cmd_login_compat(self, tag, args):
     if len(args) < 2:
         raise IllegalCommand(_("Insufficient arguments."))
     else:
         try:
             GameRegistry.registry.registerUser(
                 args[0], args[1],
                 self.transport.getPeer().host)
             self._username = args[0]
             if self._username == "admin":
                 self._state = "admin"
             else:
                 self._state = "player"
             GameRegistry.registry.addClient(self)
             GameRegistry.registry.addUnjoinedUser(self._username)
             log.msg(
                 util.printable(
                     _("Player \"%(playername)s\" has signed on") %
                     {"playername": self._username}))
             self.sendOk(tag)
         except GameRegistry.PasswordError as e:
             raise DeniedCommand(_(e.ustr()))
         except GameRegistry.UserError as e:
             raise DeniedCommand(_(e.ustr()))
Exemplo n.º 8
0
 def close(self):
     log.msg(util.printable(_("Closing game registry")))
     self._games.close()
     self._users.close()