示例#1
0
        internal static MyPacketDescriptor GetPacketDescriptor(EndpointId userId, MyP2PMessageEnum msgType, int channel)
        {
            MyPacketDescriptor descriptor = m_descriptorPool.Get();

            descriptor.MsgType = msgType;
            descriptor.Channel = channel;
            if (userId.IsValid)
            {
                descriptor.Recipients.Add(userId);
            }
            return(descriptor);
        }
示例#2
0
        private void TraceMessage(string text, string messageText, ulong userId, long messageSize, MyP2PMessageEnum sendType)
        {
            MyNetworkClient client;

            if ((MyMultiplayer.Static == null) || !MyMultiplayer.Static.SyncLayer.Clients.TryGetClient(userId, out client))
            {
                userId.ToString();
            }
            else
            {
                string displayName = client.DisplayName;
            }
            if (sendType != MyP2PMessageEnum.Reliable)
            {
                MyP2PMessageEnum enum1 = sendType;
            }
        }
示例#3
0
        public static void SendAll()
        {
            MyPacketDescriptor descriptor;
            int num = 0;

            while (m_packetsToSend.TryDequeue(out descriptor))
            {
                int num1;
                m_packetsTmp.Clear();
                m_packetsTmp.Add(descriptor.Data);
                uint             maxValue = uint.MaxValue;
                MyP2PMessageEnum msgType  = descriptor.MsgType;
                if (msgType == MyP2PMessageEnum.Reliable)
                {
                    if ((descriptor.Data != null) && (descriptor.Data.Size >= 0xf423e))
                    {
                        Split(descriptor);
                    }
                }
                else if (msgType == MyP2PMessageEnum.ReliableWithBuffering)
                {
                    if (IsLastReliable(descriptor.Channel))
                    {
                        descriptor.MsgType = MyP2PMessageEnum.Reliable;
                    }
                    if ((descriptor.Data != null) && (descriptor.Data.Size >= 0xf423e))
                    {
                        Split(descriptor);
                    }
                }
                byte num3 = 0;
                if ((descriptor.MsgType == MyP2PMessageEnum.Unreliable) || (descriptor.MsgType == MyP2PMessageEnum.UnreliableNoDelay))
                {
                    num1 = 1;
                }
                else
                {
                    num1 = 0;
                }
                byte num4 = (byte)num1;
                foreach (IPacketData data in m_packetsTmp)
                {
                    m_streamTmp.Position = 0L;
                    m_streamTmp.WriteNoAlloc((byte)0xce);
                    m_streamTmp.WriteNoAlloc(num4);
                    int position = (int)m_streamTmp.Position;
                    m_streamTmp.WriteNoAlloc(maxValue);
                    m_streamTmp.WriteNoAlloc(num3);
                    m_streamTmp.WriteNoAlloc((byte)m_packetsTmp.Count);
                    if (num3 == 0)
                    {
                        m_streamTmp.Write(descriptor.Header.Data, 0, (int)descriptor.Header.Position);
                    }
                    if (data != null)
                    {
                        int count = Math.Min(data.Size, 0xf4240);
                        if ((num3 == 0) && (m_packetsTmp.Count > 1))
                        {
                            count -= (int)descriptor.Header.Position;
                        }
                        if (data.Data != null)
                        {
                            m_streamTmp.Write(data.Data, data.Offset, count);
                        }
                        else
                        {
                            m_streamTmp.Write(data.Ptr, data.Offset, count);
                        }
                    }
                    if (num4 > 0)
                    {
                        int num7 = (int)m_streamTmp.Position;
                        m_crc32.Initialize();
                        m_crc32.ComputeHash(m_streamTmp.Data, position + 4, (num7 - position) - 4);
                        maxValue             = m_crc32.CrcValue;
                        m_streamTmp.Position = position;
                        m_streamTmp.WriteNoAlloc(maxValue);
                        m_streamTmp.Position = num7;
                    }
                    foreach (EndpointId id in descriptor.Recipients)
                    {
                        num += (int)m_streamTmp.Position;
                        MyGameService.Peer2Peer.SendPacket(id.Value, m_streamTmp.Data, (int)m_streamTmp.Position, descriptor.MsgType, descriptor.Channel);
                    }
                    num3 = (byte)(num3 + 1);
                }
                foreach (IPacketData data2 in m_packetsTmp)
                {
                    if (data2 != null)
                    {
                        data2.Return();
                    }
                }
                descriptor.Data = null;
                m_descriptorPool.Return(descriptor);
            }
            Interlocked.Add(ref m_byteCountSent, num);
        }
示例#4
0
 private MyNetworkWriter.MyPacketDescriptor InitSendStream(EndpointId endpoint, MyP2PMessageEnum msgType, MyMessageId msgId, byte index = 0)
 {
     MyNetworkWriter.MyPacketDescriptor descriptor1 = MyNetworkWriter.GetPacketDescriptor(endpoint, msgType, this.m_channel);
     descriptor1.Header.WriteByte((byte)msgId);
     descriptor1.Header.WriteByte(index);
     return(descriptor1);
 }