Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PartyBase Lifetime Sync #973

Merged
merged 13 commits into from
Oct 8, 2024
Merged
6 changes: 3 additions & 3 deletions source/Common.Tests/Common.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
Expand All @@ -21,8 +21,8 @@

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.2" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<PackageReference Include="xunit" Version="2.9.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
Expand Down
4 changes: 2 additions & 2 deletions source/Common/Common.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="LiteNetLib" Version="1.0.1.1" />
<PackageReference Include="protobuf-net" Version="3.2.26" />
<PackageReference Include="LiteNetLib" Version="1.1.0" />
<PackageReference Include="protobuf-net" Version="3.2.30" />
<PackageReference Include="Serilog" Version="2.12.0" />
<PackageReference Include="System.Text.Json" Version="8.0.4" />
</ItemGroup>
Expand Down
2 changes: 0 additions & 2 deletions source/Common/Extensions/ReflectionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,4 @@ private static object ChooseRandomEnum(Type type)
return values.GetValue(random.Next(values.Length));
}
}


}
7 changes: 4 additions & 3 deletions source/Common/Logging/BatchLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System;
using System.Collections.Concurrent;
using System.Text;
using System.Threading;

namespace Common.Logging;

Expand Down Expand Up @@ -39,7 +40,7 @@ public void LogOne(Type messageType)
{
var messageName = messageType.Name;

LogMap.AddOrUpdate(messageName, 1, (name, value) => value++);
LogMap.AddOrUpdate(messageName, 1, (name, value) => Interlocked.Increment(ref value));
}

// A method to poll for messages to log.
Expand All @@ -48,13 +49,13 @@ private void Poll(TimeSpan dt)
if (LogMap.Count == 0) return;

var stringBuilder = new StringBuilder();
stringBuilder.AppendLine($"Batch Logged messaged (every {pollInterval.Seconds} seconds)");
stringBuilder.AppendLine($"Batch Logged messaged (every {dt.Seconds} seconds)");

foreach (var messageName in LogMap.Keys)
{
if (LogMap.TryRemove(messageName, out var count) && count > 0)
{
stringBuilder.AppendLine($"\t{messageName}: {count} messages per {pollInterval.Seconds} second(s)");
stringBuilder.AppendLine($"\t{messageName}: {count} messages per {dt.Seconds} second(s)");
}
}

Expand Down
12 changes: 12 additions & 0 deletions source/Common/Logging/DebugMessageLogger.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System.Collections.Generic;

namespace Common.Logging;
public class DebugMessageLogger
{
public readonly static List<string> Messages = new List<string>();

public static void Write(string msg)
{
Messages.Add(msg);
}
}
2 changes: 1 addition & 1 deletion source/Common/Logging/LogManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace Common.Logging;

public static class LogManager
{
public static LoggerConfiguration Configuration { get; } = new LoggerConfiguration();
public static LoggerConfiguration Configuration { get; set; } = new LoggerConfiguration();

// If this is called before the Configuration is setup, logging does not work
private static Lazy<ILogger> _logger = new Lazy<ILogger>(() => Configuration.CreateLogger());
Expand Down
1 change: 0 additions & 1 deletion source/Common/Logging/MessageLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ public void LogMessage(object source, Type messageType)

if (messageType.GetCustomAttribute<BatchLogMessageAttribute>() != null)
{

return;
}

Expand Down
1 change: 1 addition & 0 deletions source/Common/Messaging/MessageBroker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ public virtual void Publish<T>(object source, T message) where T : IMessage
continue;
}

// Making synchronous to maintain sequencing of packets
//Task.Factory.StartNew(() => weakDelegate.Invoke(new object[] { payload }));

weakDelegate.Invoke(new object[] { payload });
Expand Down
9 changes: 8 additions & 1 deletion source/Common/Util/ObjectHelper.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
using System;
using Common.Logging;
using Serilog;
using System;
using System.Runtime.Serialization;
using System.Threading;

namespace Common.Util;

Expand All @@ -8,13 +11,17 @@ namespace Common.Util;
/// </summary>
public class ObjectHelper
{
private static readonly ILogger Logger = LogManager.GetLogger<ObjectHelper>();

/// <summary>
/// Creates an object skipping the constructor
/// </summary>
/// <typeparam name="T">Type of object to create</typeparam>
/// <returns>New instance of <typeparamref name="T"/></returns>
public static T SkipConstructor<T>()
{
Logger.Verbose("{pid}: Creating {type}", Thread.CurrentThread.ManagedThreadId, typeof(T));

return (T)FormatterServices.GetUninitializedObject(typeof(T));
}

Expand Down
6 changes: 2 additions & 4 deletions source/Coop.Core/Client/Policies/ClientSyncPolicy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@ public ClientSyncPolicy(IClientLogic clientLogic)

public bool AllowOriginal()
{
// When the client state is not in Campaign or Mission allow original calls
if (syncStates.Contains(clientLogic.State.GetType()) == false) return true;

return false;
// Allow original calls if not in map state or mission state
return syncStates.Contains(clientLogic.State.GetType()) == false;
}
}

This file was deleted.

