示例#1
0
 public void SendToAllClients(VNetMessage message, bool reliable)
 {
     foreach (VNetClient client in m_clientsByUID.Values)
     {
         client.SendNetMessage(message, reliable);
     }
 }
示例#2
0
 public bool ReliableMessageCheck(VNetMessage message)
 {
     if (message.GetReliableIndex() == -1)
     {
         return(false);
     }
     if (m_lastReliableRecvdIndex != message.GetReliableIndex() - 1)
     {
         return(true);
     }
     m_lastReliableRecvdIndex++;
     return(false);
 }
示例#3
0
        public bool AddNetMessage(VNetMessage message)
        {
            byte[] src = null;
            using (System.IO.MemoryStream m = new System.IO.MemoryStream())
            {
                using (System.IO.BinaryWriter writer = new System.IO.BinaryWriter(m))
                {
                    message.ToBytes(writer);
                }
                src = m.ToArray();
            }

            message.__size     = src.Length;
            header.origLength += (short)message.__size;

            int len = src.Length;

            // Carefully add the size of this message
            byte[] lengthBytes = BitConverter.GetBytes(src.Length);
            for (int i = 0; i < 4; i++)
            {
                src[4 + i] = lengthBytes[i];
            }

            if (m_cursor == VNetPacketHeader.SizeOf() &&
                header.numMessages != 0)
            {
                throw new Exception();
            }

            // Compress it
            int newCursor = m_cursor;

            if (!CompressBuffer(src, data, ref newCursor))
            {
                return(false);
            }

            // Sanity check...
            CheckCompression(src, data, m_cursor, message.__size, newCursor - m_cursor);


            m_cursor          = newCursor;
            header.dataLength = (short)(m_cursor - VNetPacketHeader.SizeOf());

            return(true);
        }
示例#4
0
        // Send a message
        public void SendNetMessage(VNetMessage message, bool isReliable)
        {
            message.SetReliableIndex(-1);
            if (isReliable)
            {
                message.SetReliableIndex(m_nextReliablePacketIndex);
                m_nextReliablePacketIndex++;

                if (m_newReliableMessages.Count >= VNetCommon.NET_CLIENT_RELIABLE_QUEUE)
                {
                    return;
                }

                VNetMessage copy = AllocateMessageCopy(message);
                m_newReliableMessages.Enqueue(copy);
            }
            PackMessage(message);
        }
示例#5
0
        void PackReliableMessages()
        {
            if (m_packetQueueIndex >= VNetCommon.NET_PACKET_QUEUE_SIZE)
            {
                return;
            }

            // Fit as many as possible
            foreach (VNetMessage message in m_staleReliableMessages)
            {
                if (!PackMessage(message))
                {
                    return;
                }
            }

            // Add all new messages to the end
            while (m_newReliableMessages.Count > 0)
            {
                VNetMessage message = m_newReliableMessages.Dequeue();
                m_staleReliableMessages.Enqueue(message);
            }
        }
示例#6
0
        // Utilities
        bool PackMessage(VNetMessage message)
        {
            // already sent too many
            if (m_packetQueueIndex == VNetCommon.NET_PACKET_QUEUE_SIZE)
            {
                return(false);
            }

            // Packe message
            VNetPacket packet = m_packetOutQueue[m_packetQueueIndex];

            if (packet.AddNetMessage(message))
            {
                packet.header.numMessages++;
                return(true);
            }
            packet.EndPacket();

            // do the next one
            m_packetQueueIndex++;

            return(PackMessage(message));
        }
示例#7
0
文件: VNet.cs 项目: wardinsky/VNet
 public void SendToGlobal(VNetMessage message)
 {
     m_multicastClient.SendNetMessage(message, false);
 }
示例#8
0
文件: VNet.cs 项目: wardinsky/VNet
 public void SendToLobby(VNetMessage message, bool reliable)
 {
     m_netSession.SendToAllClients(message, reliable);
 }
示例#9
0
 public override void Callback(VNetMessage message)
 {
     myDelegates(message as T);
 }
示例#10
0
 public virtual void Callback(VNetMessage message)
 {
 }
示例#11
0
        public void HandlePacketIn(VNetPacket packet, VNetClient client)
        {
            int numMessagesToRead = packet.header.numMessages;

            packet.StartPacketRead();

            Dictionary <int, VNetMessage> reliableIn = new Dictionary <int, VNetMessage>();

            while (numMessagesToRead-- > 0)
            {
                if (packet.UpdateNextMessageHeaders() == false)
                {
                    break;
                }

                if (m_register.ContainsKey(packet.m_nextMessageType.checksum) == false)
                {
                    packet.SkipNextMessage();
                }
                else
                {
                    VNetDispatchRegistryBase reg = m_register[packet.m_nextMessageType.checksum];
                    if (reg.GetNumCallbacks() == 0)
                    {
                        packet.SkipNextMessage();
                    }
                    else
                    {
                        VNetMessage message = reg.ConvertDataToMessage(packet);
                        message._client    = client;
                        message._packet    = packet;
                        message.__typeName = new VNetStringChksum(packet.m_nextMessageType.checksum);


                        if (message.GetReliableIndex() != -1)
                        {
                            if (reliableIn.ContainsKey(message.GetReliableIndex()))
                            {
                                continue;
                            }
                            reliableIn.Add(message.GetReliableIndex(), message);
                            continue;
                        }

                        reg.Callback(message);
                    }
                }
            }
            if (client != null)
            {
                while (reliableIn.ContainsKey(client.GetNextReliableIndex()))
                {
                    VNetMessage message = reliableIn[client.GetNextReliableIndex()];
                    client.ReliableMessageCheck(message);

                    VNetDispatchRegistryBase reg = m_register[message.GetMessageType().checksum];
                    reg.Callback(message);
                }
            }

            reliableIn.Clear();
        }
示例#12
0
 VNetMessage AllocateMessageCopy(VNetMessage message)
 {
     return(message.Clone());
 }