コード例 #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 _get_scores(self, args, out):
     ALWAYS_BEST_SCORES = 5
     check_res = self.check_args(args,
                                 ["leaderboard_id", "id", "page_size"])
     if check_res:
         out(check_res)
         return
     page_size = min(MAX_PAGE_SIZE, int(args["page_size"]))
     # get user score
     leaderboard = self.__get_leaderboard(args["leaderboard_id"])
     scores = leaderboard.around_me(args["id"], page_size=page_size)
     count = leaderboard.total_scores()
     if ALWAYS_BEST_SCORES != 0 and scores and scores[0]["rank"] != 1:
         best_scores = leaderboard.leaders(0, page_size=ALWAYS_BEST_SCORES)
         scores = best_scores + [{
             "name": "----------",
             "level": 0,
             "score": 0,
             "uid": 0,
             "rank": ALWAYS_BEST_SCORES + 1
         }] + scores
     if not scores:
         out(
             json.dumps({
                 "error": 8,
                 "leaderboard_id": args["leaderboard_id"]
             }))
         return
     res = {
         "ok": 1,
         "scores_count": count,
         "leaderboard_id": args["leaderboard_id"],
         "scores": scores
     }
     out(json.dumps(res))
コード例 #3
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}))
コード例 #4
0
ファイル: tipscore.py プロジェクト: maxme/sleepy.mongoose
 def _get_score_page(self, args, out):
     ALWAYS_BEST_SCORES = 0
     check_res = self.check_args(args,
                                 ["leaderboard_id", "start", "page_size"])
     if check_res:
         out(check_res)
         return
     page_size = min(MAX_PAGE_SIZE, int(args["page_size"]))
     leaderboard = self.__get_leaderboard(args["leaderboard_id"])
     scores = leaderboard.leaders(int(args["start"]), page_size=page_size)
     count = leaderboard.total_scores()
     if ALWAYS_BEST_SCORES != 0 and int(args["start"]) != 0:
         best_scores = leaderboard.leaders(0, page_size=ALWAYS_BEST_SCORES)
         scores = best_scores + [{
             "name": "----------",
             "level": 0,
             "score": 0,
             "uid": 0,
             "rank": ALWAYS_BEST_SCORES + 1
         }] + scores
     if not scores:
         scores = []
     res = {
         "ok": 1,
         "scores_count": count,
         "leaderboard_id": args["leaderboard_id"],
         "scores": scores
     }
     out(json.dumps(res))
コード例 #5
0
ファイル: tipscore.py プロジェクト: maxme/sleepy.mongoose
 def _get_leaderboard(self, args, out):
     check_res = self.check_args(args, ["leaderboard_id"])
     if check_res:
         out(check_res)
         return
     leaderboard = self.__get_leaderboard(args["leaderboard_id"])
     count = leaderboard.total_scores()
     res = {
         "ok": 1,
         "count": count,
         "leaderboard_id": args["leaderboard_id"]
         }
     out(json.dumps(res))
コード例 #6
0
ファイル: tipscore.py プロジェクト: maxme/sleepy.mongoose
 def _get_leaderboard(self, args, out):
     check_res = self.check_args(args, ["leaderboard_id"])
     if check_res:
         out(check_res)
         return
     leaderboard = self.__get_leaderboard(args["leaderboard_id"])
     count = leaderboard.total_scores()
     res = {
         "ok": 1,
         "count": count,
         "leaderboard_id": args["leaderboard_id"]
     }
     out(json.dumps(res))
コード例 #7
0
ファイル: tipscore.py プロジェクト: maxme/sleepy.mongoose
 def _get_score_page(self, args, out):
     ALWAYS_BEST_SCORES = 0
     check_res = self.check_args(args, ["leaderboard_id", "start", "page_size"])
     if check_res:
         out(check_res)
         return
     page_size = min(MAX_PAGE_SIZE, int(args["page_size"]))
     leaderboard = self.__get_leaderboard(args["leaderboard_id"])
     scores = leaderboard.leaders(int(args["start"]), page_size=page_size)
     count = leaderboard.total_scores()
     if ALWAYS_BEST_SCORES != 0 and int(args["start"]) != 0:
         best_scores = leaderboard.leaders(0, page_size=ALWAYS_BEST_SCORES)
         scores = best_scores + [{"name": "----------", "level": 0, "score": 0, "uid":0, "rank": ALWAYS_BEST_SCORES+1}]+ scores
     if not scores:
         scores = []
     res = {"ok": 1, "scores_count": count, "leaderboard_id": args["leaderboard_id"], "scores": scores}
     out(json.dumps(res))
コード例 #8
0
ファイル: tipscore.py プロジェクト: maxme/sleepy.mongoose
 def _get_scores(self, args, out):
     ALWAYS_BEST_SCORES = 5
     check_res = self.check_args(args, ["leaderboard_id", "id", "page_size"])
     if check_res:
         out(check_res)
         return
     page_size = min(MAX_PAGE_SIZE, int(args["page_size"]))
     # get user score
     leaderboard = self.__get_leaderboard(args["leaderboard_id"])
     scores = leaderboard.around_me(args["id"], page_size=page_size)
     count = leaderboard.total_scores()
     if ALWAYS_BEST_SCORES != 0 and scores and scores[0]["rank"] != 1:
         best_scores = leaderboard.leaders(0, page_size=ALWAYS_BEST_SCORES)
         scores = best_scores + [{"name": "----------", "level": 0, "score": 0, "uid":0, "rank": ALWAYS_BEST_SCORES+1}]+ scores
     if not scores:
         out(json.dumps({"error": 8, "leaderboard_id": args["leaderboard_id"]}))
         return
     res = {"ok": 1, "scores_count": count, "leaderboard_id": args["leaderboard_id"], "scores": scores}
     out(json.dumps(res))