lcy
7 天以前 b97ca7fc69d2cddeaf1af2d4e59ba4b413034784
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
using UnityEngine;
using System;
using System.Collections.Generic;
 
public class PackageRegedit
{
    #region 主工程原生的封包
    static object lockojb1 = new object();
    static Dictionary<ushort, Type> m_PackageTable = new Dictionary<ushort, Type>();
    static Dictionary<ushort, Type> packageTable
    {
        get
        {
            lock (lockojb1) { return m_PackageTable; }
        }
    }
    static object lockojb2 = new object();
    static Dictionary<ushort, DtcBasic> m_PackToBusinessTable = new Dictionary<ushort, DtcBasic>();
    static Dictionary<ushort, DtcBasic> packToBusinessTable
    {
        get
        {
            lock (lockojb2) { return m_PackToBusinessTable; }
        }
    }
    #endregion
 
    public static void Init()
    {
        // 登记相应的数据体及对应的数据转逻辑类(去重后)
        Register(typeof(H0102_tagCDBPlayer), typeof(DTC0102_tagCDBPlayer));
        Register(typeof(HA004_tagServerDateTime), typeof(DTCA004_tagServerDateTime));
        Register(typeof(HA103_tagMCOpenServerDay), typeof(DTCA103_tagMCOpenServerDay));
        Register(typeof(H0403_tagPlayerLoginLoadOK), typeof(DTC0403_tagPlayerLoginLoadOK));
        Register(typeof(H0101_tagServerPrepared), typeof(DTC0101_tagServerPrepared));
        Register(typeof(H0104_tagServerDisconnect), typeof(DTC0104_tagServerDisconnect));
        Register(typeof(H0724_tagRolePackCanUseCount), typeof(DTC0724_tagRolePackCanUseCount));
        Register(typeof(H0725_tagRolePackRefreshEx), typeof(DTC0725_tagRolePackRefreshEx));
        Register(typeof(H0704_tagRolePackRefresh), typeof(DTC0704_tagRolePackRefresh));
        Register(typeof(H0706_tagUseItemSuccess), typeof(DTC0706_tagUseItemSuccess));
        Register(typeof(H0707_tagItemCountRefresh), typeof(DTC0707_tagItemCountRefresh));
        Register(typeof(H0709_tagClearItem), typeof(DTC0709_tagClearItem));
        Register(typeof(H0711_tagClearItemPack), typeof(DTC0711_tagClearItemPack));
        // Register(typeof(HA204_tagMCVPackRefresh), typeof(DTCA204_tagMCVPackRefresh));
        // Register(typeof(HA205_tagMCVPackClear), typeof(DTCA205_tagMCVPackClear));
        Register(typeof(HA206_tagMCAutoItemCountRefresh), typeof(DTCA206_tagMCAutoItemCountRefresh));
        Register(typeof(HA710_tagMCGuideState), typeof(DTCA710_tagMCGuideState));
        Register(typeof(H0418_tagObjInfoRefresh), typeof(DTC0418_tagObjInfoRefresh));
        Register(typeof(HA709_tagObjInfoListRefresh), typeof(DTCA709_tagObjInfoListRefresh));
        Register(typeof(H0113_tagServerHeart), typeof(DTC0113_tagServerHeart));
        Register(typeof(H0111_tagOnlineReply), typeof(DTC0111_tagOnlineReply));
        Register(typeof(H0608_tagNPCDie), typeof(DTC0608_tagNPCDie));
        Register(typeof(H0612_tagClearObjBuff), typeof(DTC0612_tagClearObjBuff));
        Register(typeof(HA110_tagMCCoinToGoldCountInfo), typeof(DTCA110_tagMCCoinToGoldCountInfo));
        Register(typeof(HA008_tagGCPlayerRecInfo), typeof(DTCA008_tagGCPlayerRecInfo));
        Register(typeof(HAA02_tagSCFirstChargeInfo), typeof(DTCAA02_tagSCFirstChargeInfo));
        Register(typeof(HAA03_tagMCDailyPackBuyGiftInfo), typeof(DTCAA03_tagMCDailyPackBuyGiftInfo));
        Register(typeof(HA302_tagMCFuncOpenStateList), typeof(DTCA302_tagMCFuncOpenStateList));
        Register(typeof(HA320_tagSCFBInfoList), typeof(DTCA320_tagSCFBInfoList));
        Register(typeof(H0212_tagNotifyCode), typeof(DTC0212_tagNotifyCode));
        Register(typeof(H0316_tagPackResetOK), typeof(DTC0316_tagPackResetOK));
        Register(typeof(HA3BD_tagMCBuyEnterInfo), typeof(DTCA3BD_tagMCBuyEnterInfo));
        Register(typeof(HA350_tagMCTreasureResult), typeof(DTCA350_tagMCTreasureResult));
        Register(typeof(HA351_tagMCTreasureInfo), typeof(DTCA351_tagMCTreasureInfo));
        Register(typeof(HA362_tagMCMailList), typeof(DTCA362_tagMCMailList));
        Register(typeof(HA363_tagMCMailStateChange), typeof(DTCA363_tagMCMailStateChange));
        Register(typeof(HA501_tagMCNotifyRequestJoinFamilyInfo), typeof(DTCA501_tagMCNotifyRequestJoinFamilyInfo));
        Register(typeof(HA705_tagSCQueryPlayerCacheResult), typeof(DTCA705_tagSCQueryPlayerCacheResult));
        Register(typeof(HA801_tagMCGiveAwardInfo), typeof(DTCA801_tagMCGiveAwardInfo));
        Register(typeof(HA802_tagSCShopItemBuyCntInfo), typeof(DTCA802_tagSCShopItemBuyCntInfo));
        Register(typeof(HA803_tagSCShopRefreshItemInfo), typeof(DTCA803_tagSCShopRefreshItemInfo));
        Register(typeof(HA809_tagMCItemDayUseCntInfo), typeof(DTCA809_tagMCItemDayUseCntInfo));
        Register(typeof(HB117_tagMCFaceInfo), typeof(DTCB117_tagMCFaceInfo));
        Register(typeof(HB118_tagMCFacePicInfo), typeof(DTCB118_tagMCFacePicInfo));
        Register(typeof(HB120_tagMCZhanlingInfo), typeof(DTCB120_tagMCZhanlingInfo));
        Register(typeof(HA311_tagMCSyncRealmInfo), typeof(DTCA311_tagMCSyncRealmInfo));
        Register(typeof(HB110_tagMCTaskInfo), typeof(DTCB110_tagMCTaskInfo));
        Register(typeof(H3202_tagServerResponse), typeof(DTC3202_tagServerResponse));
        Register(typeof(HA130_tagMCViewBillboardRet), typeof(DTCA130_tagMCViewBillboardRet));
        Register(typeof(HB419_tagSCObjHPRefresh), typeof(DTCB419_tagSCObjHPRefresh));
        Register(typeof(HB420_tagMCTurnFightState), typeof(DTCB420_tagMCTurnFightState));
        Register(typeof(HB421_tagMCTurnFightObjAction), typeof(DTCB421_tagMCTurnFightObjAction));
        Register(typeof(HB422_tagMCTurnFightObjDead), typeof(DTCB422_tagMCTurnFightObjDead));
        Register(typeof(HB423_tagMCTurnFightObjReborn), typeof(DTCB423_tagMCTurnFightObjReborn));
        Register(typeof(HB424_tagSCTurnFightInit), typeof(DTCB424_tagSCTurnFightInit));
        Register(typeof(HB425_tagSCTurnFightReportSign), typeof(DTCB425_tagSCTurnFightReportSign));
        Register(typeof(HB426_tagSCTurnFightTag), typeof(DTCB426_tagSCTurnFightTag));
        Register(typeof(HB427_tagSCUseSkill), typeof(DTCB427_tagSCUseSkill));
        Register(typeof(HB428_tagSCBuffRefresh), typeof(DTCB428_tagSCBuffRefresh));
        Register(typeof(HB429_tagSCBuffDel), typeof(DTCB429_tagSCBuffDel));
        Register(typeof(HB430_tagSCTurnFightReport), typeof(DTCB430_tagSCTurnFightReport));
        Register(typeof(H0407_tagNPCDisappear), typeof(DTC0407_tagNPCDisappear));
        Register(typeof(HB418_tagSCObjPropertyRefreshView), typeof(DTCB418_tagSCObjPropertyRefreshView));
        Register(typeof(HB124_tagSCHeroPresetInfo), typeof(DTCB124_tagSCHeroPresetInfo));
        Register(typeof(HA207_tagSCPackBuyInfo), typeof(DTCA207_tagSCPackBuyInfo));
        Register(typeof(H0722_tagItemDeadLockRefresh), typeof(DTC0722_tagItemDeadLockRefresh));
        Register(typeof(HB125_tagSCPlayerHeroInfo), typeof(DTCB125_tagSCPlayerHeroInfo));
        Register(typeof(HA814_tagMCMakeItemAnswer), typeof(DTCA814_tagMCMakeItemAnswer));
        Register(typeof(HB122_tagSCHeroInfo), typeof(DTCB122_tagSCHeroInfo));
        Register(typeof(HA338_tagSCInvestInfo), typeof(DTCA338_tagSCInvestInfo));
        Register(typeof(HB121_tagMCTreeInfo), typeof(DTCB121_tagMCTreeInfo));
        Register(typeof(HA720_tagMCCreateRoleAwardState), typeof(DTCA720_tagMCCreateRoleAwardState));
        Register(typeof(HB405_tagMCAddExp), typeof(DTCB405_tagMCAddExp));
        Register(typeof(HB123_tagSCDropBootyInfo), typeof(DTCB123_tagSCDropBootyInfo));
        Register(typeof(HB036_tagSCGoldRushInfo), typeof(DTCB036_tagSCGoldRushInfo));
        Register(typeof(HB037_tagSCGoldRushCampInfo), typeof(DTCB037_tagSCGoldRushCampInfo));
        Register(typeof(HA722_tagSCADInfoList), typeof(DTCA722_tagSCADInfoList));
        Register(typeof(H0320_tagFBEnd), typeof(DTC0320_tagFBEnd));
        Register(typeof(HA502_tagSCDonateCntInfo), typeof(DTCA502_tagSCDonateCntInfo));
        Register(typeof(HA512_tagMCFamilyZhenbaogeInfo), typeof(DTCA512_tagMCFamilyZhenbaogeInfo));
        Register(typeof(HA513_tagMCFamilyActionInfo), typeof(DTCA513_tagMCFamilyActionInfo));
        Register(typeof(HA520_tagMCRoleFamilyInfo), typeof(DTCA520_tagMCRoleFamilyInfo));
        Register(typeof(HA524_tagSCFamilyMemDel), typeof(DTCA524_tagSCFamilyMemDel));
        Register(typeof(HA505_tagSCFamilyCrossInfo), typeof(DTCA505_tagSCFamilyCrossInfo));
        Register(typeof(HA522_tagMCFamilyReqJoinInfo), typeof(DTCA522_tagMCFamilyReqJoinInfo));
        Register(typeof(HA523_tagMCFamilyViewList), typeof(DTCA523_tagMCFamilyViewList));
        Register(typeof(HA009_tagSCGameRecInfo), typeof(DTCA009_tagSCGameRecInfo));
        Register(typeof(HA922_tagSCArenaMatchList), typeof(DTCA922_tagSCArenaMatchList));
        Register(typeof(HA923_tagSCArenaPlayerInfo), typeof(DTCA923_tagSCArenaPlayerInfo));
        Register(typeof(HB109_tagSCDailyTaskInfo), typeof(DTCB109_tagSCDailyTaskInfo));
        Register(typeof(HB201_tagSCTianziKYInfo), typeof(DTCB201_tagSCTianziKYInfo));
        Register(typeof(HA340_tagSCSuccessInfoList), typeof(DTCA340_tagSCSuccessInfoList));
        Register(typeof(HA342_tagSCSuccessAwardRecordList), typeof(DTCA342_tagSCSuccessAwardRecordList));
        Register(typeof(HB128_tagSCLLMJInfo), typeof(DTCB128_tagSCLLMJInfo));
        Register(typeof(HA30D_tagSCDaySignInfo), typeof(DTCA30D_tagSCDaySignInfo));
        Register(typeof(HA123_tagUpdatePlayerNameCount), typeof(DTCA123_tagUpdatePlayerNameCount));
        Register(typeof(HA921_tagSCRenameResult), typeof(DTCA921_tagSCRenameResult));
        Register(typeof(HA303_tagSCHorseClassInfo), typeof(DTCA303_tagSCHorseClassInfo));
        Register(typeof(HA304_tagSCHorseSkinInfo), typeof(DTCA304_tagSCHorseSkinInfo));
        Register(typeof(HB119_tagSCModelInfo), typeof(DTCB119_tagSCModelInfo));
        Register(typeof(HB126_tagSCTitleInfo), typeof(DTCB126_tagSCTitleInfo));
        Register(typeof(HB127_tagSCChatBoxInfo), typeof(DTCB127_tagSCChatBoxInfo));
        Register(typeof(HB431_tagSCTurnFightRet), typeof(DTCB431_tagSCTurnFightRet));
        Register(typeof(HB310_tagMCTalk), typeof(DTCB310_tagMCTalk));
        Register(typeof(HB311_tagMCTalkCacheList), typeof(DTCB311_tagMCTalkCacheList));
        Register(typeof(HA319_tagMCPackDownloadRecord), typeof(DTCA319_tagMCPackDownloadRecord));
        Register(typeof(HB129_tagSCLineupRecommendInfo), typeof(DTCB129_tagSCLineupRecommendInfo));
        Register(typeof(HAB05_tagSCOSACelebrationInfo), typeof(DTCAB05_tagSCOSACelebrationInfo));
        Register(typeof(HB131_tagSCHeroFatesInfo), typeof(DTCB131_tagSCHeroFatesInfo));
        Register(typeof(HB130_tagSCBeautyInfo), typeof(DTCB130_tagSCBeautyInfo));
        Register(typeof(HB040_tagSCTravelInfo), typeof(DTCB040_tagSCTravelInfo));
        Register(typeof(HA3C7_tagMCGubaoInfo), typeof(DTCA3C7_tagMCGubaoInfo));
        Register(typeof(HB202_tagSCDingjungeInfo), typeof(DTCB202_tagSCDingjungeInfo));
        Register(typeof(HB432_tagSCViewNPCAttrRet), typeof(DTCB432_tagSCViewNPCAttrRet));
        Register(typeof(HA503_tagSCFamilyTaofaInfo), typeof(DTCA503_tagSCFamilyTaofaInfo));
        Register(typeof(HA504_tagSCFamilyTaofaAtkRet), typeof(DTCA504_tagSCFamilyTaofaAtkRet));
        Register(typeof(HB132_tagSCMinggeInfo), typeof(DTCB132_tagSCMinggeInfo));
        Register(typeof(HB161_tagSCFuncPresetInfoList), typeof(DTCB161_tagSCFuncPresetInfoList));
        Register(typeof(HB162_tagSCFuncPresetSwitchInfo), typeof(DTCB162_tagSCFuncPresetSwitchInfo));
        Register(typeof(HB163_tagSCBatPresetSwitchInfo), typeof(DTCB163_tagSCBatPresetSwitchInfo));
        Register(typeof(HA001_tagBroadCastInfo), typeof(DTCA001_tagBroadCastInfo));
        Register(typeof(HA519_tagSCTagFamilyInfo), typeof(DTCA519_tagSCTagFamilyInfo));
        Register(typeof(HA131_tagSCSettingDataInfo), typeof(DTCA131_tagSCSettingDataInfo));
        Register(typeof(HAA88_tagMCActLunhuidianInfo), typeof(DTCAA88_tagMCActLunhuidianInfo));
        Register(typeof(HAA89_tagMCActLunhuidianPlayerInfo), typeof(DTCAA89_tagMCActLunhuidianPlayerInfo));
        Register(typeof(HA124_tagMCPlayerInfo), typeof(DTCA124_tagMCPlayerInfo));
        Register(typeof(HA106_tagMCCoinToGoldReport), typeof(DTCA106_tagMCCoinToGoldReport));
        Register(typeof(HA30C_tagMCPlayerRewardGetRecord), typeof(DTCA30C_tagMCPlayerRewardGetRecord));
    }
 
