示例#1
0
    private NetMsgRecvData GetRecvDate()
    {
        if (_lstRecvDatas == null || _lstRecvDatas.Count == 0)
        {
            return(null);
        }
        NetMsgRecvData data = _lstRecvDatas[0];

        _lstRecvDatas.RemoveAt(0);
        return(data);
    }
示例#2
0
    public void Update()
    {
        NetMsgRecvData recvData = null;

        while ((recvData = GetRecvDate()) != null)
        {
            recvData.Exec();
        }
        if (_blEnterGame)
        {
            _flHeartBeatTime -= Time.deltaTime;
            if (_flHeartBeatTime <= 0.01f)
            {
                _flHeartBeatTime = 30f;
                SendHeartBeat();
            }
        }
    }
示例#3
0
    public static NetMsgRecvData Read(int msgId, byte[] bts, NetMsgEventHandle handle)
    {
        MemoryStream ms = new MemoryStream(bts);

        ms.SetLength(bts.Length);

        NetMsgRecvData data = null;

        try
        {
            IMessage md = handle.mMsgParser.ParseFrom(bts);
            data = new NetMsgRecvData(handle.mCallBack, md);
        }
        catch (Exception ex)
        {
            Logger.Log("[NetPacketHelper.Read() => 反序列化数据出错,ex:" + ex + "]");
        }
        ms.Close();
        return(data);
    }
示例#4
0
    private void OnReceiveData(S2C_MSG_DATA value)
    {
        if (value.ErrorCode < 0)
        {
            Action RunOnMainThread = () =>
            {
                NetErrorHelper.DoErrorCode(value.ErrorCode);
            };

            Loom.QueueOnMainThread(RunOnMainThread);
            _recvStream.Clear();
            return;
        }

        byte[] bytes = value.Data.ToByteArray();
        _recvStream.AddBytes(bytes);
        while (_recvStream.BytesAvailable >= 4)
        {
            int    msgId   = _recvStream.ReadInt(); //消息id
            int    msgLen  = _recvStream.ReadInt(); //消息长度
            byte[] msgData = _recvStream.ReadBytes(msgLen);
            if (_dictNetHandle.ContainsKey(msgId))
            {
                NetMsgEventHandle handle = _dictNetHandle[msgId];
                NetMsgRecvData    data   = NetPacketHelper.Read(msgId, msgData, handle);
                if (data != null)
                {
                    _lstRecvDatas.Add(data);
                }
            }
            else
            {
                Logger.LogWarning("[GameServer.OnReceiveData() => 消息号:" + msgId + "未注册]");
            }
        }
        _recvStream.Clear();
    }