Ejemplo n.º 1
0
    void test()
    {
        MsgConfigLoader xl = new MsgConfigLoader();

        xl.msgConfigs = new List <MsgConfig>();

        for (int i = 0; i < 5; ++i)
        {
            MsgConfig scfg = new MsgConfig();
            scfg.mainId = 100;
            scfg.name   = "MDM_GP_LOGON";


            scfg.subcfgs = new List <MsgSubCfg>();
            for (int j = 0; j < 2; ++j)
            {
                MsgSubCfg sub = new MsgSubCfg();
                sub.assId   = 1;
                sub.type    = 0;
                sub.hasData = true;
                sub.rspType = "MSG_GP_R_LogonResult";
                sub.handler = "MDM_GP_LOGON_Handler";
                scfg.subcfgs.Add(sub);
            }
            xl.msgConfigs.Add(scfg);
        }

        XmlHelper.XmlSerializeToFile(xl, "G:/UnityProject/LotterySvn/trunk/Assets/test.xml", System.Text.Encoding.UTF8);
    }
Ejemplo n.º 2
0
    void AnalzyPackage(Lopackage pkg, bool isGameSocket = false)
    {
        if (pkg == null)
        {
            return;
        }
        NetMessageHead head = pkg.head;
        //获取消息配置
        MsgConfig msgCfg = msgCfgLoader.GetMsgConfig(head.bMainID);

        if (isGameSocket)
        {
            switch (Global.CurrentGameId)
            {
            case 10301800:                    //百家乐
                if (baccaratMsgConfigLoader != null)
                {
                    msgCfg = baccaratMsgConfigLoader.GetMsgConfig(head.bMainID);
                }
                break;
            }
        }
        if (msgCfg == null)
        {
            if (isGameSocket)
            {
                Debug.LogWarning("this messageid: " + head.bMainID + " this bAssistantID: " + head.bAssistantID + " doesn't has its config");
            }
            return;
        }
        MsgSubCfg subCfg = msgCfg.GetMsgSubCfg(head.bAssistantID);

        if (subCfg == null)
        {
            if (isGameSocket)
            {
                Debug.LogWarning("this messageid: " + head.bMainID + " this bAssistantID: " + head.bAssistantID + " doesn't has its config");
            }
            return;
        }
        //根据消息配置 获得处理类 以及 返回数据类型
        Type rspType = Type.GetType(subCfg.rspType);

        if (rspType == null)
        {
            Debug.LogError("this messageid: " + head.bMainID + " this bAssistantID: " + head.bAssistantID + " do not have subCfg.rspType");
        }
        Type InterfaceType = typeof(IHandler <>);

        InterfaceType = InterfaceType.MakeGenericType(rspType);

        Type handlerType = Type.GetType(subCfg.handler);

        if (handlerType == null)
        {
            Debug.LogError("this messageid: " + head.bMainID + " this bAssistantID: " + head.bAssistantID + " subCfg.handler error");
        }
        object obj = Activator.CreateInstance(handlerType);

        //将处理类注入
        context.injectionBinder.injector.Inject(obj);
        //调用处理类的 回调
        object[] args = new object[2];
        args[0] = head;
        if (subCfg.hasData)
        {
            if (pkg.objectData == null)
            {
                Debug.LogError("this messageid: " + head.bMainID + " this bAssistantID: " + head.bAssistantID + " pkg.objectData==null");
                args[1] = null;                //特殊处理
            }
            else if (head.uMessageSize != pkg.objectData.Length + 20)
            {
                Debug.LogError("this messageid: " + head.bMainID + " this bAssistantID: " + head.bAssistantID + " pkg.head.uMessageSize != pkg.objectData.Length");
                args[1] = null;                //特殊处理
            }
            else if (head.uMessageSize == pkg.objectData.Length + 20)
            {
                object dataObj = LoSocket.BytesToStruct(pkg.objectData, rspType);
                args[1] = dataObj;
            }
            else
            {
                Debug.LogError("this messageid: " + head.bMainID + " this bAssistantID: " + head.bAssistantID + " other error");
                args[1] = null;
            }
        }
        else
        {
            args[1] = null;
        }
        InterfaceType.InvokeMember("OnReceive", BindingFlags.Default | BindingFlags.InvokeMethod, null, obj, args);
        obj = null;
    }