    //主工程注册封包
    public static void Register(Type _pack, Type _business)
    {
        var packInstance = _pack.Assembly.CreateInstance(_pack.Name) as GameNetPackBasic;
        var businessInstance = _business.Assembly.CreateInstance(_business.Name) as DtcBasic;
        if (packToBusinessTable.ContainsKey(packInstance.cmd))
        {
            Debug.LogErrorFormat("重复封包登记: {0}!", _pack.Name);
        }
        else
        {
            packToBusinessTable[packInstance.cmd] = businessInstance;
            packageTable[packInstance.cmd] = _pack;
        }
    }
 
    public static bool Contain(ushort _cmd)
    {
        return packToBusinessTable.ContainsKey(_cmd);
    }
    public static void Distribute(GameNetPackBasic _package)
    {
 
#if UNITY_EDITOR
        if (_package.socketType == ServerType.MainFight)
            NetPkgCtl.RecordPackage(ServerType.MainFight, string.Empty, NetPackagetType.Server, _package.ToString(), FieldPrint.PrintFields(_package), FieldPrint.PrintFieldsExpand(_package, true));
#endif
 
        try
        {
            //执行主工程的封包
            if (packToBusinessTable.ContainsKey(_package.cmd) && BattleManager.Instance.IsCanDistributePackage(_package))
                packToBusinessTable[_package.cmd].Done(_package);
 
        }
        catch (Exception ex)
        {
            Debug.LogError(ex.Message + "\r\n" + ex.StackTrace);
            Debug.LogErrorFormat("封包是否为Null:{0};", _package == null);
            if (_package != null)
            {
                Debug.LogErrorFormat("封包编号是:{0}; 名是{1}", _package.cmd, _package.GetType().Name);
            }
        }
    }
 
