コード例 #1
0
ファイル: player_handler.py プロジェクト: dqchess/mario
    def post(self, cmsg):
        if cmsg.userid == 0:
            return auth.pack(None, const.ERROR_ADMINISTRTOR)

        
        user = user_data.get_user_attrs(cmsg.userid, "name", "country", 
                                            "head", "register", "level", "exp", "play", "pass",
                                            "point", "comment", "video", "visitor", "watched", "master_exp", "master_level")

        smsg = smsg_view_player()
        self._get_recent_map(cmsg.userid, smsg)
        self._get_upload_map(cmsg.userid, smsg)
        self._get_play_map(cmsg.userid, smsg)

        smsg.data.userid    = cmsg.userid
        smsg.data.name      = user[0]
        smsg.data.country   = user[1]
        smsg.data.head      = int(user[2])
        smsg.data.level     = int(user[4])
        smsg.data.exp       = int(user[5])
        smsg.data.register  = user[3]
        smsg.data.amount    = int(user[6])
        smsg.data.pas       = int(user[7])
        smsg.data.point     = int(user[8])
        smsg.data.comment   = int(user[9])
        smsg.data.video     = int(user[10])
        smsg.data.visitor   = int(user[11])
        smsg.data.watched   = int(user[12])
        smsg.data.mlevel    = int(user[14])
        smsg.data.mexp      = int(user[13])
        return auth.pack(smsg, 0, cmsg.common.userid)
コード例 #2
0
    def post(self, cmsg):
        index, life, start = user_data.get_user_attrs(cmsg.common.userid,
                                                      "mission",
                                                      "mission_life",
                                                      "mission_next")
        if int(life) <= 0:
            return auth.pack(None, const.ERROR_SYSTEM)

        mapinfo = global_data.get_challenge_mapid(const.TAG_CHALLENGE_MAP_LIST,
                                                  index)
        if mapinfo is None:
            return auth.pack(None, const.ERROR_SYSTEM)
        mapinfo = msgpack.loads(mapinfo)

        user_data.play_map(cmsg.common.userid, mapinfo[0],
                           const.GAME_CHALLENGE_PLAY_MODE)
        if start == "0":
            user_data.inc_user_attr(cmsg.common.userid, "mission_next", 1)
        map_data.play_map(mapinfo[0])

        if mapinfo[3] != '0':
            user_data.inc_user_attr(mapinfo[3], "master_exp", 1)

        smsg = smsg_challenge_play()
        smsg.map_name = mapinfo[1]
        smsg.user_name = mapinfo[2]
        smsg.user_country = mapinfo[4]
        smsg.user_head = int(mapinfo[5])
        smsg.map_data = mapinfo[6]
        map_coordinate = map_data.get_dead_coordinate(mapinfo[0], 50)
        for coord in map_coordinate:
            x, y = coord.split(":")
            smsg.x.append(int(x))
            smsg.y.append(int(y))
        return auth.pack(smsg, 0, cmsg.common.userid)
コード例 #3
0
    def buy_support(self, userid, shop_template):
        jewel, support = user_data.get_user_attrs(userid, "jewel", "support")
        if not jewel or not support or int(jewel) < shop_template.price or int(
                support) >= shop_template.arg:
            raise tornado.gen.Return(const.ERROR_NO_JEWEL)

        user_data.inc_user_attr(userid, "jewel", -(shop_template.price))
        user_data.set_user_attr(userid, "support", shop_template.arg)
        raise tornado.gen.Return(0)
コード例 #4
0
    def post(self, cmsg):
        mapid, life = user_data.get_user_attrs(cmsg.common.userid, "mapid",
                                               "mission_life")

        if int(life) <= 0:
            return auth.pack(None, const.ERROR_SYSTEM)

        user_data.play_map(cmsg.common.userid, mapid,
                           const.GAME_CHALLENGE_PLAY_MODE)
        ownerid = map_data.replay_map(mapid)
        if ownerid != '0':
            user_data.inc_user_attr(ownerid, "master_exp", 1)

        return auth.pack(None, 0, cmsg.common.userid)
