def dispatch_protocol(uniqid, command_id, sub_id, data): path = proto_2_path.get(command_id, None) if path is None: Logger.LogError("Dispatch_Protocol error:command_id:%d" % command_id) return try: module_name = __import__('logic.%s.zprotocol' % path, fromlist=['']) attr = getattr(module_name, 'proto_%d_%d' % (command_id, sub_id)) attr(uniqid, data) except: import traceback traceback.print_exc() return Logger.LogDebug("Dispatch_Protocol finish")
def _login_callback(self, uniqid, player): Logger.LogDebug("login_callback") if player is None: Logger.LogError("login_callback error,not exists") #TODO,登陆失败后清理数据 clientproxy = ClientProxyManager().get_client_proxy_by_uniqid(uniqid) if clientproxy: result = {"result": -1} clientproxy.send_data(COMMAND_ID_LOGIN,SUB_LOGIN_LOGIN, result) ClientProxyManager().remove_client_proxy(clientproxy) else: PlayerMgr().AddObj(uniqid, player) result = {"result": 1, "name": player.name(), "sex": player.sex()} player.send_data(COMMAND_ID_LOGIN, SUB_LOGIN_LOGIN, result)
def OnServer(uniqid, command_id, sub_id, data): """接收协议数据""" Logger.LogDebug("OnServer:%d,%d,%d,%s" % (uniqid, command_id, sub_id, data)) dict = None try: dict = json.loads(data) print dict.keys() except: import traceback traceback.print_exc() if dict is None: Logger.LogError("OnServer Error: dict is None:%d,%d,%d,%s" % (uniqid, command_id, sub_id, data)) return dispatch_protocol(uniqid, command_id, sub_id, dict) return 0, "success"
def OnConnector(command_id, sub_id, data): """游戏服作为客户端连接的服务器返回的数据""" Logger.LogDebug("OnConnector: %d,%d,%s" % (command_id, sub_id, data)) dict = None try: dict = json.loads(data) print dict.keys() except: import traceback traceback.print_exc() if dict is None: Logger.LogError("CallMethod Error: dict is None:%d,%d" % (command_id, sub_id, data)) return from common import SqlExec SqlExec.OnExecCallback(sub_id, dict) return 0, "success"