예제 #1
0
 def get(self, game_id, player_id, x, y):
     self.response.headers['Content-Type'] = 'text/plain'
     game = Game.get_by_id(game_id)
     if not game:
         self.response.status = 412
         self.response.write(self.response.status)
         return
     p = game.player(player_id)
     Cache.setPos(game_id, player_id, x, y)
     self.response.write(p.output())
예제 #2
0
 def get(self, game_id, player_id):
     game = Game.get_by_id(game_id)
     if not game:
         self.response.status = 404
         self.response.write(self.response.status)
         return
     player = game.player(player_id)
     self.response.headers['Content-Type'] = 'text/plain'
     self.response.status = 200
     self.response.out.write(player.seed)
예제 #3
0
 def get(self, game_id, pid):
     key = ".".join([game_id, pid])
     game = Game.get_by_id(game_id)
     if key in [p.id() for p in game.players]:
         game.remove_player(key)
         return webapp2.redirect("/%s/players" % game_id)
     else:
         self.response.headers['Content-Type'] = 'text/plain'
         self.response.status = 404
         self.response.out.write("player %s not in %s" %
                                 (key, game.players))
예제 #4
0
 def get(self, game_id, player_id, signal):
     self.response.headers['Content-Type'] = 'text/plain'
     game = Game.get_by_id(game_id)
     if not game:
         self.response.status = 412
         self.response.write(self.response.status)
         return
     p = game.player(player_id)
     p.signal_send(signal)
     self.response.status = 200
     self.response.write("sent")
예제 #5
0
 def get(game_id, self):
     self.response.headers['Content-Type'] = 'text/plain'
     if int(game_id) < 1000:
         self.response.status = 403
         self.response.write("No.")
     game = Game.get_by_id(game_id)
     if game:
         delete_game(game)
         self.response.status = 200
         self.response.write("All according to daijobu")
     else:
         self.response.status = 401
         self.response.write("The game... was already dead...")
예제 #6
0
 def get(self, game_id):
     game = Game.get_by_id(game_id)
     hist = Cache.getHist(game_id)
     if not hist:
         self.response.status = 404
         self.response.write(self.response.status)
         return
     self.response.headers['Content-Type'] = 'text/plain'
     self.response.status = 200
     self.response.out.write("|".join([
         "%s:%s" % (p, ",".join([str(h.coords) for h in hls]))
         for p, hls in hist.iteritems()
     ]))
예제 #7
0
    def get(self, game_id):
        game = Game.get_by_id(game_id)
        outlines = []
        for p in game.get_players():
            outlines.append("Player %s: %s" % (p.key.id(), p.bitfields))
            outlines.append("\t\t" + "\n\t\t".join([
                hl.print_line(game.start_time) for hl in p.history
                if hl.pickup().share_type != ShareType.NOT_SHARED
            ]))

        self.response.headers['Content-Type'] = 'text/plain'
        self.response.status = 200
        self.response.out.write("\n".join(outlines))
예제 #8
0
 def get(self, game_id):
     self.response.headers['Content-Type'] = 'text/plain'
     game = Game.get_by_id(game_id)
     if game:
         output = game.summary()
         output += "\nHistory:"
         for hl, pid in sorted(
             [(h, p.key.id().partition('.')[2]) for p in game.get_players()
              for h in p.history
              if h.pickup().share_type != ShareType.NOT_SHARED],
                 key=lambda x: x[0].timestamp,
                 reverse=True):
             output += "\n\t\t Player %s %s" % (
                 pid, hl.print_line(game.start_time))
         self.response.status = 200
         self.response.write(output)
     else:
         self.response.status = 404
         self.response.out.write("Game %s not found!" % game_id)
