Skip to content

Commit

Permalink
Migrate to .NET 8 and some other changes
Browse files Browse the repository at this point in the history
  • Loading branch information
trippyone committed Jun 29, 2024
1 parent f690608 commit 87c7965
Show file tree
Hide file tree
Showing 14 changed files with 77 additions and 687 deletions.
6 changes: 0 additions & 6 deletions App.config

This file was deleted.

75 changes: 40 additions & 35 deletions Config/ConfigManager.cs
Original file line number Diff line number Diff line change
@@ -1,47 +1,52 @@
using System;

namespace FikaServerTools.Config
namespace FikaServerTools.Config
{
public static class ConfigManager
{

public static FikaServerToolsConfig Load(string[] args)
public static FikaServerToolsConfig LoadFromArgs(string[] args)
{
FikaServerToolsConfig config = new FikaServerToolsConfig();
if(args.Length == 0)
{
Console.WriteLine("No arguments provided.");
return null;
}

FikaServerToolsConfig config = new();

try
string serviceName = args[0];

switch(serviceName)
{
for (int i = 0; i < args.Length; i++)
{
string argName = args[i];
string argValue = args[i + 1];
case "-NatPunchServer":
config.NatPunchServer.Enable = true;

switch (argName)
for (int i = 1; i < args.Length; i++)
{
case "-NatPunchServer":
config.NatPunchServer.Enable = true;
break;
case "-IP":
config.NatPunchServer.IP = argValue;
i++;
break;
case "-Port":
config.NatPunchServer.Port = int.Parse(argValue);
i++;
break;
case "-NatIntroduceAmount":
config.NatPunchServer.NatIntroduceAmount = int.Parse(argValue);
i++;
break;
default:
Logger.LogError($"Invalid argument provided: {argName}");
break;
string arg = args[i];

switch (arg)
{
case "-IP":
config.NatPunchServer.IP = args[i + 1];
i++;
break;
case "-Port":
config.NatPunchServer.Port = int.Parse(args[i + 1]);
i++;
break;
case "-NatIntroduceAmount":
config.NatPunchServer.NatIntroduceAmount = int.Parse(args[i + 1]);
i++;
break;
default:
Console.WriteLine($"Unknown argument provided: {arg}");
break;
}
}
}
}
catch (Exception ex)
{
Logger.LogError(ex.Message);
break;
default:
Console.WriteLine($"Unknown service name provided: {serviceName}");
break;

}

return config;
Expand Down
26 changes: 14 additions & 12 deletions FikaServerTools.cs
Original file line number Diff line number Diff line change
@@ -1,32 +1,34 @@
using FikaServerTools.Config;
using FikaServerTools.Networking;
using System.Threading;

namespace FikaServerTools
{
internal class FikaServerTools
{
public static FikaServerToolsConfig Config { get; set; }
public static FikaServerToolsConfig Config;
private static FikaNatPunchServer _fikaNatPunchServer;

static void Main(string[] args)
{
Config = ConfigManager.Load(args);
Config = ConfigManager.LoadFromArgs(args);

Logger.LogInfo("FikaServerTools started!");
if (Config == null)
{
Console.WriteLine("Unable to load configuration from arguments.");
return;
}

if(Config.NatPunchServer.Enable)
if (Config.NatPunchServer.Enable)
{
_fikaNatPunchServer = new FikaNatPunchServer(Config.NatPunchServer);
_fikaNatPunchServer.Start();
}

// Main thread loop
while(true)
{
_fikaNatPunchServer?.PollEvents();
Thread.Sleep(10);
while (true)
{
_fikaNatPunchServer.PollEvents();
Thread.Sleep(10);
}
}
}
}
}
}
100 changes: 7 additions & 93 deletions FikaServerTools.csproj
Original file line number Diff line number Diff line change
@@ -1,98 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{4C300ECA-8244-4B95-94DD-03A9339B5C5B}</ProjectGuid>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<RootNamespace>FikaServerTools</RootNamespace>
<AssemblyName>FikaServerTools</AssemblyName>
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Deterministic>true</Deterministic>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>disable</Nullable>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Runtime.Serialization" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Config\ConfigManager.cs" />
<Compile Include="Logger.cs" />
<Compile Include="Config\FikaServerToolsConfig.cs" />
<Compile Include="Networking\FikaNatPunchServer.cs" />
<Compile Include="FikaServerTools.cs" />
<Compile Include="Networking\LiteNetLib\BaseChannel.cs" />
<Compile Include="Networking\LiteNetLib\ConnectionRequest.cs" />
<Compile Include="Networking\LiteNetLib\INetEventListener.cs" />
<Compile Include="Networking\LiteNetLib\InternalPackets.cs" />
<Compile Include="Networking\LiteNetLib\Layers\Crc32cLayer.cs" />
<Compile Include="Networking\LiteNetLib\Layers\PacketLayerBase.cs" />
<Compile Include="Networking\LiteNetLib\Layers\XorEncryptLayer.cs" />
<Compile Include="Networking\LiteNetLib\NativeSocket.cs" />
<Compile Include="Networking\LiteNetLib\NatPunchModule.cs" />
<Compile Include="Networking\LiteNetLib\NetConstants.cs" />
<Compile Include="Networking\LiteNetLib\NetDebug.cs" />
<Compile Include="Networking\LiteNetLib\NetManager.cs" />
<Compile Include="Networking\LiteNetLib\NetManager.HashSet.cs" />
<Compile Include="Networking\LiteNetLib\NetManager.PacketPool.cs" />
<Compile Include="Networking\LiteNetLib\NetManager.Socket.cs" />
<Compile Include="Networking\LiteNetLib\NetPacket.cs" />
<Compile Include="Networking\LiteNetLib\NetPeer.cs" />
<Compile Include="Networking\LiteNetLib\NetStatistics.cs" />
<Compile Include="Networking\LiteNetLib\NetUtils.cs" />
<Compile Include="Networking\LiteNetLib\PausedSocketFix.cs" />
<Compile Include="Networking\LiteNetLib\PooledPacket.cs" />
<Compile Include="Networking\LiteNetLib\ReliableChannel.cs" />
<Compile Include="Networking\LiteNetLib\SequencedChannel.cs" />
<Compile Include="Networking\LiteNetLib\Trimming.cs" />
<Compile Include="Networking\LiteNetLib\Utils\CRC32C.cs" />
<Compile Include="Networking\LiteNetLib\Utils\FastBitConverter.cs" />
<Compile Include="Networking\LiteNetLib\Utils\INetSerializable.cs" />
<Compile Include="Networking\LiteNetLib\Utils\NetDataReader.cs" />
<Compile Include="Networking\LiteNetLib\Utils\NetDataWriter.cs" />
<Compile Include="Networking\LiteNetLib\Utils\NetPacketProcessor.cs" />
<Compile Include="Networking\LiteNetLib\Utils\NetSerializer.cs" />
<Compile Include="Networking\LiteNetLib\Utils\NtpPacket.cs" />
<Compile Include="Networking\LiteNetLib\Utils\NtpRequest.cs" />
<Compile Include="Networking\LiteNetLib\Utils\Preserve.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
<None Include="Networking\LiteNetLib\LICENSE.md" />
<None Include="packages.config" />
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

</Project>
12 changes: 6 additions & 6 deletions FikaServerTools.sln
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,23 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.8.34316.72
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FikaServerTools", "FikaServerTools.csproj", "{4C300ECA-8244-4B95-94DD-03A9339B5C5B}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FikaServerTools", "FikaServerTools.csproj", "{33C237C6-FA39-4ECC-B3E0-56AB8066EDDC}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{4C300ECA-8244-4B95-94DD-03A9339B5C5B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4C300ECA-8244-4B95-94DD-03A9339B5C5B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4C300ECA-8244-4B95-94DD-03A9339B5C5B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4C300ECA-8244-4B95-94DD-03A9339B5C5B}.Release|Any CPU.Build.0 = Release|Any CPU
{33C237C6-FA39-4ECC-B3E0-56AB8066EDDC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{33C237C6-FA39-4ECC-B3E0-56AB8066EDDC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{33C237C6-FA39-4ECC-B3E0-56AB8066EDDC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{33C237C6-FA39-4ECC-B3E0-56AB8066EDDC}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {05334491-DF7D-4076-8190-0E823AEB8FA6}
SolutionGuid = {0EEC13BF-D8EB-45ED-A35A-48AD08CEC215}
EndGlobalSection
EndGlobal
Loading

0 comments on commit 87c7965

Please sign in to comment.