├── OldSamples
├── Old XNA sample.zip
├── LibraryTestSamples
│ ├── DurableSample
│ │ ├── DurableSample.suo
│ │ ├── DurableClient
│ │ │ ├── Properties
│ │ │ │ ├── Settings.settings
│ │ │ │ ├── Settings.Designer.cs
│ │ │ │ └── AssemblyInfo.cs
│ │ │ └── Form1.cs
│ │ └── DurableServer
│ │ │ ├── Properties
│ │ │ ├── Settings.settings
│ │ │ ├── Settings.Designer.cs
│ │ │ └── AssemblyInfo.cs
│ │ │ └── Form1.cs
│ ├── GarbageThrowerSample
│ │ ├── Client
│ │ │ ├── App.config
│ │ │ ├── Program.cs
│ │ │ ├── Properties
│ │ │ │ └── AssemblyInfo.cs
│ │ │ └── Client.csproj
│ │ ├── Server
│ │ │ ├── App.config
│ │ │ ├── Properties
│ │ │ │ └── AssemblyInfo.cs
│ │ │ └── Program.cs
│ │ └── GarbageThrowerSample.sln
│ ├── ManySample
│ │ ├── ManyServer
│ │ │ ├── Form1.cs
│ │ │ ├── Properties
│ │ │ │ ├── Settings.settings
│ │ │ │ ├── Settings.Designer.cs
│ │ │ │ └── AssemblyInfo.cs
│ │ │ └── Form1.Designer.cs
│ │ └── ManyClients
│ │ │ ├── Properties
│ │ │ ├── Settings.settings
│ │ │ ├── Settings.Designer.cs
│ │ │ └── AssemblyInfo.cs
│ │ │ ├── Form1.cs
│ │ │ ├── Program.cs
│ │ │ ├── Client.Designer.cs
│ │ │ ├── Client.cs
│ │ │ └── Form1.Designer.cs
│ ├── SpeedSample
│ │ ├── SpeedClient
│ │ │ ├── Properties
│ │ │ │ ├── Settings.settings
│ │ │ │ ├── Settings.Designer.cs
│ │ │ │ └── AssemblyInfo.cs
│ │ │ └── Form1.cs
│ │ └── SpeedServer
│ │ │ ├── Properties
│ │ │ ├── Settings.settings
│ │ │ ├── Settings.Designer.cs
│ │ │ └── AssemblyInfo.cs
│ │ │ └── Form1.cs
│ ├── UnconnectedSample
│ │ └── UnconnectedSample
│ │ │ ├── Properties
│ │ │ ├── Settings.settings
│ │ │ ├── Settings.Designer.cs
│ │ │ └── AssemblyInfo.cs
│ │ │ ├── Form1.cs
│ │ │ └── Program.cs
│ └── EncryptionSample
│ │ ├── EncryptionServer
│ │ ├── Program.cs
│ │ ├── Properties
│ │ │ └── AssemblyInfo.cs
│ │ └── EncryptionServer.csproj
│ │ ├── EncryptionClient
│ │ ├── Properties
│ │ │ └── AssemblyInfo.cs
│ │ ├── Program.cs
│ │ └── EncryptionClient.csproj
│ │ └── EncryptionSample.sln
├── MasterServerSample
│ ├── MSCommon
│ │ ├── MasterServerMessageType.cs
│ │ ├── CommonConstants.cs
│ │ ├── Documentation.txt
│ │ ├── Properties
│ │ │ └── AssemblyInfo.cs
│ │ └── NativeMethods.cs
│ ├── MSClient
│ │ ├── Properties
│ │ │ ├── Settings.settings
│ │ │ ├── Settings.Designer.cs
│ │ │ └── AssemblyInfo.cs
│ │ └── Form1.cs
│ ├── MSServer
│ │ ├── Properties
│ │ │ └── AssemblyInfo.cs
│ │ └── Program.cs
│ ├── MasterServer
│ │ └── Properties
│ │ │ └── AssemblyInfo.cs
│ └── MasterServerSample.sln
├── Chat
│ ├── ChatClient
│ │ ├── Properties
│ │ │ ├── Settings.settings
│ │ │ ├── Settings.Designer.cs
│ │ │ ├── AssemblyInfo.cs
│ │ │ └── Resources.Designer.cs
│ │ └── Form1.cs
│ └── ChatServer
│ │ ├── Properties
│ │ ├── Settings.settings
│ │ ├── Settings.Designer.cs
│ │ └── AssemblyInfo.cs
│ │ └── Form1.cs
├── ImageSample
│ ├── ImageClient
│ │ ├── Properties
│ │ │ ├── Settings.settings
│ │ │ ├── Settings.Designer.cs
│ │ │ └── AssemblyInfo.cs
│ │ ├── Form1.cs
│ │ ├── Program.cs
│ │ └── ImageGetter.Designer.cs
│ └── ImageServer
│ │ ├── Properties
│ │ ├── Settings.settings
│ │ ├── Settings.Designer.cs
│ │ └── AssemblyInfo.cs
│ │ └── Form1.cs
├── File stream sample
│ ├── FileStreamClient
│ │ ├── Properties
│ │ │ ├── Settings.settings
│ │ │ ├── Settings.Designer.cs
│ │ │ └── AssemblyInfo.cs
│ │ └── Form1.cs
│ └── FileStreamServer
│ │ ├── Properties
│ │ ├── Settings.settings
│ │ ├── Settings.Designer.cs
│ │ └── AssemblyInfo.cs
│ │ ├── Form1.cs
│ │ ├── StreamingClient.cs
│ │ ├── Program.cs
│ │ └── Form1.Designer.cs
└── SamplesCommon
│ ├── Properties
│ └── AssemblyInfo.cs
│ └── NativeMethods.cs
├── Lidgren.Network
├── Messaging
│ ├── INetMessageScheduler.cs
│ ├── MessageResendReason.cs
│ ├── NetMessageScheduler.cs
│ ├── Channels
│ │ ├── NetReceiverChannel.cs
│ │ ├── NetUnreliableUnorderedReceiver.cs
│ │ ├── NetUnreliableSequencedReceiver.cs
│ │ ├── NetChannel.cs
│ │ ├── NetReliableSequencedReceiver.cs
│ │ ├── NetValueTimeoutAwaitable.cs
│ │ ├── NetSenderChannel.cs
│ │ └── NetReliableUnorderedReceiver.cs
│ ├── NetSocketResult.cs
│ ├── NetSendResult.cs
│ ├── NetUnreliableSizeBehaviour.cs
│ ├── NetStoredReliableMessage.cs
│ ├── NetDeliveryMethod.cs
│ ├── NetIncomingMessageType.cs
│ └── NetMessageView.cs
├── Peer
│ ├── NetLogLevel.cs
│ ├── NetPeerStatus.cs
│ ├── NetPeer.Logging.cs
│ ├── NetLogCode.cs
│ ├── NetPeer.Discovery.cs
│ └── NetServer.cs
├── Documentation
│ ├── ChangedFromV2.txt
│ ├── TODO.txt
│ ├── PacketLayout.txt
│ └── Improvements.txt
├── Properties
│ └── AssemblyInfo.cs
├── NetFragmentationInfo.cs
├── UPnPStatus.cs
├── Lidgren.Network.csproj
├── NetUPnPDiscoveryEventArgs.cs
├── Exceptions
│ ├── EndOfMessageException.cs
│ ├── CannotResendException.cs
│ └── LidgrenException.cs
├── Random
│ ├── NetRandomSeed.cs
│ ├── MWCRandom.cs
│ ├── CryptoRandom.cs
│ └── XorShiftRandom.cs
├── Memory
│ └── ListEnumeratorExtensions.cs
├── Buffer
│ ├── IBitBuffer.cs
│ ├── BitBufferExtensions.cs
│ └── NetBlockWriter.cs
├── Encryption
│ ├── NetEncryption.cs
│ └── NetXorEncryption.cs
├── Connection
│ └── NetConnectionStatus.cs
└── NetTime.cs
├── .travis.yml
├── Lidgren.Network.Tests
├── Byte2.cs
├── Byte3.cs
├── Program.cs
├── Lidgren.Network.Tests.csproj
├── NetAddressTests.cs
├── BitViewTests.cs
└── BitArrayTests.cs
├── README.md
├── UnitTests
├── UnitTests.csproj
├── MiscTests.cs
├── FakeReadStream.cs
└── BitArrayTests.cs
├── .editorconfig
├── LICENSE
└── Lidgren.Network.sln
/OldSamples/Old XNA sample.zip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/TechPizzaDev/lidgren-network-gen3/HEAD/OldSamples/Old XNA sample.zip
--------------------------------------------------------------------------------
/Lidgren.Network/Messaging/INetMessageScheduler.cs:
--------------------------------------------------------------------------------
1 | namespace Lidgren.Network
2 | {
3 | public interface INetMessageScheduler
4 | {
5 | }
6 | }
7 |
--------------------------------------------------------------------------------
/OldSamples/LibraryTestSamples/DurableSample/DurableSample.suo:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/TechPizzaDev/lidgren-network-gen3/HEAD/OldSamples/LibraryTestSamples/DurableSample/DurableSample.suo
--------------------------------------------------------------------------------
/Lidgren.Network/Messaging/MessageResendReason.cs:
--------------------------------------------------------------------------------
1 |
2 | namespace Lidgren.Network
3 | {
4 | internal enum MessageResendReason
5 | {
6 | Delay,
7 | HoleInSequence
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/Lidgren.Network/Peer/NetLogLevel.cs:
--------------------------------------------------------------------------------
1 | namespace Lidgren.Network
2 | {
3 | public enum NetLogLevel
4 | {
5 | Verbose = 0,
6 | Debug = 1,
7 | Warning = 2,
8 | Error = 3,
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: csharp
2 | solution: Lidgren.Network.sln
3 | install:
4 | - nuget restore Lidgren.Network.sln
5 | script:
6 | - xbuild /p:Configuration=Release Lidgren.Network.sln
7 | - mono ./UnitTests/bin/Release/UnitTests.exe
8 |
--------------------------------------------------------------------------------
/OldSamples/MasterServerSample/MSCommon/MasterServerMessageType.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace MSCommon
4 | {
5 | public enum MasterServerMessageType
6 | {
7 | RegisterHost,
8 | RequestHostList,
9 | RequestIntroduction,
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/OldSamples/LibraryTestSamples/GarbageThrowerSample/Client/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/OldSamples/LibraryTestSamples/GarbageThrowerSample/Server/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/Lidgren.Network/Documentation/ChangedFromV2.txt:
--------------------------------------------------------------------------------
1 |
2 |
3 | * The NetBuffer object is gone; instead there are NetOutgoingMessage and NetIncomingMessage objects
4 |
5 | * No need to allocate a read buffer before calling ReadMessage
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/Lidgren.Network/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Runtime.CompilerServices;
3 |
4 | [module: SkipLocalsInit]
5 |
6 | [assembly: CLSCompliant(true)]
7 | [assembly: InternalsVisibleTo("Lidgren.Network.Tests")]
8 | [assembly: InternalsVisibleTo("UnitTests")]
--------------------------------------------------------------------------------
/OldSamples/LibraryTestSamples/ManySample/ManyServer/Form1.cs:
--------------------------------------------------------------------------------
1 | using System.Windows.Forms;
2 |
3 | namespace ManyServer
4 | {
5 | public partial class Form1 : Form
6 | {
7 | public Form1()
8 | {
9 | InitializeComponent();
10 | }
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/Lidgren.Network/NetFragmentationInfo.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace Lidgren.Network
4 | {
5 | public sealed class NetFragmentationInfo
6 | {
7 | public int TotalFragmentCount;
8 | public bool[] Received;
9 | public int TotalReceived;
10 | public int FragmentSize;
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/OldSamples/Chat/ChatClient/Properties/Settings.settings:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/OldSamples/Chat/ChatServer/Properties/Settings.settings:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/OldSamples/ImageSample/ImageClient/Properties/Settings.settings:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/OldSamples/ImageSample/ImageServer/Properties/Settings.settings:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/OldSamples/MasterServerSample/MSClient/Properties/Settings.settings:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/OldSamples/File stream sample/FileStreamClient/Properties/Settings.settings:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/OldSamples/File stream sample/FileStreamServer/Properties/Settings.settings:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/OldSamples/LibraryTestSamples/ManySample/ManyClients/Properties/Settings.settings:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/OldSamples/LibraryTestSamples/ManySample/ManyServer/Properties/Settings.settings:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/OldSamples/LibraryTestSamples/SpeedSample/SpeedClient/Properties/Settings.settings:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/OldSamples/LibraryTestSamples/SpeedSample/SpeedServer/Properties/Settings.settings:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/OldSamples/LibraryTestSamples/DurableSample/DurableClient/Properties/Settings.settings:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/OldSamples/LibraryTestSamples/DurableSample/DurableServer/Properties/Settings.settings:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/OldSamples/LibraryTestSamples/UnconnectedSample/UnconnectedSample/Properties/Settings.settings:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/Lidgren.Network/Messaging/NetMessageScheduler.cs:
--------------------------------------------------------------------------------
1 | namespace Lidgren.Network
2 | {
3 | ///
4 | /// Acts as a default implementation of .
5 | ///
6 | public class NetMessageScheduler : INetMessageScheduler
7 | {
8 | // TODO: manage messages and fragmentation
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/OldSamples/MasterServerSample/MSCommon/CommonConstants.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 |
6 | namespace MSCommon
7 | {
8 | public static class CommonConstants
9 | {
10 | public const int MasterServerPort = 14343;
11 | public const int GameServerPort = 14242;
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/Lidgren.Network.Tests/Byte2.cs:
--------------------------------------------------------------------------------
1 |
2 | namespace Lidgren.Network.Tests
3 | {
4 | public struct Byte2
5 | {
6 | public byte X;
7 | public byte Y;
8 |
9 | public Byte2(byte x, byte y)
10 | {
11 | X = x;
12 | Y = y;
13 | }
14 |
15 | public Byte2(byte value) : this(value, value)
16 | {
17 | }
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | ## Lidgren.Network
2 | Networking library for .NET which uses a single UDP socket to deliver an API for connecting clients to a server,
3 | allowing for reading, sending, or streaming of messages.
4 |
5 | Depends on .NET 5 and aims to be maintained for the newest runtimes.
6 |
7 | ### Stability
8 | The current stability of this fork is low. There are barely any tests and it is not production ready.
9 | The API is also constantly being iterated upon so don't get too attached.
10 |
--------------------------------------------------------------------------------
/Lidgren.Network/Messaging/Channels/NetReceiverChannel.cs:
--------------------------------------------------------------------------------
1 |
2 | namespace Lidgren.Network
3 | {
4 | internal abstract class NetReceiverChannel : NetChannel
5 | {
6 | protected NetReceiverChannel(NetConnection connection, int windowSize) : base(connection, windowSize)
7 | {
8 | }
9 |
10 | protected override void OnWindowSizeChanged()
11 | {
12 | }
13 |
14 | public abstract void ReceiveMessage(in NetMessageView message);
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/OldSamples/File stream sample/FileStreamClient/Form1.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Windows.Forms;
3 |
4 | namespace FileStreamClient
5 | {
6 | public partial class Form1 : Form
7 | {
8 | public Form1()
9 | {
10 | InitializeComponent();
11 | progressBar1.Minimum = 0;
12 | progressBar1.Maximum = 100;
13 | }
14 |
15 | private void button1_Click(object sender, EventArgs e)
16 | {
17 | Program.Connect(textBox1.Text, Int32.Parse(textBox2.Text));
18 | }
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/Lidgren.Network/Documentation/TODO.txt:
--------------------------------------------------------------------------------
1 |
2 | Completed features:
3 | * Message coalescing
4 | * Peer, connection statistics
5 | * Lag, loss and duplication simulation for testing
6 | * Connection approval
7 | * Throttling
8 | * Clock synchronization to detect jitter per packet (NetTime.RemoteNow)
9 | * Peer discovery
10 | * Message fragmentation
11 |
12 | Missing features:
13 | * Receipts 25% done, need design
14 | * More realistic lag/loss (lumpy)
15 | * Detect estimated packet loss
16 | * More advanced ack packet
17 |
18 |
--------------------------------------------------------------------------------
/UnitTests/UnitTests.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 | net8.0
4 | Exe
5 | enable
6 | true
7 | false
8 | false
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/Lidgren.Network/Documentation/PacketLayout.txt:
--------------------------------------------------------------------------------
1 |
2 | PER MESSAGE:
3 | 7 bits - NetMessageType
4 | 1 bit - Is a message fragment?
5 |
6 | [8 bits NetMessageLibraryType, if NetMessageType == Library]
7 |
8 | [16 bits sequence number, if NetMessageType >= UserSequenced]
9 |
10 | 8/16 bits - Payload length in bits (variable size ushort)
11 |
12 | [16 bits fragments group id, if fragmented]
13 | [16 bits fragments total count, if fragmented]
14 | [16 bits fragment number, if fragmented]
15 |
16 | [x - Payload] if length > 0
17 |
18 |
--------------------------------------------------------------------------------
/Lidgren.Network.Tests/Byte3.cs:
--------------------------------------------------------------------------------
1 |
2 | namespace Lidgren.Network.Tests
3 | {
4 | public struct Byte3
5 | {
6 | public byte X;
7 | public byte Y;
8 | public byte Z;
9 |
10 | public Byte3(byte x, byte y, byte z)
11 | {
12 | X = x;
13 | Y = y;
14 | Z = z;
15 | }
16 |
17 | public Byte3(Byte2 xy, byte z) : this(xy.X, xy.Y, z)
18 | {
19 | }
20 |
21 | public Byte3(byte value) : this(value, value, value)
22 | {
23 | }
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/OldSamples/LibraryTestSamples/ManySample/ManyClients/Form1.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.ComponentModel;
4 | using System.Data;
5 | using System.Drawing;
6 | using System.Linq;
7 | using System.Text;
8 | using System.Windows.Forms;
9 |
10 | namespace ManyClients
11 | {
12 | public partial class Form1 : Form
13 | {
14 | public Form1()
15 | {
16 | InitializeComponent();
17 | }
18 |
19 | private void button1_Click(object sender, EventArgs e)
20 | {
21 | Program.CreateClient();
22 | }
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/OldSamples/File stream sample/FileStreamServer/Form1.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Windows.Forms;
3 |
4 | namespace FileStreamServer
5 | {
6 | public partial class Form1 : Form
7 | {
8 | public Form1()
9 | {
10 | InitializeComponent();
11 | }
12 |
13 | private void button1_Click(object sender, EventArgs e)
14 | {
15 | OpenFileDialog dlg = new OpenFileDialog();
16 | dlg.CheckFileExists = true;
17 | var res = dlg.ShowDialog();
18 |
19 | if (res != DialogResult.OK)
20 | return;
21 |
22 | Program.Start(dlg.FileName);
23 | }
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/Lidgren.Network/UPnPStatus.cs:
--------------------------------------------------------------------------------
1 | namespace Lidgren.Network
2 | {
3 | ///
4 | /// Status of the UPnP capabilities
5 | ///
6 | public enum UPnPStatus
7 | {
8 | Idle,
9 |
10 | ///
11 | /// Still discovering UPnP capabilities.
12 | ///
13 | Discovering,
14 |
15 | ///
16 | /// UPnP is not available.
17 | ///
18 | NotAvailable,
19 |
20 | ///
21 | /// UPnP is available and ready to use.
22 | ///
23 | Available
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/Lidgren.Network/Messaging/NetSocketResult.cs:
--------------------------------------------------------------------------------
1 |
2 | namespace Lidgren.Network
3 | {
4 | public readonly struct NetSocketResult
5 | {
6 | public bool Success { get; }
7 | public bool ConnectionReset { get; }
8 |
9 | public NetSocketResult(bool success, bool connectionReset)
10 | {
11 | Success = success;
12 | ConnectionReset = connectionReset;
13 | }
14 |
15 | public void Deconstruct(out bool success, out bool connectionReset)
16 | {
17 | success = Success;
18 | connectionReset = ConnectionReset;
19 | }
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/.editorconfig:
--------------------------------------------------------------------------------
1 | [*.cs]
2 |
3 | # CA1303: Do not pass literals as localized parameters
4 | dotnet_diagnostic.CA1303.severity = suggestion
5 |
6 | # CA1028: Enum Storage should be Int32
7 | dotnet_diagnostic.CA1028.severity = silent
8 |
9 | # CA2000: Dispose objects before losing scope
10 | dotnet_diagnostic.CA2000.severity = none
11 |
12 | # CA1000: Do not declare static members on generic types
13 | dotnet_diagnostic.CA1000.severity = none
14 |
15 | # CA1051: Do not declare visible instance fields
16 | dotnet_diagnostic.CA1051.severity = none
17 |
18 | # CA2225: Operator overloads have named alternates
19 | dotnet_diagnostic.CA2225.severity = none
20 |
--------------------------------------------------------------------------------
/Lidgren.Network/Messaging/Channels/NetUnreliableUnorderedReceiver.cs:
--------------------------------------------------------------------------------
1 |
2 | namespace Lidgren.Network
3 | {
4 | internal sealed class NetUnreliableUnorderedReceiver : NetReceiverChannel
5 | {
6 | public NetUnreliableUnorderedReceiver(NetConnection connection)
7 | : base(connection, 1)
8 | {
9 | }
10 |
11 | public override void ReceiveMessage(in NetMessageView message)
12 | {
13 | NetConnection connection = Connection;
14 |
15 | // ack no matter what
16 | connection.QueueAck(message.BaseMessageType, message.SequenceNumber);
17 |
18 | connection.Peer.ReleaseMessage(message);
19 | }
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/OldSamples/LibraryTestSamples/UnconnectedSample/UnconnectedSample/Form1.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Windows.Forms;
3 |
4 | namespace UnconnectedSample
5 | {
6 | public partial class Form1 : Form
7 | {
8 | public Form1()
9 | {
10 | InitializeComponent();
11 | }
12 |
13 | private void button1_Click(object sender, EventArgs e)
14 | {
15 | uint port;
16 | if (UInt32.TryParse(textBox2.Text, out port) == false)
17 | {
18 | MessageBox.Show("Please fill in the port of the target peer");
19 | return;
20 | }
21 |
22 | Program.Send(textBox1.Text, (int)port, textBox3.Text);
23 | }
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/Lidgren.Network/Peer/NetPeerStatus.cs:
--------------------------------------------------------------------------------
1 |
2 | namespace Lidgren.Network
3 | {
4 | ///
5 | /// Status for a NetPeer instance
6 | ///
7 | public enum NetPeerStatus
8 | {
9 | ///
10 | /// NetPeer is not running; socket is not bound
11 | ///
12 | NotRunning = 0,
13 |
14 | ///
15 | /// NetPeer is in the process of starting up
16 | ///
17 | Starting = 1,
18 |
19 | ///
20 | /// NetPeer is bound to socket and listening for packets
21 | ///
22 | Running = 2,
23 |
24 | ///
25 | /// Shutdown has been requested and will be executed shortly
26 | ///
27 | ShutdownRequested = 3,
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/Lidgren.Network.Tests/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 |
4 | namespace Lidgren.Network.Tests
5 | {
6 | class Program
7 | {
8 | static int Main(string[] args)
9 | {
10 | List newArgs = new List(args);
11 | newArgs.Insert(0, typeof(Program).Assembly.Location);
12 |
13 | int returnCode = Xunit.ConsoleClient.Program.Main(newArgs.ToArray());
14 | Console.WriteLine("Tests finished. Press any key to exit.");
15 | if (!Console.IsInputRedirected)
16 | {
17 | Console.ReadKey(true);
18 | }
19 | return returnCode;
20 | }
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/OldSamples/LibraryTestSamples/DurableSample/DurableServer/Form1.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Windows.Forms;
3 |
4 | using SamplesCommon;
5 |
6 | namespace DurableServer
7 | {
8 | public partial class Form1 : Form
9 | {
10 | private NetPeerSettingsWindow m_settingsWindow;
11 |
12 | public Form1()
13 | {
14 | InitializeComponent();
15 | }
16 |
17 | private void button1_Click(object sender, EventArgs e)
18 | {
19 | if (m_settingsWindow == null)
20 | {
21 | m_settingsWindow = new NetPeerSettingsWindow("Durable server settings", Program.Server);
22 | m_settingsWindow.Show();
23 | }
24 | else
25 | {
26 | m_settingsWindow.Close();
27 | m_settingsWindow = null;
28 | }
29 | }
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/OldSamples/Chat/ChatServer/Form1.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.ComponentModel;
4 | using System.Text;
5 | using System.Windows.Forms;
6 |
7 | namespace ChatServer
8 | {
9 | public partial class Form1 : Form
10 | {
11 | public Form1()
12 | {
13 | InitializeComponent();
14 | }
15 |
16 | private void button1_Click(object sender, EventArgs e)
17 | {
18 | if (button1.Text == "Start")
19 | {
20 | Program.StartServer();
21 | button1.Text = "Shut down";
22 | }
23 | else
24 | {
25 | Program.Shutdown();
26 | button1.Text = "Start";
27 | }
28 | }
29 |
30 | private void button2_Click(object sender, EventArgs e)
31 | {
32 | Program.DisplaySettings();
33 | }
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/OldSamples/LibraryTestSamples/SpeedSample/SpeedServer/Form1.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.ComponentModel;
4 | using System.Drawing;
5 | using System.Text;
6 | using System.Windows.Forms;
7 |
8 | namespace SpeedTestServer
9 | {
10 | public partial class Form1 : Form
11 | {
12 | public Form1()
13 | {
14 | InitializeComponent();
15 | }
16 |
17 | private void button1_Click(object sender, EventArgs e)
18 | {
19 | Program.DisplaySettings();
20 | }
21 |
22 | private void button2_Click(object sender, EventArgs e)
23 | {
24 | if (button2.Text == "Start")
25 | {
26 | Program.Start();
27 | button2.Text = "Shutdown";
28 | }
29 | else
30 | {
31 | Program.Shutdown();
32 | button2.Text = "Start";
33 | }
34 | }
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/Lidgren.Network/Messaging/NetSendResult.cs:
--------------------------------------------------------------------------------
1 |
2 | namespace Lidgren.Network
3 | {
4 | ///
5 | /// Result of a SendMessage call
6 | ///
7 | public enum NetSendResult
8 | {
9 | ///
10 | /// Failed to enqueue message because there is no connection.
11 | ///
12 | FailedNotConnected = 0,
13 |
14 | ///
15 | /// No recipients were specified or that all given recipients disconnected.
16 | ///
17 | NoRecipients = 1,
18 |
19 | ///
20 | /// Message is being sent by the peer.
21 | ///
22 | Sent = 2,
23 |
24 | ///
25 | /// Message is queued for sending.
26 | ///
27 | Queued = 3,
28 |
29 | ///
30 | /// Message was discarded and an error message was logged.
31 | ///
32 | Dropped = 4,
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/Lidgren.Network/Lidgren.Network.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 | net8.0
4 | enable
5 |
6 |
7 |
8 | true
9 | portable
10 | true
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/Lidgren.Network/Messaging/NetUnreliableSizeBehaviour.cs:
--------------------------------------------------------------------------------
1 |
2 | namespace Lidgren.Network
3 | {
4 | ///
5 | /// Behaviour of unreliable sends above MTU.
6 | ///
7 | public enum NetUnreliableSizeBehaviour
8 | {
9 | ///
10 | /// Unreliable message will ignore MTU and send everything in a single packet.
11 | ///
12 | IgnoreMTU = 0,
13 |
14 | ///
15 | /// Use normal fragmentation for unreliable messages.
16 | /// If a fragment is dropped, memory is reclaimed after .
17 | ///
18 | NormalFragmentation = 1,
19 |
20 | ///
21 | /// Drops unreliable messages above the current MTU.
22 | ///
23 | DropAboveMTU = 2,
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/Lidgren.Network/NetUPnPDiscoveryEventArgs.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace Lidgren.Network
4 | {
5 | public class NetUPnPDiscoveryEventArgs : EventArgs
6 | {
7 | public NetUPnP UPnP { get; }
8 | public UPnPStatus Status { get; }
9 | public TimeSpan DiscoveryStartTime { get; }
10 | public TimeSpan DiscoveryEndTime { get; }
11 | public TimeSpan DiscoveryDuration => DiscoveryEndTime - DiscoveryStartTime;
12 |
13 | public NetUPnPDiscoveryEventArgs(
14 | NetUPnP upnp, UPnPStatus status, TimeSpan discoveryStartTime, TimeSpan discoveryEndTime)
15 | {
16 | UPnP = upnp ?? throw new ArgumentNullException(nameof(upnp));
17 | Status = status;
18 | DiscoveryStartTime = discoveryStartTime;
19 | DiscoveryEndTime = discoveryEndTime;
20 | }
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/OldSamples/MasterServerSample/MSClient/Form1.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.ComponentModel;
4 | using System.Data;
5 | using System.Drawing;
6 | using System.Linq;
7 | using System.Text;
8 | using System.Windows.Forms;
9 |
10 | namespace MSClient
11 | {
12 | public partial class Form1 : Form
13 | {
14 | public Form1()
15 | {
16 | InitializeComponent();
17 | }
18 |
19 | private void button1_Click(object sender, EventArgs e)
20 | {
21 | Program.GetServerList(textBox1.Text);
22 | }
23 |
24 | private void button2_Click(object sender, EventArgs e)
25 | {
26 | if (comboBox1.SelectedItem == null)
27 | return;
28 |
29 | var splits = comboBox1.SelectedItem.ToString().Split(' ');
30 | var host = Int64.Parse(splits[0]);
31 | Program.RequestNATIntroduction(host);
32 | }
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/OldSamples/LibraryTestSamples/SpeedSample/SpeedClient/Form1.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.ComponentModel;
4 | using System.Drawing;
5 | using System.Text;
6 | using System.Windows.Forms;
7 |
8 | namespace SpeedTestClient
9 | {
10 | public partial class Form1 : Form
11 | {
12 | public Form1()
13 | {
14 | InitializeComponent();
15 | comboBox1.SelectedIndex = 0;
16 | }
17 |
18 | private void button2_Click(object sender, EventArgs e)
19 | {
20 | int seqChan;
21 | Int32.TryParse(textBox3.Text, out seqChan);
22 | int port;
23 | Int32.TryParse(textBox2.Text, out port);
24 | Program.Connect(textBox1.Text, port, comboBox1.SelectedItem.ToString(), seqChan);
25 | }
26 |
27 | private void button1_Click(object sender, EventArgs e)
28 | {
29 | Program.DisplaySettings();
30 | }
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/Lidgren.Network/Messaging/Channels/NetUnreliableSequencedReceiver.cs:
--------------------------------------------------------------------------------
1 |
2 | namespace Lidgren.Network
3 | {
4 | internal sealed class NetUnreliableSequencedReceiver : NetReceiverChannel
5 | {
6 | private int _lastReceivedSequenceNumber = -1;
7 |
8 | public NetUnreliableSequencedReceiver(NetConnection connection)
9 | : base(connection, 1)
10 | {
11 | }
12 |
13 | public override void ReceiveMessage(in NetMessageView message)
14 | {
15 | NetConnection connection = Connection;
16 | int nr = message.SequenceNumber;
17 |
18 | // ack no matter what
19 | connection.QueueAck(message.BaseMessageType, nr);
20 |
21 | int relate = NetUtility.RelativeSequenceNumber(nr, _lastReceivedSequenceNumber + 1);
22 | if (relate < 0)
23 | return; // drop if late
24 |
25 | _lastReceivedSequenceNumber = nr;
26 | connection.Peer.ReleaseMessage(message);
27 | }
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/Lidgren.Network/Messaging/NetStoredReliableMessage.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Diagnostics;
3 |
4 | namespace Lidgren.Network
5 | {
6 | [DebuggerDisplay("{" + nameof(GetDebuggerDisplay) + "(),nq}")]
7 | internal struct NetStoredReliableMessage
8 | {
9 | public int SequenceNumber;
10 | public int NumSent;
11 | public TimeSpan LastSent;
12 | public NetOutgoingMessage? Message;
13 |
14 | public void Reset()
15 | {
16 | SequenceNumber = default;
17 | NumSent = default;
18 | LastSent = default;
19 | Message = default;
20 | }
21 |
22 | private string GetDebuggerDisplay()
23 | {
24 | return ToString();
25 | }
26 |
27 | public override string ToString()
28 | {
29 | return Message != null ? Message.DebuggerDisplay : "Empty";
30 | }
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/Lidgren.Network/Exceptions/EndOfMessageException.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace Lidgren.Network
4 | {
5 | public class EndOfMessageException : LidgrenException
6 | {
7 | private const string DefaultMessage =
8 | "Attempt to read past the buffer. " +
9 | "Likely caused by mismatching Write/Reads, different size, or order.";
10 |
11 | public EndOfMessageException() : base(DefaultMessage)
12 | {
13 | }
14 |
15 | public EndOfMessageException(string? message) : base(PassMessage(message))
16 | {
17 | }
18 |
19 | public EndOfMessageException(string? message, Exception? innerException) : base(PassMessage(message), innerException)
20 | {
21 | }
22 |
23 | private static string PassMessage(string? message)
24 | {
25 | return string.IsNullOrEmpty(message) ? DefaultMessage : message;
26 | }
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/Lidgren.Network.Tests/Lidgren.Network.Tests.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | net8.0
6 | enable
7 | Lidgren.Network.Tests.Program
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 | all
16 | runtime; build; native; contentfiles; analyzers; buildtransitive
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/OldSamples/LibraryTestSamples/DurableSample/DurableClient/Form1.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Windows.Forms;
3 |
4 | using SamplesCommon;
5 |
6 | namespace DurableClient
7 | {
8 | public partial class Form1 : Form
9 | {
10 | private NetPeerSettingsWindow m_settingsWindow;
11 |
12 | public Form1()
13 | {
14 | InitializeComponent();
15 | }
16 |
17 | private void button1_Click(object sender, EventArgs e)
18 | {
19 | if (string.IsNullOrEmpty(textBox1.Text))
20 | textBox1.Text = "localhost";
21 |
22 | Program.Connect(textBox1.Text);
23 | }
24 |
25 | private void button2_Click(object sender, EventArgs e)
26 | {
27 | if (m_settingsWindow == null)
28 | {
29 | m_settingsWindow = new NetPeerSettingsWindow("Durable client settings", Program.Client);
30 | m_settingsWindow.Show();
31 | }
32 | else
33 | {
34 | m_settingsWindow.Close();
35 | m_settingsWindow = null;
36 | }
37 | }
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/OldSamples/ImageSample/ImageClient/Form1.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.ComponentModel;
4 | using System.Drawing;
5 | using System.Linq;
6 | using System.Text;
7 | using System.Windows.Forms;
8 | using Lidgren.Network;
9 | using SamplesCommon;
10 |
11 | namespace ImageClient
12 | {
13 | public partial class Form1 : Form
14 | {
15 | private NetPeer m_dummyPeer;
16 | private NetPeerConfiguration m_config;
17 |
18 | public Form1()
19 | {
20 | m_config = new NetPeerConfiguration("ImageTransfer");
21 | m_dummyPeer = new NetPeer(m_config);
22 | InitializeComponent();
23 | }
24 |
25 | private void button1_Click(object sender, EventArgs e)
26 | {
27 | Program.SpawnGetter(textBox1.Text, m_config);
28 | }
29 |
30 | private void button2_Click(object sender, EventArgs e)
31 | {
32 | NetPeerSettingsWindow win = new NetPeerSettingsWindow("Client settings", m_dummyPeer);
33 | win.Show();
34 | }
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/Lidgren.Network/Messaging/Channels/NetChannel.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace Lidgren.Network;
4 |
5 | internal abstract class NetChannel
6 | {
7 | private int _windowSize;
8 |
9 | protected int _windowStart;
10 |
11 | public NetConnection Connection { get; }
12 |
13 | public int WindowSize
14 | {
15 | get => _windowSize;
16 | protected set
17 | {
18 | LidgrenException.AssertIsPowerOfTwo((ulong) value, nameof(value));
19 | if (_windowSize == 1)
20 | {
21 | throw new InvalidOperationException();
22 | }
23 | _windowSize = value;
24 | OnWindowSizeChanged();
25 | }
26 | }
27 |
28 | protected NetChannel(NetConnection connection, int windowSize)
29 | {
30 | Connection = connection ?? throw new ArgumentNullException(nameof(connection));
31 | WindowSize = windowSize;
32 | }
33 |
34 | protected abstract void OnWindowSizeChanged();
35 |
36 | public virtual void Reset()
37 | {
38 | _windowStart = 0;
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/Lidgren.Network/Random/NetRandomSeed.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Threading;
3 |
4 | namespace Lidgren.Network
5 | {
6 | ///
7 | /// Helper for generating random integer numbers.
8 | ///
9 | public static class NetRandomSeed
10 | {
11 | private static int _seedIncrement = -1640531527;
12 |
13 | ///
14 | /// Generates a 32-bit random seed.
15 | ///
16 | [CLSCompliant(false)]
17 | public static uint GetUInt32()
18 | {
19 | ulong seed = GetUInt64();
20 | uint low = (uint)seed;
21 | uint high = (uint)(seed >> 32);
22 | return low ^ high;
23 | }
24 |
25 | ///
26 | /// Generates a 64-bit random seed.
27 | ///
28 | [CLSCompliant(false)]
29 | public static ulong GetUInt64()
30 | {
31 | // TODO: optimize
32 |
33 | ulong seed = (ulong)System.Diagnostics.Stopwatch.GetTimestamp();
34 | seed ^= (ulong)Environment.WorkingSet;
35 | ulong s2 = (ulong)Interlocked.Increment(ref _seedIncrement);
36 | s2 |= ((ulong)Guid.NewGuid().GetHashCode()) << 32;
37 | seed ^= s2;
38 | return seed;
39 | }
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/OldSamples/LibraryTestSamples/ManySample/ManyClients/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Windows.Forms;
5 | using SamplesCommon;
6 |
7 | namespace ManyClients
8 | {
9 | static class Program
10 | {
11 | public static List Clients;
12 |
13 | [STAThread]
14 | static void Main()
15 | {
16 | Application.EnableVisualStyles();
17 | Application.SetCompatibleTextRenderingDefault(false);
18 |
19 | Clients = new List();
20 |
21 | Application.Idle += new EventHandler(AppIdle);
22 | Application.Run(new Form1());
23 |
24 | foreach (var c in Clients)
25 | c.Shutdown();
26 | }
27 |
28 | static void AppIdle(object sender, EventArgs e)
29 | {
30 | while (NativeMethods.AppStillIdle)
31 | {
32 | foreach (var c in Clients)
33 | c.Heartbeat();
34 | System.Threading.Thread.Sleep(1);
35 | }
36 | }
37 |
38 | internal static void CreateClient()
39 | {
40 | Client client = new Client();
41 | client.Show();
42 | Clients.Add(client);
43 | }
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2015 lidgren
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/Lidgren.Network/Peer/NetPeer.Logging.cs:
--------------------------------------------------------------------------------
1 | using System.Diagnostics;
2 |
3 | namespace Lidgren.Network
4 | {
5 | public partial class NetPeer
6 | {
7 | public delegate void LogEvent(NetPeer sender, NetLogLevel level, in NetLogMessage message);
8 |
9 | public event LogEvent? VerboseMessage;
10 | public event LogEvent? DebugMessage;
11 | public event LogEvent? WarningMessage;
12 | public event LogEvent? ErrorMessage;
13 |
14 | [Conditional("DEBUG")]
15 | internal void LogVerbose(in NetLogMessage message)
16 | {
17 | VerboseMessage?.Invoke(this, NetLogLevel.Verbose, message);
18 | }
19 |
20 | internal void LogDebug(in NetLogMessage message)
21 | {
22 | DebugMessage?.Invoke(this, NetLogLevel.Debug, message);
23 | }
24 |
25 | internal void LogWarning(in NetLogMessage message)
26 | {
27 | WarningMessage?.Invoke(this, NetLogLevel.Warning, message);
28 | }
29 |
30 | internal void LogError(in NetLogMessage message)
31 | {
32 | ErrorMessage?.Invoke(this, NetLogLevel.Error, message);
33 | }
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/Lidgren.Network/Memory/ListEnumeratorExtensions.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 |
3 | namespace Lidgren.Network
4 | {
5 | internal static class ListEnumeratorExtensions
6 | {
7 | ///
8 | /// Creates a struct enumerator over the enumerable, trying to iterate over it using list indexing
9 | /// if the enumerable implements or ,
10 | /// falling back to otherwise.
11 | ///
12 | /// The generic type of the collection.
13 | /// The collection to be enumerated.
14 | /// The struct enumerator.
15 | public static ListEnumerator AsListEnumerator(this IEnumerable enumerable)
16 | {
17 | if (enumerable is IReadOnlyList roList)
18 | return new ListEnumerator(roList);
19 | else if (enumerable is IList list)
20 | return new ListEnumerator(list);
21 | return new ListEnumerator(enumerable.GetEnumerator());
22 | }
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/UnitTests/MiscTests.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | using Lidgren.Network;
4 |
5 | namespace UnitTests
6 | {
7 | public static class MiscTests
8 | {
9 | public static void Run()
10 | {
11 | var config = new NetPeerConfiguration("Test");
12 |
13 | config.EnableMessageType(NetIncomingMessageType.UnconnectedData);
14 | if (config.IsMessageTypeEnabled(NetIncomingMessageType.UnconnectedData) == false)
15 | throw new LidgrenException("setting enabled message types failed");
16 |
17 | config.SetMessageTypeEnabled(NetIncomingMessageType.UnconnectedData, false);
18 | if (config.IsMessageTypeEnabled(NetIncomingMessageType.UnconnectedData) == true)
19 | throw new LidgrenException("setting enabled message types failed");
20 |
21 | Console.WriteLine("Hex test: " + NetUtility.ToHexString(new byte[] { 0xDE, 0xAD, 0xBE, 0xEF }));
22 |
23 | if (NetBitWriter.BitsForValue(uint.MaxValue + 1ul) != 33)
24 | throw new LidgrenException("BitCountForValue failed");
25 |
26 | Console.WriteLine("Misc tests OK");
27 | }
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/OldSamples/ImageSample/ImageServer/Form1.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.ComponentModel;
4 | using System.Drawing;
5 | using System.Linq;
6 | using System.Text;
7 | using System.Windows.Forms;
8 | using SamplesCommon;
9 |
10 | namespace ImageServer
11 | {
12 | public partial class Form1 : Form
13 | {
14 | private NetPeerSettingsWindow m_settingsWindow;
15 |
16 | public Form1()
17 | {
18 | InitializeComponent();
19 | }
20 |
21 | private void button1_Click(object sender, EventArgs e)
22 | {
23 | if (m_settingsWindow == null)
24 | {
25 | m_settingsWindow = new NetPeerSettingsWindow("Image server settings", Program.Server);
26 | m_settingsWindow.Show();
27 | }
28 | else
29 | {
30 | m_settingsWindow.Close();
31 | m_settingsWindow = null;
32 | }
33 | }
34 |
35 | private void button2_Click(object sender, EventArgs e)
36 | {
37 | OpenFileDialog dlg = new OpenFileDialog();
38 | dlg.Filter = "Image files|*.png;*.jpg;*.jpeg";
39 | DialogResult res = dlg.ShowDialog();
40 | if (res != DialogResult.OK)
41 | return;
42 | Program.Start(dlg.FileName);
43 | }
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/Lidgren.Network/Messaging/NetDeliveryMethod.cs:
--------------------------------------------------------------------------------
1 |
2 | using System;
3 |
4 | namespace Lidgren.Network
5 | {
6 | ///
7 | /// How the library deals with resends and handling of late messages.
8 | ///
9 | public enum NetDeliveryMethod : byte
10 | {
11 | // Publicly visible subset of NetMessageType
12 |
13 | ///
14 | /// Indicates an error.
15 | ///
16 | Unknown = 0,
17 |
18 | ///
19 | /// Unreliable, unordered delivery.
20 | ///
21 | Unreliable = NetMessageType.UserUnreliable,
22 |
23 | ///
24 | /// Unreliable delivery, but automatically dropping late messages.
25 | ///
26 | UnreliableSequenced = NetMessageType.UserSequenced1,
27 |
28 | ///
29 | /// Reliable delivery, but unordered.
30 | ///
31 | ReliableUnordered = NetMessageType.UserReliableUnordered,
32 |
33 | ///
34 | /// Reliable delivery, except for late messages which are dropped.
35 | ///
36 | ReliableSequenced = NetMessageType.UserReliableSequenced1,
37 |
38 | ///
39 | /// Reliable, ordered delivery.
40 | ///
41 | ReliableOrdered = NetMessageType.UserReliableOrdered1,
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/OldSamples/Chat/ChatClient/Properties/Settings.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated by a tool.
4 | // Runtime Version:4.0.30319.18444
5 | //
6 | // Changes to this file may cause incorrect behavior and will be lost if
7 | // the code is regenerated.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace ChatClient.Properties {
12 |
13 |
14 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
15 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")]
16 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
17 |
18 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
19 |
20 | public static Settings Default {
21 | get {
22 | return defaultInstance;
23 | }
24 | }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/OldSamples/Chat/ChatServer/Properties/Settings.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated by a tool.
4 | // Runtime Version:4.0.30319.18444
5 | //
6 | // Changes to this file may cause incorrect behavior and will be lost if
7 | // the code is regenerated.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace ChatServer.Properties {
12 |
13 |
14 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
15 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")]
16 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
17 |
18 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
19 |
20 | public static Settings Default {
21 | get {
22 | return defaultInstance;
23 | }
24 | }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/OldSamples/ImageSample/ImageClient/Properties/Settings.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated by a tool.
4 | // Runtime Version:4.0.30319.18444
5 | //
6 | // Changes to this file may cause incorrect behavior and will be lost if
7 | // the code is regenerated.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace ImageClient.Properties {
12 |
13 |
14 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
15 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")]
16 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
17 |
18 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
19 |
20 | public static Settings Default {
21 | get {
22 | return defaultInstance;
23 | }
24 | }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/OldSamples/ImageSample/ImageServer/Properties/Settings.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated by a tool.
4 | // Runtime Version:4.0.30319.18444
5 | //
6 | // Changes to this file may cause incorrect behavior and will be lost if
7 | // the code is regenerated.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace ImageServer.Properties {
12 |
13 |
14 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
15 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")]
16 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
17 |
18 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
19 |
20 | public static Settings Default {
21 | get {
22 | return defaultInstance;
23 | }
24 | }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/OldSamples/MasterServerSample/MSClient/Properties/Settings.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated by a tool.
4 | // Runtime Version:4.0.30319.18444
5 | //
6 | // Changes to this file may cause incorrect behavior and will be lost if
7 | // the code is regenerated.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace MSClient.Properties {
12 |
13 |
14 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
15 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "12.0.0.0")]
16 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
17 |
18 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
19 |
20 | public static Settings Default {
21 | get {
22 | return defaultInstance;
23 | }
24 | }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/OldSamples/File stream sample/FileStreamClient/Properties/Settings.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated by a tool.
4 | // Runtime Version:4.0.30319.18444
5 | //
6 | // Changes to this file may cause incorrect behavior and will be lost if
7 | // the code is regenerated.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace FileStreamClient.Properties {
12 |
13 |
14 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
15 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")]
16 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
17 |
18 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
19 |
20 | public static Settings Default {
21 | get {
22 | return defaultInstance;
23 | }
24 | }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/OldSamples/File stream sample/FileStreamServer/Properties/Settings.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated by a tool.
4 | // Runtime Version:4.0.30319.18444
5 | //
6 | // Changes to this file may cause incorrect behavior and will be lost if
7 | // the code is regenerated.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace FileStreamServer.Properties {
12 |
13 |
14 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
15 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")]
16 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
17 |
18 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
19 |
20 | public static Settings Default {
21 | get {
22 | return defaultInstance;
23 | }
24 | }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/OldSamples/LibraryTestSamples/ManySample/ManyClients/Properties/Settings.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated by a tool.
4 | // Runtime Version:4.0.30319.18444
5 | //
6 | // Changes to this file may cause incorrect behavior and will be lost if
7 | // the code is regenerated.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace ManyClients.Properties {
12 |
13 |
14 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
15 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")]
16 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
17 |
18 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
19 |
20 | public static Settings Default {
21 | get {
22 | return defaultInstance;
23 | }
24 | }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/OldSamples/LibraryTestSamples/ManySample/ManyServer/Properties/Settings.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated by a tool.
4 | // Runtime Version:4.0.30319.18444
5 | //
6 | // Changes to this file may cause incorrect behavior and will be lost if
7 | // the code is regenerated.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace ManyServer.Properties {
12 |
13 |
14 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
15 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")]
16 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
17 |
18 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
19 |
20 | public static Settings Default {
21 | get {
22 | return defaultInstance;
23 | }
24 | }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/OldSamples/LibraryTestSamples/DurableSample/DurableClient/Properties/Settings.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated by a tool.
4 | // Runtime Version:4.0.30319.18444
5 | //
6 | // Changes to this file may cause incorrect behavior and will be lost if
7 | // the code is regenerated.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace DurableClient.Properties {
12 |
13 |
14 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
15 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")]
16 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
17 |
18 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
19 |
20 | public static Settings Default {
21 | get {
22 | return defaultInstance;
23 | }
24 | }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/OldSamples/LibraryTestSamples/DurableSample/DurableServer/Properties/Settings.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated by a tool.
4 | // Runtime Version:4.0.30319.18444
5 | //
6 | // Changes to this file may cause incorrect behavior and will be lost if
7 | // the code is regenerated.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace DurableServer.Properties {
12 |
13 |
14 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
15 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")]
16 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
17 |
18 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
19 |
20 | public static Settings Default {
21 | get {
22 | return defaultInstance;
23 | }
24 | }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/OldSamples/LibraryTestSamples/SpeedSample/SpeedClient/Properties/Settings.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated by a tool.
4 | // Runtime Version:4.0.30319.18444
5 | //
6 | // Changes to this file may cause incorrect behavior and will be lost if
7 | // the code is regenerated.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace SpeedTestClient.Properties {
12 |
13 |
14 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
15 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")]
16 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
17 |
18 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
19 |
20 | public static Settings Default {
21 | get {
22 | return defaultInstance;
23 | }
24 | }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/OldSamples/LibraryTestSamples/SpeedSample/SpeedServer/Properties/Settings.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated by a tool.
4 | // Runtime Version:4.0.30319.18444
5 | //
6 | // Changes to this file may cause incorrect behavior and will be lost if
7 | // the code is regenerated.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace SpeedTestServer.Properties {
12 |
13 |
14 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
15 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")]
16 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
17 |
18 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
19 |
20 | public static Settings Default {
21 | get {
22 | return defaultInstance;
23 | }
24 | }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/OldSamples/LibraryTestSamples/UnconnectedSample/UnconnectedSample/Properties/Settings.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated by a tool.
4 | // Runtime Version:4.0.30319.18444
5 | //
6 | // Changes to this file may cause incorrect behavior and will be lost if
7 | // the code is regenerated.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace UnconnectedSample.Properties {
12 |
13 |
14 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
15 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")]
16 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
17 |
18 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
19 |
20 | public static Settings Default {
21 | get {
22 | return defaultInstance;
23 | }
24 | }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/Lidgren.Network/Documentation/Improvements.txt:
--------------------------------------------------------------------------------
1 |
2 | Improvements over last version of library:
3 |
4 | * New delivery type: Reliable sequenced (Lost packets are resent but late arrivals are dropped)
5 | * Disconnects and shutdown requests are now queued properly, so calling shutdown will still send any queued messages before shutting down
6 | * All messages are pooled/recycled for zero garbage
7 | * Reduced CPU usage and lower latencies (in the <1 ms range, but still) due to better socket polling
8 | * All public members of NetPeer/NetConnection are completely thread safe
9 | * Larger number of delivery channels
10 | * More exact roundtrip measurement
11 | * Method serialize entire objects via reflection
12 | * Unique identifier now exists for all peers/connections
13 | * More flexible peer discovery; filters possible and arbitrary data can be sent with response
14 | * Much better protection against malformed messages crashing the app
15 |
16 | API enhancements:
17 | * NetPeerConfiguration immutable properties now locked once NetPeer is initialized
18 | * Messages cannot be send twice by accident
19 | * Impossible to confuse sending and receiving buffers since they're different classes
20 | * No more confusion if user should create a buffer or preallocate and reuse
21 |
22 |
23 |
--------------------------------------------------------------------------------
/Lidgren.Network/Exceptions/CannotResendException.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace Lidgren.Network
4 | {
5 | public class CannotResendException : ArgumentException
6 | {
7 | private const string DefaultMessage =
8 | "The message has already been sent. " +
9 | "Use other methods to send to multiple recipients efficiently.";
10 |
11 | public CannotResendException() : base(DefaultMessage)
12 | {
13 | }
14 |
15 | public CannotResendException(string? paramName) : base(DefaultMessage, paramName)
16 | {
17 | }
18 |
19 | public CannotResendException(string? message, string? paramName) : base(PassMessage(message), paramName)
20 | {
21 | }
22 |
23 | public CannotResendException(string? message, Exception? innerException) : base(PassMessage(message), innerException)
24 | {
25 | }
26 |
27 | public CannotResendException(string? message, string? paramName, Exception? innerException) :
28 | base(PassMessage(message), paramName, innerException)
29 | {
30 |
31 | }
32 |
33 | private static string PassMessage(string? message)
34 | {
35 | return string.IsNullOrEmpty(message) ? DefaultMessage : message;
36 | }
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/OldSamples/MasterServerSample/MSCommon/Documentation.txt:
--------------------------------------------------------------------------------
1 |
2 | C is a computer behind a NAT
3 | H is a computer behind a different NAT
4 | M is a computer not behind a NAT
5 |
6 | H wishes to host a game and C wishes to join it, but since they are both behind NAT they cannot contact eachother directly. M must help.
7 |
8 | -------
9 |
10 | 1. H sends a message to M, registering itself as a game host. H is added to the host list at M. (sample code)
11 |
12 | 2. C requests the host list from M. (sample code)
13 |
14 | 3. C reads the host list and decides to join the game hosted by H. (sample code)
15 |
16 | 3. C sends a request to M for introduction between C and H. (sample code)
17 |
18 | 4. M gets the request and sends a NatIntroduction message to both C and H with their external addresses. (NetPeer.Introduce())
19 |
20 | 5a. C gets the intro message and sends a NAT punch message to the external address of H (automatically by library)
21 | 5b. H gets the intro message and sends a NAT punch message to the external address of C (automatically by library)
22 |
23 | 6. If everything goes well, C will get the punch message from H and both NAT routers are now properly configured.
24 |
25 | 7. C will receive a NatIntroductionSuccess message and can now call Connect() as usual (automatically by library)
26 |
27 |
28 |
--------------------------------------------------------------------------------
/OldSamples/ImageSample/ImageClient/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Windows.Forms;
5 | using SamplesCommon;
6 | using Lidgren.Network;
7 |
8 | namespace ImageClient
9 | {
10 | static class Program
11 | {
12 | public static Form1 MainForm;
13 | public static List Getters = new List();
14 |
15 | [STAThread]
16 | static void Main()
17 | {
18 | Application.EnableVisualStyles();
19 | Application.SetCompatibleTextRenderingDefault(false);
20 | MainForm = new Form1();
21 |
22 | try
23 | {
24 | Application.Idle += new EventHandler(AppLoop);
25 | Application.Run(MainForm);
26 | }
27 | catch (Exception ex)
28 | {
29 | MessageBox.Show("Ouch: " + ex);
30 | }
31 | }
32 |
33 | static void AppLoop(object sender, EventArgs e)
34 | {
35 | while (NativeMethods.AppStillIdle)
36 | {
37 | foreach (ImageGetter getter in Getters)
38 | getter.Heartbeat();
39 | System.Threading.Thread.Sleep(1);
40 | }
41 | }
42 |
43 | internal static void SpawnGetter(string host, NetPeerConfiguration copyConfig)
44 | {
45 | ImageGetter getter = new ImageGetter(host, copyConfig);
46 | Getters.Add(getter);
47 | getter.Show();
48 | }
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/Lidgren.Network/Buffer/IBitBuffer.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace Lidgren.Network
4 | {
5 | public interface IBitBuffer : IDisposable
6 | {
7 | int BitCapacity { get; set; }
8 |
9 | int ByteCapacity { get; set; }
10 |
11 | ///
12 | /// Gets or sets the length of the used portion of the buffer in bits.
13 | ///
14 | int BitLength { get; set; }
15 |
16 | ///
17 | /// Gets or sets the length of the used portion of the buffer in bytes.
18 | ///
19 | int ByteLength { get; set; }
20 |
21 | ///
22 | /// Gets or sets the position within the buffer in bits.
23 | ///
24 | int BitPosition { get; set; }
25 |
26 | ///
27 | /// Gets or sets the position within the buffer in bytes.
28 | ///
29 | int BytePosition { get; set; }
30 |
31 | ///
32 | /// Ensures that the buffer can hold this number of bits.
33 | ///
34 | void EnsureBitCapacity(int bitCount);
35 |
36 | ///
37 | /// Reduces capacity down to what's needed for the current data.
38 | ///
39 | void TrimExcess();
40 |
41 | byte[] GetBuffer();
42 | }
43 |
44 | //public abstract class BitBuffer : IBitBuffer
45 | //{
46 | //}
47 | }
48 |
--------------------------------------------------------------------------------
/Lidgren.Network/Random/MWCRandom.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace Lidgren.Network
4 | {
5 | ///
6 | /// Multiply With Carry based random.
7 | ///
8 | public class MWCRandom : NetRandom
9 | {
10 | ///
11 | /// Get global instance of .
12 | ///
13 | public static new MWCRandom Global { get; } = new MWCRandom();
14 |
15 | private uint _w;
16 | private uint _z;
17 |
18 | ///
19 | /// Constructor with randomized seed.
20 | ///
21 | public MWCRandom()
22 | {
23 | Initialize(NetRandomSeed.GetUInt64());
24 | }
25 |
26 | ///
27 | [CLSCompliant(false)]
28 | public override void Initialize(int seed)
29 | {
30 | _w = (uint)seed;
31 | _z = _w * 16777619;
32 | }
33 |
34 | ///
35 | [CLSCompliant(false)]
36 | public void Initialize(ulong seed)
37 | {
38 | _w = (uint)seed;
39 | _z = (uint)(seed >> 32);
40 | }
41 |
42 | ///
43 | [CLSCompliant(false)]
44 | public override uint NextUInt32()
45 | {
46 | _z = 36969 * (_z & 65535) + (_z >> 16);
47 | _w = 18000 * (_w & 65535) + (_w >> 16);
48 | return (_z << 16) + _w;
49 | }
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/UnitTests/FakeReadStream.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.IO;
3 |
4 | namespace UnitTests
5 | {
6 | public class FakeReadStream : Stream
7 | {
8 | private long _length;
9 | private long _position;
10 |
11 | public override bool CanRead => true;
12 | public override bool CanSeek => false;
13 | public override bool CanWrite => false;
14 |
15 | public override long Length => _length;
16 |
17 | public override long Position
18 | {
19 | get => _position;
20 | set => Seek(value, SeekOrigin.Begin);
21 | }
22 |
23 | public FakeReadStream(long length)
24 | {
25 | SetLength(length);
26 | }
27 |
28 | public override int Read(byte[] buffer, int offset, int count)
29 | {
30 | long toRead = Math.Min(_length - _position, count);
31 | _position += toRead;
32 | return (int)toRead;
33 | }
34 |
35 | public override void SetLength(long value)
36 | {
37 | _length = value;
38 | }
39 |
40 | public override void Flush()
41 | {
42 | }
43 |
44 | public override long Seek(long offset, SeekOrigin origin)
45 | {
46 | throw new NotSupportedException();
47 | }
48 |
49 | public override void Write(byte[] buffer, int offset, int count)
50 | {
51 | throw new NotSupportedException();
52 | }
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/OldSamples/LibraryTestSamples/GarbageThrowerSample/Client/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 |
4 | using Lidgren.Network;
5 | using System.Threading;
6 | using System.Net;
7 |
8 | namespace Client
9 | {
10 | class Program
11 | {
12 | static void Main(string[] args)
13 | {
14 | NetPeerConfiguration config = new NetPeerConfiguration("garbagethrower");
15 | var client = new NetClient(config);
16 |
17 | client.Start();
18 |
19 | var target = new IPEndPoint(NetUtility.Resolve("localhost"), 14242);
20 | var buffer = new byte[1024];
21 | var rnd = new Random();
22 |
23 | int batch = 0;
24 | // use RawSend to throw poop at server
25 | while(true)
26 | {
27 | rnd.NextBytes(buffer);
28 | int length = rnd.Next(1, 1023);
29 |
30 | switch (rnd.Next(2))
31 | {
32 | case 0:
33 | // complete randomness
34 | break;
35 | case 1:
36 | // semi-sensical
37 | buffer[1] = 0; // not a fragment, sequence number 0
38 | buffer[2] = 0; // not a fragment, sequence number 0
39 | buffer[3] = (byte)length; // correct payload length
40 | buffer[4] = (byte)(length >> 8); // correct payload length
41 | break;
42 | }
43 |
44 | // fling teh poop
45 | client.RawSend(buffer, 0, length, target);
46 |
47 | batch++;
48 | if (batch >= 3)
49 | {
50 | batch = 0;
51 | Thread.Sleep(0);
52 | }
53 | }
54 | }
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/OldSamples/LibraryTestSamples/EncryptionSample/EncryptionServer/Program.cs:
--------------------------------------------------------------------------------
1 | using Lidgren.Network;
2 | using System;
3 |
4 | namespace EncryptionServer
5 | {
6 | class Program
7 | {
8 | static void Main(string[] args)
9 | {
10 | var config = new NetPeerConfiguration("enctest");
11 | config.MaximumConnections = 1;
12 | config.Port = 14242;
13 | var server = new NetServer(config);
14 | server.Start();
15 |
16 | var encryption = new NetAESEncryption(server, "Hallonpalt");
17 |
18 | // loop forever
19 | while (true)
20 | {
21 | var inc = server.ReadMessage();
22 | if (inc != null)
23 | {
24 | switch (inc.MessageType)
25 | {
26 | case NetIncomingMessageType.DebugMessage:
27 | case NetIncomingMessageType.WarningMessage:
28 | case NetIncomingMessageType.VerboseDebugMessage:
29 | case NetIncomingMessageType.ErrorMessage:
30 | Console.WriteLine(inc.ReadString());
31 | break;
32 | case NetIncomingMessageType.StatusChanged:
33 | var status = (NetConnectionStatus)inc.ReadByte();
34 | Console.WriteLine(inc.SenderConnection + " (" + status + ") " + inc.ReadString());
35 | break;
36 | case NetIncomingMessageType.Data:
37 | var ok = inc.Decrypt(encryption);
38 | Console.WriteLine("Data (decrypted: " + (ok ? "ok" : "fail") + ") " + inc.ReadString());
39 | break;
40 | }
41 | }
42 | System.Threading.Thread.Sleep(1);
43 | }
44 | }
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/OldSamples/Chat/ChatClient/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("ChatClient")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("ChatClient")]
13 | [assembly: AssemblyCopyright("Copyright © 2012")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("585ecb61-e1fb-4a44-8a0c-2bc06d450fe4")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/OldSamples/Chat/ChatServer/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("ChatServer")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("ChatServer")]
13 | [assembly: AssemblyCopyright("Copyright © 2012")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("9ef4cd93-2efb-4c87-8cf3-ef329d157b94")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/OldSamples/ImageSample/ImageClient/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("ImageClient")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("ImageClient")]
13 | [assembly: AssemblyCopyright("Copyright © 2012")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("b29fc143-5a2c-462d-9df3-04320a9d5e13")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/OldSamples/ImageSample/ImageServer/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("ImageServer")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("ImageServer")]
13 | [assembly: AssemblyCopyright("Copyright © 2012")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("ce1aecdc-6beb-43b4-828a-fd395fc7e188")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/OldSamples/LibraryTestSamples/GarbageThrowerSample/Client/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("Client")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("Client")]
13 | [assembly: AssemblyCopyright("Copyright © 2014")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("0c9a409f-00cd-4b05-87f6-6f4a86d82987")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/OldSamples/LibraryTestSamples/GarbageThrowerSample/Server/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("Server")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("Server")]
13 | [assembly: AssemblyCopyright("Copyright © 2014")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("afeebf34-cb2c-4377-ace7-5c55f2882c0d")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/OldSamples/LibraryTestSamples/ManySample/ManyServer/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("ManyServer")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("ManyServer")]
13 | [assembly: AssemblyCopyright("Copyright © 2012")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("38556e1a-2608-406f-869b-2935943be269")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/OldSamples/MasterServerSample/MSClient/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("MSClient")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("Microsoft")]
12 | [assembly: AssemblyProduct("MSClient")]
13 | [assembly: AssemblyCopyright("Copyright © Microsoft 2010")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("bedb3e73-43c8-4b0d-a982-528a08a745c6")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/OldSamples/MasterServerSample/MSCommon/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("MSCommon")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("Microsoft")]
12 | [assembly: AssemblyProduct("MSCommon")]
13 | [assembly: AssemblyCopyright("Copyright © Microsoft 2010")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("24cc031a-d470-439a-89f6-573e5ea1d969")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/OldSamples/MasterServerSample/MSServer/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("MSServer")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("Microsoft")]
12 | [assembly: AssemblyProduct("MSServer")]
13 | [assembly: AssemblyCopyright("Copyright © Microsoft 2010")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("c265af7f-3dad-4edf-8ff7-44f03eb2c8e4")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/OldSamples/SamplesCommon/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("SamplesCommon")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("Microsoft")]
12 | [assembly: AssemblyProduct("SamplesCommon")]
13 | [assembly: AssemblyCopyright("Copyright © Microsoft 2010")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("7d1622f4-1dc7-4e94-8ec0-0a2a295dcf9a")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/OldSamples/LibraryTestSamples/SpeedSample/SpeedClient/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("SpeedClient")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("SpeedClient")]
13 | [assembly: AssemblyCopyright("Copyright © 2012")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("dcd70d6e-8d70-460c-a2dd-0ac9d36237ab")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/OldSamples/LibraryTestSamples/SpeedSample/SpeedServer/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("SpeedServer")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("SpeedServer")]
13 | [assembly: AssemblyCopyright("Copyright © 2012")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("2def9135-b4c4-4988-addb-fc00a0fe2f3a")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/Lidgren.Network/Encryption/NetEncryption.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace Lidgren.Network
4 | {
5 | ///
6 | /// Base class for an encryption algorithm.
7 | ///
8 | public abstract class NetEncryption : IDisposable
9 | {
10 | public NetPeer Peer { get; private set; }
11 |
12 | public bool IsDisposed { get; private set; }
13 |
14 | public abstract bool SupportsIV { get; }
15 |
16 | ///
17 | /// Constructs the base encryption object.
18 | ///
19 | public NetEncryption(NetPeer peer)
20 | {
21 | Peer = peer ?? throw new ArgumentNullException(nameof(peer));
22 | }
23 |
24 | public abstract void SetKey(byte[] key);
25 |
26 | public abstract void SetIV(byte[] iv);
27 |
28 | ///
29 | /// Encrypt an outgoing message in place.
30 | ///
31 | public abstract bool Encrypt(NetOutgoingMessage message);
32 |
33 | ///
34 | /// Decrypt an incoming message in place.
35 | ///
36 | public abstract bool Decrypt(NetIncomingMessage message);
37 |
38 | public void Dispose()
39 | {
40 | Dispose(true);
41 | GC.SuppressFinalize(this);
42 | }
43 |
44 | protected virtual void Dispose(bool disposing)
45 | {
46 | if (!IsDisposed)
47 | {
48 | IsDisposed = true;
49 | }
50 | }
51 |
52 | ~NetEncryption()
53 | {
54 | Dispose(false);
55 | }
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/OldSamples/File stream sample/FileStreamClient/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("FileStreamClient")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("FileStreamClient")]
13 | [assembly: AssemblyCopyright("Copyright © 2012")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("2937bc24-32d3-461a-85d9-7235380742f0")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/OldSamples/File stream sample/FileStreamServer/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("FileStreamServer")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("FileStreamServer")]
13 | [assembly: AssemblyCopyright("Copyright © 2012")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("89332fe6-d655-4932-98c6-77bd03dee333")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/OldSamples/LibraryTestSamples/DurableSample/DurableClient/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("DurableClient")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("DurableClient")]
13 | [assembly: AssemblyCopyright("Copyright © 2012")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("af8ebf93-f447-4c22-8fc3-fb02e2e16b13")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/OldSamples/LibraryTestSamples/DurableSample/DurableServer/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("DurableServer")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("DurableServer")]
13 | [assembly: AssemblyCopyright("Copyright © 2012")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("6ad0e88c-40c0-4ca8-bc4c-91a8b64b5776")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/OldSamples/MasterServerSample/MasterServer/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("MasterServer")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("Microsoft")]
12 | [assembly: AssemblyProduct("MasterServer")]
13 | [assembly: AssemblyCopyright("Copyright © Microsoft 2010")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("649338d3-b80b-4710-b801-21e593935c21")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/OldSamples/LibraryTestSamples/ManySample/ManyClients/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("ManyClients")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("Microsoft")]
12 | [assembly: AssemblyProduct("ManyClients")]
13 | [assembly: AssemblyCopyright("Copyright © Microsoft 2010")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("140e8b00-0bb5-4e9e-847c-56ad106f01a4")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/OldSamples/LibraryTestSamples/UnconnectedSample/UnconnectedSample/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("UnconnectedSample")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("UnconnectedSample")]
13 | [assembly: AssemblyCopyright("Copyright © 2012")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("615bd8c4-8874-4171-91dc-677905db3e40")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/Lidgren.Network/Connection/NetConnectionStatus.cs:
--------------------------------------------------------------------------------
1 |
2 | namespace Lidgren.Network
3 | {
4 | ///
5 | /// Status for a instance.
6 | ///
7 | public enum NetConnectionStatus : byte
8 | {
9 | ///
10 | /// No connection, or attempt, in place
11 | ///
12 | None,
13 |
14 | ///
15 | /// Connect has been sent; waiting for ConnectResponse
16 | ///
17 | InitiatedConnect,
18 |
19 | ///
20 | /// Connect was received, but ConnectResponse hasn't been sent yet
21 | ///
22 | ReceivedInitiation,
23 |
24 | ///
25 | /// Connect was received and released to the application.
26 | /// Awaiting or .
27 | ///
28 | RespondedAwaitingApproval,
29 |
30 | ///
31 | /// Connect was received and ConnectResponse has been sent; waiting for ConnectionEstablished
32 | ///
33 | RespondedConnect,
34 |
35 | ///
36 | /// Connected
37 | ///
38 | Connected, // we received ConnectResponse (if initiator) or ConnectionEstablished (if passive)
39 |
40 | ///
41 | /// In the process of disconnecting
42 | ///
43 | Disconnecting,
44 |
45 | ///
46 | /// Disconnected
47 | ///
48 | Disconnected
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/OldSamples/LibraryTestSamples/EncryptionSample/EncryptionClient/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("EncryptionClient")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("EA Digital Illusions CE AB")]
12 | [assembly: AssemblyProduct("EncryptionClient")]
13 | [assembly: AssemblyCopyright("Copyright © EA Digital Illusions CE AB 2014")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("6146cc08-8436-4a5b-9cb9-d8a646bdadc0")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/OldSamples/LibraryTestSamples/EncryptionSample/EncryptionServer/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("EncryptionServer")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("EA Digital Illusions CE AB")]
12 | [assembly: AssemblyProduct("EncryptionServer")]
13 | [assembly: AssemblyCopyright("Copyright © EA Digital Illusions CE AB 2014")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("20821c63-4381-4c9f-9c34-e8f8d5ca39b5")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/OldSamples/Chat/ChatClient/Form1.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.ComponentModel;
4 | using System.Drawing;
5 | using System.Text;
6 | using System.Windows.Forms;
7 |
8 | namespace ChatClient
9 | {
10 | public partial class Form1 : Form
11 | {
12 | public Form1()
13 | {
14 | InitializeComponent();
15 |
16 | textBox1.KeyDown += new KeyEventHandler(textBox1_KeyDown);
17 | }
18 |
19 | public void EnableInput()
20 | {
21 | textBox1.Enabled = true;
22 | button1.Enabled = true;
23 | }
24 |
25 | public void DisableInput()
26 | {
27 | textBox1.Enabled = false;
28 | button1.Enabled = false;
29 | }
30 |
31 | void textBox1_KeyDown(object sender, KeyEventArgs e)
32 | {
33 | if (e.KeyCode == Keys.Return || e.KeyCode == Keys.Enter)
34 | {
35 | // return is equivalent to clicking "send"
36 | button1_Click(sender, e);
37 | }
38 | }
39 |
40 | private void button3_Click(object sender, EventArgs e)
41 | {
42 | Program.DisplaySettings();
43 | }
44 |
45 | private void button2_Click(object sender, EventArgs e)
46 | {
47 | if (button2.Text == "Connect")
48 | {
49 | int port;
50 | Int32.TryParse(textBox3.Text, out port);
51 | Program.Connect(textBox2.Text, port);
52 | button2.Text = "Disconnect";
53 | }
54 | else
55 | {
56 | Program.Shutdown();
57 | button2.Text = "Connect";
58 | }
59 | }
60 |
61 | private void button1_Click(object sender, EventArgs e)
62 | {
63 | // Send
64 | if (!string.IsNullOrEmpty(textBox1.Text))
65 | Program.Send(textBox1.Text);
66 | textBox1.Text = "";
67 |
68 | }
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/Lidgren.Network/Exceptions/LidgrenException.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Diagnostics;
3 | using System.Diagnostics.CodeAnalysis;
4 |
5 | namespace Lidgren.Network
6 | {
7 | ///
8 | /// Exception commonly thrown by the Lidgren Network Library.
9 | ///
10 | public class LidgrenException : Exception
11 | {
12 | public LidgrenException() : base()
13 | {
14 | }
15 |
16 | public LidgrenException(string? message) : base(message)
17 | {
18 | }
19 |
20 | public LidgrenException(string? message, Exception? innerException) : base(message, innerException)
21 | {
22 | }
23 |
24 | ///
25 | /// Throws an exception, in DEBUG only, if first parameter is false.
26 | ///
27 | [Conditional("DEBUG")]
28 | public static void Assert([DoesNotReturnIf(false)] bool condition, string? message)
29 | {
30 | if (!condition)
31 | throw new LidgrenException(message);
32 | }
33 |
34 | ///
35 | /// Throws an exception, in DEBUG only, if first parameter is false.
36 | ///
37 | [Conditional("DEBUG")]
38 | public static void Assert([DoesNotReturnIf(false)] bool condition)
39 | {
40 | if (!condition)
41 | throw new LidgrenException();
42 | }
43 |
44 | internal static void AssertIsPowerOfTwo(ulong value, string paramName)
45 | {
46 | if (!NetUtility.IsPowerOfTwo(value))
47 | {
48 | throw new ArgumentOutOfRangeException(paramName, "Value must be a power of two.");
49 | }
50 | }
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/Lidgren.Network.Tests/NetAddressTests.cs:
--------------------------------------------------------------------------------
1 | using System.Net;
2 | using System.Net.Sockets;
3 | using Xunit;
4 |
5 | namespace Lidgren.Network.Tests;
6 |
7 | public class NetAddressTests
8 | {
9 | private static IPEndPoint ScopedIPv6 { get; } = new(
10 | new IPAddress(
11 | new byte[] { 0xfe, 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
12 | scopeid: 0xdeadbeef),
13 | port: 1);
14 |
15 | [Fact]
16 | public void WriteAsIPv6To()
17 | {
18 | IPEndPoint endPoint = new(IPAddress.Loopback, 1);
19 | IPEndPoint endPointV6 = NetUtility.MapToIPv6(endPoint);
20 |
21 | NetAddress buf = new(AddressFamily.InterNetworkV6);
22 | new NetAddress(endPoint).WriteAsIPv6To(buf);
23 | NetAddress cmp = new(endPointV6);
24 | Assert.Equal(buf, cmp);
25 |
26 | Equal(endPointV6, cmp.GetIPEndPoint());
27 | }
28 |
29 | [Fact]
30 | public void WriteAsIPv6To_PreserveScope()
31 | {
32 | NetAddress cmp = new(ScopedIPv6);
33 | NetAddress buf = new(AddressFamily.InterNetworkV6);
34 | cmp.WriteAsIPv6To(buf);
35 | Assert.Equal(buf, cmp);
36 |
37 | Equal(ScopedIPv6, cmp.GetIPEndPoint());
38 | }
39 |
40 | [Fact]
41 | public void WriteTo_PreserveScope()
42 | {
43 | NetAddress buf = new(AddressFamily.InterNetworkV6);
44 | NetAddress cmp = new(ScopedIPv6);
45 | cmp.WriteTo(buf);
46 | Assert.Equal(buf, cmp);
47 |
48 | Equal(ScopedIPv6, cmp.GetIPEndPoint());
49 | }
50 |
51 | private static void Equal(IPEndPoint expected, IPEndPoint value)
52 | {
53 | Assert.Equal(expected.Address.ScopeId, value.Address.ScopeId);
54 | Assert.Equal(expected, value);
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/OldSamples/MasterServerSample/MSCommon/NativeMethods.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Runtime.InteropServices;
4 | using System.Windows.Forms;
5 |
6 | namespace MSCommon
7 | {
8 | public static class NativeMethods
9 | {
10 | [DllImport("user32.dll", CharSet = CharSet.Auto)]
11 | public static extern int SendMessage(IntPtr hWnd, int wMsg, IntPtr wParam, IntPtr lParam);
12 | public const int WM_VSCROLL = 277; // Vertical scroll
13 | public const int SB_BOTTOM = 7; // Scroll to bottom
14 |
15 | [StructLayout(LayoutKind.Sequential)]
16 | public struct PeekMsg
17 | {
18 | public IntPtr hWnd;
19 | public Message msg;
20 | public IntPtr wParam;
21 | public IntPtr lParam;
22 | public uint time;
23 | public System.Drawing.Point p;
24 | }
25 |
26 | [System.Security.SuppressUnmanagedCodeSecurity] // We won't use this maliciously
27 | [DllImport("User32.dll", CharSet = CharSet.Auto)]
28 | public static extern bool PeekMessage(out PeekMsg msg, IntPtr hWnd, uint messageFilterMin, uint messageFilterMax, uint flags);
29 |
30 | public static bool AppStillIdle
31 | {
32 | get
33 | {
34 | PeekMsg msg;
35 | return !PeekMessage(out msg, IntPtr.Zero, 0, 0, 0);
36 | }
37 | }
38 |
39 | public static void AppendText(RichTextBox box, string line)
40 | {
41 | try
42 | {
43 | box.AppendText(line + Environment.NewLine);
44 | ScrollRichTextBox(box);
45 | }
46 | catch
47 | {
48 | }
49 | }
50 |
51 | public static void ScrollRichTextBox(RichTextBox box)
52 | {
53 | if (box == null || box.IsDisposed || box.Disposing)
54 | return;
55 | SendMessage(box.Handle, WM_VSCROLL, (IntPtr)SB_BOTTOM, IntPtr.Zero);
56 | }
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/OldSamples/SamplesCommon/NativeMethods.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Runtime.InteropServices;
4 | using System.Windows.Forms;
5 |
6 | namespace SamplesCommon
7 | {
8 | public static class NativeMethods
9 | {
10 | [DllImport("user32.dll", CharSet = CharSet.Auto)]
11 | public static extern int SendMessage(IntPtr hWnd, int wMsg, IntPtr wParam, IntPtr lParam);
12 | public const int WM_VSCROLL = 277; // Vertical scroll
13 | public const int SB_BOTTOM = 7; // Scroll to bottom
14 |
15 | [StructLayout(LayoutKind.Sequential)]
16 | public struct PeekMsg
17 | {
18 | public IntPtr hWnd;
19 | public Message msg;
20 | public IntPtr wParam;
21 | public IntPtr lParam;
22 | public uint time;
23 | public System.Drawing.Point p;
24 | }
25 |
26 | [System.Security.SuppressUnmanagedCodeSecurity] // We won't use this maliciously
27 | [DllImport("User32.dll", CharSet = CharSet.Auto)]
28 | public static extern bool PeekMessage(out PeekMsg msg, IntPtr hWnd, uint messageFilterMin, uint messageFilterMax, uint flags);
29 |
30 | public static bool AppStillIdle
31 | {
32 | get
33 | {
34 | PeekMsg msg;
35 | return !PeekMessage(out msg, IntPtr.Zero, 0, 0, 0);
36 | }
37 | }
38 |
39 | public static void AppendText(RichTextBox box, string line)
40 | {
41 | if (box == null || box.IsDisposed)
42 | return;
43 | try
44 | {
45 | box.AppendText(line + Environment.NewLine);
46 | ScrollRichTextBox(box);
47 | }
48 | catch
49 | {
50 | }
51 | }
52 |
53 | public static void ScrollRichTextBox(RichTextBox box)
54 | {
55 | if (box == null || box.IsDisposed || box.Disposing)
56 | return;
57 | SendMessage(box.Handle, WM_VSCROLL, (IntPtr)SB_BOTTOM, IntPtr.Zero);
58 | }
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/Lidgren.Network/Messaging/Channels/NetReliableSequencedReceiver.cs:
--------------------------------------------------------------------------------
1 |
2 | namespace Lidgren.Network
3 | {
4 | internal sealed class NetReliableSequencedReceiver : NetReceiverChannel
5 | {
6 | public NetReliableSequencedReceiver(NetConnection connection, int windowSize)
7 | : base(connection, windowSize)
8 | {
9 | }
10 |
11 | private void AdvanceWindow()
12 | {
13 | _windowStart = NetUtility.PowOf2Mod(_windowStart + 1, NetConstants.SequenceNumbers);
14 | }
15 |
16 | public override void ReceiveMessage(in NetMessageView message)
17 | {
18 | NetConnection connection = Connection;
19 | NetPeer peer = connection.Peer;
20 | int windowSize = WindowSize;
21 | int nr = message.SequenceNumber;
22 |
23 | int relate = NetUtility.RelativeSequenceNumber(nr, _windowStart);
24 |
25 | // ack no matter what
26 | connection.QueueAck(message.BaseMessageType, nr);
27 |
28 | if (relate == 0)
29 | {
30 | // Log("Received message #" + message.SequenceNumber + " right on time");
31 |
32 | // excellent, right on time
33 |
34 | AdvanceWindow();
35 | peer.ReleaseMessage(message);
36 | return;
37 | }
38 |
39 | if (relate < 0)
40 | {
41 | peer.LogVerbose(NetLogMessage.FromValues(NetLogCode.DuplicateOrLateMessage,
42 | message, value: _windowStart, maxValue: windowSize));
43 | return;
44 | }
45 |
46 | // relate > 0 = early message
47 | if (relate > windowSize)
48 | {
49 | // too early message!
50 | peer.LogVerbose(NetLogMessage.FromValues(NetLogCode.TooEarlyMessage,
51 | message, value: _windowStart, maxValue: windowSize));
52 | return;
53 | }
54 |
55 | // ok
56 | _windowStart = NetUtility.PowOf2Mod(_windowStart + relate, NetConstants.SequenceNumbers);
57 | peer.ReleaseMessage(message);
58 | return;
59 | }
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/Lidgren.Network/Random/CryptoRandom.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Runtime.InteropServices;
3 | using System.Security.Cryptography;
4 |
5 | namespace Lidgren.Network
6 | {
7 | ///
8 | /// based random; very slow but cryptographically safe.
9 | ///
10 | public class CryptoRandom : NetRandom, IDisposable
11 | {
12 | ///
13 | /// Global instance of .
14 | ///
15 | public static new CryptoRandom Global { get; } = new CryptoRandom();
16 |
17 | private bool _isDisposed;
18 | private RandomNumberGenerator _rng = RandomNumberGenerator.Create();
19 |
20 | ///
21 | /// Seeds in do not create deterministic sequences.
22 | ///
23 | public override void Initialize(int seed)
24 | {
25 | Span tmp = stackalloc byte[(int)((uint)seed % 16)];
26 | _rng.GetBytes(tmp); // just prime it
27 | }
28 |
29 | [CLSCompliant(false)]
30 | public override uint NextUInt32()
31 | {
32 | Span tmp = stackalloc uint[1];
33 | NextBytes(MemoryMarshal.AsBytes(tmp));
34 | return tmp[0];
35 | }
36 |
37 | public override void NextBytes(Span buffer)
38 | {
39 | _rng.GetBytes(buffer);
40 | }
41 |
42 | protected virtual void Dispose(bool disposing)
43 | {
44 | if (!_isDisposed)
45 | {
46 | if (disposing)
47 | _rng.Dispose();
48 |
49 | _isDisposed = true;
50 | }
51 | }
52 |
53 | public void Dispose()
54 | {
55 | Dispose(true);
56 | GC.SuppressFinalize(this);
57 | }
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/OldSamples/LibraryTestSamples/EncryptionSample/EncryptionClient/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | using Lidgren.Network;
4 |
5 | namespace EncryptionClient
6 | {
7 | class Program
8 | {
9 | static void Main(string[] args)
10 | {
11 | var config = new NetPeerConfiguration("enctest");
12 | var client = new NetClient(config);
13 | client.Start();
14 |
15 | System.Threading.Thread.Sleep(100); // give server time to start up
16 |
17 | client.Connect("localhost", 14242);
18 |
19 | var encryption = new NetAESEncryption(client, "Hallonpalt");
20 |
21 | // loop forever
22 | while (true)
23 | {
24 | // read messages
25 | var inc = client.ReadMessage();
26 | if (inc != null)
27 | {
28 | switch (inc.MessageType)
29 | {
30 | case NetIncomingMessageType.DebugMessage:
31 | case NetIncomingMessageType.WarningMessage:
32 | case NetIncomingMessageType.VerboseDebugMessage:
33 | case NetIncomingMessageType.ErrorMessage:
34 | Console.WriteLine(inc.ReadString());
35 | break;
36 | case NetIncomingMessageType.StatusChanged:
37 | var status = (NetConnectionStatus)inc.ReadByte();
38 | Console.WriteLine(inc.SenderConnection + " (" + status + ") " + inc.ReadString());
39 | break;
40 | }
41 | }
42 |
43 | // if we're connected, get input and send
44 | if (client.ServerConnection != null && client.ServerConnection.Status == NetConnectionStatus.Connected)
45 | {
46 | Console.WriteLine("Type a message:");
47 | var input = Console.ReadLine();
48 |
49 | var msg = client.CreateMessage();
50 | msg.Write(input);
51 | encryption.Encrypt(msg);
52 |
53 | var ok = client.SendMessage(msg, NetDeliveryMethod.ReliableOrdered);
54 | Console.WriteLine("Message sent: " + ok);
55 | }
56 | }
57 | }
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/Lidgren.Network.Tests/BitViewTests.cs:
--------------------------------------------------------------------------------
1 | using System.Numerics;
2 | using Xunit;
3 |
4 | namespace Lidgren.Network.Tests.BitVector
5 | {
6 | public class BitVectorByte : BitViewTest
7 | {
8 | [Fact]
9 | public void ValueToVectorComparison()
10 | {
11 | ValueComparison(byte.MinValue, byte.MaxValue);
12 | ValueComparison(1, 2);
13 | }
14 | }
15 |
16 | public class BitVectorInt16 : BitViewTest
17 | {
18 | [Fact]
19 | public void ValueToVectorComparison()
20 | {
21 | ValueComparison(ushort.MinValue, ushort.MaxValue);
22 | ValueComparison(1, 2);
23 | }
24 | }
25 |
26 | public class BitVectorByte3 : BitViewTest
27 | {
28 | [Fact]
29 | public void ValueToVectorComparison()
30 | {
31 | ValueComparison(new Byte3(byte.MinValue), new Byte3(byte.MaxValue));
32 | ValueComparison(new Byte3(1), new Byte3(2));
33 | }
34 | }
35 |
36 | public class BitVectorInt32 : BitViewTest
37 | {
38 | [Fact]
39 | public void ValueToVectorComparison()
40 | {
41 | ValueComparison(int.MinValue, int.MaxValue);
42 | ValueComparison(1, 2);
43 | }
44 | }
45 |
46 | public class BitVectorInt64 : BitViewTest
47 | {
48 | [Fact]
49 | public void ValueToVectorComparison()
50 | {
51 | ValueComparison(long.MinValue, long.MaxValue);
52 | ValueComparison(1, 2);
53 | }
54 | }
55 |
56 | public class BitVectorNumericsByteVector : BitViewTest>
57 | {
58 | [Fact]
59 | public void ValueToVectorComparison()
60 | {
61 | ValueComparison(new Vector(byte.MinValue), new Vector(byte.MaxValue));
62 | ValueComparison(new Vector(1), new Vector(2));
63 | }
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/Lidgren.Network.Tests/BitArrayTests.cs:
--------------------------------------------------------------------------------
1 | using System.Buffers;
2 | using Xunit;
3 |
4 | namespace Lidgren.Network.Tests
5 | {
6 | public class BitArrayTests
7 | {
8 | [Fact]
9 | public void Equality()
10 | {
11 | NetBitArray array1 = new NetBitArray(1);
12 | NetBitArray array2 = new NetBitArray(2);
13 |
14 | Assert.True(array1.Equals(array1));
15 | Assert.False(array1.Equals(array2));
16 | Assert.False(array2.Equals(array1));
17 |
18 | array1[0] = true;
19 | array2[0] = true;
20 |
21 | Assert.True(array1.Equals(array1));
22 | Assert.False(array1.Equals(array2));
23 | Assert.False(array2.Equals(array1));
24 | }
25 |
26 | [Fact]
27 | public void Slice()
28 | {
29 | for (int i = 0; i < NetBitArray.BitsPerElement * (64 + 1) + 1; i++)
30 | {
31 | NetBitArray array1 = new NetBitArray(i);
32 |
33 | NetBitArray array2 = array1[..array1.Length];
34 | Assert.True(array1.Equals(array2));
35 |
36 | NetBitArray array3 = array1[0..^0];
37 | Assert.True(array1.Equals(array3));
38 |
39 | NetBitArray array4 = array1[array1.Length..];
40 | Assert.True(array4.Length == 0);
41 | }
42 | }
43 |
44 | [Fact]
45 | public void Write()
46 | {
47 | NetBuffer buffer = new NetBuffer(ArrayPool.Shared);
48 |
49 | for (int i = 0; i < NetBitArray.BitsPerElement * (64 + 1) + 1; i++)
50 | {
51 | NetBitArray array = new NetBitArray(i);
52 |
53 | buffer.Write(array);
54 |
55 | buffer.BitPosition = 0;
56 |
57 | NetBitArray readArray = buffer.ReadBitArray();
58 |
59 | //Assert.True(array == readArray);
60 | }
61 | }
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/Lidgren.Network/Messaging/NetIncomingMessageType.cs:
--------------------------------------------------------------------------------
1 |
2 | namespace Lidgren.Network
3 | {
4 | ///
5 | /// The type of a .
6 | ///
7 | ///
8 | /// Library note: values are power-of-two, but they are not flags -
9 | /// it's a convenience for .
10 | ///
11 | public enum NetIncomingMessageType
12 | {
13 | ///
14 | /// Error; this value should never appear.
15 | ///
16 | Error = 0,
17 |
18 | ///
19 | /// The connection status has changed.
20 | ///
21 | StatusChanged = 1 << 0, // Data (string)
22 |
23 | ///
24 | /// Data sent using SendUnconnectedMessage.
25 | ///
26 | UnconnectedData = 1 << 1, // Data (Based on data received)
27 |
28 | ///
29 | /// Connection approval is needed.
30 | ///
31 | ConnectionApproval = 1 << 2, // Data
32 |
33 | ///
34 | /// Application data.
35 | ///
36 | Data = 1 << 3, // Data (Based on data received)
37 |
38 | ///
39 | /// Receipt of delivery.
40 | ///
41 | Receipt = 1 << 4, // Data
42 |
43 | ///
44 | /// Discovery request for a response.
45 | ///
46 | DiscoveryRequest = 1 << 5, // (no data)
47 |
48 | ///
49 | /// Discovery response to a request.
50 | ///
51 | DiscoveryResponse = 1 << 6, // Data
52 |
53 | ///
54 | /// NAT introduction was successful.
55 | ///
56 | NatIntroductionSuccess = 1 << 7, // Data (as passed to master server)
57 |
58 | ///
59 | /// Stream of application data is being transferred.
60 | ///
61 | DataStream = 1 << 8, // Data
62 |
63 | ///
64 | /// A roundtrip was measured and was updated.
65 | ///
66 | ConnectionLatencyUpdated = 1 << 9, // Seconds as a TimeSpan
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/Lidgren.Network/Encryption/NetXorEncryption.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace Lidgren.Network
4 | {
5 | ///
6 | /// Example class of XOR encryption. Not suitable for use due to weakness.
7 | ///
8 | [Obsolete("XOR encryption is very weak and should not be used.")]
9 | public sealed class NetXorEncryption : NetEncryption
10 | {
11 | private byte[] _key = Array.Empty();
12 |
13 | public override bool SupportsIV => false;
14 |
15 | public NetXorEncryption(NetPeer peer) : base(peer)
16 | {
17 | }
18 |
19 | public override void SetKey(byte[] data)
20 | {
21 | _key = (byte[])data.Clone();
22 | }
23 |
24 | public override void SetIV(byte[] iv)
25 | {
26 | throw new NotSupportedException();
27 | }
28 |
29 | public override bool Encrypt(NetOutgoingMessage message)
30 | {
31 | if (message == null)
32 | throw new ArgumentNullException(nameof(message));
33 |
34 | byte[] data = message.GetBuffer();
35 | Span slice = data.AsSpan(0, message.ByteLength);
36 | for (int i = 0; i < slice.Length; i++)
37 | {
38 | int offset = i % _key.Length;
39 | slice[i] = (byte)(slice[i] ^ _key[offset]);
40 | }
41 | return true;
42 | }
43 |
44 | public override bool Decrypt(NetIncomingMessage message)
45 | {
46 | if (message == null)
47 | throw new ArgumentNullException(nameof(message));
48 |
49 | byte[] data = message.GetBuffer();
50 | Span slice = data.AsSpan(0, message.ByteLength);
51 | for (int i = 0; i < slice.Length; i++)
52 | {
53 | int offset = i % _key.Length;
54 | slice[i] = (byte)(slice[i] ^ _key[offset]);
55 | }
56 | return true;
57 | }
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/OldSamples/LibraryTestSamples/GarbageThrowerSample/Server/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 |
4 | using Lidgren.Network;
5 |
6 | namespace Server
7 | {
8 | class Program
9 | {
10 | static void Main(string[] args)
11 | {
12 | NetPeerConfiguration config = new NetPeerConfiguration("garbagethrower");
13 | config.MaximumConnections = 1;
14 | config.Port = 14242;
15 | config.PingInterval = 2.0f;
16 | config.ConnectionTimeout = 2.0f;
17 | var server = new NetServer(config);
18 |
19 | server.Start();
20 |
21 | while (true)
22 | {
23 | NetIncomingMessage msg;
24 | while ((msg = server.ReadMessage()) != null)
25 | {
26 | switch (msg.MessageType)
27 | {
28 | case NetIncomingMessageType.StatusChanged:
29 | var status = (NetConnectionStatus)msg.ReadByte();
30 | var reason = msg.ReadString();
31 | Console.WriteLine("New status: " + status + " (" + reason + ")");
32 | break;
33 | case NetIncomingMessageType.WarningMessage:
34 | case NetIncomingMessageType.VerboseDebugMessage:
35 | case NetIncomingMessageType.ErrorMessage:
36 | case NetIncomingMessageType.DebugMessage:
37 |
38 | var str = msg.ReadString();
39 | if (str.StartsWith("Malformed packet; stated") ||
40 | str.StartsWith("Received unhandled library message") ||
41 | str.StartsWith("Unexpected NetMessageType"))
42 | break; // we'll get a bunch of these and we're fine with that
43 |
44 | Console.WriteLine(msg.MessageType + ": " + str);
45 | break;
46 | case NetIncomingMessageType.Data:
47 | Console.WriteLine("Received " + msg.LengthBits + " bits of data");
48 | break;
49 | case NetIncomingMessageType.UnconnectedData:
50 | Console.WriteLine("Received " + msg.LengthBits + " bits of unconnected data");
51 | break;
52 | default:
53 | Console.WriteLine("Received " + msg.MessageType);
54 | break;
55 | }
56 | }
57 | }
58 | }
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/OldSamples/LibraryTestSamples/EncryptionSample/EncryptionSample.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 2012
4 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EncryptionClient", "EncryptionClient\EncryptionClient.csproj", "{CC8B3DBA-3DA6-407F-B659-91AE02BC67D6}"
5 | EndProject
6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EncryptionServer", "EncryptionServer\EncryptionServer.csproj", "{C97A1420-D706-4446-AC8A-3A88ABDC1F0F}"
7 | EndProject
8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lidgren.Network", "..\..\..\Lidgren.Network\Lidgren.Network.csproj", "{49BA1C69-6104-41AC-A5D8-B54FA9F696E8}"
9 | EndProject
10 | Global
11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
12 | Debug|Any CPU = Debug|Any CPU
13 | Release|Any CPU = Release|Any CPU
14 | EndGlobalSection
15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
16 | {CC8B3DBA-3DA6-407F-B659-91AE02BC67D6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
17 | {CC8B3DBA-3DA6-407F-B659-91AE02BC67D6}.Debug|Any CPU.Build.0 = Debug|Any CPU
18 | {CC8B3DBA-3DA6-407F-B659-91AE02BC67D6}.Release|Any CPU.ActiveCfg = Release|Any CPU
19 | {CC8B3DBA-3DA6-407F-B659-91AE02BC67D6}.Release|Any CPU.Build.0 = Release|Any CPU
20 | {C97A1420-D706-4446-AC8A-3A88ABDC1F0F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
21 | {C97A1420-D706-4446-AC8A-3A88ABDC1F0F}.Debug|Any CPU.Build.0 = Debug|Any CPU
22 | {C97A1420-D706-4446-AC8A-3A88ABDC1F0F}.Release|Any CPU.ActiveCfg = Release|Any CPU
23 | {C97A1420-D706-4446-AC8A-3A88ABDC1F0F}.Release|Any CPU.Build.0 = Release|Any CPU
24 | {49BA1C69-6104-41AC-A5D8-B54FA9F696E8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
25 | {49BA1C69-6104-41AC-A5D8-B54FA9F696E8}.Debug|Any CPU.Build.0 = Debug|Any CPU
26 | {49BA1C69-6104-41AC-A5D8-B54FA9F696E8}.Release|Any CPU.ActiveCfg = Release|Any CPU
27 | {49BA1C69-6104-41AC-A5D8-B54FA9F696E8}.Release|Any CPU.Build.0 = Release|Any CPU
28 | EndGlobalSection
29 | GlobalSection(SolutionProperties) = preSolution
30 | HideSolutionNode = FALSE
31 | EndGlobalSection
32 | EndGlobal
33 |
--------------------------------------------------------------------------------
/OldSamples/LibraryTestSamples/ManySample/ManyClients/Client.Designer.cs:
--------------------------------------------------------------------------------
1 | namespace ManyClients
2 | {
3 | partial class Client
4 | {
5 | ///
6 | /// Required designer variable.
7 | ///
8 | private System.ComponentModel.IContainer components = null;
9 |
10 | ///
11 | /// Clean up any resources being used.
12 | ///
13 | /// true if managed resources should be disposed; otherwise, false.
14 | protected override void Dispose(bool disposing)
15 | {
16 | if (disposing && (components != null))
17 | {
18 | components.Dispose();
19 | }
20 | base.Dispose(disposing);
21 | }
22 |
23 | #region Windows Form Designer generated code
24 |
25 | ///
26 | /// Required method for Designer support - do not modify
27 | /// the contents of this method with the code editor.
28 | ///
29 | private void InitializeComponent()
30 | {
31 | this.button1 = new System.Windows.Forms.Button();
32 | this.SuspendLayout();
33 | //
34 | // button1
35 | //
36 | this.button1.Location = new System.Drawing.Point(82, 21);
37 | this.button1.Name = "button1";
38 | this.button1.Size = new System.Drawing.Size(106, 23);
39 | this.button1.TabIndex = 0;
40 | this.button1.Text = "Send message";
41 | this.button1.UseVisualStyleBackColor = true;
42 | this.button1.Click += new System.EventHandler(this.button1_Click);
43 | //
44 | // Client
45 | //
46 | this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
47 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
48 | this.ClientSize = new System.Drawing.Size(264, 69);
49 | this.Controls.Add(this.button1);
50 | this.Font = new System.Drawing.Font("Segoe UI", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
51 | this.Name = "Client";
52 | this.Text = "Client";
53 | this.ResumeLayout(false);
54 |
55 | }
56 |
57 | #endregion
58 |
59 | private System.Windows.Forms.Button button1;
60 | }
61 | }
--------------------------------------------------------------------------------
/Lidgren.Network/Random/XorShiftRandom.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace Lidgren.Network
4 | {
5 | ///
6 | /// Xor Shift based random.
7 | ///
8 | public sealed class XorShiftRandom : NetRandom
9 | {
10 | ///
11 | /// Get global instance of .
12 | ///
13 | public static new XorShiftRandom Global { get; } = new XorShiftRandom();
14 |
15 | //private const uint BaseX = 123456789;
16 | private const uint BaseY = 362436069;
17 | private const uint BaseZ = 521288629;
18 | private const uint BaseW = 88675123;
19 |
20 | private uint _x;
21 | private uint _y;
22 | private uint _z;
23 | private uint _w;
24 |
25 | ///
26 | /// Constructor with randomized seed.
27 | ///
28 | public XorShiftRandom()
29 | {
30 | Initialize(NetRandomSeed.GetUInt64());
31 | }
32 |
33 | ///
34 | /// Constructor with provided 64-bit seed.
35 | ///
36 | [CLSCompliant(false)]
37 | public XorShiftRandom(ulong seed)
38 | {
39 | Initialize(seed);
40 | }
41 |
42 | ///
43 | [CLSCompliant(false)]
44 | public override void Initialize(int seed)
45 | {
46 | _x = (uint)seed;
47 | _y = BaseY;
48 | _z = BaseZ;
49 | _w = BaseW;
50 | }
51 |
52 | ///
53 | [CLSCompliant(false)]
54 | public void Initialize(ulong seed)
55 | {
56 | _x = (uint)seed;
57 | _y = BaseY;
58 | _z = (uint)(seed << 32);
59 | _w = BaseW;
60 | }
61 |
62 | ///
63 | [CLSCompliant(false)]
64 | public override uint NextUInt32()
65 | {
66 | uint t = _x ^ (_x << 11);
67 | _x = _y; _y = _z; _z = _w;
68 | return _w = _w ^ (_w >> 19) ^ t ^ (t >> 8);
69 | }
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/OldSamples/MasterServerSample/MSServer/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 |
4 | using Lidgren.Network;
5 | using MSCommon;
6 | using System.Net;
7 |
8 | namespace MSServer
9 | {
10 | class Program
11 | {
12 | static void Main(string[] args)
13 | {
14 | IPEndPoint masterServerEndpoint = NetUtility.Resolve("localhost", CommonConstants.MasterServerPort);
15 |
16 | NetPeerConfiguration config = new NetPeerConfiguration("game");
17 | config.SetMessageTypeEnabled(NetIncomingMessageType.NatIntroductionSuccess, true);
18 | config.Port = 14242;
19 |
20 | NetServer server = new NetServer(config);
21 | server.Start();
22 |
23 | Console.WriteLine("Server started; waiting 5 seconds...");
24 | System.Threading.Thread.Sleep(5000);
25 |
26 | var lastRegistered = -60.0f;
27 |
28 | while(Console.KeyAvailable == false || Console.ReadKey().Key != ConsoleKey.Escape)
29 | {
30 | // (re-)register periodically with master server
31 | if (NetTime.Now > lastRegistered + 60)
32 | {
33 | // register with master server
34 | NetOutgoingMessage regMsg = server.CreateMessage();
35 | regMsg.Write((byte)MasterServerMessageType.RegisterHost);
36 | IPAddress mask;
37 | IPAddress adr = NetUtility.GetMyAddress(out mask);
38 | regMsg.Write(server.UniqueIdentifier);
39 | regMsg.Write(new IPEndPoint(adr, 14242));
40 | Console.WriteLine("Sending registration to master server");
41 | server.SendUnconnectedMessage(regMsg, masterServerEndpoint);
42 | lastRegistered = (float)NetTime.Now;
43 | }
44 |
45 | NetIncomingMessage inc;
46 | while ((inc = server.ReadMessage()) != null)
47 | {
48 | switch (inc.MessageType)
49 | {
50 | case NetIncomingMessageType.VerboseDebugMessage:
51 | case NetIncomingMessageType.DebugMessage:
52 | case NetIncomingMessageType.WarningMessage:
53 | case NetIncomingMessageType.ErrorMessage:
54 | Console.WriteLine(inc.ReadString());
55 | break;
56 | }
57 | }
58 |
59 | System.Threading.Thread.Sleep(1);
60 | }
61 |
62 | Console.ReadKey();
63 | }
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/OldSamples/LibraryTestSamples/UnconnectedSample/UnconnectedSample/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Windows.Forms;
4 |
5 | using SamplesCommon;
6 |
7 | using Lidgren.Network;
8 |
9 | namespace UnconnectedSample
10 | {
11 | static class Program
12 | {
13 | public static Form1 MainForm;
14 | public static NetPeer Peer;
15 |
16 | [STAThread]
17 | static void Main()
18 | {
19 | Application.EnableVisualStyles();
20 | Application.SetCompatibleTextRenderingDefault(false);
21 | MainForm = new Form1();
22 |
23 | NetPeerConfiguration config = new NetPeerConfiguration("unconntest");
24 | config.EnableMessageType(NetIncomingMessageType.UnconnectedData);
25 | config.AcceptIncomingConnections = false; // don't accept connections; we're just using unconnected messages in this sample
26 |
27 | Peer = new NetPeer(config);
28 | Peer.Start();
29 |
30 | Application.Idle += new EventHandler(AppLoop);
31 | Application.Run(MainForm);
32 | }
33 |
34 | static void AppLoop(object sender, EventArgs e)
35 | {
36 | while (NativeMethods.AppStillIdle)
37 | {
38 | // read any incoming messages
39 | NetIncomingMessage im;
40 | while((im = Peer.ReadMessage()) != null)
41 | {
42 | switch (im.MessageType)
43 | {
44 | case NetIncomingMessageType.DebugMessage:
45 | case NetIncomingMessageType.VerboseDebugMessage:
46 | case NetIncomingMessageType.WarningMessage:
47 | case NetIncomingMessageType.ErrorMessage:
48 | MainForm.richTextBox1.AppendText(im.ReadString() + Environment.NewLine);
49 | break;
50 | case NetIncomingMessageType.UnconnectedData:
51 | MainForm.richTextBox1.AppendText("Received from " + im.SenderEndPoint + ": " + im.ReadString() + Environment.NewLine);
52 | break;
53 | }
54 | Peer.Recycle(im);
55 | }
56 |
57 | System.Threading.Thread.Sleep(1);
58 | }
59 | }
60 |
61 | internal static void Send(string host, int port, string text)
62 | {
63 | NetOutgoingMessage om = Peer.CreateMessage();
64 | om.Write(text);
65 |
66 | Peer.SendUnconnectedMessage(om, host, port);
67 | }
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/OldSamples/File stream sample/FileStreamServer/StreamingClient.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using Lidgren.Network;
3 | using System.IO;
4 |
5 | namespace FileStreamServer
6 | {
7 | public class StreamingClient
8 | {
9 | private FileStream m_inputStream;
10 | private int m_sentOffset;
11 | private int m_chunkLen;
12 | private byte[] m_tmpBuffer;
13 | private NetConnection m_connection;
14 |
15 | public StreamingClient(NetConnection conn, string fileName)
16 | {
17 | m_connection = conn;
18 | m_inputStream = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read);
19 | m_chunkLen = m_connection.Peer.Configuration.MaximumTransmissionUnit - 20;
20 | m_tmpBuffer = new byte[m_chunkLen];
21 | m_sentOffset = 0;
22 | }
23 |
24 | public void Heartbeat()
25 | {
26 | if (m_inputStream == null)
27 | return;
28 |
29 | if (m_connection.CanSendImmediately(NetDeliveryMethod.ReliableOrdered, 1))
30 | {
31 | // send another part of the file!
32 | long remaining = m_inputStream.Length - m_sentOffset;
33 | int sendBytes = (remaining > m_chunkLen ? m_chunkLen : (int)remaining);
34 |
35 | // just assume we can read the whole thing in one Read()
36 | m_inputStream.Read(m_tmpBuffer, 0, sendBytes);
37 |
38 | NetOutgoingMessage om;
39 | if (m_sentOffset == 0)
40 | {
41 | // first message; send length, chunk length and file name
42 | om = m_connection.Peer.CreateMessage(sendBytes + 8);
43 | om.Write((ulong)m_inputStream.Length);
44 | om.Write(Path.GetFileName(m_inputStream.Name));
45 | m_connection.SendMessage(om, NetDeliveryMethod.ReliableOrdered, 1);
46 | }
47 |
48 | om = m_connection.Peer.CreateMessage(sendBytes + 8);
49 | om.Write(m_tmpBuffer, 0, sendBytes);
50 |
51 | m_connection.SendMessage(om, NetDeliveryMethod.ReliableOrdered, 1);
52 | m_sentOffset += sendBytes;
53 |
54 | //Program.Output("Sent " + m_sentOffset + "/" + m_inputStream.Length + " bytes to " + m_connection);
55 |
56 | if (remaining - sendBytes <= 0)
57 | {
58 | m_inputStream.Close();
59 | m_inputStream.Dispose();
60 | m_inputStream = null;
61 | }
62 | }
63 | }
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/Lidgren.Network/NetTime.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Diagnostics;
3 |
4 | namespace Lidgren.Network
5 | {
6 | ///
7 | /// Time helper.
8 | ///
9 | public static class NetTime
10 | {
11 | ///
12 | /// Gets the number of ticks in the timer mechanism upon application start.
13 | ///
14 | public static long InitializedTimestamp { get; } = Stopwatch.GetTimestamp();
15 |
16 | ///
17 | /// Gets the frequency of the timer as the number of seconds per tick.
18 | ///
19 | public static double InverseFrequency { get; } = 1.0 / Stopwatch.Frequency;
20 |
21 | ///
22 | /// Gets the amount of time elapsed since the application started in seconds.
23 | ///
24 | public static double NowSeconds => (Stopwatch.GetTimestamp() - InitializedTimestamp) * InverseFrequency;
25 |
26 | ///
27 | /// Gets the amount of time elapsed since the application started.
28 | ///
29 | public static TimeSpan Now => TimeSpan.FromSeconds(NowSeconds);
30 |
31 | ///
32 | /// Given seconds it will output a human friendly readable string
33 | /// (milliseconds if less than 10 seconds).
34 | ///
35 | public static string ToReadable(double seconds, IFormatProvider? formatProvider = null)
36 | {
37 | if (seconds >= 10)
38 | return TimeSpan.FromSeconds(seconds).ToString(null, formatProvider);
39 |
40 | return (seconds * 1000.0).ToString("N2", formatProvider) + " ms";
41 | }
42 |
43 | ///
44 | /// Given time it will output a human friendly readable string
45 | /// (milliseconds if less than 10 seconds).
46 | ///
47 | public static string ToReadable(TimeSpan time, IFormatProvider? formatProvider = null)
48 | {
49 | if (time.TotalSeconds >= 10)
50 | return time.ToString(null, formatProvider);
51 |
52 | return time.TotalMilliseconds.ToString("N2", formatProvider) + " ms";
53 | }
54 | }
55 | }
--------------------------------------------------------------------------------
/OldSamples/LibraryTestSamples/ManySample/ManyServer/Form1.Designer.cs:
--------------------------------------------------------------------------------
1 | namespace ManyServer
2 | {
3 | partial class Form1
4 | {
5 | ///
6 | /// Required designer variable.
7 | ///
8 | private System.ComponentModel.IContainer components = null;
9 |
10 | ///
11 | /// Clean up any resources being used.
12 | ///
13 | /// true if managed resources should be disposed; otherwise, false.
14 | protected override void Dispose(bool disposing)
15 | {
16 | if (disposing && (components != null))
17 | {
18 | components.Dispose();
19 | }
20 | base.Dispose(disposing);
21 | }
22 |
23 | #region Windows Form Designer generated code
24 |
25 | ///
26 | /// Required method for Designer support - do not modify
27 | /// the contents of this method with the code editor.
28 | ///
29 | private void InitializeComponent()
30 | {
31 | this.richTextBox1 = new System.Windows.Forms.RichTextBox();
32 | this.SuspendLayout();
33 | //
34 | // richTextBox1
35 | //
36 | this.richTextBox1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
37 | | System.Windows.Forms.AnchorStyles.Left)
38 | | System.Windows.Forms.AnchorStyles.Right)));
39 | this.richTextBox1.Location = new System.Drawing.Point(12, 168);
40 | this.richTextBox1.Name = "richTextBox1";
41 | this.richTextBox1.Size = new System.Drawing.Size(808, 283);
42 | this.richTextBox1.TabIndex = 0;
43 | this.richTextBox1.Text = "";
44 | //
45 | // Form1
46 | //
47 | this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
48 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
49 | this.ClientSize = new System.Drawing.Size(832, 463);
50 | this.Controls.Add(this.richTextBox1);
51 | this.Font = new System.Drawing.Font("Segoe UI", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
52 | this.Name = "Form1";
53 | this.Text = "Form1";
54 | this.ResumeLayout(false);
55 |
56 | }
57 |
58 | #endregion
59 |
60 | public System.Windows.Forms.RichTextBox richTextBox1;
61 |
62 | }
63 | }
64 |
65 |
--------------------------------------------------------------------------------
/Lidgren.Network/Peer/NetLogCode.cs:
--------------------------------------------------------------------------------
1 | namespace Lidgren.Network
2 | {
3 | public enum NetLogCode
4 | {
5 | Unknown = 0,
6 | PacketCallbackException,
7 | InvalidPacketSize,
8 | ConnectionReset,
9 | SendFailure,
10 | ReceiveFailure,
11 | FullSendFailure,
12 | MessageSizeExceeded,
13 | FragmentGroupTimeout,
14 | UPnPInvalidResponse,
15 | UPnPPortForwardFailed,
16 | UPnPPortDeleteFailed,
17 | UPnPExternalIPFailed,
18 | SuppressedUnreliableAck,
19 | SocketWouldBlock,
20 | DuplicateConnection,
21 | MissingHandshake,
22 | InvalidHandshake,
23 | MessageTypeDisabled,
24 | UnhandledLibraryMessage,
25 | UnconnectedLibraryMessage,
26 | HeartbeatException,
27 | DisconnectedHandshake,
28 | MissingIPv6ForDualStack,
29 | InvalidFragmentIndex,
30 | InvalidFragmentHeader,
31 | UnexpectedHandshakeStatus,
32 | NotConnected,
33 | AlreadyConnected,
34 | IgnoringMultipleConnects,
35 | UnexpectedApprove,
36 | UnexpectedLibraryError,
37 | SocketShutdownException,
38 | SocketCloseException,
39 | SocketRebindDelayed,
40 | PingPongMismatch,
41 |
42 | EarlyMessage,
43 | TooEarlyMessage,
44 | DuplicateMessage,
45 | DuplicateOrLateMessage,
46 | WithheldMessage,
47 | HostPortChanged,
48 | SocketBound,
49 | ConnectionTimedOut,
50 | DeadlineTimeoutInitialized,
51 | UnexpectedConnect,
52 | UnexpectedMTUExpandRequest,
53 | DuplicateFragment,
54 | ReceivedFragment,
55 | FragmentGroupFinished,
56 | ResendingConnect,
57 | ResendingRespondedConnect,
58 | UnhandledConnect,
59 | UnhandledHandshakeMessage,
60 | InitiatedAverageRoundtripTime,
61 | UpdatedAverageRoundtripTime,
62 | SimulatedLoss,
63 | SimulatedDelay,
64 | ExpandedMTU,
65 | AbortingConnectionAttempt,
66 | NATIntroductionReceived,
67 | NATPunchSent,
68 | HostNATPunchSuccess,
69 | ClientNATPunchSuccess,
70 | ReliableMessageTooLarge,
71 | HailMessageTooLarge,
72 | DisconnectedPeer,
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/Lidgren.Network/Messaging/Channels/NetValueTimeoutAwaitable.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Threading;
3 | using System.Threading.Tasks;
4 | using System.Threading.Tasks.Sources;
5 |
6 | namespace Lidgren.Network
7 | {
8 | internal class NetValueTimeoutAwaitable : IValueTaskSource
9 | {
10 | private static NetQueue _pool = new(16);
11 |
12 | private ManualResetValueTaskSourceCore _mrvtsc;
13 | private CancellationToken _cancellationToken;
14 |
15 | public TimeSpan TimeoutTarget { get; private set; }
16 |
17 | public static NetValueTimeoutAwaitable Rent()
18 | {
19 | if (!_pool.TryDequeue(out NetValueTimeoutAwaitable? item))
20 | {
21 | item = new NetValueTimeoutAwaitable();
22 | }
23 | return item;
24 | }
25 |
26 | public ValueTask RunAsync(TimeSpan timeoutTarget, CancellationToken cancellationToken)
27 | {
28 | TimeoutTarget = timeoutTarget;
29 | _cancellationToken = cancellationToken;
30 |
31 | return new ValueTask(this, _mrvtsc.Version);
32 | }
33 |
34 | public bool TryComplete(TimeSpan now, int value)
35 | {
36 | if (_cancellationToken.IsCancellationRequested)
37 | {
38 | _mrvtsc.SetException(new OperationCanceledException());
39 | return true;
40 | }
41 | if (value > 0 || now > TimeoutTarget)
42 | {
43 | _mrvtsc.SetResult(value);
44 | return true;
45 | }
46 | return false;
47 | }
48 |
49 | public int GetResult(short token)
50 | {
51 | int result = _mrvtsc.GetResult(token);
52 | _mrvtsc.Reset();
53 |
54 | if (_pool.Count < 16)
55 | {
56 | _pool.Enqueue(this);
57 | }
58 |
59 | return result;
60 | }
61 |
62 | public ValueTaskSourceStatus GetStatus(short token)
63 | {
64 | return _mrvtsc.GetStatus(token);
65 | }
66 |
67 | public void OnCompleted(Action