diff --git a/source/Fenrir.Multiplayer.Tests.External/ExternalFixtures.cs b/source/Fenrir.Multiplayer.Tests.External/ExternalFixtures.cs
new file mode 100644
index 0000000..020f6e6
--- /dev/null
+++ b/source/Fenrir.Multiplayer.Tests.External/ExternalFixtures.cs
@@ -0,0 +1,23 @@
+namespace Fenrir.Multiplayer.Tests
+{
+ // Type with the same structure, Name and Namespace as one in the Fenrir.Multiplayer.Tests assembly
+ // This file is included in both assemblies: Fenrir.Multiplayer.Tests and Fenrir.Multiplayer.Tests.External
+ public class TestExternalClass : IByteStreamSerializable
+ {
+ public string Value;
+
+ public void Deserialize(IByteStreamReader reader)
+ {
+ Value = reader.ReadString();
+ }
+
+ public void Serialize(IByteStreamWriter writer)
+ {
+ writer.Write(Value);
+ }
+
+ public TestExternalClass()
+ {
+ }
+ }
+}
diff --git a/source/Fenrir.Multiplayer.Tests.External/Fenrir.Multiplayer.Tests.External.csproj b/source/Fenrir.Multiplayer.Tests.External/Fenrir.Multiplayer.Tests.External.csproj
new file mode 100644
index 0000000..866db47
--- /dev/null
+++ b/source/Fenrir.Multiplayer.Tests.External/Fenrir.Multiplayer.Tests.External.csproj
@@ -0,0 +1,11 @@
+
+
+
+ netstandard2.0
+
+
+
+
+
+
+
diff --git a/source/Fenrir.Multiplayer.Tests/Fenrir.Multiplayer.Tests.csproj b/source/Fenrir.Multiplayer.Tests/Fenrir.Multiplayer.Tests.csproj
index bd5005c..d10ce62 100644
--- a/source/Fenrir.Multiplayer.Tests/Fenrir.Multiplayer.Tests.csproj
+++ b/source/Fenrir.Multiplayer.Tests/Fenrir.Multiplayer.Tests.csproj
@@ -15,7 +15,14 @@
+
+
+
+
+
+ External
+
diff --git a/source/Fenrir.Multiplayer.Tests/Integration/IntegrationTests.cs b/source/Fenrir.Multiplayer.Tests/Integration/IntegrationTests.cs
index fa9ad81..77a3aa4 100644
--- a/source/Fenrir.Multiplayer.Tests/Integration/IntegrationTests.cs
+++ b/source/Fenrir.Multiplayer.Tests/Integration/IntegrationTests.cs
@@ -1,3 +1,4 @@
+extern alias External;
using Fenrir.Multiplayer.LiteNet;
using Fenrir.Multiplayer.Tests.Fixtures;
using Microsoft.VisualStudio.TestTools.UnitTesting;
@@ -6,7 +7,10 @@
using System;
using System.Linq;
using System.Net.Http;
+using System.Runtime.InteropServices;
using System.Threading.Tasks;
+using TestExternalClass2 = External::Fenrir.Multiplayer.Tests.TestExternalClass;
+
namespace Fenrir.Multiplayer.Tests
{
@@ -319,6 +323,62 @@ public async Task NetworkClient_SendRequest_SendsRequest()
Assert.AreEqual(request.Value, "test_value");
}
+
+ [TestMethod, Timeout(TestTimeout)]
+ public async Task NetworkClient_SendRequest_SendsGenericRequest()
+ {
+ using var logger = new TestLogger();
+ using var networkServer = new NetworkServer(logger);
+
+ TaskCompletionSource> requestTcs = new TaskCompletionSource>();
+ networkServer.AddRequestHandler(new TcsRequestHandler>(requestTcs));
+
+ networkServer.Start();
+
+ Assert.AreEqual(ServerStatus.Running, networkServer.Status, "server is not running");
+
+ using var networkClient = new NetworkClient(logger);
+ var connectionResponse = await networkClient.Connect("http://127.0.0.1:27016");
+
+ Assert.AreEqual(ConnectionState.Connected, networkClient.State, "client is connected");
+ Assert.IsTrue(connectionResponse.Success, "connection rejected");
+
+ networkClient.Peer.SendRequest(new TestGenericValueTypeRequest() { Data = new TestStruct() { Value = "test_value" } });
+
+ TestGenericValueTypeRequest request = await requestTcs.Task;
+
+ Assert.AreEqual(request.Data.Value, "test_value");
+ }
+
+
+ [TestMethod, Timeout(TestTimeout)]
+ public async Task NetworkClient_SendRequest_SendsGenericRequest_WithExtenralAssemblyType()
+ {
+ // This test checks if requests still work if client and server use the same type, defined in two different assemblies (e.g. Client.csproj and Server.csproj)
+
+ using var logger = new TestLogger();
+ using var networkServer = new NetworkServer(logger);
+
+ TaskCompletionSource> requestTcs = new TaskCompletionSource>();
+ networkServer.AddRequestHandler(new TcsRequestHandler>(requestTcs));
+
+ networkServer.Start();
+
+ Assert.AreEqual(ServerStatus.Running, networkServer.Status, "server is not running");
+
+ using var networkClient = new NetworkClient(logger);
+ var connectionResponse = await networkClient.Connect("http://127.0.0.1:27016");
+
+ Assert.AreEqual(ConnectionState.Connected, networkClient.State, "client is connected");
+ Assert.IsTrue(connectionResponse.Success, "connection rejected");
+
+ networkClient.Peer.SendRequest(new TestGenericTypeRequest() { Data = new TestExternalClass2() { Value = "test_value" } });
+
+ TestGenericTypeRequest request = await requestTcs.Task;
+
+ Assert.AreEqual(request.Data.Value, "test_value");
+ }
+
[TestMethod, Timeout(TestTimeout)]
public async Task NetworkClient_SendRequest_SendsRequest_WithRequestTypeFactory()
{
@@ -930,6 +990,58 @@ public void Serialize(IByteStreamWriter writer)
}
}
+ [StructLayout(LayoutKind.Sequential, Pack = 1)]
+ struct TestStruct : IByteStreamSerializable
+ {
+ public string Value;
+
+ public void Deserialize(IByteStreamReader reader)
+ {
+ Value = reader.ReadString();
+ }
+
+ public void Serialize(IByteStreamWriter writer)
+ {
+ writer.Write(Value);
+ }
+ }
+
+ class TestGenericTypeRequest : IRequest, IByteStreamSerializable
+ where T : IByteStreamSerializable, new()
+ {
+ public T Data;
+
+ public void Deserialize(IByteStreamReader reader)
+ {
+ Data = new T();
+ Data.Deserialize(reader);
+ }
+
+ public void Serialize(IByteStreamWriter writer)
+ {
+ Data.Serialize(writer);
+ }
+ }
+
+
+ class TestGenericValueTypeRequest : IRequest, IByteStreamSerializable
+ where T : struct, IByteStreamSerializable
+ {
+ public T Data;
+
+ public void Deserialize(IByteStreamReader reader)
+ {
+ Data = new T();
+ Data.Deserialize(reader);
+ }
+
+ public void Serialize(IByteStreamWriter writer)
+ {
+ Data.Serialize(writer);
+ }
+ }
+
+
class TestResponse : IResponse, IByteStreamSerializable
{
public string Value;
diff --git a/source/Fenrir.Multiplayer.sln b/source/Fenrir.Multiplayer.sln
index 3e48657..1cb1515 100644
--- a/source/Fenrir.Multiplayer.sln
+++ b/source/Fenrir.Multiplayer.sln
@@ -1,12 +1,14 @@
Microsoft Visual Studio Solution File, Format Version 12.00
-# Visual Studio Version 16
-VisualStudioVersion = 16.0.30002.166
+# Visual Studio Version 17
+VisualStudioVersion = 17.8.34309.116
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Fenrir.Multiplayer", "Fenrir.Multiplayer\Fenrir.Multiplayer.csproj", "{0D167B4F-D88A-442E-91C5-645D7D66434B}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Fenrir.Multiplayer.Tests", "Fenrir.Multiplayer.Tests\Fenrir.Multiplayer.Tests.csproj", "{74CB5DED-9A49-4AD1-A0E9-FAE4ACE3AE70}"
EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Fenrir.Multiplayer.Tests.External", "Fenrir.Multiplayer.Tests.External\Fenrir.Multiplayer.Tests.External.csproj", "{642F9319-7D63-483E-9727-522C2AFDDE55}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -21,6 +23,10 @@ Global
{74CB5DED-9A49-4AD1-A0E9-FAE4ACE3AE70}.Debug|Any CPU.Build.0 = Debug|Any CPU
{74CB5DED-9A49-4AD1-A0E9-FAE4ACE3AE70}.Release|Any CPU.ActiveCfg = Release|Any CPU
{74CB5DED-9A49-4AD1-A0E9-FAE4ACE3AE70}.Release|Any CPU.Build.0 = Release|Any CPU
+ {642F9319-7D63-483E-9727-522C2AFDDE55}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {642F9319-7D63-483E-9727-522C2AFDDE55}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {642F9319-7D63-483E-9727-522C2AFDDE55}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {642F9319-7D63-483E-9727-522C2AFDDE55}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
diff --git a/source/Fenrir.Multiplayer/Fenrir.Multiplayer.csproj b/source/Fenrir.Multiplayer/Fenrir.Multiplayer.csproj
index 6b7daf2..bd559ce 100644
--- a/source/Fenrir.Multiplayer/Fenrir.Multiplayer.csproj
+++ b/source/Fenrir.Multiplayer/Fenrir.Multiplayer.csproj
@@ -5,7 +5,7 @@
true
true
Fenrir Multiplayer Library
- 1.0.24
+ 1.0.25
README.md
diff --git a/source/UnityPackage/Assets/Runtime/Network/TypeHashMap.cs b/source/UnityPackage/Assets/Runtime/Network/TypeHashMap.cs
index bac07f5..5e4ef3b 100644
--- a/source/UnityPackage/Assets/Runtime/Network/TypeHashMap.cs
+++ b/source/UnityPackage/Assets/Runtime/Network/TypeHashMap.cs
@@ -140,7 +140,7 @@ public bool HasTypeHash()
/// Deterministic type hash
private ulong CalculateTypeHash(Type type)
{
- return DeterministicHashUtility.CalculateHash(type.FullName);
+ return DeterministicHashUtility.CalculateHash(type.ToString());
}
}
}