-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: adding EpicNetworkAuthenticator that will authenticate using th…
…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
1 parent
f383a8b
commit 9b97d76
Showing
5 changed files
with
60 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
11
Assets/EpicSocket/Runtime/EpicNetworkAuthenticator.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters