Пример #1
0
    def post(self):
        platform = self.get_argument("platform", "")
        auth_params = self.get_argument("auth_params", "")

        if not auth_utils.check_param_legal(platform):
            self.finish(json_encode({"mc": MsgCode['ParamError']}))
            return

        # 根据平台不同进行分发
        platform_config = Platform.get_plat_config(platform)
        if not platform_config:
            self.finish(json_encode({"mc": MsgCode['PlatformNotExist']}))
            return

        if not hasattr(platform_auth, platform_config["checker"]):
            self.finish(json_encode({"mc": MsgCode['AccountAuthParamError']}))
            return

        func = getattr(platform_auth, platform_config["checker"])
        success, code, complete_account_id = func(platform, auth_params)

        if not success:
            self.finish(json_encode({"mc": code}))
            return

        if platform_config["sign"] in NEED_OPEN_ID_PLATS:
            account = Account.get_account(complete_account_id)
            if not account.open_id:  # 0 - 未检测 1 - 已预约 2 - 没预约 3 - 已兑奖
                open_id = platform_auth.fetch_plat_openid(auth_params)
                account.update_open_id(open_id)

        account_id = complete_account_id.split("_")[1]
        msg = build_login_game_data(platform, account_id,
                                    auth_utils.white_ip_check(self))
        self.write(json_encode(msg))
Пример #2
0
    def post(self):
        try:
            plat_sign = self.get_argument("platform", "")

            if not auth_utils.check_param_legal(plat_sign):
                self.finish(json_encode({"mc": MsgCode['ParamError']}))
                return

            platform = Platform.get_platform_info()
            platform_data = {}
            if not platform:
                self.write(json_encode({"mc": MsgCode['PlatformNotExist']}))
            else:
                platform_data["cdn_url"] = platform["cdn_url"]
                platform_data["remote_manifest_url"] = platform[
                    "remote_manifest_url"]

                if auth_utils.white_ip_check(self):
                    platform_data["resource_version"] = platform[
                        "test_resource_version"]
                else:
                    platform_data["resource_version"] = platform[
                        "prod_resource_version"]

                msg = {}
                msg["mc"] = 100
                msg["data"] = {}
                msg["data"]["platform"] = platform_data

                self.write(json_encode(msg))
        except Exception, e:
            self.interal_error_handle(e)
Пример #3
0
    def post(self):
        try:
            plat_sign = self.get_argument("platform", "")

            if not auth_utils.check_param_legal(plat_sign):
                self.finish(json_encode({"mc": MsgCode['ParamError']}))
                return

            platform = Platform.get_platform_info()
            platform_data = {}
            if not platform:
                self.write(json_encode({"mc": MsgCode['PlatformNotExist']}))
            else:
                platform_data["cdn_url"] = platform["cdn_url"]
                platform_data["remote_manifest_url"] = platform["remote_manifest_url"]

                if auth_utils.white_ip_check(self):
                    platform_data["resource_version"] = platform["test_resource_version"]
                else:
                    platform_data["resource_version"] = platform["prod_resource_version"]

                msg = {}
                msg["mc"] = 100
                msg["data"] = {}
                msg["data"]["platform"] = platform_data

                self.write(json_encode(msg))
        except Exception,e:
            self.interal_error_handle(e)
Пример #4
0
    def post(self):
        try:
            platform = self.get_argument("platform", "")

            if not auth_utils.check_param_legal(platform):
                self.finish(json_encode({"mc": MsgCode['ParamError']}))
                return

            tmp_account_id = None
            while not tmp_account_id:
                tmp_account_id = gen_account_id()
                account = Account.get_account("%s_%s" %
                                              (platform, tmp_account_id))
                if not isinstance(account, Account):
                    tmp_account_id = None

            tmp_password = gen_password()

            complete_account_id = "%s_%s" % (platform, tmp_account_id)
            Account.register(complete_account_id, tmp_password, 0)

            msg = build_login_game_data(platform, tmp_account_id,
                                        auth_utils.white_ip_check(self))
            msg["data"]["password"] = tmp_password

            self.write(json_encode(msg))
        except Exception, e:
            self.interal_error_handle(e)
