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

Convert movement packets #492

Open
wants to merge 36 commits into
base: arena-vertical-slice
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
1361bda
Initial look at movement packet
Ciel1996 Jan 18, 2023
0365c30
- Added Movement event and subclasses with ToMovementPacket() - method
Ciel1996 Jan 19, 2023
9fa4901
- Using IMemoryCache with a TTL of 1s to rate limit packets sent
Ciel1996 Jan 20, 2023
e75fde8
Removed unused using
Ciel1996 Jan 20, 2023
5f81436
- Replaced IMemoryCache with Policy.RateLimit
Ciel1996 Jan 21, 2023
eac1ace
Reworking the message-to-packet logic
Ciel1996 Jan 30, 2023
6a354a8
- Using Timer to send packets regularly
Ciel1996 Feb 3, 2023
fc7a3b1
- removed Polly
Ciel1996 Feb 4, 2023
b361719
Refactored according to feedback
Ciel1996 Feb 7, 2023
2a5e918
forgot to save Missions.csproj
Ciel1996 Feb 7, 2023
de88af5
Made ProtoBuf compatible; Introduced test to proof ProtoBuf serializa…
Ciel1996 Feb 15, 2023
4cdfb51
Merge branch 'arena-vertical-slice' into convert-movement-packets
Ciel1996 Feb 15, 2023
ad1e0e7
Fixing lost updates from merge
Ciel1996 Feb 15, 2023
d207a43
Merge branch 'arena-vertical-slice' into convert-movement-packets
Ciel1996 Feb 15, 2023
f304081
Merge branch 'arena-vertical-slice' into convert-movement-packets
Ciel1996 Feb 15, 2023
aff8ce5
Merge branch 'convert-movement-packets' of https://github.com/Bannerl…
Ciel1996 Feb 15, 2023
1e2cef6
Fixed some more issues found in review and replaced MovementPacket wi…
Ciel1996 Feb 17, 2023
1567365
Update ClientDebug.csproj.user
Ciel1996 Feb 17, 2023
b1ecc6e
- Removed AgentData
Ciel1996 Feb 19, 2023
7a535cd
Merge branch 'arena-vertical-slice' into convert-movement-packets
Ciel1996 Feb 19, 2023
80def62
Removed unused code
garrettluskey Feb 24, 2023
b470870
removed unused code
garrettluskey Feb 24, 2023
3c916fc
- Added AgentPublisher polling Agent.Main regularly for movement changes
Ciel1996 Feb 25, 2023
38535bd
Merge branch 'convert-movement-packets' of https://github.com/Bannerl…
garrettluskey Feb 25, 2023
808a1af
Merge branch 'arena-vertical-slice' into convert-movement-packets
Ciel1996 Feb 25, 2023
a81cdd1
Merge branch 'arena-vertical-slice' into convert-movement-packets
Ciel1996 Mar 2, 2023
29a8dfc
Merge branch 'arena-vertical-slice' into convert-movement-packets
Ciel1996 Mar 7, 2023
da38f71
Merge branch 'arena-vertical-slice' into convert-movement-packets
garrettluskey Mar 20, 2023
77fa062
Fixed some namespaces
Ciel1996 Mar 20, 2023
c3b42ca
replaced async method by Timer as suggested;
Ciel1996 Mar 31, 2023
ee38d75
added AgentPublisherConfig
Ciel1996 Apr 3, 2023
089729c
Merge branch 'arena-vertical-slice' into convert-movement-packets
Ciel1996 Apr 3, 2023
aab1634
Used DI for relevant classes and interfaces
Ciel1996 Apr 3, 2023
2fcaeb9
Fixed dependencies
Ciel1996 Apr 4, 2023
771d502
Movements are received by the message broker now.
Ciel1996 Apr 8, 2023
425952e
Merge branch 'arena-vertical-slice' into convert-movement-packets
Ciel1996 Apr 28, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion source/ClientDebug/ClientDebug.csproj.user
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@
<StartProgram>..\mb2\bin\Win64_Shipping_Client\Bannerlord.exe</StartProgram>
<StartWorkingDirectory>..\..\..\..\mb2\bin\Win64_Shipping_Client\</StartWorkingDirectory>
</PropertyGroup>
</Project>
</Project>
8 changes: 4 additions & 4 deletions source/MissionTestMod/app.config
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@
<assemblyIdentity name="System.Threading.Tasks.Extensions" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.2.0.1" newVersion="4.2.0.1" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Bcl.AsyncInterfaces" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-7.0.0.0" newVersion="7.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
39 changes: 39 additions & 0 deletions source/MissionTests/AgentMovementDeltaSerializationTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using Common.Serialization;
using Missions.Services.Agents.Messages;
using Missions.Services.Agents.Packets;
using Missions.Services.Network.Surrogates;
using ProtoBuf.Meta;
using System;
using TaleWorlds.Library;
using Xunit;

