def game_mgr_fight_system_service_run(controller, req, res): if not req.parse_success or not req.content: Log().warn("service %d req parse err %s" % (config.GAME_MGR_FIGHT_SYSTEM_SERVICE, req.parse_err)) return room_id = req.content["room_id"] opt = req.content["opt"] param = req.content["param"] # 客户端上来的参数按 英文逗号分隔 msg = '' room_runtime = controller.mem_cache.get(ckv.get_ckv_room_runtime(room_id)) if room_runtime is None: res.content = {"ret": -1, "err_msg": '', "opt": opt, "msg": msg} return if opt == "attacked": attack_id, player_id, hp = [int(v) for v in param.split(",")] room_runtime.fight_system.attacked(attack_id, player_id, hp) msg = "#".join([ str(attack_id), str(room_runtime.fight_system.get_gaol(attack_id)) ]) elif opt == "query_players": msg = room_runtime.fight_system.query_players_hp() res.content = {"ret": 0, "err_msg": '', "opt": opt, "msg": msg}
def synchronization_report_action_service_run(controller, req, res): if not req.parse_success or not req.content: Log().warn("service %d req parse err %s" % (config.SYNCHRONIZATION_REPORT_ACTION_SERVICE, req.parse_err)) return user_id = req.content["user_id"] action = req.content["action"] client_frame = req.content["frame"] err_msg = '' req_dict = controller.handler_dict[config.ROOM_MGR_QUERY_USER_BELONGED_ROOM_SERVICE].inline_call(controller, { "user_id": user_id }) if req_dict["ret"] != 0: res.content = { "ret": -1, "err_msg": "report action error:" + req_dict["err_msg"] } return room_id = req_dict["room_id"] room_runtime = controller.mem_cache.get(ckv.get_ckv_room_runtime(room_id)) sync_controller = room_runtime.get_sync() if sync_controller.report_logic_frame(controller, client_frame, user_id, action): ret = 0 else: ret = -1 res.content = { "ret": ret, "err_msg": err_msg, "frame": sync_controller.server_frame }
def init_room_runtime(controller, room_id): room_runtime_key = ckv.get_ckv_room_runtime(room_id) room_runtime = controller.mem_cache.get(room_runtime_key) if room_runtime is None: room_runtime = room_mgr.GameRoom(room_id) controller.mem_cache.set(room_runtime_key, room_runtime) return room_runtime
def out_of_last_room(controller, user_id): res_dict = controller.handler_dict[ config.ROOM_MGR_QUERY_USER_BELONGED_ROOM_SERVICE].inline_call( controller, { "user_id": user_id, }) if res_dict["ret"] == 0: room_id = res_dict["room_id"] room_runtime = controller.mem_cache.get( ckv.get_ckv_room_runtime(room_id)) room_runtime.remove_user(user_id) if room_runtime.empty(): controller.mem_cache.remove(ckv.get_ckv_room_runtime(room_id)) user_runtime = controller.mem_cache.get( ckv.get_ckv_user_runtime(user_id)) user_runtime.clear() controller.mem_cache.remove(ckv.get_ckv_user_runtime(user_id))
def game_mgr_player_event_service_run(controller, req, res): if not req.parse_success or not req.content: Log().warn("service %d req parse err %s" % (config.GAME_MGR_PLAYER_EVENT_SERVICE, req.parse_err)) return room_id = req.content["room_id"] opt = req.content["opt"] event = req.content["event"] param = req.content["param"] room_runtime = controller.mem_cache.get(ckv.get_ckv_room_runtime(room_id)) res.content = {"ret": 0, "opt": opt, "err_msg": ''}
def game_mgr_register_robot_service_run(controller, req, res): if not req.parse_success or not req.content: Log().warn("service %d req parse err %s" % (config.GAME_MGR_REGISTER_ROBOT_SERVICE, req.parse_err)) return room_id = req.content["room_id"] robot_key = req.content["robot_key"] user_id = req.content["user_id"] born_point = 0 ret = 0 err_msg = '' room_runtime = controller.mem_cache.get(ckv.get_ckv_room_runtime(room_id)) if room_runtime is None: res.content = {"ret": -1, "err_msg": "room not exist"} return fight_system = room_runtime.fight_system if robot_key in fight_system.robots_keys.keys(): old_user_id, robot_id = fight_system.robots_keys.get(robot_key) if user_id != old_user_id and room_runtime.isOnline(old_user_id): res.content = {ret: -1, err_msg: "has been controller"} return else: robot_id = common.get_server_core(controller).get_robot_id() fight_system.robots_keys[robot_key] = (user_id, robot_id) if robot_id not in fight_system.players: controller.handler_dict[ config.ROOM_MGR_ENTER_ROOM_SERVICE].inline_call( controller, { "user_id": robot_id, "room_type": 3, "room_id": room_id }) res.content = { "ret": ret, "err_msg": err_msg, "robot_id": robot_id, "robot_key": robot_key, "born": born_point }
def synchronization_query_action_service_run(controller, req, res): if not req.parse_success or not req.content: Log().warn( "service %d req parse err %s" % (config.SYNCHRONIZATION_QUERY_ACTION_SERVICE, req.parse_err)) return client_frame = req.content["frame"] user_id = req.content["user_id"] ret = 0 err_msg = '' # 查询用户所在游戏房间 req_dict = controller.handler_dict[ config.ROOM_MGR_QUERY_USER_BELONGED_ROOM_SERVICE].inline_call( controller, {"user_id": user_id}) if req_dict["ret"] != 0: res.content = { "ret": -1, "err_msg": "query action error:" + req_dict["err_msg"] } return room_id = req_dict["room_id"] room_runtime = controller.mem_cache.get(ckv.get_ckv_room_runtime(room_id)) sync_controller = room_runtime.get_sync() action = sync_controller.query_logic_frame(user_id, client_frame) if action is None: ret = -1 err_msg = 'query error' action = '' res.content = { "ret": ret, "err_msg": err_msg, "action": action, "frame": sync_controller.server_frame }
def room_mgr_query_room_users_service_run(controller, req, res): if not req.parse_success or not req.content: Log().warn("service %d req parse err %s" % (config.ROOM_MGR_QUERY_ROOM_USERS_SERVICE, req.parse_err)) return room_id = req.content["room_id"] err_msg = "" ret = 0 user_id_list = '' room_runtime = controller.mem_cache.get(ckv.get_ckv_room_runtime(room_id)) if room_runtime is None: ret = -1 else: user_id_list = room_runtime.get_user_id_list_str() res.content = { "ret": ret, "user_id_list": user_id_list, "err_msg": err_msg }
def game_mgr_query_born_point_service_run(controller, req, res): if not req.parse_success or not req.content: Log().warn("service %d req parse err %s" % (config.GAME_MGR_QUERY_BORN_POINT_SERVICE, req.parse_err)) return user_id = req.content["user_id"] room_id = req.content["room_id"] ret = 0 err_msg = '' born_point = -1 room_runtime = controller.mem_cache.get(ckv.get_ckv_room_runtime(room_id)) if room_runtime is None: res.content = { "ret": -1, "err_msg": "room not exist", "born": born_point, "user_id": user_id } return born_point = room_runtime.fight_system.query_player_born_point(user_id) if born_point is None: ret = -1 err_msg = 'user not exist' born_point = -1 res.content = { "ret": ret, "err_msg": err_msg, "born": born_point, "user_id": user_id }
def game_mgr_add_hp_service_run(controller, req, res): if not req.parse_success or not req.content: Log().warn("service %d req parse err %s" % (config.GAME_MGR_ADD_HP_SERVICE, req.parse_err)) return user_id = req.content["user_id"] hp = req.content["hp"] # 获取玩家所在房间 req_dict = controller.handler_dict[ config.ROOM_MGR_QUERY_USER_BELONGED_ROOM_SERVICE].inline_call( controller, {"user_id": user_id}) if req_dict["ret"] != 0: res.content = { "ret": -1, "err_msg": '', } return room_id = req_dict["room_id"] room_runtime = controller.mem_cache.get(ckv.get_ckv_room_runtime(room_id)) room_runtime.fight_system.add_hp(user_id, hp) res.content = {"ret": 0, "err_msg": ''}