コード例 #5
0
    def buy_exp(self, userid, shop_template):
        jewel, exp_time = user_data.get_user_attrs(userid, "jewel", "exp_time")
        if not jewel or not exp_time or int(jewel) < shop_template.price:
            raise tornado.gen.Return(const.ERROR_NO_JEWEL)

        exp_next_time = long(exp_time)
        if exp_next_time < util.now_time():
            exp_next_time = util.now_time(
            ) + shop_template.arg * 24 * 60 * 60 * 1000
        else:
            exp_next_time = exp_next_time + shop_template.arg * 24 * 60 * 60 * 1000

        user_data.inc_user_attr(userid, "jewel", -(shop_template.price))
        user_data.set_user_attr(userid, "exp_time", exp_next_time)
        raise tornado.gen.Return(0)
コード例 #6
0
    def post(self, cmsg):
        user = user_data.get_user_attrs(cmsg.common.userid, "head", "name",
                                        "country", "master_exp",
                                        "master_level", "upload")
        user = filter(None, user)
        if not user or len(user) != 6:
            return auth.pack(None, const.ERROR_SYSTEM)

        master_level = int(user[4])
        master_exp = int(user[3])
        upload = int(user[5])

        master_template = self.application.static_data.get_master_template(
            master_level)
        if not master_template:
            return auth.pack(None, const.ERROR_SYSTEM)

        if upload >= master_template.upload:
            return auth.pack(None, const.ERROR_SYSTEM)

        usermap = user_data.get_usermap_attrs(cmsg.common.userid, cmsg.id,
                                              "name", "url", "data", "upload")
        usermap = filter(None, usermap)
        if not usermap or len(usermap) != 4:
            return auth.pack(None, const.ERROR_SYSTEM)
        if usermap[3] != '0':
            return auth.pack(None, const.ERROR_SYSTEM)

        master_exp, master_level = self._check_levelup(master_exp,
                                                       master_level)

        # 上传录像
        uptime = None
        upvideo = ""
        if cmsg.video != "":
            upvideo = cmsg.video
            uptime = cmsg.time

        mapid = global_data.get_counter(const.TAG_MAP_COUNT)
        map_data.upload_map(mapid, usermap[0], usermap[1], usermap[2],
                            cmsg.common.userid, user[1], user[2], user[0],
                            cmsg.ver, uptime)
        user_data.upload_usermap(cmsg.common.userid, cmsg.id, mapid,
                                 master_exp, master_level, upvideo)

        self._index_map(mapid, usermap[0])

        return auth.pack(None, 0, cmsg.common.userid)
コード例 #7
0
    def post(self, cmsg):
        country, index, top, life, start, version, relive = user_data.get_user_attrs(cmsg.common.userid,
                                               "country",
                                               "mission",
                                               "mission_hard",
                                               "mission_life",
                                               "mission_next",
                                               "mission_ver",
                                               "mission_relive")

        challenge_info = cache_data.get_cache(const.TAG_CHALLENGE_INFO, 300)

        if version is None or int(version) != challenge_info.get("version", 0):
            index   = 0
            top     = 0
            life    = 10
            start   = 0
            user_data.set_user_attrs(cmsg.common.userid, {"mission":0,
                                                          "mission_hard":0,
                                                          "mission_life":10,
                                                          "mission_next":0,
                                                          "mission_ver":challenge_info.get("version", 0),
                                                          "mission_total":0,
                                                          "mission_relive":0})

        # 重置(如果没有过关)
        if int(life) <= 0 and int(index) < 8:
            first_reset = (int(index) > 0) and 1 or 0
            index   = 0
            life    = 10
            start   = 0
            user_data.set_user_attrs(cmsg.common.userid, {"mission":0, "mission_hard":first_reset, "mission_life":10, "mission_next":0, "mission_relive":0, "mission_total":0})

        smsg = smsg_challenge_view()
        smsg.index  = int(index)
        smsg.life   = int(life)
        smsg.life_num = int(relive) if relive else 0
        smsg.start  = 2 if int(index) >= 8 else int(start)
        if challenge_info:
            smsg.exp    = challenge_info.get("exp") or 0
            smsg.jewel  = challenge_info.get("jewel") or 0
            smsg.date   = challenge_info.get("date") or ""
            if country == "CN":
                smsg.subject = challenge_info.get("cn_subject")
            else:
                smsg.subject = challenge_info.get("en_subject")
        return auth.pack(smsg, 0, cmsg.common.userid)