namespace IntroductionServerTests
{
public class AgentMovementDeltaSerializationTest
{
[Fact]
public void Serialize_Test()
{
try
{
RuntimeTypeModel.Default.SetSurrogate<Vec3, Vec3Surrogate>();
RuntimeTypeModel.Default.SetSurrogate<Vec2, Vec2Surrogate>();
}
catch
{
// nop
}

var delta = new AgentMovement(Guid.NewGuid());

var bytes = ProtoBufSerializer.Serialize(delta);

Assert.NotNull(bytes);
Assert.NotEmpty(bytes);

var desDelta = (AgentMovement)ProtoBufSerializer.Deserialize(bytes);

Assert.Equal(delta, desDelta);
}
}
}
1 change: 1 addition & 0 deletions source/MissionTests/MissionTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="AgentMovementDeltaSerializationTest.cs" />
<Compile Include="AutoFacTests.cs" />
<Compile Include="NetworkAgentRegistryTests.cs" />
<Compile Include="ClientInfoTests.cs" />
Expand Down
5 changes: 1 addition & 4 deletions source/MissionTests/NetworkAgentRegistryTests.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
using Common.Messaging;
using Missions.Services.Network;
using Missions.Services.Network;
using System;
using LiteNetLib;
using System.Collections.Generic;
using System.Runtime.Serialization;
using System.Text;
using TaleWorlds.CampaignSystem;
using TaleWorlds.MountAndBlade;
using Xunit;

