Exemplo n.º 1
0
        private NetworkMessage ConvertOrderedUnreliableMessage(NetworkMessage input, Connection <T> connection)
        {
            if (input.sendType != NetworkMessageType.ORDERED_UNRELIABLE)
            {
                return(input);
            }
            int newSize = 12;

            if (input.data != null)
            {
                newSize += input.data.Length;
            }
            NetworkMessage converted = NetworkMessage.Create(-3, newSize, NetworkMessageType.UNORDERED_UNRELIABLE);

            DarkUtils.WriteInt32ToByteArray(connection.sendOrderID++, converted.data.data, 0);
            if (connection.sendOrderID == Int32.MaxValue)
            {
                connection.sendOrderID = 0;
            }
            DarkUtils.WriteInt32ToByteArray(input.type, converted.data.data, 4);
            DarkUtils.WriteInt32ToByteArray(newSize - 8, converted.data.data, 8);
            if (input.data != null)
            {
                Array.Copy(input.data.data, 0, converted.data.data, 12, input.data.Length);
            }
            input.Destroy();
            return(input);
        }
Exemplo n.º 2
0
 private void HandleReal(NetworkMessage nm, Connection <T> connection)
 {
     connection.lastReceiveTime = DateTime.UtcNow.Ticks;
     if (callbacks.ContainsKey(nm.type))
     {
         callbacks[nm.type](nm.data, connection);
     }
     nm.Destroy();
 }
 public void Destroy()
 {
     if (networkMessage != null)
     {
         networkMessage.Destroy();
     }
     networkMessage = null;
     Recycler <ReliableMessageSendTracking <T> > .ReleaseObject(this);
 }
Exemplo n.º 4
0
 internal void SendMessageWithHighPriority(NetworkMessage nm, Connection <T> c)
 {
     if (network != null && !c.destroyed)
     {
         network.SendRawHighPriority(nm, c);
     }
     else
     {
         nm.Destroy();
     }
 }
Exemplo n.º 5
0
 public void SendMessage(NetworkMessage nm, Connection <T> c)
 {
     if (network != null && !c.destroyed)
     {
         network.SendRaw(nm, c);
     }
     else
     {
         nm.Destroy();
     }
 }
Exemplo n.º 6
0
 public void SendMessage(NetworkMessage nm)
 {
     if (serverConnection != null)
     {
         SendMessage(nm, serverConnection);
     }
     else
     {
         nm.Destroy();
     }
 }
Exemplo n.º 7
0
 public void ReleaseAllObjects(Connection <T> connection)
 {
     lock (sendMessages)
     {
         if (sendMessages.ContainsKey(connection))
         {
             Queue <NetworkMessage> dropMessages = sendMessages[connection];
             while (dropMessages.Count > 0)
             {
                 NetworkMessage dropMessage = dropMessages.Dequeue();
                 dropMessage.Destroy();
             }
             sendMessages.Remove(connection);
         }
     }
 }
Exemplo n.º 8
0
 public void SendMessageToAll(NetworkMessage nm)
 {
     lock (connections)
     {
         if (connections.Count > 0)
         {
             nm.usageCount = connections.Count;
             foreach (KeyValuePair <Guid, Connection <T> > kvp in connections)
             {
                 SendMessage(nm, kvp.Value);
             }
         }
         else
         {
             nm.Destroy();
         }
     }
 }
Exemplo n.º 9
0
        private void ActualSendMessage(NetworkMessage sendMessage, Connection <T> connection)
        {
            if (sendMessage.data != null)
            {
                connection.tokens -= sendMessage.data.Length;
            }
            NetworkMessage converted = ConvertOrderedUnreliableMessage(sendMessage, connection);

            if (sendMessage.type == -4)
            {
                connection.reliableMessageHandler.RealSendPart(sendMessage);
            }
            int sendBytes = WriteRawMessageToBuffer(sendMessage);

            sendMessage.Destroy();
            try
            {
                int bytesSent = socket.SendTo(sendBuffer, 0, sendBytes, SocketFlags.None, connection.remoteEndpoint);
            }
            catch
            {
                handler.HandleRawError(connection);
            }
        }