فهرست منبع

Merge pull request #1 from c6burns/master

added build system and tracing to file
Coburn 6 سال پیش
والد
کامیت
d553870b2c

+ 4 - 0
.gitignore

@@ -1,3 +1,7 @@
 README.md
 Source/Native/build/
+build*
 *.bak
+**/bin
+**/obj
+.vs

+ 45 - 0
Directory.Build.props

@@ -0,0 +1,45 @@
+<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+    
+    <PropertyGroup>
+        <SlnDir>$(MSBuildThisFileDirectory)</SlnDir>
+        <SlnDir Condition="!HasTrailingSlash('$(SlnDir)')">$(SlnDir)\</SlnDir>
+        
+        <CsDir>$(SlnDir)MSBuild\</CsDir>
+        
+        <SdkDir>$(MSBuildExtensionsPath)</SdkDir>
+        <SdkDir Condition="!HasTrailingSlash('$(SdkDir)')">$(SdkDir)\</SdkDir>
+    </PropertyGroup>
+
+    <PropertyGroup>
+        <OSPlatformWindows Condition="'$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::Windows)))' == 'true'">true</OSPlatformWindows>
+        <OSPlatformLinux Condition="'$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::Linux)))' == 'true'">true</OSPlatformLinux>
+        <OSPlatformOSX Condition="'$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::OSX)))' == 'true'">true</OSPlatformOSX>
+    </PropertyGroup>
+
+    <PropertyGroup Condition="'$(OSPlatformWindows)' == 'true'">
+        <DefineConstants>$(DefineConstants);EN_PLATFORM_WINDOWS;EN_SOCK_API_WINSOCK</DefineConstants>
+    </PropertyGroup>
+
+    <PropertyGroup Condition="'$(OSPlatformLinux)' == 'true'">
+        <DefineConstants>$(DefineConstants);EN_PLATFORM_LINUX;EN_SOCK_API_POSIX</DefineConstants>
+    </PropertyGroup>
+
+    <PropertyGroup Condition="'$(OSPlatformOSX)' == 'true'">
+        <DefineConstants>$(DefineConstants);EN_PLATFORM_OSX;EN_SOCK_API_POSIX</DefineConstants>
+    </PropertyGroup>
+
+    <PropertyGroup>
+        <PluginDir>$(SlnDir)build_cmake_enet\</PluginDir>
+        <PluginDir Condition="'$(OSPlatformWindows)' == 'true'">$(PluginDir)$(Configuration)\</PluginDir>
+        <PluginArchDir></PluginArchDir>
+        <PluginBaseName>enet</PluginBaseName>
+        
+        <PluginPrefix Condition="'$(OSPlatformLinux)' == 'true'">lib</PluginPrefix>
+		<PluginPrefix Condition="'$(OSPlatformOSX)' == 'true'">lib</PluginPrefix>
+
+        <PluginExt Condition="'$(PluginExt)' == ''">dll</PluginExt>
+        <PluginExt Condition="'$(OSPlatformLinux)' == 'true'">so</PluginExt>
+        <PluginExt Condition="'$(OSPlatformOSX)' == 'true'">dylib</PluginExt>
+    </PropertyGroup>
+    
+</Project>

+ 0 - 0
Directory.Build.rsp


+ 69 - 0
ENet-CSharp.sln

@@ -0,0 +1,69 @@
+
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio 15
+VisualStudioVersion = 15.0.26124.0
+MinimumVisualStudioVersion = 15.0.26124.0
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "MSBuild", "MSBuild", "{3C9CA6C8-3AAB-4D16-BF28-E66AA81F9854}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CMake", "MSBuild\CMake\CMake.csproj", "{CB21753B-56F0-46D2-8495-40CC8F5915A7}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ENet-CSharp", "MSBuild\ENetCSharp\ENetCSharp.csproj", "{311EBFD0-E0DE-439E-9AE3-CBE210E1A9EF}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ENetTests", "MSBuild\ENetTests\ENetTests.csproj", "{E25F1A0A-7FCB-4CA2-9CFF-AAE6DD28EB0E}"
+EndProject
+Global
+	GlobalSection(SolutionConfigurationPlatforms) = preSolution
+		Debug|Any CPU = Debug|Any CPU
+		Debug|x64 = Debug|x64
+		Debug|x86 = Debug|x86
+		Release|Any CPU = Release|Any CPU
+		Release|x64 = Release|x64
+		Release|x86 = Release|x86
+	EndGlobalSection
+	GlobalSection(SolutionProperties) = preSolution
+		HideSolutionNode = FALSE
+	EndGlobalSection
+	GlobalSection(ProjectConfigurationPlatforms) = postSolution
+		{CB21753B-56F0-46D2-8495-40CC8F5915A7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{CB21753B-56F0-46D2-8495-40CC8F5915A7}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{CB21753B-56F0-46D2-8495-40CC8F5915A7}.Debug|x64.ActiveCfg = Debug|Any CPU
+		{CB21753B-56F0-46D2-8495-40CC8F5915A7}.Debug|x64.Build.0 = Debug|Any CPU
+		{CB21753B-56F0-46D2-8495-40CC8F5915A7}.Debug|x86.ActiveCfg = Debug|Any CPU
+		{CB21753B-56F0-46D2-8495-40CC8F5915A7}.Debug|x86.Build.0 = Debug|Any CPU
+		{CB21753B-56F0-46D2-8495-40CC8F5915A7}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{CB21753B-56F0-46D2-8495-40CC8F5915A7}.Release|Any CPU.Build.0 = Release|Any CPU
+		{CB21753B-56F0-46D2-8495-40CC8F5915A7}.Release|x64.ActiveCfg = Release|Any CPU
+		{CB21753B-56F0-46D2-8495-40CC8F5915A7}.Release|x64.Build.0 = Release|Any CPU
+		{CB21753B-56F0-46D2-8495-40CC8F5915A7}.Release|x86.ActiveCfg = Release|Any CPU
+		{CB21753B-56F0-46D2-8495-40CC8F5915A7}.Release|x86.Build.0 = Release|Any CPU
+		{311EBFD0-E0DE-439E-9AE3-CBE210E1A9EF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{311EBFD0-E0DE-439E-9AE3-CBE210E1A9EF}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{311EBFD0-E0DE-439E-9AE3-CBE210E1A9EF}.Debug|x64.ActiveCfg = Debug|Any CPU
+		{311EBFD0-E0DE-439E-9AE3-CBE210E1A9EF}.Debug|x64.Build.0 = Debug|Any CPU
+		{311EBFD0-E0DE-439E-9AE3-CBE210E1A9EF}.Debug|x86.ActiveCfg = Debug|Any CPU
+		{311EBFD0-E0DE-439E-9AE3-CBE210E1A9EF}.Debug|x86.Build.0 = Debug|Any CPU
+		{311EBFD0-E0DE-439E-9AE3-CBE210E1A9EF}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{311EBFD0-E0DE-439E-9AE3-CBE210E1A9EF}.Release|Any CPU.Build.0 = Release|Any CPU
+		{311EBFD0-E0DE-439E-9AE3-CBE210E1A9EF}.Release|x64.ActiveCfg = Release|Any CPU
+		{311EBFD0-E0DE-439E-9AE3-CBE210E1A9EF}.Release|x64.Build.0 = Release|Any CPU
+		{311EBFD0-E0DE-439E-9AE3-CBE210E1A9EF}.Release|x86.ActiveCfg = Release|Any CPU
+		{311EBFD0-E0DE-439E-9AE3-CBE210E1A9EF}.Release|x86.Build.0 = Release|Any CPU
+		{E25F1A0A-7FCB-4CA2-9CFF-AAE6DD28EB0E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{E25F1A0A-7FCB-4CA2-9CFF-AAE6DD28EB0E}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{E25F1A0A-7FCB-4CA2-9CFF-AAE6DD28EB0E}.Debug|x64.ActiveCfg = Debug|Any CPU
+		{E25F1A0A-7FCB-4CA2-9CFF-AAE6DD28EB0E}.Debug|x64.Build.0 = Debug|Any CPU
+		{E25F1A0A-7FCB-4CA2-9CFF-AAE6DD28EB0E}.Debug|x86.ActiveCfg = Debug|Any CPU
+		{E25F1A0A-7FCB-4CA2-9CFF-AAE6DD28EB0E}.Debug|x86.Build.0 = Debug|Any CPU
+		{E25F1A0A-7FCB-4CA2-9CFF-AAE6DD28EB0E}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{E25F1A0A-7FCB-4CA2-9CFF-AAE6DD28EB0E}.Release|Any CPU.Build.0 = Release|Any CPU
+		{E25F1A0A-7FCB-4CA2-9CFF-AAE6DD28EB0E}.Release|x64.ActiveCfg = Release|Any CPU
+		{E25F1A0A-7FCB-4CA2-9CFF-AAE6DD28EB0E}.Release|x64.Build.0 = Release|Any CPU
+		{E25F1A0A-7FCB-4CA2-9CFF-AAE6DD28EB0E}.Release|x86.ActiveCfg = Release|Any CPU
+		{E25F1A0A-7FCB-4CA2-9CFF-AAE6DD28EB0E}.Release|x86.Build.0 = Release|Any CPU
+	EndGlobalSection
+	GlobalSection(NestedProjects) = preSolution
+		{CB21753B-56F0-46D2-8495-40CC8F5915A7} = {3C9CA6C8-3AAB-4D16-BF28-E66AA81F9854}
+		{311EBFD0-E0DE-439E-9AE3-CBE210E1A9EF} = {3C9CA6C8-3AAB-4D16-BF28-E66AA81F9854}
+		{E25F1A0A-7FCB-4CA2-9CFF-AAE6DD28EB0E} = {3C9CA6C8-3AAB-4D16-BF28-E66AA81F9854}
+	EndGlobalSection
+EndGlobal

+ 66 - 0
MSBuild/CMake/CMake.Build.targets

@@ -0,0 +1,66 @@
+<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+
+    <PropertyGroup>
+        <CMakeProjName>enet</CMakeProjName>
+        <CMakeSourceDir>$(SlnDir)Source\Native</CMakeSourceDir>
+        <CMakeBinaryDir>$(SlnDir)build_cmake_enet</CMakeBinaryDir>
+        <CMakeBuildType Condition="'$(CMakeBuildType)' == ''">Debug</CMakeBuildType>
+        <CMakeBuildType Condition="'$(Configuration)' == 'Release'">Release</CMakeBuildType>
+        <CMakeOpts>$(CMakeOpts) -DENET_SHARED=ON</CMakeOpts>
+        <CMakeOpts Condition="'$(CMakeBuildType)' == 'Debug'">$(CMakeOpts) -DENET_DEBUG=ON</CMakeOpts>
+        <CMakeGenerator></CMakeGenerator>
+        <CMakeConfigBuildType></CMakeConfigBuildType>
+    </PropertyGroup>
+
+    <PropertyGroup Condition="'$(OSPlatformWindows)' == 'true'">
+        <CMakeVSArch></CMakeVSArch>
+        <CMakeVSArch Condition="'$(Platform)' == 'x64'">Win64</CMakeVSArch>
+		<CMakeVSArch Condition="'$(Platform)' == 'AnyCPU'">Win64</CMakeVSArch>
+        <CMakeVSToolset></CMakeVSToolset>
+        <!--<CMakeVSToolset>-T v141</CMakeVSToolset>-->
+        <CMakeGenerator>-G"Visual Studio 15 2017 $(CMakeVSArch)" $(CMakeVSToolset)</CMakeGenerator>
+    </PropertyGroup>
+    <PropertyGroup Condition="'$(OSPlatformWindows)' != 'true'">
+        <CMakeConfigBuildType>-DCMAKE_BUILD_TYPE=$(CMakeBuildType)</CMakeConfigBuildType>
+    </PropertyGroup>
+
+    <Target Name="CMakeBuildClean" BeforeTargets="Clean">
+        <Message Text="CMake -- cleaning project: $(CMakeProjName)" Importance="high" />
+        <RemoveDir Directories="$(CMakeBinaryDir)"/>
+        <MakeDir Directories="$(CMakeBinaryDir)"/>
+        <OnError ExecuteTargets="CMakeCleanFailed" />
+    </Target>
+
+    <Target Name="CMakeConfigTarget" BeforeTargets="Build;VSTest">
+        <Message Text="CMake -- configuring $(CMakeBuildType) $(Platform): $(CMakeProjName)" Importance="high" />
+        <MakeDir Directories="$(CMakeBinaryDir)" />
+        <Message Text="cmake $(CMakeGenerator) $(CMakeConfigBuildType) $(CMakeOpts) $(CMakeSourceDir)" Importance="high" />
+        <Exec Command="cmake $(CMakeGenerator) $(CMakeConfigBuildType) $(CMakeOpts) $(CMakeSourceDir)" WorkingDirectory="$(CMakeBinaryDir)" StandardOutputImportance="low" StandardErrorImportance="high" />
+        <OnError ExecuteTargets="CMakeBuildFailed" />
+    </Target>
+
+    <Target Name="CMakeBuildTarget" BeforeTargets="Build;VSTest">
+        <Message Text="CMake -- building project: $(CMakeProjName)" Importance="high" />
+        <Exec Command="cmake --build . --config $(CMakeBuildType)" WorkingDirectory="$(CMakeBinaryDir)" StandardOutputImportance="low" StandardErrorImportance="high" />
+        <OnError ExecuteTargets="CMakeBuildFailed" />
+    </Target>
+
+    <Target Name="CMakeBuildSuccess" BeforeTargets="Build;VSTest">
+        <Message Text="CMake -- build succeeded: $(CMakeProjName)" Importance="high" />
+    </Target>
+
+    <Target Name="CMakeCleanFailed">
+        <Warning Text="CMake -- the most common cause of CMake clean errors is file locking (eg. windows console in the build dir)" />
+        <Warning Text="CMake -- please unlock or reboot and try cleaning again before filing an issue on github:" />
+        <Warning Text="CMake -- https://github.com/cburns/socklynx" />
+        <Error Text="CMake -- build failed: $(CMakeProjName)" />
+    </Target>
+
+    <Target Name="CMakeBuildFailed">
+        <Warning Text="CMake -- the most common cause of CMake build errors is changing config without cleaning" />
+        <Warning Text="CMake -- please try cleaning and building again before filing an issue on github:" />
+        <Warning Text="CMake -- https://github.com/cburns/socklynx" />
+        <Error Text="CMake -- build failed: $(CMakeProjName)" />
+    </Target>
+
+</Project>

+ 11 - 0
MSBuild/CMake/CMake.Copy.targets

@@ -0,0 +1,11 @@
+<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+
+    <Target Name="CMakeContentCopy" AfterTargets="Build">
+        <PropertyGroup>
+            <PluginFullPath>$(PluginDir)$(PluginArchDir)$(PluginPrefix)$(PluginBaseName).$(PluginExt)</PluginFullPath>
+        </PropertyGroup>
+
+        <Copy SourceFiles="$(PluginFullPath)" DestinationFolder="$(OutputPath)" SkipUnchangedFiles="true" />
+    </Target>
+
+</Project>

+ 18 - 0
MSBuild/CMake/CMake.csproj

@@ -0,0 +1,18 @@
+<Project Sdk="Microsoft.NET.Sdk">
+
+    <PropertyGroup>
+        <TargetFramework>netcoreapp2.2</TargetFramework>
+        <EnableDefaultCompileItems>false</EnableDefaultCompileItems>
+        <EnableDefaultNoneItems>false</EnableDefaultNoneItems>
+        <EnableDefaultItems>false</EnableDefaultItems>
+    </PropertyGroup>
+
+    <Import Project="$(CsDir)Common\BannerTask.targets" Condition="'$(BuildingInsideVisualStudio)' != 'true'" />
+
+    <Target Name="ConsoleBanner" BeforeTargets="Build" Condition="'$(BuildingInsideVisualStudio)' != 'true'">
+        <BannerTask TextFile="$(CsDir)Common\Banner.txt" />
+    </Target>
+
+    <Import Project="CMake.Build.targets" />
+
+</Project>

+ 203 - 0
MSBuild/Common/Banner.txt

@@ -0,0 +1,203 @@
+                                                              ..---..._
+                                                        ..--""         "-.
+                                                   ..-"""                 ".
+                                               ..-""                        "
+                                            .-"
+                                         .-"      ... -_
+                                     .="   _..-" F   .-"-.....___-..
+                                     "L_ _-'    ."  j"  .-":   /"-._ "-
+                                        "      :  ."  j"  :   :    |"" ".
+                                  ......---------"""""""""""-:_     |   |\
+                        ...---""""                             -.   f   | "
+                ...---""       . ..----""""""""..                ".-... f  ".
+         ..---"""       ..---""""""""-..--"""""""""^^::            |. "-.    .
+     .--"           .mm::::::::::::::::::::::::::...  ""L           |x   ".
+   -"             mm;;;;;;;;;;XXXXXXXXXXXXX:::::::::::.. |           |x.   -
+ xF        -._ .mF;;;;;;XXXXXXXXXXXXXXXXXXXXXXXXXX:::::::|            |X:.  "
+j         |   j;;;;;XXX#############################::::::|            XX::::
+|          |.#;::XXX##################################::::|            |XX:::
+|          j#::XXX#######################################::             XXX::
+|         .#:XXX###########################################             |XX::
+|         #XXX##############################XX############Fl             XXX:
+|        .XXX###################XX#######X##XXX###########Fl             lXX:
+ |       #XX##################XXX######XXXXXXX###########F j             lXXX
+ |       #X#########X#X#####XXX#######XXXXXX#######XXX##F  jl            XXXX
+ |       #X#######XX#"  V###XX#' ####XXXXXX##F"T##XXXXXX.  V   /  .    .#XXXX
+  |       #########"     V#XX#'  "####XXXX##.---.##XXXXXX.    /  /  / .##XXXX
+  |       "######X' .--"" "V##L   #####XXX#"      "###XXXX. ."  /  / .###XXXX
+  |         #####X "   .m###m##L   ####XX#      m###m"###XX#   /  / .#####XXX
+   |         "###X   .mF""   "y     #####     mX"   "Y#"^####X   / .######XXX
+   |           "T#   #"        #     ####    X"       "F""###XX"###########XX
+   |             L  d"     dXX  xm   "^##L mx     dXX  YL-"##XX"S""##########
+    |            xL J     Xd%    T      ""  T    XdX    L. "##XS.f |#########
+    |             BL      X## X                  X## X      T#SS"  |#########
+    |              #L     X%##X                  X%##X|     j#SSS /##########
+     |              #L  ._ TXXX-"           "-._  XXXF.-    ###SS\###########
+     |              ##   """""                  """"""      ##DS.\###########
+     |              TF                                      ##BBS.T#########F
+      |             #L           ---                        ###BBS.T########'
+      |            '##            ""                     jL|###BSSS.T#######
+       |          '####             ______              .:#|##WWBBBSS.T####F
+      J L        '######.            \___/            _c::#|###WWWBSSS|####
+     J ;;       '########m            \_/            c:::'#|###WWWBBSS.T##"
+    J ;;;L      :########.:m.          _          _cf:::'.L|####WWWWSSS|#"
+  .J ;;;;B      ########B....:m..             _,c%%%:::'...L####WWWBBSSj
+ x  ;;;;dB      #######BB.......##m...___..cc%%%%%::::'....|#####WWBBDS.|
+" ;;;;;ABB#     #######BB........##j%%%%%%%%%%%%%%:::'..... #####WWWWDDS|
+.;;;;;dBBB#     #######BB.........%%%%%%%%%%%%%%%:::'...   j####WWWWWBDF
+;;;;;BBB####    ######BBB.........%%%%%%%%%%%%%%:::'..     #####WWWWWWS
+;;;;dBBB####    ######BBB..........^%%%%%%%%%%:::"         #####WWWWWWB
+;;;:BBB######   X#####BBB"..........."^YYYYY::"            #####WWWWWWW
+;;.BB#########  X######BBB........:''                      #####WWWWWWW
+;;BB##########L X######BBB.......mmmm..                 ..x#####WWWWWWB.
+;dBB########### X#######BB.....        "-._           x""  #####WWWWWWBL
+;BBB###########L X######BB...              "-              ######WWWWBBBL
+BBB#############. ######BBB.                                #####WWWWBBBB
+BBB############## X#####BBB                                 #####WWWWWBBB
+BBB############### T#####BB                                  #####WWWBBB     :
+BB################# T###BBP                                   #####WWBB"    .#
+BB##################..W##P                                      ###BBB"    .##
+BB###################..l                                         "WW"      ###
+BB####################j ___                                        " l    j###
+BBB##################J_-   """-..             ':::'   .-""""""""""-.  l  .####
+BBB######B##########J########    "-.           ::'  -" ..mmm####mm.."-.< #####
+MCL-5/7/88 BBB#####J############    "-_        :|  " .###############mmLlR####
+BBBBBBBBBBBBBBB###/         #######    -.     .:| ".#####F^^^P^^"""^^^Y#lT####
+BBBBBBBBBBBBBBBBBj|####mm        ######xx-...:::|" ###f      .....      "#T###
+BBBBBBBBBBBBBBBBjj##########mm..           ":::."j##F  .mm#########mmm.. Yj###
+BBBBBBBBBBBBBBBB|^WWWSRR############mmmmm xx """mjF.mm####################j###
+BBBBBBBBBBBBBBBB|                      ######mmmmmm#######################j###
+BBBBBBBBBBBBBBBBY#m...   ..mmm##########PPPPP#####m..                    lj###
+BBBBBBBBBBBBBBBBB2##############^^""     ..umF^^^Tx ^##mmmm........mmmmmmlj###
+BBBBBBBBBBBBBBBBBJT######^^^""     .mm##PPPF"...."m.  "^^###############lj####
+BBBBBBBBBBBBBBBBB##^L         .mmm###PPP............"m..    """"^^^^^"" lj####
+BBBBBBBBBBBBBBBB#####Y#mmx#########P.................."^:muuuummmmmm###^.#####
+BBBBBBBBBBBBBBBB#####::Y##mPPPPF^".......|.............. ""^^######^^"...#####
+BBBBBBBBBBBBBB########..................F............      \     ........#####
+BBBBBBBBBBBBB#########.................|..........          :       ....l#####
+BBBBBBBBBBBB###########...............F.........             \        ..######
+BBBBBBBBBBB#############.............|........                :         dA####
+BBBBBBBBBB##############.....................                           kM####
+BBBBBBBBB################..................                             k#####
+BBBBBBB##################................                               k#####
+BBBBB#####################.............                                 t#####
+BB########################............                                  "E####
+B########################F............                           .       "####
+#########################............'      |                    ..       "L##
+########################F............                           ...        "L#
+#######################F............'                           .....       "#
+######################F.............                           .......       "
+#####################$..............                         .........
+#####################lmmm.............                      ...........   ..m#
+####################j########mmmm.............            ......mmmmmm########
+###################j###::::;:::::########mmmmmmm##############################
+##################j:::::::;:::::::;;::##############################^^^""""
+##################.mm:::mmm######mmmm:::' ^^^^^^""#######^^""""
+#################F...^m::;::################mmm  .mm"""
+#################.......m;::::::::::::#########^"
+################F.........###mmm::::;' .##^"""
+ ##############F...........:#######m.m#"
+   ############..............':####
+     #########F............mm^""
+       #######..........m^""
+          ####.......%^"
+             #.....x"
+             |.x""
+            .-"
+          .-
+        .-
+      .-
+     -
+   -"
+ -"
+"
+                                                                             x
+                                                                           xx
+                                                                         xx
+                                                                     xxx"
+                                                                 xxx"
+                                                           .xxxx"
+                                                   ___xxx""
+                                             .xxxx""....F
+                """"mmxxxxx          ___xxx^^^..........'
+                   .xx^^^^YYYY###xxx^^.................|
+                .xx^"        #######x..................|
+             .xx"          ###########mx..............f
+           .x^            ##############xx............|
+          j"             ##############    x..........;
+.........#              ############       #x.........|
+x.......j"              ##########       ####x.......f
+ xxx....#..            ########        #######x......|
+   xxxx.#....         #######        ##########x.....|
+      xxx......       #####         #########   x....|
+         xxx......    ###          #######      #m...|
+           xxx......  ##           ######      ####..|
+             xxx......#.          #####       ######m|
+               xxxx.......        ###        #######Fx
+                   xxx......      #         j#####    m
+                      xx......              ####      Jxm
+                       xxx......           ####      j###Km
+                          xxx.....         ###      j####F  m
+                             xx......       #       ###F    .m
+                               xxx ....            j##F    .###m
+                               m..xx.....          ##F    j#####K^mm.
+                                m...xx......       ##     #####F    ####mm
+                                m .....x......     F     j####F    ########
+                                 m  ......x.....         ###F    J##########
+                                 "m  ........x....      .#F     #########^^|
+                                  "......mmF^^^x....    ##     ######      |
+                                   lL..jF        x.... .F      ####       |
+                                   lTLJF           x....      ####        |
+                                   l::|.            "....    j###       ##
+                                    l....            L....   ###F     x##
+                                     l....       ..m##L...   ##F     j###
+                                     l:...        #####L...  #F     j####
+                                      l....    ####     ...        #####
+                                      "....              ...       ####F |
+                                       l....              ...     j###F  |
+                                        #...               ....   ###F    |
+                                        "#..              .jL.... ##F     |
+                                         ##.            .m###L....#F      |
+                                         "##        ..mm###### ....       |
+                                          |                   |...        |
+                                          k                    |...       |
+                                          l                    |...       k
+                                           k                 .m#L...     Jk
+                                           ##            ..mm####L...     k
+                                           ###         d########' L....   |
+                                           l                   |   "-.__-"
+                                           l                   |
+                                           l                  j#
+                                           :                 j##
+                                            k               j##'
+                                            l            .m###k
+                                            l           ###^^"|
+                                            |                 |
+                                            j               .##
+                                            |              ######
+                                            |==          ##### ####
+                                           .k          #####"   ####
+                                           l         #####^     ####
+                                           l       ###         ####'
+                                           !                 m###F
+                                           |               ######
+                                           |           mm##m###'
+                                           |.       m########F
+                                           |.    m#######F" #
+                                           d.   ###        #
+                                          |..             .'
+                                          |..             |
+                                           k..           :
+                                           \...          F
+                                            |...        #d
+                                            |...       ###
+                                             L...     ####.
+                                             |...    j### |
+  ___                                         L...   ###  |
+ |_ _|__ _ _ __   ___  _ __ __ _ _ __   ___ ___ ..  j##    k
+  | |/ _` | '_ \ / _ \| '__/ _` | '_ \ / __/ _ \... ##     |
+  | | (_| | | | | (_) | | | (_| | | | | (_|  __/ \...      .
+ |___\__, |_| |_|\___/|_|  \__,_|_| |_|\___\___|   "^-____-
+     |___/ Mothers, hide your daughters!
+------------------------------------------------------------------------------
+

+ 54 - 0
MSBuild/Common/BannerTask.cs

@@ -0,0 +1,54 @@
+using System;
+using System.IO;
+using System.Threading;
+using Microsoft.Build.Framework;
+using Microsoft.Build.Utilities;
+
+public class BannerTask : Task
+{
+    ITaskItem _textFileItem;
+    FileStream _fileStream;
+    StreamReader _filein;
+    StreamWriter _stdout;
+    bool _taskSucceeded;
+    int _width;
+
+    [Required]
+    public ITaskItem TextFile { get; set; }
+
+    public override bool Execute()
+    {
+        try
+        {
+            _textFileItem = TextFile;
+            if (_textFileItem == null || _textFileItem.ItemSpec.Length <= 0)
+            {
+                throw new FileNotFoundException("Invalid TaskItem passed to BannerTask::TextFile");
+            }
+
+            _taskSucceeded = true;
+            using (_fileStream = new FileStream(_textFileItem.ItemSpec, FileMode.Open, FileAccess.Read))
+            using (_filein = new StreamReader(_fileStream))
+            using (_stdout = new StreamWriter(Console.OpenStandardOutput()))
+            {
+                _stdout.AutoFlush = true;
+                _width = Console.BufferWidth;
+                if (_width >= 80)
+                {
+                    while (_filein.Peek() > 0)
+                    {
+                        _stdout.WriteLine(_filein.ReadLine());
+                        Thread.Sleep(5);
+                    }
+                }
+            }
+        }
+        catch (Exception e)
+        {
+            Log.LogError("SockLynx Build Error: " + e.Message);
+            _taskSucceeded = false;
+        }
+
+        return _taskSucceeded;
+    }
+}

+ 12 - 0
MSBuild/Common/BannerTask.targets

@@ -0,0 +1,12 @@
+<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+    <UsingTask TaskName="BannerTask" TaskFactory="RoslynCodeTaskFactory" AssemblyFile="$(SdkDir)Microsoft.Build.Tasks.Core.dll">
+        <ParameterGroup>
+            <TextFile ParameterType="Microsoft.Build.Framework.ITaskItem" Required="true" />
+        </ParameterGroup>
+        <Task>
+            <Reference Include="$(SdkDir)Microsoft.Build.Framework.dll" />
+            <Reference Include="$(SdkDir)Microsoft.Build.Utilities.Core.dll" />
+            <Code Type="Class" Language="cs" Source="$(CsDir)Common/BannerTask.cs" />
+        </Task>
+    </UsingTask>
+</Project>

+ 30 - 0
MSBuild/ENetCSharp/ENetCSharp.csproj

@@ -0,0 +1,30 @@
+<Project Sdk="Microsoft.NET.Sdk">
+
+  <PropertyGroup>
+    <TargetFramework>netstandard2.0</TargetFramework>
+  </PropertyGroup>
+
+  <PropertyGroup Condition="'$(Configuration)'=='Debug'">
+    <Optimize>false</Optimize>
+    <CheckForOverflowUnderflow>True</CheckForOverflowUnderflow>
+  </PropertyGroup>
+
+  <PropertyGroup Condition="'$(Configuration)'=='Release'">
+    <Optimize>true</Optimize>
+    <CheckForOverflowUnderflow>True</CheckForOverflowUnderflow>
+  </PropertyGroup>
+
+  <ItemGroup>
+    <Compile Include="$(SlnDir)Source\Managed\*.cs" />
+  </ItemGroup>
+
+  <ItemGroup>
+    <ProjectReference Include="$(CsDir)CMake\CMake.csproj">
+      <ReferenceOutputAssembly>false</ReferenceOutputAssembly>
+      <SkipGetTargetFrameworkProperties>true</SkipGetTargetFrameworkProperties>
+    </ProjectReference>
+  </ItemGroup>
+
+  <Import Project="$(CsDir)CMake\CMake.Copy.targets" />
+
+</Project>

+ 20 - 0
MSBuild/ENetTests/ENetTests.csproj

@@ -0,0 +1,20 @@
+<Project Sdk="Microsoft.NET.Sdk">
+
+  <PropertyGroup>
+    <TargetFramework>netcoreapp2.1</TargetFramework>
+    <IsPackable>false</IsPackable>
+  </PropertyGroup>
+
+  <ItemGroup>
+    <PackageReference Include="nunit" Version="3.11.0" />
+    <PackageReference Include="NUnit3TestAdapter" Version="3.12.0" />
+    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" />
+  </ItemGroup>
+
+  <ItemGroup>
+    <ProjectReference Include="$(CsDir)ENetCSharp\ENetCSharp.csproj" />
+  </ItemGroup>
+
+  <Import Project="$(CsDir)CMake\CMake.Copy.targets" />
+  
+</Project>

+ 8 - 0
MSBuild/ENetTests/Properties/launchSettings.json

@@ -0,0 +1,8 @@
+{
+  "profiles": {
+    "SockLynxTests": {
+      "commandName": "Project",
+      "nativeDebugging": true
+    }
+  }
+}

+ 194 - 0
MSBuild/ENetTests/UnitTests.cs

@@ -0,0 +1,194 @@
+using NUnit.Framework;
+using System;
+using System.Net;
+using System.Diagnostics;
+using ENet;
+
+public class UnitTests
+{
+    enum ClientState
+    {
+        None,
+        Connecting,
+        Connected,
+        SendData,
+        RecvData,
+        Disconnecting,
+        Disconnected,
+    }
+
+    [OneTimeSetUp]
+    public void FixtureSetup()
+    {
+    }
+
+    [OneTimeTearDown]
+    public void FixtureCleanup()
+    {
+    }
+
+    [SetUp]
+    public void TestSetup()
+    {
+    }
+
+    [TearDown]
+    public void TestCleanup()
+    {
+    }
+
+    [Test]
+    public void InitAndUninit()
+    {
+        using (Host host = new Host())
+        {
+        }
+    }
+
+    [Test]
+    public void SendAndRecv()
+    {
+        const ushort port = 7777;
+        const int maxClients = 1;
+        const byte dataVal = 42;
+
+        int clientEvents = 0;
+        int clientConnected = 0;
+        int clientDisconnected = 0;
+        int clientTimeout = 0;
+        int clientNone = 0;
+        int clientRecvData = 0;
+        int serverEvents = 0;
+        int serverConnected = 0;
+        int serverDisconnected = 0;
+        int serverRecvData = 0;
+        int serverTimeout = 0;
+        int serverNone = 0;
+
+        ClientState clientState = ClientState.None;
+
+        using (Host client = new Host())
+        using (Host server = new Host())
+        {
+            Address address = new Address();
+            address.Port = port;
+            server.Create(address, maxClients);
+
+            address.SetIP("127.0.0.1");
+            client.Create();
+
+            Peer clientPeer = default;
+            Stopwatch sw = Stopwatch.StartNew();
+            while (clientState != ClientState.Disconnected && sw.ElapsedMilliseconds < 10000)
+            {
+                while (server.Service(15, out Event netEvent) > 0)
+                {
+                    serverEvents++;
+                    switch (netEvent.Type)
+                    {
+                        case EventType.None:
+                            serverNone++;
+                            break;
+                        case EventType.Connect:
+                            serverConnected++;
+                            break;
+                        case EventType.Disconnect:
+                            serverDisconnected++;
+                            clientState = ClientState.Disconnected;
+                            break;
+                        case EventType.Timeout:
+                            serverTimeout++;
+                            break;
+                        case EventType.Receive:
+                            serverRecvData++;
+                            Packet packet = default(Packet);
+                            byte[] data = new byte[64];
+                            netEvent.Packet.CopyTo(data);
+
+                            for (int i = 0; i < data.Length; i++) Assert.True(data[i] == dataVal);
+
+                            packet.Create(data);
+                            netEvent.Peer.Send(0, ref packet);
+                            netEvent.Packet.Dispose();
+                            break;
+                    }
+                }
+                server.Flush();
+
+                while (client.Service(15, out Event netEvent) > 0)
+                {
+                    clientEvents++;
+                    switch (netEvent.Type)
+                    {
+                        case EventType.None:
+                            clientNone++;
+                            break;
+                        case EventType.Connect:
+                            clientConnected++;
+                            clientState = ClientState.Connected;
+                            break;
+                        case EventType.Disconnect:
+                            clientDisconnected++;
+                            clientState = ClientState.Disconnected;
+                            break;
+                        case EventType.Timeout:
+                            clientTimeout++;
+                            break;
+                        case EventType.Receive:
+                            clientRecvData++;
+                            byte[] data = new byte[64];
+                            Packet packet = netEvent.Packet;
+                            packet.CopyTo(data);
+                            for (int i = 0; i < data.Length; i++) Assert.True(data[i] == dataVal);
+                            netEvent.Packet.Dispose();
+
+                            clientState = ClientState.RecvData;
+                            break;
+                    }
+                }
+                client.Flush();
+
+                if (clientState == ClientState.None)
+                {
+                    clientState = ClientState.Connecting;
+                    clientPeer = client.Connect(address);
+                }
+                else if (clientState == ClientState.Connected)
+                {
+                    Packet packet = default(Packet);
+                    byte[] data = new byte[64];
+                    for (int i = 0; i < data.Length; i++) data[i] = dataVal;
+
+                    packet.Create(data);
+                    clientPeer.Send(0, ref packet);
+
+                    clientState = ClientState.SendData;
+                }
+                else if (clientState == ClientState.RecvData)
+                {
+                    clientPeer.DisconnectNow(0);
+                    clientState = ClientState.Disconnecting;
+                }
+            }
+        }
+
+        Assert.True(clientEvents != 0, "client host never generated an event");
+        Assert.True(serverEvents != 0, "server host never generated an event");
+
+        Assert.True(clientState == ClientState.Disconnected, "client didn't fully disconnect");
+
+        Assert.AreEqual(1, clientConnected, "client should have connected once");
+        Assert.AreEqual(1, serverConnected, "server should have had one inbound connect");
+
+        Assert.AreEqual(1, clientRecvData, "client should have recvd once");
+        Assert.AreEqual(1, serverRecvData, "server should have recvd once");
+
+        Assert.AreEqual(0, clientTimeout, "client had timeout events");
+        Assert.AreEqual(0, serverTimeout, "server had timeout events");
+
+        Assert.AreEqual(0, clientNone, "client had none events");
+        Assert.AreEqual(0, serverNone, "server had none events");
+
+        Assert.AreEqual(1, serverDisconnected, "server should have had one client disconnect");
+    }
+}

+ 7 - 5
Source/Native/CMakeLists.txt

@@ -1,10 +1,10 @@
-cmake_minimum_required(VERSION 2.6)
+cmake_minimum_required(VERSION 3.1)
 project(enet C)
 
-set(ENET_DEBUG "0" CACHE BOOL "Enable debug functionality")
-set(ENET_STATIC "0" CACHE BOOL "Create a static library")
-set(ENET_SHARED "0" CACHE BOOL "Create a shared library")
-set(ENET_LZ4 "0" CACHE BOOL "Add support for an optional packet-level compression")
+set(ENET_DEBUG OFF CACHE BOOL "Enable debug functionality")
+set(ENET_STATIC OFF CACHE BOOL "Create a static library")
+set(ENET_SHARED OFF CACHE BOOL "Create a shared library")
+set(ENET_LZ4 OFF CACHE BOOL "Add support for an optional packet-level compression")
 
 if (ENET_DEBUG)
     add_definitions(-DENET_DEBUG)
@@ -20,6 +20,7 @@ if (ENET_STATIC)
 
     if (WIN32)
         target_link_libraries(enet_static winmm ws2_32)
+		target_compile_definitions(enet PRIVATE _CRT_SECURE_NO_WARNINGS)
         SET_TARGET_PROPERTIES(enet_static PROPERTIES PREFIX "")
     endif()
 endif()
@@ -30,6 +31,7 @@ if (ENET_SHARED)
 
     if (WIN32)
         target_link_libraries(enet winmm ws2_32)
+		target_compile_definitions(enet PRIVATE _CRT_SECURE_NO_WARNINGS)
         SET_TARGET_PROPERTIES(enet PROPERTIES PREFIX "")
     endif()
 endif()

+ 51 - 18
Source/Native/enet.h

@@ -24,9 +24,11 @@
 #ifndef ENET_H
 #define ENET_H
 
-#include <stdlib.h>
+#include <stdarg.h>
 #include <stdbool.h>
 #include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
 #include <time.h>
 
 #define ENET_VERSION_MAJOR 2
@@ -51,6 +53,40 @@
 #define ENET_SRTT_INITIAL 1.0
 #define ENET_SRTT_PARA_G 0.125
 
+static FILE *enet_log_fp = NULL;
+enum enet_log_type
+{
+	ENET_LOG_TYPE_TRACE,
+	ENET_LOG_TYPE_ERROR,
+};
+static const char *const enet_log_type_names[] = {
+	[ENET_LOG_TYPE_TRACE] = "TRACE",
+	[ENET_LOG_TYPE_ERROR] = "ERROR",
+};
+#if ENET_DEBUG
+	#define ENET_LOG_TRACE(...) enet_log(ENET_LOG_TYPE_TRACE, __FUNCTION__, __LINE__, __VA_ARGS__)
+	#define ENET_LOG_ERROR(...) g_enet_fp = fopen("enet_log.txt", "a")
+#else
+	#define ENET_LOG_TRACE(...) ((void)0)
+	#define ENET_LOG_ERROR(...) ((void)0)
+#endif
+#define ENET_LOG_FILE "enet_log.txt"
+static inline void enet_log(enum enet_log_type type, const char *func, int line, const char *fmt, ...)
+{
+	if (!enet_log_fp) enet_log_fp = fopen(ENET_LOG_FILE, "a");
+	if (!enet_log_fp) return;
+	va_list args;
+	time_t tstamp = time(NULL);
+	struct tm *local_time = localtime(&tstamp);
+	char time_buf[64];
+	time_buf[strftime(time_buf, sizeof(time_buf), "%Y-%m-%d %H:%M:%S", local_time)] = '\0';
+	fprintf(enet_log_fp, "%s [%s] [%s:%d] ", time_buf, enet_log_type_names[type], func, line);
+	va_start(args, fmt);
+	vfprintf(enet_log_fp, fmt, args);
+	va_end(args);
+	fflush(enet_log_fp);
+}
+
 /*
 =======================================================================
 
@@ -2865,20 +2901,18 @@ extern "C" {
 				} else if (ENET_TIME_DIFFERENCE(host->serviceTime, currentPeer->packetLossEpoch) >= ENET_PEER_PACKET_LOSS_INTERVAL && currentPeer->packetsSent > 0) {
 					enet_uint32 packetLoss = currentPeer->packetsLost * ENET_PEER_PACKET_LOSS_SCALE / currentPeer->packetsSent;
 
-					#ifdef ENET_DEBUG
-						printf(
-							"peer %u: %f%%+-%f%% packet loss, %u+-%u ms round trip time, %f%% throttle, %u/%u outgoing, %u/%u incoming\n", currentPeer->incomingPeerID,
-							currentPeer->packetLoss / (float)ENET_PEER_PACKET_LOSS_SCALE,
-							currentPeer->packetLossVariance / (float)ENET_PEER_PACKET_LOSS_SCALE, currentPeer->roundTripTime, currentPeer->roundTripTimeVariance,
-							currentPeer->packetThrottle / (float)ENET_PEER_PACKET_THROTTLE_SCALE,
-
-							enet_list_size(&currentPeer->outgoingReliableCommands),
-							enet_list_size(&currentPeer->outgoingUnreliableCommands),
-
-							currentPeer->channels != NULL ? enet_list_size(&currentPeer->channels->incomingReliableCommands) : 0,
-							currentPeer->channels != NULL ? enet_list_size(&currentPeer->channels->incomingUnreliableCommands) : 0
-						);
-					#endif
+					ENET_LOG_TRACE(
+						"peer %u: %f%%+-%f%% packet loss, %u+-%u ms round trip time, %f%% throttle, %u/%u outgoing, %u/%u incoming\n", currentPeer->incomingPeerID,
+						currentPeer->packetLoss / (float)ENET_PEER_PACKET_LOSS_SCALE,
+						currentPeer->packetLossVariance / (float)ENET_PEER_PACKET_LOSS_SCALE, currentPeer->roundTripTime, currentPeer->roundTripTimeVariance,
+						currentPeer->packetThrottle / (float)ENET_PEER_PACKET_THROTTLE_SCALE,
+
+						enet_list_size(&currentPeer->outgoingReliableCommands),
+						enet_list_size(&currentPeer->outgoingUnreliableCommands),
+
+						currentPeer->channels != NULL ? enet_list_size(&currentPeer->channels->incomingReliableCommands) : 0,
+						currentPeer->channels != NULL ? enet_list_size(&currentPeer->channels->incomingUnreliableCommands) : 0
+					);
 
 					currentPeer->packetLossVariance -= currentPeer->packetLossVariance / 4;
 
@@ -2937,9 +2971,7 @@ extern "C" {
 							host->headerFlags |= ENET_PROTOCOL_HEADER_FLAG_COMPRESSED;
 							shouldCompress = compressedSize;
 
-							#ifdef ENET_DEBUG
-								printf("peer %u: compressed %u->%u (%u%%)\n", currentPeer->incomingPeerID, originalSize, compressedSize, (compressedSize * 100) / originalSize);
-							#endif
+							ENET_LOG_TRACE("peer %u: compressed %u->%u (%u%%)\n", currentPeer->incomingPeerID, originalSize, compressedSize, (compressedSize * 100) / originalSize);
 						}
 					}
 				#endif
@@ -3997,6 +4029,7 @@ extern "C" {
 			enet_peer_reset(currentPeer);
 		}
 
+		ENET_LOG_TRACE("host created successfully\n");
 		return host;
 	}