Expand Down
31 changes: 22 additions & 9 deletions source/MissionTests/NetworkMessageSerializationTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,17 @@ public NetworkMessageSerializationTest()
[Fact]
public void Serialize_Test()
{
RuntimeTypeModel.Default.SetSurrogate<Vec3, Vec3Surrogate>();
RuntimeTypeModel.Default.SetSurrogate<Vec2, Vec2Surrogate>();
RuntimeTypeModel.Default.SetSurrogate<CharacterObject, CharacterObjectSurrogate>();
RuntimeTypeModel.Default.SetSurrogate<Equipment, EquipmentSurrogate>();
try
{
RuntimeTypeModel.Default.SetSurrogate<Vec3, Vec3Surrogate>();
RuntimeTypeModel.Default.SetSurrogate<Vec2, Vec2Surrogate>();
RuntimeTypeModel.Default.SetSurrogate<CharacterObject, CharacterObjectSurrogate>();
RuntimeTypeModel.Default.SetSurrogate<Equipment, EquipmentSurrogate>();
}
catch
{
// nop
}

var character = (CharacterObject)FormatterServices.GetUninitializedObject(typeof(CharacterObject));

Expand All @@ -64,11 +71,17 @@ public void Serialize_Test()
[Fact]
public void Serialize2_Test()
{
RuntimeTypeModel.Default.SetSurrogate<Vec3, Vec3Surrogate>();
RuntimeTypeModel.Default.SetSurrogate<Vec2, Vec2Surrogate>();
RuntimeTypeModel.Default.SetSurrogate<CharacterObject, CharacterObjectSurrogate>();
RuntimeTypeModel.Default.SetSurrogate<AttackCollisionData, AttackCollisionDataSurrogate>();
RuntimeTypeModel.Default.SetSurrogate<Blow, BlowSurrogate>();
try
{
RuntimeTypeModel.Default.SetSurrogate<Vec3, Vec3Surrogate>();
RuntimeTypeModel.Default.SetSurrogate<Vec2, Vec2Surrogate>();
RuntimeTypeModel.Default.SetSurrogate<CharacterObject, CharacterObjectSurrogate>();
RuntimeTypeModel.Default.SetSurrogate<Equipment, EquipmentSurrogate>();
}
catch
{
// nop
}

var attackerGuid = Guid.NewGuid();

Expand Down
8 changes: 4 additions & 4 deletions source/MissionTests/app.config
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@
<bindingRedirect oldVersion="0.0.0.0-4.2.0.1" newVersion="4.2.0.1" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Collections.Immutable" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-1.2.5.0" newVersion="1.2.5.0" />
<assemblyIdentity name="Microsoft.Bcl.AsyncInterfaces" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-7.0.0.0" newVersion="7.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Bcl.AsyncInterfaces" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-7.0.0.0" newVersion="7.0.0.0" />
<assemblyIdentity name="System.Collections.Immutable" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-1.2.5.0" newVersion="1.2.5.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
Expand Down
13 changes: 12 additions & 1 deletion source/Missions/MissionModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
using GameInterface;
using IntroServer.Config;
using Missions.Services;
using Missions.Services.Agents;
using Missions.Services.Agents.Packets;
using Missions.Services.Agents.Handlers;
using Missions.Services.Arena;
using Missions.Services.BoardGames;
Expand All @@ -13,11 +15,13 @@
using Missions.Services.Missiles.Handlers;
using Missions.Services.Network;
using Missions.Services.Taverns;
using System;

namespace Missions
{
public class MissionModule : Module
{

protected override void Load(ContainerBuilder builder)
{
// TODO find how to make this not disgusting
Expand Down Expand Up @@ -52,11 +56,14 @@ protected override void Load(ContainerBuilder builder)
.SingleInstance()
.PropertiesAutowired(PropertyWiringOptions.AllowCircularDependencies);


builder.RegisterInstance(NetworkAgentRegistry.Instance)
.As<INetworkAgentRegistry>()
.SingleInstance();

builder.RegisterInstance(new AgentPublisherConfig())
.As<IAgentPublisherConfig>()
.SingleInstance();

// Interface classes
builder.RegisterType<LiteNetP2PClient>().As<INetwork>().AsSelf().InstancePerLifetimeScope();

Expand All @@ -73,6 +80,10 @@ protected override void Load(ContainerBuilder builder)
builder.RegisterType<AgentDamageHandler>().As<IAgentDamageHandler>().InstancePerLifetimeScope();
builder.RegisterType<AgentDeathHandler>().As<IAgentDeathHandler>().InstancePerLifetimeScope();

builder.RegisterType<EventPacketHandler>().AsSelf().InstancePerLifetimeScope();
builder.RegisterType<MovementHandler>().AsSelf().InstancePerLifetimeScope();
builder.RegisterType<AgentPublisher>().AsSelf().InstancePerLifetimeScope();

base.Load(builder);
}
}
Expand Down
35 changes: 29 additions & 6 deletions source/Missions/Missions.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,23 @@
<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>
</Reference>
<Reference Include="Microsoft.Extensions.DependencyInjection.Abstractions, Version=7.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Extensions.DependencyInjection.Abstractions.7.0.0\lib\net462\Microsoft.Extensions.DependencyInjection.Abstractions.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Extensions.Logging.Abstractions, Version=7.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Extensions.Logging.Abstractions.7.0.0\lib\net462\Microsoft.Extensions.Logging.Abstractions.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Extensions.Options, Version=7.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Extensions.Options.7.0.0\lib\net462\Microsoft.Extensions.Options.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Extensions.Primitives, Version=7.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Extensions.Primitives.7.0.0\lib\net462\Microsoft.Extensions.Primitives.dll</HintPath>
</Reference>
<Reference Include="protobuf-net, Version=3.0.0.0, Culture=neutral, PublicKeyToken=257b51d87d2e4d67, processorArchitecture=MSIL">
<HintPath>..\packages\protobuf-net.3.2.16\lib\net462\protobuf-net.dll</HintPath>
<HintPath>..\packages\protobuf-net.3.1.26\lib\net462\protobuf-net.dll</HintPath>
</Reference>
<Reference Include="protobuf-net.Core, Version=3.0.0.0, Culture=neutral, PublicKeyToken=257b51d87d2e4d67, processorArchitecture=MSIL">
<HintPath>..\packages\protobuf-net.Core.3.2.16\lib\net462\protobuf-net.Core.dll</HintPath>
<HintPath>..\packages\protobuf-net.Core.3.1.26\lib\net462\protobuf-net.Core.dll</HintPath>
</Reference>
<Reference Include="SandBox">
<HintPath>..\..\mb2\Modules\SandBox\bin\Win64_Shipping_Client\SandBox.dll</HintPath>
Expand All @@ -70,9 +82,10 @@
<Reference Include="System.Buffers, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.Buffers.4.5.1\lib\net461\System.Buffers.dll</HintPath>
</Reference>
<Reference Include="System.Collections.Immutable, Version=7.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.Collections.Immutable.7.0.0\lib\net462\System.Collections.Immutable.dll</HintPath>
<Reference Include="System.Collections.Immutable, Version=1.2.5.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.Collections.Immutable.1.7.1\lib\net461\System.Collections.Immutable.dll</HintPath>
</Reference>
<Reference Include="System.ComponentModel.DataAnnotations" />
<Reference Include="System.Configuration" />
<Reference Include="System.Core" />
<Reference Include="System.Diagnostics.DiagnosticSource, Version=4.0.5.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
Expand All @@ -92,6 +105,9 @@
<Reference Include="System.Threading.Tasks.Extensions, Version=4.2.0.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.Threading.Tasks.Extensions.4.5.4\lib\net461\System.Threading.Tasks.Extensions.dll</HintPath>
</Reference>
<Reference Include="System.ValueTuple, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.ValueTuple.4.5.0\lib\net47\System.ValueTuple.dll</HintPath>
</Reference>
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
Expand Down Expand Up @@ -162,8 +178,16 @@
<Compile Include="Services\Agents\Messages\WeaponPickedup.cs" />
<Compile Include="Services\Agents\Messages\WeaponDropped.cs" />
<Compile Include="ContainerProvider.cs" />
<Compile Include="Services\Agents\AgentPublisherConfig.cs" />
<Compile Include="Services\Agents\Messages\ActionDataChanged.cs" />
<Compile Include="Services\Agents\AgentPublisher.cs" />
<Compile Include="Services\Agents\Messages\LookDirectionChanged.cs" />
<Compile Include="Services\Agents\Messages\MountDataChanged.cs" />
<Compile Include="Services\Agents\Messages\IMovementEvent.cs" />
<Compile Include="Services\Agents\Messages\MovementInputVectorChanged.cs" />
<Compile Include="Services\Agents\Packets\AgentMovement.cs" />
<Compile Include="MissionModule.cs" />
<Compile Include="Services\Agents\Packets\MovementPacket.cs" />
<Compile Include="Services\Agents\Packets\MovementHandler.cs" />
<Compile Include="Services\Agents\Patches\AgentDropPatch.cs" />
<Compile Include="Services\Agents\Patches\AgentPickupPatch.cs" />
<Compile Include="Services\Agents\Patches\AgentShieldDamagePatch.cs" />
Expand Down Expand Up @@ -223,7 +247,6 @@
<Compile Include="Services\Network\LiteNetP2PClient.cs" />
<Compile Include="Services\Network\NetworkAgentRegistry.cs" />
<Compile Include="Services\Agents\Packets\AgentActionData.cs" />
<Compile Include="Services\Agents\Packets\AgentData.cs" />
<Compile Include="Services\Agents\Packets\AgentEquipmentData.cs" />
<Compile Include="Services\Agents\Packets\AgentGroupController.cs" />
<Compile Include="Services\Agents\Packets\AgentMountData.cs" />
Expand Down
Loading