    /// <summary>
    /// 转换一个协议包
    /// </summary>
    /// <param name="vBytes"></param>
    /// <returns></returns>
    public static GameNetPackBasic TransPack(ServerType socketType, ushort cmd, byte[] vBytes)
    {
#if UNITY_EDITOR
        int length = vBytes.Length;
        string vStr = "";
        for (int i = 0; i < length; i++)
        {
            vStr += vBytes[i].ToString("x2").ToUpper() + ",";
        }
#endif
        // 主工程有登记
        if (packageTable.ContainsKey(cmd))
        {
            var packageType = packageTable[cmd];
            // 实例化并强转为协议包基类
            var packageInstance = packageType.Assembly.CreateInstance(packageType.Name) as GameNetPackBasic;
            packageInstance.ReadFromBytes(vBytes);// 解析内容
 
            packageInstance.socketType = socketType;
#if UNITY_EDITOR
            NetPkgCtl.RecordPackage(socketType, vStr, NetPackagetType.Server, packageInstance.ToString(), FieldPrint.PrintFields(packageInstance), FieldPrint.PrintFieldsExpand(packageInstance, true));
#endif
            return packageInstance;
        }
        else //未注册
        {
#if UNITY_EDITOR
            NetPkgCtl.RecordPackage(socketType, vStr, NetPackagetType.Server, string.Empty, string.Empty, null);
#endif
        }
        return null;
    }
}