コード例 #1
0
ファイル: tipscore.py プロジェクト: maxme/sleepy.mongoose
 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}))
コード例 #2
0
ファイル: tipscore.py プロジェクト: maxme/sleepy.mongoose
 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}))
コード例 #3
0
ファイル: tipscore.py プロジェクト: maxme/sleepy.mongoose
 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"], }))
コード例 #4
0
ファイル: tipscore.py プロジェクト: maxme/sleepy.mongoose
 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"],
         }))