Skip to content

Commit

Permalink
fixing weaver not registering messages
Browse files Browse the repository at this point in the history
  • Loading branch information
James-Frowen committed Mar 25, 2021
1 parent 9bfee51 commit f2ecca2
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Assets/Mirage/Runtime/NetworkServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public NetworkTime Time
get { return _time; }
}

public IMessageHandler MessageHandler { get; private set; }
public IMessageHandler MessageHandler { get; internal set; }

/// <summary>
/// This shuts down the server and disconnects all clients.
Expand Down
26 changes: 20 additions & 6 deletions Assets/Mirage/Weaver/Processors/ReaderWriterProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -221,18 +221,32 @@ private static bool IsMessageMethod(MethodReference method)
method.Is(typeof(MessagePacker), nameof(MessagePacker.Pack)) ||
method.Is(typeof(MessagePacker), nameof(MessagePacker.GetId)) ||
method.Is(typeof(MessagePacker), nameof(MessagePacker.Unpack)) ||
method.Is<IMessageSender>(nameof(IMessageSender.Send)) ||
method.Is<IMessageSender>(nameof(IMessageReceiver.RegisterHandler)) ||
method.Is<IMessageSender>(nameof(IMessageReceiver.UnregisterHandler)) ||
method.Is<NetworkPlayer>(nameof(NetworkPlayer.Send)) ||
// interfaces and types that implement them
method.Is<IMessageReceiver>(nameof(IMessageReceiver.RegisterHandler)) ||
method.Is<IMessageHandler>(nameof(IMessageHandler.RegisterHandler)) ||
method.Is<MessageBroker>(nameof(MessageBroker.RegisterHandler)) ||

method.Is<IMessageReceiver>(nameof(IMessageReceiver.UnregisterHandler)) ||
method.Is<IMessageHandler>(nameof(IMessageHandler.UnregisterHandler)) ||
method.Is<MessageBroker>(nameof(MessageBroker.UnregisterHandler)) ||

method.Is<IMessageSender>(nameof(IMessageSender.Send)) ||
method.Is<IMessageHandler>(nameof(IMessageHandler.Send)) ||
method.Is<MessageBroker>(nameof(MessageBroker.Send)) ||

method.Is<INotifySender>(nameof(INotifySender.SendNotify)) ||
method.Is<IMessageHandler>(nameof(IMessageHandler.SendNotify)) ||
method.Is<MessageBroker>(nameof(MessageBroker.SendNotify)) ||

method.Is<INetworkPlayer>(nameof(NetworkPlayer.Send)) ||
method.Is<NetworkPlayer>(nameof(NetworkPlayer.Send)) ||

method.Is<INetworkClient>(nameof(NetworkClient.Send)) ||
method.Is<NetworkClient>(nameof(NetworkClient.Send)) ||

method.Is<INetworkServer>(nameof(INetworkServer.SendToAll)) ||
method.Is<NetworkServer>(nameof(NetworkServer.SendToAll)) ||
method.Is<NetworkServer>(nameof(NetworkServer.SendToMany)) ||
method.Is<INetworkServer>(nameof(INetworkServer.SendToAll));
method.Is<NetworkServer>(nameof(NetworkServer.SendToMany));
}

private static bool IsReadWriteMethod(MethodReference method)
Expand Down
7 changes: 7 additions & 0 deletions Assets/Tests/Runtime/ClientServer/ClientServerSetup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections;
using System.Linq;
using Cysharp.Threading.Tasks;
using NUnit.Framework;
using UnityEngine;
using UnityEngine.TestTools;

Expand Down Expand Up @@ -132,5 +133,11 @@ public IEnumerator ShutdownHost() => UniTask.ToCoroutine(async () =>
});

#endregion

[Test]
public void SetupTest()
{
Assert.Pass();
}
}
}
13 changes: 11 additions & 2 deletions Assets/Tests/Runtime/NetworkIdentityCallbackTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System.Collections.Generic;
using System.Threading;
using Cysharp.Threading.Tasks;
using NSubstitute;
using NUnit.Framework;
using UnityEngine;
Expand Down Expand Up @@ -26,20 +28,27 @@ public override void OnRebuildObservers(HashSet<INetworkPlayer> observers, bool
private NetworkClient client;
private GameObject networkServerGameObject;

IMessageHandler messageHandler;
IConnection tconn42;
IConnection tconn43;


[SetUp]
public void SetUp()
{
messageHandler = Substitute.For<IMessageHandler>();
messageHandler.ProcessMessagesAsync(Arg.Any<INetworkPlayer>()).Returns(UniTask.Never(CancellationToken.None));

networkServerGameObject = new GameObject();
server = networkServerGameObject.AddComponent<NetworkServer>();
server.MessageHandler = messageHandler;
serverObjectManager = networkServerGameObject.AddComponent<ServerObjectManager>();
serverObjectManager.Server = server;
client = networkServerGameObject.AddComponent<NetworkClient>();

gameObject = new GameObject();
identity = gameObject.AddComponent<NetworkIdentity>();

identity.Server = server;
identity.ServerObjectManager = serverObjectManager;

Expand All @@ -60,8 +69,8 @@ public void TearDown()
[Test]
public void AddAllReadyServerConnectionsToObservers()
{
var connection1 = new NetworkPlayer(tconn42, Substitute.For<IMessageHandler>()) { IsReady = true };
var connection2 = new NetworkPlayer(tconn43, Substitute.For<IMessageHandler>()) { IsReady = false };
var connection1 = new NetworkPlayer(tconn42, messageHandler) { IsReady = true };
var connection2 = new NetworkPlayer(tconn43, messageHandler) { IsReady = false };
// add some server connections
server.Players.Add(connection1);
server.Players.Add(connection2);
Expand Down
2 changes: 1 addition & 1 deletion Assets/Tests/Runtime/Serializers/MessageBrokerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ void ParsePacket(ArraySegment<byte> data)
[Test]
public void SendsNotifyPacket()
{
messageBroker.SendNotify(Arg.Any<INetworkPlayer>(), data, 1);
messageBroker.SendNotify(player, data, 1);

Assert.That(lastSent, Is.EqualTo(new NotifyPacket
{
Expand Down

0 comments on commit f2ecca2

Please sign in to comment.