Пример #5
0
    def post(self):
        platform = self.get_argument("platform", "")
        auth_params = self.get_argument("auth_params", "")

        if not auth_utils.check_param_legal(platform):
            self.finish(json_encode({"mc": MsgCode['ParamError']}))
            return

        # 根据平台不同进行分发
        platform_config = Platform.get_plat_config(platform)
        if not platform_config:
            self.finish(json_encode({"mc": MsgCode['PlatformNotExist']}))
            return

        if not hasattr(platform_auth, platform_config["checker"]):
            self.finish(json_encode({"mc": MsgCode['AccountAuthParamError']}))
            return

        func = getattr(platform_auth, platform_config["checker"])
        success, code, complete_account_id = func(platform, auth_params)

        if not success:
            self.finish(json_encode({"mc": code}))
            return

        if platform_config["sign"] in NEED_OPEN_ID_PLATS:
            account = Account.get_account(complete_account_id)
            if not account.open_id: # 0 - 未检测 1 - 已预约 2 - 没预约 3 - 已兑奖
                open_id = platform_auth.fetch_plat_openid(auth_params)
                account.update_open_id(open_id)

        account_id = complete_account_id.split("_")[1]
        msg = build_login_game_data(platform, account_id, auth_utils.white_ip_check(self))
        self.write(json_encode(msg))
Пример #6
0
    def post(self):
        try:
            platform = self.get_argument("platform", "")

            if not auth_utils.check_param_legal(platform):
                self.finish(json_encode({"mc": MsgCode['ParamError']}))
                return

            tmp_account_id = None
            while not tmp_account_id:
                tmp_account_id = gen_account_id()
                account = Account.get_account("%s_%s" % (platform, tmp_account_id))
                if not isinstance(account, Account):
                    tmp_account_id = None

            tmp_password = gen_password()

            complete_account_id = "%s_%s" % (platform, tmp_account_id)
            Account.register(complete_account_id, tmp_password, 0)

            msg = build_login_game_data(platform, tmp_account_id, auth_utils.white_ip_check(self))
            msg["data"]["password"] = tmp_password

            self.write(json_encode(msg))
        except Exception,e:
            self.interal_error_handle(e)
Пример #7
0
    def post(self):
        try:
            platform = self.get_argument("platform", "")
            auth_params = self.get_argument("auth_params", "")

            if not auth_utils.check_param_legal(platform):
                self.finish(json_encode({"mc": MsgCode['ParamError']}))
                return

            try:
                params_list = auth_params.split("|")

                account_id = params_list[0].split("_")[1]
                password = params_list[1].split("_")[1]  # 自己的账号系统

                if not auth_utils.check_param_legal(account_id, password):
                    raise

                if len(account_id) < 6 or len(account_id) > 18 or len(
                        password) < 6 or len(password) > 18:
                    raise
            except:
                self.finish(
                    json_encode({"mc": MsgCode['AccountRegistParamsError']}))
                return

            complete_account_id = "%s_%s" % (platform, account_id)

            if Account.check_account_exist(complete_account_id):
                self.finish(json_encode({"mc":
                                         MsgCode['AccountAlreadyExist']}))
                return

            Account.register(complete_account_id, password)

            msg = build_login_game_data(platform, account_id,
                                        auth_utils.white_ip_check(self))
            self.write(json_encode(msg))
        except Exception, e:
            self.interal_error_handle(e)
Пример #8
0
    def post(self):
        try:
            platform = self.get_argument("platform", "")
            auth_params = self.get_argument("auth_params", "")

            if not auth_utils.check_param_legal(platform):
                self.finish(json_encode({"mc": MsgCode['ParamError']}))
                return

            try:
                params_list = auth_params.split("|")

                account_id = params_list[0].split("_")[1]
                password = params_list[1].split("_")[1] # 自己的账号系统

                if not auth_utils.check_param_legal(account_id, password):
                    raise

                if len(account_id) < 6 or len(account_id) > 18 or len(password) < 6 or len(password) > 18:
                    raise
            except:
                self.finish(json_encode({"mc": MsgCode['AccountRegistParamsError']}))
                return

            complete_account_id = "%s_%s" % (platform, account_id)

            if Account.check_account_exist(complete_account_id):
                self.finish(json_encode({"mc": MsgCode['AccountAlreadyExist']}))
                return

            Account.register(complete_account_id, password)

            msg = build_login_game_data(platform, account_id, auth_utils.white_ip_check(self))
            self.write(json_encode(msg))
        except Exception,e:
            self.interal_error_handle(e)
Пример #9
0
    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))
Пример #10
0
    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