8 changes: 4 additions & 4 deletions source/Coop.Core/Coop.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,15 @@
<TreatWarningsAsErrors>False</TreatWarningsAsErrors>
</PropertyGroup>
<ItemGroup>
<Compile Remove="Client\Services\MobileParties\Messages\Data\**" />
<Compile Remove="Server\Services\Kingdoms\Messages\**" />
<EmbeddedResource Remove="Client\Services\MobileParties\Messages\Data\**" />
<EmbeddedResource Remove="Server\Services\Kingdoms\Messages\**" />
<None Remove="Client\Services\MobileParties\Messages\Data\**" />
<None Remove="Server\Services\Kingdoms\Messages\**" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Autofac" Version="7.0.1" />
<PackageReference Include="Autofac" Version="8.1.0" />
<PackageReference Include="Krafs.Publicizer" Version="2.2.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down Expand Up @@ -89,9 +92,6 @@
<HintPath>..\..\mb2\bin\Win64_Shipping_Client\TaleWorlds.Library.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Folder Include="Client\Services\MobileParties\Messages\Data\" />
</ItemGroup>
<ItemGroup>
<Publicize Include="TaleWorlds.Library" />
</ItemGroup>
Expand Down
15 changes: 13 additions & 2 deletions source/Coop.Core/Server/Policies/ServerSyncPolicy.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using GameInterface.Policies;
using Coop.Core.Server.States;
using GameInterface.Policies;

namespace Coop.Core.Server.Policies;

Expand All @@ -9,5 +10,15 @@ namespace Coop.Core.Server.Policies;
/// <inheritdoc cref="ISyncPolicy"/>
internal class ServerSyncPolicy : ISyncPolicy
{
public bool AllowOriginal() => false;
private readonly IServerLogic serverLogic;

public ServerSyncPolicy(IServerLogic serverLogic)
{
this.serverLogic = serverLogic;
}

public bool AllowOriginal()
{
return !(serverLogic.State is ServerRunningState);
}
}

This file was deleted.

This file was deleted.

6 changes: 3 additions & 3 deletions source/Coop.IntegrationTests/Coop.IntegrationTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Autofac" Version="7.0.1" />
<PackageReference Include="Autofac" Version="8.1.0" />
<PackageReference Include="Krafs.Publicizer" Version="2.2.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.Hosting" Version="7.0.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.2" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<PackageReference Include="xunit" Version="2.9.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
Expand Down
10 changes: 5 additions & 5 deletions source/Coop.Tests/Coop.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<PlatformTarget>x64</PlatformTarget>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Autofac" Version="7.0.1" />
<PackageReference Include="Autofac" Version="8.1.0" />
<PackageReference Include="Krafs.Publicizer" Version="2.2.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand All @@ -37,8 +37,8 @@
<PackageReference Include="MonoMod.Utils" Version="22.7.31.1" />
<PackageReference Include="Moq" Version="4.18.4" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.2" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<PackageReference Include="xunit" Version="2.9.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
Expand Down Expand Up @@ -71,7 +71,7 @@
</Reference>
</ItemGroup>
<ItemGroup>
<Publicize Include="TaleWorlds.CampaignSystem"/>
<Publicize Include="TaleWorlds.Library"/>
<Publicize Include="TaleWorlds.CampaignSystem" />
<Publicize Include="TaleWorlds.Library" />
</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion source/Coop.Tests/Extensions/NetPeerExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public static void SetQueueLength(this NetPeer peer, int queueLength)

FieldInfo OutgoingQueue = BaseChannelType.GetField("OutgoingQueue", BindingFlags.NonPublic | BindingFlags.Instance)!;

Type QueueType = typeof(ConcurrentQueue<>).MakeGenericType(NetPacketType);
Type QueueType = typeof(Queue<>).MakeGenericType(NetPacketType);
MethodInfo Enqueue = QueueType.GetMethod("Enqueue")!;
MethodInfo Dequeue = QueueType.GetMethod("Clear")!;
MethodInfo Array_GetValue = typeof(Array).GetMethod(nameof(Array.GetValue), BindingFlags.Public | BindingFlags.Instance, new Type[] { typeof(int) })!;
Expand Down
4 changes: 2 additions & 2 deletions source/Coop/Coop.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@
<RunPostBuildEvent>Always</RunPostBuildEvent>
</PropertyGroup>
<ItemGroup>
<Reference Include="0Harmony, Version=2.2.2.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Bannerlord.Lib.Harmony.2.2.2\lib\net472\0Harmony.dll</HintPath>
<Reference Include="0Harmony, Version=2.3.3.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Lib.Harmony.2.3.3\lib\net472\0Harmony.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Bcl.AsyncInterfaces, Version=7.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Bcl.AsyncInterfaces.7.0.0\lib\net462\Microsoft.Bcl.AsyncInterfaces.dll</HintPath>
Expand Down
2 changes: 1 addition & 1 deletion source/Coop/packages.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Bannerlord.Lib.Harmony" version="2.2.2" targetFramework="net472" />
<package id="Lib.Harmony" version="2.3.3" targetFramework="net472" />
<package id="Microsoft.Bcl.AsyncInterfaces" version="7.0.0" targetFramework="net472" />
<package id="Mono.Cecil" version="0.11.4" targetFramework="net472" />
<package id="MonoMod.RuntimeDetour" version="22.7.31.1" targetFramework="net472" />
Expand Down
Loading