From 3bd903aeb80dd22220d7a50a8447aff80130e589 Mon Sep 17 00:00:00 2001 From: lidgren Date: Thu, 17 Jun 2010 16:47:23 +0000 Subject: [PATCH] Wrong appidentifier now sends immediate Disconnect BarebonesClient/Server added --- AllSamples.sln | 14 ++++ Lidgren.Network/NetPeer.Internal.cs | 4 ++ .../BarebonesClient/BarebonesClient.csproj | 58 ++++++++++++++++ Samples/BarebonesClient/Program.cs | 69 +++++++++++++++++++ .../Properties/AssemblyInfo.cs | 36 ++++++++++ .../BarebonesServer/BarebonesServer.csproj | 58 ++++++++++++++++ Samples/BarebonesServer/Program.cs | 63 +++++++++++++++++ .../Properties/AssemblyInfo.cs | 36 ++++++++++ 8 files changed, 338 insertions(+) create mode 100644 Samples/BarebonesClient/BarebonesClient.csproj create mode 100644 Samples/BarebonesClient/Program.cs create mode 100644 Samples/BarebonesClient/Properties/AssemblyInfo.cs create mode 100644 Samples/BarebonesServer/BarebonesServer.csproj create mode 100644 Samples/BarebonesServer/Program.cs create mode 100644 Samples/BarebonesServer/Properties/AssemblyInfo.cs diff --git a/AllSamples.sln b/AllSamples.sln index f132bd3..d321a5a 100644 --- a/AllSamples.sln +++ b/AllSamples.sln @@ -21,6 +21,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DurableServer", "Samples\Du EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DurableClient", "Samples\DurableClient\DurableClient.csproj", "{0B4B02BB-0F43-4466-A369-0682281AF60E}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BarebonesServer", "Samples\BarebonesServer\BarebonesServer.csproj", "{438173C5-8E95-4AE1-AAAB-5C1009F05302}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BarebonesClient", "Samples\BarebonesClient\BarebonesClient.csproj", "{BC0CBAEE-70FE-4B1E-A2FA-BCC731F1E48F}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -63,6 +67,14 @@ Global {0B4B02BB-0F43-4466-A369-0682281AF60E}.Debug|Any CPU.Build.0 = Debug|Any CPU {0B4B02BB-0F43-4466-A369-0682281AF60E}.Release|Any CPU.ActiveCfg = Release|Any CPU {0B4B02BB-0F43-4466-A369-0682281AF60E}.Release|Any CPU.Build.0 = Release|Any CPU + {438173C5-8E95-4AE1-AAAB-5C1009F05302}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {438173C5-8E95-4AE1-AAAB-5C1009F05302}.Debug|Any CPU.Build.0 = Debug|Any CPU + {438173C5-8E95-4AE1-AAAB-5C1009F05302}.Release|Any CPU.ActiveCfg = Release|Any CPU + {438173C5-8E95-4AE1-AAAB-5C1009F05302}.Release|Any CPU.Build.0 = Release|Any CPU + {BC0CBAEE-70FE-4B1E-A2FA-BCC731F1E48F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {BC0CBAEE-70FE-4B1E-A2FA-BCC731F1E48F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {BC0CBAEE-70FE-4B1E-A2FA-BCC731F1E48F}.Release|Any CPU.ActiveCfg = Release|Any CPU + {BC0CBAEE-70FE-4B1E-A2FA-BCC731F1E48F}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -75,5 +87,7 @@ Global {321F68AE-7F97-415E-A3F9-7C477EFF95EE} = {DA6697E7-4DD4-45EF-90A7-2FC265855019} {034984CA-FB37-44AF-BBF9-EC58ED75F5F3} = {DA6697E7-4DD4-45EF-90A7-2FC265855019} {0B4B02BB-0F43-4466-A369-0682281AF60E} = {DA6697E7-4DD4-45EF-90A7-2FC265855019} + {438173C5-8E95-4AE1-AAAB-5C1009F05302} = {DA6697E7-4DD4-45EF-90A7-2FC265855019} + {BC0CBAEE-70FE-4B1E-A2FA-BCC731F1E48F} = {DA6697E7-4DD4-45EF-90A7-2FC265855019} EndGlobalSection EndGlobal diff --git a/Lidgren.Network/NetPeer.Internal.cs b/Lidgren.Network/NetPeer.Internal.cs index 9c592d5..a128087 100644 --- a/Lidgren.Network/NetPeer.Internal.cs +++ b/Lidgren.Network/NetPeer.Internal.cs @@ -485,6 +485,10 @@ namespace Lidgren.Network { // wrong app ident LogWarning("Connect received with wrong appidentifier (need '" + m_configuration.AppIdentifier + "' found '" + appIdent + "') from " + senderEndpoint); + + NetOutgoingMessage bye = CreateLibraryMessage(NetMessageLibraryType.Disconnect, "Wrong app identifier!"); + SendUnconnectedLibraryMessage(bye, NetMessageLibraryType.Disconnect, senderEndpoint); + break; } diff --git a/Samples/BarebonesClient/BarebonesClient.csproj b/Samples/BarebonesClient/BarebonesClient.csproj new file mode 100644 index 0000000..7bb0178 --- /dev/null +++ b/Samples/BarebonesClient/BarebonesClient.csproj @@ -0,0 +1,58 @@ + + + + Debug + AnyCPU + 9.0.21022 + 2.0 + {BC0CBAEE-70FE-4B1E-A2FA-BCC731F1E48F} + Exe + Properties + BarebonesClient + BarebonesClient + v3.5 + 512 + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + 3.5 + + + + + + + + + + {FA245447-5F23-4AA1-BD5F-8D2DDF33CFBD} + Lidgren.Network + + + + + \ No newline at end of file diff --git a/Samples/BarebonesClient/Program.cs b/Samples/BarebonesClient/Program.cs new file mode 100644 index 0000000..09d5bb4 --- /dev/null +++ b/Samples/BarebonesClient/Program.cs @@ -0,0 +1,69 @@ +using System; +using System.Text; +using System.Threading; + +using Lidgren.Network; + +namespace BarebonesClient +{ + class Program + { + static void Main(string[] args) + { + NetPeerConfiguration config = new NetPeerConfiguration("barebones"); + config.SimulatedLoss = 0.1f; + NetClient client = new NetClient(config); + client.Start(); + + Thread.Sleep(2000); + + client.Connect("localhost", 14242); + + while (Console.KeyAvailable == false || Console.ReadKey().Key != ConsoleKey.Escape) + { + NetIncomingMessage inc; + while ((inc = client.ReadMessage()) != null) + { + switch (inc.MessageType) + { + case NetIncomingMessageType.StatusChanged: + NetConnectionStatus status = (NetConnectionStatus)inc.ReadByte(); + string reason = inc.ReadString(); + Console.WriteLine("New status: " + status + " (" + reason + ")"); + if (status == NetConnectionStatus.Connected) + { + // + // We're connected - send stuff + // + NetOutgoingMessage om = client.CreateMessage(); + + // temporary code to verify issue with large messages + StringBuilder bdr = new StringBuilder(); + for (int i = 0; i < 1000; i++) + bdr.Append("Hallonsmurf" + i.ToString()); + om.Write(bdr.ToString()); + + client.SendMessage(om, NetDeliveryMethod.ReliableOrdered); + } + break; + case NetIncomingMessageType.DebugMessage: + case NetIncomingMessageType.VerboseDebugMessage: + case NetIncomingMessageType.WarningMessage: + case NetIncomingMessageType.ErrorMessage: + Console.WriteLine(inc.ReadString()); + break; + case NetIncomingMessageType.UnconnectedData: + Console.WriteLine("Received unconnected data from " + inc.SenderEndpoint + ", conn is " + inc.SenderConnection); + break; + case NetIncomingMessageType.Data: + Console.WriteLine("Received " + inc.LengthBytes + " bytes of data from " + inc.SenderConnection + ", endpoint is " + inc.SenderEndpoint); + break; + } + } + Thread.Sleep(1); + } + Console.WriteLine("Application exiting"); + while (true) ; + } + } +} diff --git a/Samples/BarebonesClient/Properties/AssemblyInfo.cs b/Samples/BarebonesClient/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..942b9e4 --- /dev/null +++ b/Samples/BarebonesClient/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("BarebonesClient")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("Microsoft")] +[assembly: AssemblyProduct("BarebonesClient")] +[assembly: AssemblyCopyright("Copyright © Microsoft 2010")] +[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("30270c13-84c7-4b20-971f-44adbd45635b")] + +// 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/BarebonesServer/BarebonesServer.csproj b/Samples/BarebonesServer/BarebonesServer.csproj new file mode 100644 index 0000000..f70e5de --- /dev/null +++ b/Samples/BarebonesServer/BarebonesServer.csproj @@ -0,0 +1,58 @@ + + + + Debug + AnyCPU + 9.0.21022 + 2.0 + {438173C5-8E95-4AE1-AAAB-5C1009F05302} + Exe + Properties + BarebonesServer + BarebonesServer + v3.5 + 512 + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + 3.5 + + + + + + + + + + {FA245447-5F23-4AA1-BD5F-8D2DDF33CFBD} + Lidgren.Network + + + + + \ No newline at end of file diff --git a/Samples/BarebonesServer/Program.cs b/Samples/BarebonesServer/Program.cs new file mode 100644 index 0000000..3deacb2 --- /dev/null +++ b/Samples/BarebonesServer/Program.cs @@ -0,0 +1,63 @@ +using System; +using System.Text; +using System.Threading; + +using Lidgren.Network; + +namespace BarebonesServer +{ + class Program + { + static void Main(string[] args) + { + NetPeerConfiguration config = new NetPeerConfiguration("barebones"); + config.Port = 14242; + config.SimulatedLoss = 0.1f; + NetServer server = new NetServer(config); + server.Start(); + + NetIncomingMessage inc; + while (Console.KeyAvailable == false || Console.ReadKey().Key != ConsoleKey.Escape) + { + while ((inc = server.ReadMessage()) != null) + { + switch (inc.MessageType) + { + case NetIncomingMessageType.DebugMessage: + case NetIncomingMessageType.VerboseDebugMessage: + case NetIncomingMessageType.WarningMessage: + case NetIncomingMessageType.ErrorMessage: + Console.WriteLine(inc.ReadString()); + break; + case NetIncomingMessageType.StatusChanged: + NetConnectionStatus status = (NetConnectionStatus)inc.ReadByte(); + string reason = inc.ReadString(); + Console.WriteLine("New status: " + status + " (" + reason + ")"); + break; + case NetIncomingMessageType.UnconnectedData: + Console.WriteLine("Received unconnected data from " + inc.SenderEndpoint + ", conn is " + inc.SenderConnection); + break; + case NetIncomingMessageType.Data: + Console.WriteLine("Received " + inc.LengthBytes + " bytes of data from " + inc.SenderConnection + ", endpoint is " + inc.SenderEndpoint); + + // temporary code to verify issue with large messages + StringBuilder bdr = new StringBuilder(); + for (int i = 0; i < 1000; i++) + bdr.Append("Hallonsmurf" + i.ToString()); + + string str = inc.ReadString(); + + Console.WriteLine("Compare gives: " + str.CompareTo(bdr.ToString())); + + break; + } + } + + Thread.Sleep(1); + } + + Console.WriteLine("Application exiting"); + while (true) ; + } + } +} diff --git a/Samples/BarebonesServer/Properties/AssemblyInfo.cs b/Samples/BarebonesServer/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..f7ef425 --- /dev/null +++ b/Samples/BarebonesServer/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("BarebonesServer")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("Microsoft")] +[assembly: AssemblyProduct("BarebonesServer")] +[assembly: AssemblyCopyright("Copyright © Microsoft 2010")] +[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("f0faed82-6c17-41dc-a45e-c9534a29eff8")] + +// 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")]