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 18 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>
2 changes: 1 addition & 1 deletion source/MissionTestMod/MissionTestMod.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@
<Name>Common</Name>
</ProjectReference>
<ProjectReference Include="..\Missions\Missions.csproj">
<Project>{E12F967C-1CC9-4E4D-8D8F-5029E0BA96EE}</Project>
<Project>{e12f967c-1cc9-4e4d-8d8f-5029e0ba96ee}</Project>
<Name>Missions</Name>
</ProjectReference>
</ItemGroup>
Expand Down
8 changes: 8 additions & 0 deletions source/MissionTestMod/app.config
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +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="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-4.0.4.1" newVersion="4.0.4.1" />
</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(Vec3.Zero, Vec2.Zero, new AgentEquipmentData(), null, null, Guid.NewGuid());

var bytes = ProtoBufSerializer.Serialize(delta);

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

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

Assert.Equal(delta, desDelta);
}
}
}
3 changes: 2 additions & 1 deletion source/MissionTests/MissionTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="AgentMovementDeltaSerializationTest.cs" />
<Compile Include="NetworkAgentRegistryTests.cs" />
<Compile Include="ClientInfoTests.cs" />
<Compile Include="NetworkMessageSerializationTest.cs" />
Expand All @@ -124,7 +125,7 @@
<Name>IntroServer</Name>
</ProjectReference>
<ProjectReference Include="..\Missions\Missions.csproj">
<Project>{E12F967C-1CC9-4E4D-8D8F-5029E0BA96EE}</Project>
<Project>{e12f967c-1cc9-4e4d-8d8f-5029e0ba96ee}</Project>
<Name>Missions</Name>
</ProjectReference>
</ItemGroup>
Expand Down
11 changes: 9 additions & 2 deletions source/MissionTests/NetworkMessageSerializationTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,15 @@ public class NetworkMessageSerializationTest
[Fact]
public void Serialize_Test()
{
RuntimeTypeModel.Default.SetSurrogate<Vec3, Vec3Surrogate>();
RuntimeTypeModel.Default.SetSurrogate<Vec2, Vec2Surrogate>();
try
{
RuntimeTypeModel.Default.SetSurrogate<Vec3, Vec3Surrogate>();
RuntimeTypeModel.Default.SetSurrogate<Vec2, Vec2Surrogate>();
}
catch
{
// nop
}

var character = (CharacterObject)FormatterServices.GetUninitializedObject(typeof(CharacterObject));
NetworkMissionJoinInfo missionJoinInfo = new NetworkMissionJoinInfo(character, default(Guid), default(Vec3), default(Guid[]), default(Vec3[]), Array.Empty<string>());
Expand Down
8 changes: 8 additions & 0 deletions source/MissionTests/app.config
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +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="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-4.0.4.1" newVersion="4.0.4.1" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
30 changes: 26 additions & 4 deletions source/Missions/Missions.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,20 @@
<Reference Include="LiteNetLib, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\LiteNetLib.0.9.5.2\lib\net35\LiteNetLib.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Bcl.AsyncInterfaces, Version=1.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Bcl.AsyncInterfaces.1.1.0\lib\net461\Microsoft.Bcl.AsyncInterfaces.dll</HintPath>
<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.1.26\lib\net462\protobuf-net.dll</HintPath>
Expand Down Expand Up @@ -76,6 +88,7 @@
<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 @@ -89,12 +102,15 @@
<Reference Include="System.Numerics.Vectors, Version=4.1.4.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.Numerics.Vectors.4.5.0\lib\net46\System.Numerics.Vectors.dll</HintPath>
</Reference>
<Reference Include="System.Runtime.CompilerServices.Unsafe, Version=4.0.4.1, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.Runtime.CompilerServices.Unsafe.4.5.3\lib\net461\System.Runtime.CompilerServices.Unsafe.dll</HintPath>
<Reference Include="System.Runtime.CompilerServices.Unsafe, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.Runtime.CompilerServices.Unsafe.6.0.0\lib\net461\System.Runtime.CompilerServices.Unsafe.dll</HintPath>
</Reference>
<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 @@ -139,6 +155,12 @@
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Services\Agents\Messages\ActionDataChanged.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\Messages\AgentMovement.cs" />
<Compile Include="Services\Agents\Messages\AgentShoot.cs" />
<Compile Include="Services\Agents\Messages\AgentDamaged.cs" />
<Compile Include="Services\Agents\Messages\AgentDamageData.cs" />
Expand Down
4 changes: 2 additions & 2 deletions source/Missions/Services/Agents/Extensions/AgentExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using TaleWorlds.MountAndBlade;
using Missions.Services.Network;
using Missions.Services.Network;
using TaleWorlds.MountAndBlade;

namespace Missions.Services.Agents.Extensions
{
Expand Down
32 changes: 32 additions & 0 deletions source/Missions/Services/Agents/Messages/ActionDataChanged.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using Missions.Services.Agents.Packets;
using System;
using TaleWorlds.MountAndBlade;

namespace Missions.Services.Agents.Messages
{
/// <summary>
/// An <see cref="IEvent"/> used to propagate movement related changes of <see cref="AgentActionData"/> of an <see cref="Agent"/>.
/// </summary>
public readonly struct ActionDataChanged : IMovementEvent
{
/// <summary>
/// The changed <see cref="AgentActionData"/> propagated by this <see cref="IEvent"/>.
/// </summary>
public AgentActionData AgentActionData { get; }

/// <inheritdoc />
public Agent Agent { get; }

/// <summary>
/// Constructor
/// </summary>
/// <param name="agent"></param>
/// <param name="agentActionData"></param>
public ActionDataChanged(Agent agent, AgentActionData agentActionData)
{
Agent = agent;
AgentActionData = agentActionData;
}

}
}
Loading