コード例 #8
0
    def post(self, cmsg):
        smsg = smsg_view_map_point_rank()
        map_users = map_data.get_rank_map_list(
            const.TAG_MAP_POINT.format(cmsg.map_id), 0, -1, False)
        for users in map_users:
            userattrs = user_data.get_user_attrs(users[0], "name", "level",
                                                 "country", "visitor")
            rank_info = smsg.ranks.add()
            rank_info.player_name = userattrs[0]
            rank_info.player_point = int(users[1])
            rank_info.player_level = int(userattrs[1])
            rank_info.player_country = userattrs[2]
            rank_info.video_id = int(users[0])
            rank_info.user_id = int(users[0])
            rank_info.visitor = int(userattrs[3])

        return auth.pack(smsg, 0, cmsg.common.userid)
コード例 #9
0
    def post(self, cmsg):
        jewel, relife = user_data.get_user_attrs(cmsg.common.userid, "jewel", "mission_relive")
        jewel  = int(jewel)
        relife = int(relife) + 1
        if relife > 6:
            relife = 6
        mission_template = self.application.static_data.get_mission_template(relife)
        if not mission_template:
            return auth.pack(None, const.ERROR_SYSTEM)

        if jewel < mission_template.jewel:
            return auth.pack(None, const.ERROR_NO_JEWEL)

        user_data.inc_user_attrs(cmsg.common.userid, [("mission_life",10), ("jewel", -mission_template.jewel),
                                                      ("mission_relive",1)])

        return auth.pack(None, 0, cmsg.common.userid)
コード例 #10
0
ファイル: view_handler.py プロジェクト: dqchess/mario
    def post(self, cmsg):
        exp, level = user_data.get_user_attrs(cmsg.common.userid, "master_exp", "master_level")
        if exp is None or level is None:
            return auth.pack(None, const.ERROR_SYSTEM)

        exp             = int(exp)
        level           = int(level)
        before_level    = level
        exp, level = self._check_levelup(exp, level)
        if level != before_level:
            user_data.set_user_attrs(cmsg.common.userid, {"master_exp":exp,
                                                          "master_level":level})

        smsg = smsg_view_edit()
        smsg.exp    = exp
        smsg.level  = level
        map_list = user_data.get_usermap_set_with_script(cmsg.common.userid, 
                                                         self.application.get_usermap_script)
        if not map_list:
            for i in range(12):
                data = smsg.infos.add()
                data.id = 0
                data.name = ""
                data.url = ""
                data.date = ""
                data.upload = 0
        else:
            for map_data in map_list:
                data = smsg.infos.add()
                if map_data:
                    data.id     = int(map_data[0])
                    data.name   = map_data[1]
                    data.url    = map_data[2]
                    data.date   = map_data[3]
                    data.upload = int(map_data[4])
                else:
                    data.id = 0
                    data.name = ""
                    data.url = ""
                    data.date = ""
                    data.upload = 0
        
        return auth.pack(smsg, 0, cmsg.common.userid)
コード例 #11
0
    def post(self, cmsg):
        jewel, download_num = user_data.get_user_attrs(cmsg.common.userid, "jewel", "download_num")
        if download_num is None:
            download_num = 0

        name, ownerid, url, data = map_data.get_map_attrs(cmsg.id, "name", "ownerid", "url", "data")

        download_num = int(download_num)
        if download_num >= const.DOWNLOAD_MAX:
            return auth.pack(None, const.ERROR_SYSTEM)

        download_template = self.application.static_data.get_download_template(download_num)
        if not download_template:
            return auth.pack(None, const.ERROR_SYSTEM)

        need_guild = 0
        need_jewel = -download_template.price
        if int(ownerid) != cmsg.common.userid:
            need_guild = 1
            if int(jewel) < download_template.price:
                return auth.pack(None, const.ERROR_NO_JEWEL)
        else:
            need_jewel = 0


        empty_slot = -1
        edit_map_list = user_data.get_usermap_list(cmsg.common.userid)
        if not edit_map_list:
            user_data.create_usermap_list(cmsg.common.userid)
            empty_slot = 1
        else:
            for i in range(len(edit_map_list)):
                if edit_map_list[i] == '0':
                    empty_slot = i
                    break

        if empty_slot == -1:
            return auth.pack(None, const.ERROR_DOWNLOAD)

        mapid = global_data.get_counter(const.TAG_USERMAP_COUNT)
        user_data.create_usermap(cmsg.common.userid, mapid, empty_slot, name, url, data, need_guild, need_jewel)

        return auth.pack(None, 0, cmsg.common.userid)
