コード例 #1
0
ファイル: game.py プロジェクト: wade333777/cocos-js-tips
    def post(self):
        """游戏登录接口
        """
        account_id = self.get_argument("account_id")
        server_id = self.get_argument("server_id")
        platform = self.get_argument("platform")
        session_id = self.get_argument("session_id")

        server = Server.get_server_by_id(server_id)
        if not server:
            self.finish(json_encode({"mc": MsgCode['ServerNotExist']}))
            return

        # 当服务器还未开启或者维护时,内部账户随意进出游戏
        if int(server["state"]) != settings.SERVER_STATE_OPEN and not auth_utils.white_ip_check(self):
           code = MsgCode['ServerNotOpen'] if int(server["state"]) == settings.SERVER_STATE_CLOSE else MsgCode['ServerUpdateing']
           self.finish(json_encode({'mc': code}))
           return

        check_result = auth_utils.login_auth(session_id, account_id, server_id)
        if check_result:
            self.finish(json_encode(check_result))
            return

        complete_account_id = "%s_%s" % (platform, account_id)
        uid = Account.get_user_id(complete_account_id, server_id)
        if not uid:
            self.finish(json_encode({"mc": MsgCode['GameLoginFail']}))
            return

        user_login_data = {"aid": account_id, "uid": uid, "sid": server_id, "pf": platform}
        ki_user = User.install(user_login_data)
        if not isinstance(ki_user, User):
            self.finish(json_encode({"mc": MsgCode['GameLoginFail']}))
            return

        if ki_user.ext_info.ban_account and ki_user.ext_info.ban_account > int(time.time()):
            self.finish(json_encode({"mc": MsgCode["UserFrozen"]}))
            return

        server_time = int(time.time())
        ki_user.update_user_login_info(server_time)
        user_guide_checker(ki_user) # 为前端加引导保护器,防止玩家引导断掉 导致无法进行游戏
        ki_user.vip.update_card_when_request() # 更新玩家vip月卡信息
        ki_user.activity.update_effective_acts(ki_user.sid, ki_user.game_info.role_level) # 更新活动数据
        act_helper.update_after_login(ki_user)
        if charge_service.ismember_of_paid_set(uid):
            vip_logic.charge_refresh(ki_user) # 如果有未发送元宝的订单,立即发送元宝

        _set_secure_cookie(self, account_id, uid, platform, server_time, server_id) # 返回COOKIE

        # boss_hero_rank = BossService.login_notice(ki_user.sid, ki_user.uid)
        # if boss_hero_rank and boss_hero_rank == 1:
        #     NoticeService.broadcast(ki_user.sid, 20, {'uid': ki_user.uid, 'name': ki_user.name}, boss_hero_rank)

        msg = {}
        msg["mc"] = MsgCode['GameLoginSucc']

        msg["data"] = {}
        msg["data"]["user_data"] = fetch_user_data(ki_user)
        msg["data"]["server_time"] = server_time

        self.write(json_encode(msg))
コード例 #2
0
ファイル: kiauth.py プロジェクト: wade333777/cocos-js-tips
    def process_request(self, handler, clear):
        """
        匹配路由后,执行处理handler时调用,**支持异步**
        :param handler: handler对象

        """
        request_path = handler.request.uri

        if request_path.startswith("/A6ksi"):
            return

        if request_path.startswith("/notification/"):
            return

        if request_path.startswith("/platform/version"):
            return

        if request_path.startswith("/platform/regist"):
            return

        if request_path.startswith("/platform/express"):
            return

        if request_path.startswith("/platform/bind"):
            return

        if request_path.startswith("/platform/auth"):
            return

        if request_path.startswith("/game/login"):
            return

        if request_path.startswith("/debug"):
            return

        # game api需要检验服务器状态
        cookie = handler.get_secure_cookie("user_cookie_chain")
        if not cookie:
            handler.finish(ujson.dumps({"mc": MsgCode["CookieAuthFailed"]}))
            return 1

        cookie_data = _handle_secure_cookie(cookie)
        server_state = Server.get_server_state_by_id(int(cookie_data["sid"]))
        # 当服务器还未开启或者维护时,内部账户随意进出游戏
        if int(server_state) != settings.SERVER_STATE_OPEN and not auth_utils.white_ip_check(handler):
           code = MsgCode['ServerNotOpen'] if int(server_state) == settings.SERVER_STATE_CLOSE else MsgCode['ServerUpdateing']
           handler.finish(ujson.dumps({"mc": code}))
           return 1

        authed_cookie_data = auth_utils.auth_cookie(cookie_data)
        if not authed_cookie_data:
            handler.finish(ujson.dumps({"mc": MsgCode["CookieAuthFailed"]}))
            return 1

        ki_user = User.install(authed_cookie_data)
        if not isinstance(ki_user, User):
            handler.finish(ujson.dumps({"mc": MsgCode["UserGetDataFailed"]}))
            return 1

        # 双开检测,防止玩家多端登录
        if ki_user.last_sign_time != int(cookie_data["ts"]):
            handler.finish(ujson.dumps({"mc": MsgCode["GameLoginByOthers"]}))
            return 1

        # TODO 用户状态监测
        if ki_user.ext_info.ban_account and ki_user.ext_info.ban_account > int(time.time()):
            handler.finish(ujson.dumps({"mc": MsgCode["UserFrozen"]}))
            return 1

        handler.request.request_context.user = ki_user

        if request_path.startswith("/debug"):
            return 1