Skip to content

Commit

Permalink
refactor: making NetworkClient implement IMessageSender (MirageNet#671)
Browse files Browse the repository at this point in the history
* refactor: splitting IMessageHandler into multiple interfaces

* adding comments

* fixing typo

* updating weaver to use new interfaces

* refactor: making NetworkClient implement IMessageSender

* removing calls to INetworkClient because they are now in IMessageSender
  • Loading branch information
James-Frowen committed Mar 8, 2021
1 parent 0522edf commit 84830b9
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 9 deletions.
7 changes: 1 addition & 6 deletions Assets/Mirage/Runtime/INetworkClient.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
using Cysharp.Threading.Tasks;
using UnityEngine.Events;

namespace Mirage
{
public interface INetworkClient
public interface INetworkClient : IMessageSender
{

/// <summary>
Expand Down Expand Up @@ -38,9 +37,5 @@ public interface INetworkClient
bool IsLocalClient { get; }

void Disconnect();

void Send<T>(T message, int channelId = Channel.Reliable);

UniTask SendAsync<T>(T message, int channelId = Channel.Reliable);
}
}
7 changes: 6 additions & 1 deletion Assets/Mirage/Runtime/NetworkClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,12 @@ public UniTask SendAsync<T>(T message, int channelId = Channel.Reliable)

public void Send<T>(T message, int channelId = Channel.Reliable)
{
Connection.SendAsync(message, channelId).Forget();
Connection.Send(message, channelId);
}

public UniTask SendAsync(ArraySegment<byte> segment, int channelId = Channel.Reliable)
{
return Connection.SendAsync(segment, channelId);
}

internal void Update()
Expand Down
2 changes: 0 additions & 2 deletions Assets/Mirage/Weaver/Processors/ReaderWriterProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,6 @@ private static bool IsMessageMethod(MethodReference method)
method.Is<NetworkConnection>(nameof(NetworkConnection.SendAsync)) ||
method.Is<NetworkConnection>(nameof(NetworkConnection.RegisterHandler)) ||
method.Is<NetworkConnection>(nameof(NetworkConnection.UnregisterHandler)) ||
method.Is<INetworkClient>(nameof(INetworkClient.Send)) ||
method.Is<INetworkClient>(nameof(INetworkClient.SendAsync)) ||
method.Is<NetworkClient>(nameof(NetworkClient.Send)) ||
method.Is<NetworkClient>(nameof(NetworkClient.SendAsync)) ||
method.Is<NetworkServer>(nameof(NetworkServer.SendToAll)) ||
Expand Down

0 comments on commit 84830b9

Please sign in to comment.