Ejemplo n.º 1
0
 def get(self, game_id):
     pos = Cache.getPos(game_id)
     if pos:
         self.response.headers['Content-Type'] = 'text/plain'
         self.response.status = 200
         self.response.out.write("|".join(
             ["%s:%s,%s" % (p, x, y) for p, (x, y) in pos.iteritems()]))
     else:
         self.response.headers['Content-Type'] = 'text/plain'
         self.response.status = 404
Ejemplo n.º 2
0
    def get(self, game_id, player_id):
        seedlines = []
        lines = paramVal(self, "seed").split(",")
        game = Game.get_by_id(game_id)
        hist = Cache.getHist(game_id)
        if not hist:
            Cache.setHist(game_id, player_id, [])
        pos = Cache.getPos(game_id)
        if not pos:
            Cache.setPos(game_id, player_id, 0, 0)
        if not game:
            flags = lines[0].split("|")
            mode_opt = [f[5:] for f in flags if f.lower().startswith("mode=")]
            shared_opt = [
                f[7:].split(" ") for f in flags
                if f.lower().startswith("shared=")
            ]
            mode = mode_opt[0].lower() if mode_opt else None
            if mode:
                mode = mode_map[mode] if mode in mode_map else int(mode)

            shared = shared_opt[0] if shared_opt else None
            game = get_new_game(_mode=mode, _shared=shared, id=game_id)
        for l in lines[1:]:
            line = l.split("|")
            if len(line) < 3:
                print "ERROR: malformed seed line %s, skipping" % l
            else:
                seedlines.append("%s:%s" %
                                 (line[0], Pickup.name(line[1], line[2])))
        player = game.player(player_id)
        player.seed = "\n".join(seedlines)
        player.put()
        self.response.headers['Content-Type'] = 'text/plain'
        self.response.status = 200
        self.response.out.write("ok")