diff --git a/Samples/LibraryTestSamples/EncryptionSample/EncryptionClient/EncryptionClient.csproj b/Samples/LibraryTestSamples/EncryptionSample/EncryptionClient/EncryptionClient.csproj new file mode 100644 index 0000000..1d7cf90 --- /dev/null +++ b/Samples/LibraryTestSamples/EncryptionSample/EncryptionClient/EncryptionClient.csproj @@ -0,0 +1,59 @@ + + + + + Debug + AnyCPU + {CC8B3DBA-3DA6-407F-B659-91AE02BC67D6} + Exe + Properties + EncryptionClient + EncryptionClient + v4.5.1 + 512 + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + {49ba1c69-6104-41ac-a5d8-b54fa9f696e8} + Lidgren.Network + + + + + \ No newline at end of file diff --git a/Samples/LibraryTestSamples/EncryptionSample/EncryptionClient/Program.cs b/Samples/LibraryTestSamples/EncryptionSample/EncryptionClient/Program.cs new file mode 100644 index 0000000..3a47c97 --- /dev/null +++ b/Samples/LibraryTestSamples/EncryptionSample/EncryptionClient/Program.cs @@ -0,0 +1,59 @@ +using System; + +using Lidgren.Network; + +namespace EncryptionClient +{ + class Program + { + static void Main(string[] args) + { + var config = new NetPeerConfiguration("enctest"); + var client = new NetClient(config); + client.Start(); + + System.Threading.Thread.Sleep(100); // give server time to start up + + client.Connect("localhost", 14242); + + var encryption = new NetAESEncryption(client, "Hallonpalt"); + + // loop forever + while (true) + { + // read messages + var inc = client.ReadMessage(); + if (inc != null) + { + switch (inc.MessageType) + { + case NetIncomingMessageType.DebugMessage: + case NetIncomingMessageType.WarningMessage: + case NetIncomingMessageType.VerboseDebugMessage: + case NetIncomingMessageType.ErrorMessage: + Console.WriteLine(inc.ReadString()); + break; + case NetIncomingMessageType.StatusChanged: + var status = (NetConnectionStatus)inc.ReadByte(); + Console.WriteLine(inc.SenderConnection + " (" + status + ") " + inc.ReadString()); + break; + } + } + + // if we're connected, get input and send + if (client.ServerConnection != null && client.ServerConnection.Status == NetConnectionStatus.Connected) + { + Console.WriteLine("Type a message:"); + var input = Console.ReadLine(); + + var msg = client.CreateMessage(); + msg.Write(input); + encryption.Encrypt(msg); + + var ok = client.SendMessage(msg, NetDeliveryMethod.ReliableOrdered); + Console.WriteLine("Message sent: " + ok); + } + } + } + } +} diff --git a/Samples/LibraryTestSamples/EncryptionSample/EncryptionClient/Properties/AssemblyInfo.cs b/Samples/LibraryTestSamples/EncryptionSample/EncryptionClient/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..b134a2a --- /dev/null +++ b/Samples/LibraryTestSamples/EncryptionSample/EncryptionClient/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("EncryptionClient")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("EA Digital Illusions CE AB")] +[assembly: AssemblyProduct("EncryptionClient")] +[assembly: AssemblyCopyright("Copyright © EA Digital Illusions CE AB 2014")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("6146cc08-8436-4a5b-9cb9-d8a646bdadc0")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Samples/LibraryTestSamples/EncryptionSample/EncryptionSample.sln b/Samples/LibraryTestSamples/EncryptionSample/EncryptionSample.sln new file mode 100644 index 0000000..ec0d915 --- /dev/null +++ b/Samples/LibraryTestSamples/EncryptionSample/EncryptionSample.sln @@ -0,0 +1,32 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 2012 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EncryptionClient", "EncryptionClient\EncryptionClient.csproj", "{CC8B3DBA-3DA6-407F-B659-91AE02BC67D6}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EncryptionServer", "EncryptionServer\EncryptionServer.csproj", "{C97A1420-D706-4446-AC8A-3A88ABDC1F0F}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lidgren.Network", "..\..\..\Lidgren.Network\Lidgren.Network.csproj", "{49BA1C69-6104-41AC-A5D8-B54FA9F696E8}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {CC8B3DBA-3DA6-407F-B659-91AE02BC67D6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {CC8B3DBA-3DA6-407F-B659-91AE02BC67D6}.Debug|Any CPU.Build.0 = Debug|Any CPU + {CC8B3DBA-3DA6-407F-B659-91AE02BC67D6}.Release|Any CPU.ActiveCfg = Release|Any CPU + {CC8B3DBA-3DA6-407F-B659-91AE02BC67D6}.Release|Any CPU.Build.0 = Release|Any CPU + {C97A1420-D706-4446-AC8A-3A88ABDC1F0F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C97A1420-D706-4446-AC8A-3A88ABDC1F0F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C97A1420-D706-4446-AC8A-3A88ABDC1F0F}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C97A1420-D706-4446-AC8A-3A88ABDC1F0F}.Release|Any CPU.Build.0 = Release|Any CPU + {49BA1C69-6104-41AC-A5D8-B54FA9F696E8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {49BA1C69-6104-41AC-A5D8-B54FA9F696E8}.Debug|Any CPU.Build.0 = Debug|Any CPU + {49BA1C69-6104-41AC-A5D8-B54FA9F696E8}.Release|Any CPU.ActiveCfg = Release|Any CPU + {49BA1C69-6104-41AC-A5D8-B54FA9F696E8}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/Samples/LibraryTestSamples/EncryptionSample/EncryptionServer/EncryptionServer.csproj b/Samples/LibraryTestSamples/EncryptionSample/EncryptionServer/EncryptionServer.csproj new file mode 100644 index 0000000..0ba2bf5 --- /dev/null +++ b/Samples/LibraryTestSamples/EncryptionSample/EncryptionServer/EncryptionServer.csproj @@ -0,0 +1,59 @@ + + + + + Debug + AnyCPU + {C97A1420-D706-4446-AC8A-3A88ABDC1F0F} + Exe + Properties + EncryptionServer + EncryptionServer + v4.5.1 + 512 + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + {49ba1c69-6104-41ac-a5d8-b54fa9f696e8} + Lidgren.Network + + + + + \ No newline at end of file diff --git a/Samples/LibraryTestSamples/EncryptionSample/EncryptionServer/Program.cs b/Samples/LibraryTestSamples/EncryptionSample/EncryptionServer/Program.cs new file mode 100644 index 0000000..cf0db48 --- /dev/null +++ b/Samples/LibraryTestSamples/EncryptionSample/EncryptionServer/Program.cs @@ -0,0 +1,46 @@ +using Lidgren.Network; +using System; + +namespace EncryptionServer +{ + class Program + { + static void Main(string[] args) + { + var config = new NetPeerConfiguration("enctest"); + config.MaximumConnections = 1; + config.Port = 14242; + var server = new NetServer(config); + server.Start(); + + var encryption = new NetAESEncryption(server, "Hallonpalt"); + + // loop forever + while (true) + { + var inc = server.ReadMessage(); + if (inc != null) + { + switch (inc.MessageType) + { + case NetIncomingMessageType.DebugMessage: + case NetIncomingMessageType.WarningMessage: + case NetIncomingMessageType.VerboseDebugMessage: + case NetIncomingMessageType.ErrorMessage: + Console.WriteLine(inc.ReadString()); + break; + case NetIncomingMessageType.StatusChanged: + var status = (NetConnectionStatus)inc.ReadByte(); + Console.WriteLine(inc.SenderConnection + " (" + status + ") " + inc.ReadString()); + break; + case NetIncomingMessageType.Data: + var ok = inc.Decrypt(encryption); + Console.WriteLine("Data (decrypted: " + (ok ? "ok" : "fail") + ") " + inc.ReadString()); + break; + } + } + System.Threading.Thread.Sleep(1); + } + } + } +} diff --git a/Samples/LibraryTestSamples/EncryptionSample/EncryptionServer/Properties/AssemblyInfo.cs b/Samples/LibraryTestSamples/EncryptionSample/EncryptionServer/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..786df50 --- /dev/null +++ b/Samples/LibraryTestSamples/EncryptionSample/EncryptionServer/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("EncryptionServer")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("EA Digital Illusions CE AB")] +[assembly: AssemblyProduct("EncryptionServer")] +[assembly: AssemblyCopyright("Copyright © EA Digital Illusions CE AB 2014")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("20821c63-4381-4c9f-9c34-e8f8d5ca39b5")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")]