コード例 #12
0
    def post(self, cmsg):
        smsg = smsg_challenge_rank()
        rank_list = global_data.get_map_list(const.TAG_RANK_CHALLENGE, 0, -1,
                                             True)
        if rank_list:
            for useridpoint in rank_list:
                user = user_data.get_user_attrs(useridpoint[0], "name",
                                                "country", "head", "level",
                                                "visitor")
                userinfo = smsg.ranks.add()
                userinfo.user_head = int(user[2])
                userinfo.user_name = user[0]
                userinfo.user_country = user[1]
                userinfo.user_id = int(useridpoint[0])
                userinfo.user_visitor = int(user[4])
                userinfo.user_level = int(user[3])
                userinfo.user_index = int(useridpoint[1]) / 100000
                userinfo.user_life = 100000 - (int(useridpoint[1]) -
                                               userinfo.user_index * 100000)

        return auth.pack(smsg, 0, cmsg.common.userid)
コード例 #13
0
    def post(self, cmsg):
        mapid, index, life, top, total = user_data.get_user_attrs(
            cmsg.common.userid, "mapid", "mission", "mission_life",
            "mission_hard", "mission_total")
        map_data.complete_map(mapid, cmsg.common.userid, -2, cmsg.x, cmsg.y, 0,
                              self.application.update_map_script)

        if int(life) <= 0:
            rank = 0
            if int(index) >= 1:
                global_data.challenge_rank(
                    const.TAG_RANK_CHALLENGE, cmsg.common.userid,
                    int(index) * 100000 + 100000 - int(total),
                    self.application.challenge_rank_script, top)

                rank = global_data.challenge_finish_rank(
                    const.TAG_RANK_CHALLENGE_CUR, cmsg.common.userid,
                    int(index) * 100000 + 100000 - int(total),
                    self.application.challenge_rank_finish_script)
            smsg = smsg_challenge_finish()
            smsg.suc = 1
            smsg.exp = 0
            smsg.jewel = 0
            smsg.rank = rank
            all_map = global_data.get_challenge_map(
                const.TAG_CHALLENGE_MAP_LIST, 0, index)
            for mapid in all_map:
                author = smsg.authors.add()
                submap = msgpack.loads(mapid)
                author.user_head = int(submap[5])
                author.user_name = submap[2]
                author.user_country = submap[4]
                author.map_name = submap[1]
            return auth.pack(None, -1, cmsg.common.userid, smsg)

        return auth.pack(None, 0, cmsg.common.userid)
