class PayHandler(tornado.web.RequestHandler): @auth.authenticated def post(self, cmsg): openid = user_data.get_user_attr(cmsg.common.userid, "openid") if openid is None: return auth.pack(None, const.ERROR_SYSTEM) jewel = 0 try: rechargs = self.application.db.query( "select id, amount from pay_t where userid = 0 and openid = %s and pt = %s", openid, cmsg.channel) for recharge in rechargs: jewel += recharge["amount"] / 10 self.application.db.update( "update pay_t set userid = %s where id = %s", cmsg.common.userid, recharge["id"]) except Exception, e: LOGGER.error("%s@%s", cmsg.channel, e) return auth.pack(None, const.ERROR_PAY) if jewel == 0: return auth.pack(None, -1, cmsg.common.userid) user_data.inc_user_attr(cmsg.common.userid, "jewel", jewel) smsg = smsg_pay() smsg.jewel = jewel return auth.pack(smsg, 0, cmsg.common.userid)
def post(self, cmsg): if not user_data.check_life(cmsg.common.userid, self.application.static_data): user_life_time = user_data.get_user_attr(cmsg.common.userid, "life_time") error = msg_life_error() error.server_time = util.now_time() error.life_time = long(user_life_time) return auth.pack(None, -1, cmsg.common.userid, error) mapatts = map_data.get_map_attrs(cmsg.id, "ownerid", "template", "data", "hard", "amount") user_data.play_map(cmsg.common.userid, cmsg.id, const.GAME_NORMAL_MODE) if mapatts[0] != '0': user_data.inc_user_attr(mapatts[0], "master_exp", 1) map_data.play_map(cmsg.id) dead_coordinate = map_data.get_dead_coordinate(cmsg.id, int(mapatts[4])) smsg = smsg_play_map() smsg.map_data = mapatts[2] for coord in dead_coordinate: x, y = coord.split(":") smsg.x.append(int(x)) smsg.y.append(int(y)) return auth.pack(smsg, 0, cmsg.common.userid)
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)
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)
def post(self, cmsg): if not user_data.exist_usermap(cmsg.common.userid, cmsg.id): return auth.pack(None, const.ERROR_SYSTEM) user_data.set_usermap_attrs(cmsg.common.userid, cmsg.id, { "url": cmsg.url, "data": cmsg.mapdata }) return auth.pack(None, 0, cmsg.common.userid)
def post(self, cmsg): if not util.check_input_nospace(cmsg.name, 16): return auth.pack(None, const.ERROR_INPUT) if not user_data.exist_usermap(cmsg.common.userid, cmsg.id): return auth.pack(None, const.ERROR_SYSTEM) user_data.set_usermap_attr(cmsg.common.userid, cmsg.id, "name", cmsg.name) return auth.pack(None, 0, cmsg.common.userid)
def post(self, cmsg): user_map_edit_list = user_data.get_usermap_list(cmsg.common.userid) try: index = user_map_edit_list.index(str(cmsg.id)) if index < 0 or index >= 12: return auth.pack(None, const.ERROR_SYSTEM) except: return auth.pack(None, const.ERROR_SYSTEM) user_data.delete_usermap(cmsg.common.userid, cmsg.id, index) return auth.pack(None, 0, cmsg.common.userid)
def post(self, cmsg): mapattrs = user_data.get_usermap_attrs(cmsg.common.userid, cmsg.map_id, "id", "name", "url", "date", "upload") if not mapattrs: return auth.pack(None, const.ERROR_SYSTEM) smsg = smsg_view_edit_single() smsg.info.id = int(mapattrs[0]) smsg.info.name = mapattrs[1] smsg.info.url = mapattrs[2] smsg.info.date = mapattrs[3] smsg.info.upload = int(mapattrs[4]) return auth.pack(smsg, 0, cmsg.common.userid)
def post(self, cmsg): edit_map_list = user_data.get_usermap_list(cmsg.common.userid) if not edit_map_list: user_data.create_usermap_list(cmsg.common.userid) if edit_map_list and edit_map_list[0] != '0': return auth.pack(None, const.ERROR_HAS_GUIDE) mapid = global_data.get_counter(const.TAG_USERMAP_COUNT) user_data.create_usermap(cmsg.common.userid, mapid, 0, "empty", cmsg.url, cmsg.data, 100) return auth.pack(None, 0, cmsg.common.userid)
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)
def post(self, cmsg): mapid = user_data.get_user_attr(cmsg.common.userid, "mapid") if user_data.like_pass_map(cmsg.common.userid, mapid, self.application.like_script) == 1: map_data.inc_map_attr(mapid, "like", 1) return auth.pack(None, 0, cmsg.common.userid)
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)
def post(self, cmsg): if not user_data.check_life(cmsg.common.userid, self.application.static_data): user_life_time = user_data.get_user_attr(cmsg.common.userid, "life_time") error = msg_life_error() error.server_time = util.now_time() error.life_time = long(user_life_time) if user_life_time else util.now_time() return auth.pack(None, -1, cmsg.common.userid, error) mapcache = user_data.get_user_attr(cmsg.common.userid, "mapid") if not mapcache: return auth.pack(None, const.ERROR_SYSTEM) user_data.play_map(cmsg.common.userid, mapcache, const.GAME_NORMAL_MODE) ownerid = map_data.replay_map(mapcache) if ownerid != '0': user_data.inc_user_attr(ownerid, "master_exp", 1) return auth.pack(None, 0, cmsg.common.userid)
def post(self, cmsg): openid = user_data.get_user_attr(cmsg.common.userid, "openid") if openid is None: return auth.pack(None, const.ERROR_SYSTEM) jewel = 0 try: rechargs = self.application.db.query( "select id, amount from pay_t where userid = 0 and openid = %s and pt = %s", openid, cmsg.channel) for recharge in rechargs: jewel += recharge["amount"] / 10 self.application.db.update( "update pay_t set userid = %s where id = %s", cmsg.common.userid, recharge["id"]) except Exception, e: LOGGER.error("%s@%s", cmsg.channel, e) return auth.pack(None, const.ERROR_PAY)
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)
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)
def post(self, cmsg): smsg = smsg_favorite_map() if not user_data.is_favourite_map(cmsg.common.userid, cmsg.id): smsg.num = map_data.inc_map_attr(cmsg.id, "favorite", 1) user_data.favourite_map(cmsg.common.userid, cmsg.id, False) else: smsg.num = map_data.inc_map_attr(cmsg.id, "favorite", -1) user_data.favourite_map(cmsg.common.userid, cmsg.id, True) return auth.pack(smsg, 0, cmsg.common.userid)
def post(self, cmsg): start = cmsg.index * 10 end = cmsg.index * 10 + 9 userid = cmsg.common.userid smsg = None # 最受欢迎 if cmsg.type == const.MAP_MOST_POPULAR: smsg = self._get_global_map(const.TAG_RANK_MOST_POPULAR_EX, userid, start, end, True, cmsg.ver) # 最新上传 elif cmsg.type == const.MAP_NEWER_UPLOAD: smsg = self._get_global_map(const.TAG_RANK_NEWER_UPLOAD, userid, start, end, True, cmsg.ver) # 近期热门 elif cmsg.type == const.MAP_RECENT_POPULAR: smsg = self._get_global_map(const.TAG_RANK_RECENT_POPULAR, userid, start, end, True, cmsg.ver) # 初级难度 elif cmsg.type == const.MAP_PRIMARY_HARD: smsg = self._get_global_map(const.TAG_RANK_PRIMARY_HARD, userid, start, end, False, cmsg.ver) # 中级难度 elif cmsg.type == const.MAP_MIDDLE_HARD: smsg = self._get_global_map(const.TAG_RANK_MIDDLE_HARD, userid, start, end, False, cmsg.ver) # 高级难度 elif cmsg.type == const.MAP_SENIOR_HARD: smsg = self._get_global_map(const.TAG_RANK_SENIOR_HARD, userid, start, end, False, cmsg.ver) # 大师难度 elif cmsg.type == const.MAP_MASTER_HARD: smsg = self._get_global_map(const.TAG_RANK_MASTER_HARD, userid, start, end, False, cmsg.ver) # 我收藏的 elif cmsg.type == const.MAP_MY_FAFOURITE: smsg = self._get_user_map(const.TAG_USER_FAFOURITE.format(cmsg.common.userid), userid, start, end, False) # 我上传的 elif cmsg.type == const.MAP_MY_UPLOAD: smsg = self._get_user_map(const.TAG_USER_UPLOAD.format(cmsg.common.userid), userid, start, end, True) # 我最近玩的 elif cmsg.type == const.MAP_MY_RECENT_PLAY: smsg = self._get_user_map(const.TAG_USER_TIME.format(cmsg.common.userid), userid, start, end, True) else: return auth.pack(None, const.ERROR_SYSTEM) return auth.pack(smsg, 0, cmsg.common.userid)
def post(self): cmsg = self.application.msg_factory(self.request.uri) result = auth.unpack(cmsg, self.request.body) if not result: self.__inter_response(auth.pack(None, const.ERROR_DECODE)) return if cmsg.DESCRIPTOR.fields_by_name.has_key("common"): result = auth.check(cmsg.common.userid, cmsg.common.sig, cmsg.common.pck_id) if isinstance(result, int): if result != 0: self.__inter_response(auth.pack(None, result)) return else: self.__inter_response(result) return response = yield self.application.executer.cmd(self._handle_msg, cmsg) self.__inter_response(response)
def post(self, cmsg): if cmsg.index < 0 or cmsg.index >= 12: return auth.pack(None, const.ERROR_SYSTEM) edit_map_list = user_data.get_usermap_list(cmsg.common.userid) if not edit_map_list: user_data.create_usermap_list(cmsg.common.userid) else: if edit_map_list[cmsg.index] != '0': return auth.pack(None, const.ERROR_SYSTEM) mapid = global_data.get_counter(const.TAG_USERMAP_COUNT) user_data.create_usermap(cmsg.common.userid, mapid, cmsg.index) smsg = smsg_create_map() smsg.map.id = mapid smsg.map.name = "empty" smsg.map.url = "" smsg.map.date = util.now_date_str() smsg.map.upload = 0 return auth.pack(smsg, 0, cmsg.common.userid)
def post(self, cmsg): video_data = "" if cmsg.video_id == cmsg.common.userid: video_data = user_data.watch_video_map(cmsg.video_id, cmsg.map_id, True) else: user_data.inc_user_attr(cmsg.common.userid, "video", 1) video_data = user_data.watch_video_map(cmsg.video_id, cmsg.map_id, False) smsg = smsg_view_video() smsg.video_data = video_data if video_data else "" smsg.map_data = map_data.get_map_attr(cmsg.map_id, "data") or "" return auth.pack(smsg, 0, cmsg.common.userid)
def post(self, cmsg): if not util.check_input(cmsg.text, 512): return auth.pack(None, const.ERROR_INPUT) userattrs = user_data.comment_map(cmsg.common.userid) keys = [ const.TAG_COMMENT_COUNT, const.TAG_MAP_COMMENT.format(cmsg.id), const.TAG_COMMENT_CACHE.format(cmsg.id), const.TAG_MAP.format(cmsg.id) ] args = [ 'head', userattrs[0], 'name', userattrs[1], 'country', userattrs[2], 'visitor', userattrs[3], 'text', cmsg.text, 'date', util.now_date_str(), 'userid', cmsg.common.userid, ] map_data.comment_map(cmsg.id, self.application.create_comment_script, keys, args) smsg = smsg_comment() smsg.comment.head = int(userattrs[0]) smsg.comment.name = userattrs[1] smsg.comment.country = userattrs[2] smsg.comment.text = cmsg.text smsg.comment.date = util.now_date_str() smsg.comment.userid = cmsg.common.userid smsg.comment.visitor = int(userattrs[3]) return auth.pack(smsg, 0, cmsg.common.userid)
def post(self, cmsg): if not util.check_input(cmsg.name, 32): return auth.pack(None, const.ERROR_INPUT) smsg = smsg_view_map() smsg.page = 0 import platform if platform.system() == "Windows": return auth.pack(smsg, 0, cmsg.common.userid) map_list = None import redis_search.query # 纯英文数字组合 if re.match('^[a-zA-Z0-9]+$', cmsg.name): if cmsg.name.isdigit() and len(cmsg.name) == 8: if int(cmsg.name) < 10010000: return auth.pack(smsg, 0, cmsg.common.userid) if map_data.exist_map(cmsg.name): map_list = [cmsg.name] else: return auth.pack(smsg, 0, cmsg.common.userid) else: map_query = redis_search.query.complete(const.TAG_MAP_SEARCH, cmsg.name) map_list = [s["id"] for s in map_query] map_query = redis_search.query.query(const.TAG_MAP_SEARCH, cmsg.name) map_list_temp = [s["id"] for s in map_query] for itemyuan in map_list_temp: if itemyuan not in map_list: map_list.append(itemyuan) # 其他情况 else: map_query = redis_search.query.query(const.TAG_MAP_SEARCH, cmsg.name) map_list = [s["id"] for s in map_query] if len(map_list) == 0: return auth.pack(smsg, 0, cmsg.common.userid) maps = map_data.get_map_set(0, map_list, "id", "name", "url", "amount", "pass") favorite_and_pass = user_data.is_favourite_and_pass_map(cmsg.common.userid, map_list) i = 0 for info in maps: map = smsg.infos.add() map.id = int(info[0]) map.name = info[1] map.url = info[2] map.amount = int(info[3]) map.pas = int(info[4]) map.collect = favorite_and_pass[i * 2] map.finish = favorite_and_pass[i * 2 + 1] i = i + 1 return auth.pack(smsg, 0, cmsg.common.userid)
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)
class ViewCommentHandler(tornado.web.RequestHandler): @auth.authenticated def post(self, cmsg): comments = map_data.view_comment(cmsg.id, self.application.get_comment_script) mapattrs = map_data.get_map_attrs(cmsg.id, "id", "name", "url", "ownerid", "ownername", "country", "head", "favorite", "amount", "pass", "date", "template", "hard", "like") is_user_favourite, is_user_pass = user_data.is_favourite_and_pass_map( cmsg.common.userid, [cmsg.id]) smsg = smsg_view_comment() smsg.infos.id = int(mapattrs[0]) smsg.infos.name = mapattrs[1] smsg.infos.url = mapattrs[2] smsg.infos.owner_id = int(mapattrs[3]) smsg.infos.owner_name = mapattrs[4] smsg.infos.country = mapattrs[5] smsg.infos.head = int(mapattrs[6]) smsg.infos.favorite = int(mapattrs[7]) smsg.infos.amount = int(mapattrs[8]) smsg.infos.pas = int(mapattrs[9]) smsg.infos.date = mapattrs[10] smsg.infos.collect = is_user_favourite smsg.infos.finish = is_user_pass smsg.infos.difficulty = int(mapattrs[12]) smsg.infos.like = int(mapattrs[13]) if mapattrs[13] else 0 if comments: try: for comment in comments: data_dict = {} for index in range(0, len(comment), 2): data_dict[comment[index]] = comment[index + 1] data = smsg.comments.add() data.head = int(data_dict.get("head")) data.name = data_dict.get("name") data.country = data_dict.get("country") data.visitor = int(data_dict.get("visitor")) data.text = data_dict.get("text") data.date = data_dict.get("date") data.userid = int(data_dict.get("userid")) except Exception, e: print e pass return auth.pack(smsg, 0, cmsg.common.userid)
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)
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)
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)
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)
def post(self, cmsg): if not util.check_input(cmsg.code, 16, True, True): return auth.pack(None, const.ERROR_INPUT) try: libao_pici = cmsg.code[:2] libao_type = cmsg.code[2:3] libao_reward = cmsg.code[3:5] except: return auth.pack(None, const.ERROR_LIBAO) if libao_type == '0': if user_data.has_libao(cmsg.common.userid, cmsg.code): return auth.pack(None, const.ERROR_LIBAO) key = const.TAG_GAME_LIBAO + libao_pici if not global_data.has_libao(key, cmsg.code): return auth.pack(None, const.ERROR_LIBAO) else: if user_data.has_libao(cmsg.common.userid, libao_pici): return auth.pack(None, const.ERROR_LIBAO) key = const.TAG_GAME_LIBAO + libao_pici if not global_data.has_libao(key, cmsg.code): return auth.pack(None, const.ERROR_LIBAO) reward = global_data.get_libao_reward(const.TAG_GAME_LIBAO_REWARD, libao_reward) life = reward.get("life", 0) if reward else 0 if life > 0: user_data.inc_user_attr(cmsg.common.userid, "life", life) if libao_type == '0': user_data.add_libao(cmsg.common.userid, cmsg.code) else: user_data.add_libao(cmsg.common.userid, libao_pici) key = const.TAG_GAME_LIBAO + libao_pici global_data.remove_libao(key, cmsg.code) smsg = smsg_libao() smsg.life = life return auth.pack(smsg, 0, cmsg.common.userid)