项目实战—网络部分

消息类型的定义在    MessageDef   中

消息发送类:NetSender  类

C2GS  表示   请求服务

GS2C  标识  服务器返回

请求服务  不填充消息体

   // 领取势力奖励
        public void OnFactionForceReward()
        {
            Globals.MNetManager.SendProtobufMsg(EMSGID.C2GS_GET_FORCE_REWARD_REQ, null, true);
        }

 请求服务   填充消息体

        // 转换势力
        public void OnFactionChangeForce(int id)
        {
            WozMsg.pb_ChangeForceReq msg = new WozMsg.pb_ChangeForceReq();
            msg.ForceId = id;
            Globals.MNetManager.SendProtobufMsg(EMSGID.C2GS_CHANGE_FORCE_REQ, msg, true);
        }

接受消息   NetReceiver  类

接受过来,解析,添加到Item中,然后通知界面显示

   // 领取尸潮围剿积分奖励
        [PacketHandlerAttribute(EMSGID.GS2C_BCT_GET_POINT_REWARD_RES, typeof(WozMsg.pb_BCTGetPointRewardRes))]
        public void OnBCTGetPointRewardRes(CGameMessage cmsg)
        {
            var msg = WozMsg.pb_BCTGetPointRewardRes.Parser.ParseFrom(cmsg.stream);
            if (!CheckErroInfo(msg.Result))
                return;
            Dictionary<int, int> dic = ConvertMsgItem(msg.Items);
            HelpUtil.AddItem(dic, "尸潮围剿积分奖励");
            EventManager.Notify(EventNames.Faction.BCT_PointReward, dic);
        }

猜你喜欢

转载自blog.csdn.net/qq_35647121/article/details/81907811
今日推荐