コード例 #14
0
    def post(self, cmsg):
        mapid, index, life, top, total = user_data.get_user_attrs(cmsg.common.userid,
                                               "mapid",
                                               "mission",
                                               "mission_life",
                                               "mission_hard",
                                               "mission_total")

        map_data.complete_map(mapid,
                              cmsg.common.userid,
                              -1,
                              0,
                              0,
                              cmsg.point,
                              self.application.update_map_script)

        # 成功结束
        if int(index) + 1 >= 8:
            global_data.challenge_rank(const.TAG_RANK_CHALLENGE,
                                          cmsg.common.userid, 
                                          (int(index) + 1) * 100000 + 100000 - int(total),
                                          self.application.challenge_rank_script,
                                          top)

            challenge_info = cache_data.get_cache(const.TAG_CHALLENGE_INFO, 300)
            inc_exp = challenge_info.get("exp") or 0
            inc_jewel = challenge_info.get("jewel") or 0
            user_data.challenge_complete(cmsg.common.userid, inc_exp, inc_jewel, self.application.static_data)

            rank = 0
            rank = global_data.challenge_finish_rank(const.TAG_RANK_CHALLENGE_CUR,
                                                  cmsg.common.userid, 
                                                  int(index) * 100000 + 100000 - int(total),
                                                  self.application.challenge_rank_finish_script)
            
            smsg = smsg_challenge_finish()
            smsg.suc = 0
            smsg.exp = inc_exp
            smsg.jewel = inc_jewel
            smsg.rank = rank
            all_map = global_data.get_challenge_map(const.TAG_CHALLENGE_MAP_LIST, 0, -1)
            for mapid in all_map:
                author = smsg.authors.add()
                submap = msgpack.loads(mapid)
                author.user_head    = int(submap[5])
                author.user_name    = submap[2]
                author.user_country = submap[4]
                author.map_name     = submap[1]
            return auth.pack(None, -1, cmsg.common.userid, smsg)

        
        mapinfo = global_data.get_challenge_mapid(const.TAG_CHALLENGE_MAP_LIST, int(index) + 1)
        if mapinfo is None:
            return auth.pack(None, const.ERROR_SYSTEM)
        mapinfo = msgpack.loads(mapinfo)
        
        user_data.play_map(cmsg.common.userid, mapinfo[0], const.GAME_CHALLENGE_SUCC_MODE)
        map_data.play_map(mapinfo[0])
        if mapinfo[3] != '0':
            user_data.inc_user_attr(mapinfo[3], "master_exp", 1)

        smsg = smsg_challenge_play()
        smsg.map_name       = mapinfo[1]
        smsg.user_name      = mapinfo[2]
        smsg.user_country   = mapinfo[4]
        smsg.user_head      = int(mapinfo[5])
        smsg.map_data       = mapinfo[6]
        map_coordinate = map_data.get_dead_coordinate(mapinfo[0], 50)
        for coord in map_coordinate:
            x, y = coord.split(":")
            smsg.x.append(int(x))
            smsg.y.append(int(y))

        return auth.pack(smsg, 0, cmsg.common.userid)
コード例 #15
0
ファイル: complete_handler.py プロジェクト: dqchess/mario
    def post(self, cmsg):
        userattrs = user_data.get_user_attrs(cmsg.common.userid, "level",
                                             "exp", "exp_time", "support",
                                             "mapid")
        userattrs = filter(None, userattrs)
        if not userattrs or len(userattrs) != 5:
            return auth.pack(None, const.ERROR_SYSTEM)
        mapid = userattrs[4]

        # 更新地图数据
        amount, pas, rank, template_id = map_data.complete_map(
            mapid, cmsg.common.userid, cmsg.suc, cmsg.x, cmsg.y, cmsg.time,
            self.application.update_map_script)

        exp_inc = 0
        exp_etra = 0
        support = 0
        hard = 0
        next_mapid = 0
        next_templateid = 0
        if cmsg.suc == 0:
            # 考试地图
            if template_id != '0':
                map_template = self.application.static_data.get_map_template(
                    int(template_id))
                if map_template:
                    if map_template.support > int(userattrs[3]):
                        support = map_template.support
                    next_templateid = map_template.nextid
                    next_map_template = self.application.static_data.get_map_template(
                        next_templateid)
                    if next_map_template:
                        hard = next_map_template.hard
                        next_mapid = next_templateid
                    else:
                        hard = 0
                        next_mapid = -1
            # 经验
            exp_inc = 2
            if not user_data.is_pass_map(cmsg.common.userid, mapid):
                exp_inc = self._get_exp(amount, pas)
            if util.now_time() < long(userattrs[2]):
                exp_etra = exp_inc

        # 升级
        level, exp, shengji = self._check_levelup(
            int(userattrs[0]), exp_inc + exp_etra + int(userattrs[1]))
        user_life_time1 = None
        if shengji:
            level_template = self.application.static_data.get_level_template(
                level)
            if level_template:
                user_life, user_life_time = user_data.get_user_attrs(
                    cmsg.common.userid, "life", "life_time")
                if int(user_life) < level_template.life_max and long(
                        user_life_time) < util.now_time():
                    user_life_time1 = util.now_time() + const.LIEF_TIME
        user_data.complete_map(cmsg.common.userid, mapid, cmsg.suc, cmsg.point,
                               cmsg.video, level, exp, rank, support,
                               next_templateid, user_life_time1, cmsg.time)

        smsg = smsg_complete_map()
        smsg.exp = exp_inc
        smsg.rank = rank
        smsg.testify = support
        smsg.extra_exp = exp_etra
        smsg.mapid = next_mapid
        smsg.support = hard
        return auth.pack(smsg, 0, cmsg.common.userid)