Skip to content

Commit

Permalink
Fix serilog disposing sockets upon receiving them as an argument (why?)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mooshua committed Aug 27, 2023
1 parent 341c265 commit 74156ca
Show file tree
Hide file tree
Showing 11 changed files with 34 additions and 23 deletions.
5 changes: 5 additions & 0 deletions api/BitMod/BitMod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ public void Start()

Logger.Information("[BitMod] Starting server on {@IP}:{@Port}", ip.ToString(), port);
_server.Start(ip, port);

while (true)
{

}
}

public void Stop()
Expand Down
3 changes: 1 addition & 2 deletions api/BitMod/BitMod.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@
<AssemblyName>bitmod</AssemblyName>
<Company>EdgeGamers</Company>
<DebugType>embedded</DebugType>
<Configurations>Debug;Release</Configurations>
<Platforms>AnyCPU</Platforms>
<LangVersion>latest</LangVersion>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="CommunityServerAPI" Version="1.0.4" />
<PackageReference Include="CommunityServerAPI" Version="1.0.4.1" />
<PackageReference Include="Lilikoi" Version="0.1.0-prerelease.28" />
<PackageReference Include="Serilog" Version="3.0.2-dev-02044" />
</ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion api/BitMod/Handler/BaseHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public abstract class BaseHandler<TPlayer, TGameServer> : IDisposable
public BaseHandler(ServerListener<TPlayer, TGameServer> server)
{
_server = server;
_server.LogLevel |= LogLevel.All;
_server.LogLevel = LogLevel.All;

_server.OnGameServerConnecting += OnGameServerConnecting;
_server.OnCreatingGameServerInstance += OnCreatingGameServerInstance;
Expand Down
2 changes: 1 addition & 1 deletion api/BitMod/Handler/RoutingHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,5 @@ public override BitPlayer OnCreatingPlayerInstance(ulong steamid)
=> new BitPlayer();

public override void OnLog(LogLevel name, string value, object? sender)
=> _logger.Verbose("[API] {@Level} {@Value} ({@Sender})", name, value, sender);
=> _logger.Verbose("[API] {@Level} {@Value}", name, value);
}
1 change: 0 additions & 1 deletion builtin/BitMod.Whitelist/BitMod.Whitelist.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

<ItemGroup>
<ProjectReference Include="..\..\api\BitMod\BitMod.csproj" />
<ProjectReference Include="..\BitMod.Flags\BitMod.Flags.csproj" />
</ItemGroup>

</Project>
1 change: 0 additions & 1 deletion standalone/BitMod.Config/Cache/ConfigWatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ public ConfigWatcher(string configFileName, ILogger logger, KVSerializer seriali
_configObject = new ConfigObject(
new KVObject(_configFileName, Enumerable.Empty<KVObject>()));

_watcher = new FileSystemWatcher();
_watcher = new FileSystemWatcher();
_watcher.Path = Path.Join(System.Environment.CurrentDirectory, CONFIG_PATH);
_watcher.NotifyFilter = NotifyFilters.FileName | NotifyFilters.LastWrite | NotifyFilters.Size | NotifyFilters.Size;
Expand Down
2 changes: 2 additions & 0 deletions standalone/BitMod.Launcher/BitMod.Launcher.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
<Configurations>Debug;Release</Configurations>
<Platforms>AnyCPU</Platforms>

<EnableCompressionInSingleFile>true</EnableCompressionInSingleFile>

<PublishDir>$(BitModBuild)</PublishDir>
<OutDir>$(BitModDev)</OutDir>
<LangVersion>latest</LangVersion>
Expand Down
27 changes: 14 additions & 13 deletions standalone/BitMod.Launcher/Program.cs
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
// See https://aka.ms/new-console-template for more information


using BitMod.Config;
using BitMod.Config;
using BitMod.Logging;
using BitMod.Plugins;

var configSystem = new ConfigurationSystem();
var logging = new LoggingSystem(configSystem);
var pluginSystem = new PluginSystem();

var log = logging.GetLogger();
public static class Program
{
public static void Main()
{
var configSystem = new ConfigurationSystem();
var logging = new LoggingSystem(configSystem);
var pluginSystem = new PluginSystem();

var bitmod = new BitMod.BitMod(log, configSystem, pluginSystem);
var log = logging.GetLogger();

bitmod.Start();
log.Information("Launching BitMod...");

ManualResetEvent close = new ManualResetEvent(false);
var bitmod = new BitMod.BitMod(log, configSystem, pluginSystem);

close.WaitOne();
bitmod.Start();
}
}
6 changes: 4 additions & 2 deletions standalone/BitMod.Logging/LoggingSystem.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using BitMod.Public;
using System.IO;

using BitMod.Public;

using Serilog;
using Serilog.Events;
Expand Down Expand Up @@ -28,7 +30,7 @@ public ILogger GetLogger()
LevelAlias.Minimum,
theme: AnsiConsoleTheme.Sixteen,
outputTemplate: "[{Timestamp:HH:mm:ss}] {Properties} {Level:u4}: {Message:lj}{NewLine}{Exception}" )
.WriteTo.File(Path.Join(System.Environment.CurrentDirectory, LOG_PATH, LOG_NAME), LogEventLevel.Debug)
.WriteTo.File(Path.Join(System.Environment.CurrentDirectory, LOG_PATH, LOG_NAME), LogEventLevel.Debug, rollingInterval: RollingInterval.Day, retainedFileCountLimit: 60)
.CreateLogger();
}
}
5 changes: 4 additions & 1 deletion standalone/BitMod.Plugins/Plugin.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
using System.Reflection;
using System;
using System.IO;
using System.Linq;
using System.Reflection;

using BitMod.Public;

Expand Down
3 changes: 2 additions & 1 deletion standalone/BitMod.Plugins/PluginWatcher.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Reflection;
using System.IO;
using System.Reflection;

using McMaster.NETCore.Plugins;

Expand Down

0 comments on commit 74156ca

Please sign in to comment.