예제 #9
0
 def get(self, game_id, player_id, coords, kind, id):
     game = Game.get_by_id(game_id)
     if not game:
         self.response.status = 412
         self.response.write(self.response.status)
         return
     remove = paramFlag(self, "remove")
     coords = int(coords)
     if coords in coord_correction_map:
         coords = coord_correction_map[coords]
     if coords not in all_locs:
         print "Coord mismatch error! %s not in all_locs or correction map. Sync %s.%s, pickup %s|%s" % (
             coords, game_id, player_id, kind, id)
     dedup = not paramFlag(
         self, "override") and not remove and game.mode in DEDUP_MODES
     pickup = Pickup.n(kind, id)
     if not pickup:
         print "ERROR: Couldn't build pickup %s|%s" % (kind, id)
         self.response.status = 406
         return
     self.response.status = game.found_pickup(player_id, pickup, coords,
                                              remove, dedup)
     self.response.write(self.response.status)
예제 #10
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")
예제 #11
0
    def post(self):
        mode = self.request.get("mode").lower()
        pathdiff = self.request.get("pathdiff").lower()
        variations = set([
            x for x in [
                "forcetrees", "hardmode", "notp", "starved", "ohko",
                "noplants", "discmaps", "0xp", "nobonus"
            ] if self.request.get(x)
        ])
        logic_paths = [
            x for x in [
                "normal", "speed", "lure", "speed-lure", "dboost",
                "dboost-light", "dboost-hard", "cdash", "dbash", "extended",
                "lure-hard", "timed-level", "glitched", "extended-damage",
                "extreme"
            ] if self.request.get(x)
        ]
        playercount = self.request.get("playerCount")
        syncid = self.request.get("syncid")
        syncmode = self.request.get("syncmode").lower()
        syncmode = mode_map[syncmode] if syncmode in mode_map else int(
            syncmode)
        seed = self.request.get("seed")
        share_types = [f for f in share_map.keys() if self.request.get(f)]

        game_id = False
        if not seed:
            seed = str(random.randint(10000000, 100000000))
        if syncid:
            syncid = int(syncid)
            oldGame = Game.get_by_id(syncid)
            if oldGame != None:
                if syncid > 999:
                    delete_game(oldGame)
                    game_id = get_new_game(_mode=syncmode,
                                           _shared=share_types,
                                           id=syncid).key.id()
                else:
                    self.response.status = 405
                    self.response.write(
                        "Seed ID in use! Leave blank or pick a different number."
                    )
                    return
            else:
                game_id = get_new_game(_mode=syncmode,
                                       _shared=share_types,
                                       id=syncid).key.id()

        if not game_id:
            game_id = get_new_game(_mode=syncmode,
                                   _shared=share_types).key.id()

        urlargs = ["m=%s" % mode]
        urlargs.append("vars=%s" % "|".join(variations))
        urlargs.append("lps=%s" % "|".join(logic_paths))
        urlargs.append("s=%s" % seed)
        urlargs.append("pc=%s" % playercount)
        urlargs.append("pd=%s" % pathdiff)
        urlargs.append("shr=%s" % "+".join(share_types))
        urlargs.append("sym=%s" % syncmode)
        urlargs.append("gid=%s" % game_id)
        for flg in ["dk", "ev", "sk", "rb", "tp", "hot", "wild"]:
            if self.request.get(flg):
                urlargs.append("%s=1" % flg)
        self.response.headers['Content-Type'] = 'text/html'
        out = "<html><body>"
        url = '/getseed?%s' % "&".join(urlargs)
        out += "<div><a target='_blank' href='%s&p=spoiler'>Spoiler</a></div>" % url
        out += "<div><a target='_blank' href='/%s/map?paths=%s'>Map</a></div>" % (
            game_id, "+".join(logic_paths))
        out += "<div><a target='_blank' href='/%s/history'>History</a></div>" % game_id

        for i in range(1, 1 + int(playercount)):
            purl = url + "&p=%s" % i
            out += "<div>Player %s: <a target='_blank' href=%s>%s%s</a></div>" % (
                i, purl, base_site, purl)
        out += "</body></html>"
        self.response.out.write(out)