Skip to content

Commit

Permalink
feat: adding EpicNetworkAuthenticator that will authenticate using th…
Browse files Browse the repository at this point in the history
…e product Id

uses the product id that the player uses to connect to the relay

BREAKING CHANGE: now requires mirage v143
  • Loading branch information
James-Frowen committed Jun 18, 2023
1 parent f383a8b commit 9b97d76
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 3 deletions.
46 changes: 46 additions & 0 deletions Assets/EpicSocket/Runtime/EpicNetworkAuthenticator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using Mirage.Authentication;
using UnityEngine;

namespace Mirage.Sockets.EpicSocket
{
public class EpicNetworkAuthenticator : NetworkAuthenticator<EpicNetworkAuthenticator.AuthMessage>
{
[SerializeField] private NetworkClient _client;
[SerializeField] private bool _automaticallyAuthenticate = true;

protected override AuthenticationResult Authenticate(INetworkPlayer player, AuthMessage message)
{
var address = player.Address;

var epicEndPoint = (EpicEndPoint)address;

var user = epicEndPoint.UserId;
return AuthenticationResult.CreateSuccess(this, user);
}

private void Awake()
{
_client.Connected.AddListener(OnClientConnected);
}

private void OnClientConnected(INetworkPlayer player)
{
if (!_automaticallyAuthenticate)
return;

// if we connect via epic, then we should send the auth message
// this will cause server to authenticate the player via the product id by the userId they are using to connect
var address = player.Address;
if (address is EpicEndPoint)
{
player.Send(new AuthMessage());
}
}

[NetworkMessage]
public struct AuthMessage
{
// we dont need to send any thing, we will get the product id from the connection
}
}
}
11 changes: 11 additions & 0 deletions Assets/EpicSocket/Runtime/EpicNetworkAuthenticator.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Assets/EpicSocket/Runtime/RelayHandle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ internal class RelayHandle
private byte[] _receiveBuffer = new byte[P2PInterface.MaxPacketSize];

public bool IsOpen { get; private set; }
/// <summary>Host user</summary>
/// <summary>User that is hosting relay</summary>
public ProductUserId RemoteUser => _remoteUser;

private static RelayHandle s_instance;
Expand Down
2 changes: 1 addition & 1 deletion Assets/EpicSocket/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"url": "https://github.com/MirageNet/EpicSocket.git"
},
"dependencies": {
"com.miragenet.mirage": "120.0.0",
"com.miragenet.mirage": "143.0.0",
"com.playeveryware.eos": "2.2.0"
},
"samples": []
Expand Down
2 changes: 1 addition & 1 deletion Packages/manifest.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"dependencies": {
"com.miragenet.mirage": "120.0.0",
"com.miragenet.mirage": "143.0.0",
"com.playeveryware.eos": "2.2.0",
"com.unity.collab-proxy": "1.2.16",
"com.unity.ide.rider": "1.1.4",
Expand Down

0 comments on commit 9b97d76

Please sign in to comment.