Esempio n. 1
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();
    }