def _put_score(self, args, out): check_res = self.check_args(args, ["leaderboard_id", "name", "id", "score", "level"], salt=True) if check_res: out(check_res) return # FIXME must check signature try: score = int(args["score"]) level = int(args["level"]) name = args["name"] leaderboard_id = args["leaderboard_id"] leaderboard = self.__get_leaderboard(leaderboard_id) cur_score = leaderboard.score_only_for(args["id"]) res = 1 rank = 0 if not cur_score or score > cur_score: leaderboard.rank_uid(args["id"], score, level, name) rank = leaderboard.rank_for(args["id"]) res = 2 else: rank = leaderboard.rank_for(args["id"]) count = leaderboard.total_scores() out(json.dumps({"ok": res, "scores_count": count, "rank": rank, "leaderboard_id": args["leaderboard_id"]})) except Exception as e: print e out(json.dumps({"error": -1}))
def _put_score(self, args, out): check_res = self.check_args( args, ["leaderboard_id", "name", "id", "score", "level"], salt=True) if check_res: out(check_res) return # FIXME must check signature try: score = int(args["score"]) level = int(args["level"]) name = args["name"] leaderboard_id = args["leaderboard_id"] leaderboard = self.__get_leaderboard(leaderboard_id) cur_score = leaderboard.score_only_for(args["id"]) res = 1 rank = 0 if not cur_score or score > cur_score: leaderboard.rank_uid(args["id"], score, level, name) rank = leaderboard.rank_for(args["id"]) res = 2 else: rank = leaderboard.rank_for(args["id"]) count = leaderboard.total_scores() out( json.dumps({ "ok": res, "scores_count": count, "rank": rank, "leaderboard_id": args["leaderboard_id"] })) except Exception as e: print e out(json.dumps({"error": -1}))
def _get_rank(self, args, out): check_res = self.check_args(args, ["leaderboard_id", "id"]) if check_res: out(check_res) return rank = leaderboard.rank_for(args["id"]) out(json.dumps({"rank": rank, "leaderboard_id": args["leaderboard_id"], }))
def _get_rank(self, args, out): check_res = self.check_args(args, ["leaderboard_id", "id"]) if check_res: out(check_res) return rank = leaderboard.rank_for(args["id"]) out( json.dumps({ "rank": rank, "leaderboard_id": args["leaderboard_id"], }))