Exemple #1
0
 bool DropSequencedData(ENetChannel channel, ENetProtocolCommandHeader header)
 {
     ushort reliableWindow = (ushort)(header.ReliableSequenceNumber / PEER_RELIABLE_WINDOW_SIZE);
     ushort currentWindow = (ushort)(channel.IncomingSequenceNumber / PEER_RELIABLE_WINDOW_SIZE);
     if (header.ReliableSequenceNumber < channel.IncomingSequenceNumber) reliableWindow += PEER_RELIABLE_WINDOWS;
     return reliableWindow < currentWindow || reliableWindow >= currentWindow + PEER_FREE_RELIABLE_WINDOWS - 1;
 }
    /// <summary>
    /// Send a message to everyone listening.
    /// </summary>
    /// <param name="channel">Choose whether you want this message to be transmitted reliable or not</param>
    /// <param name="message">The actual message you want to spread</param>
    public void BroadcastNetworkData(ENetChannel channel, NetworkData message)
    {
        if (Net.GetState() != ENetworkState.Running)
        {
            Debug.LogError("Do not try to send data if network is not running!");
            return;
        }

        Net.BroadcastMessage(channel, message.Serialize());
    }
    /// <summary>
    /// Send a message through a specific connection / to a specific destination.
    /// </summary>
    /// <param name="connection">Destination of this message</param>
    /// <param name="channel">Choose whether you want this message to be transmitted reliable or not</param>
    /// <param name="message">The actual message</param>
    /// <returns>False, if the given connection handle is (no longer) valid.</returns>
    public void SendNetworkData(ConnectionHandle connection, ENetChannel channel, NetworkData message)
    {
        if (Net.GetState() != ENetworkState.Running)
        {
            Debug.LogError("Do not try to send data if network is not running!");
            return;
        }

        Net.SendMessage(connection, channel, message.Serialize());
    }
Exemple #4
0
 internal ENetPeer(IPEndPoint Address, ushort IncomingPeerID, ENetProtocolConnect packet, ENetChannelTypeLayout channelLayout)
 {
     this.Address        = Address;
     this.SessionID      = packet.SessionID;
     this.MTU            = packet.MTU <PROTOCOL_MINIMUM_MTU?PROTOCOL_MINIMUM_MTU : packet.MTU> PROTOCOL_MAXIMUM_MTU ? PROTOCOL_MAXIMUM_MTU : packet.MTU;
     this.FragmentLength = (MTU - ENetCommand.SEND_FRAGMENT.Size()) - sizeof(ENetProtocolHeader);
     this.OutgoingPeerID = packet.OutgoingPeerID;
     this.IncomingPeerID = IncomingPeerID;
     this.WindowSize     = PROTOCOL_MAXIMUM_WINDOW_SIZE > packet.WindowSize ? packet.WindowSize : PROTOCOL_MAXIMUM_WINDOW_SIZE;
     this.Channels       = new ConcurrentDictionary <byte, ENetChannel>();
     for (byte i = 0; i < channelLayout.ChannelCount(); i++)
     {
         Channels[i] = new ENetChannel(channelLayout[i]);
     }
 }