Skip to content
This repository was archived by the owner on Aug 15, 2022. It is now read-only.

Basic Authentication

Peter Halasz edited this page Apr 14, 2020 · 3 revisions

[WORK IN PROGRESS] This page is a work in progress.

  • Implement IUserAuthenticator.
  • Add the new authenticator before calling Connect on the networker.
    • use the SetAuthenticator method
public void IssueChallenge(NetWorker networker, NetworkingPlayer player, Action<NetworkingPlayer, BMSByte> issueChallengeAction, Action<NetworkingPlayer> skipAuthAction)
{
    issueChallengeAction(player, new BMSByte());
}
public void AcceptChallenge(NetWorker networker, BMSByte challenge, Action<BMSByte> authServerAction, Action rejectServerAction)
{
    Ticket = Client.Instance.Auth.GetAuthSessionTicket();
    var data = ObjectMapper.BMSByte(Client.Instance.SteamId, Ticket.Data);
    authServerAction(data);
}
public void VerifyResponse(NetWorker networker, NetworkingPlayer player, BMSByte response, Action<NetworkingPlayer> authUserAction, Action<NetworkingPlayer> rejectUserAction)
{
    ulong steamid = response.GetBasicType<ulong>();
    byte[] ticketBinary = response.GetByteArray(response.StartIndex());

    if (AuthUser(steamid, ticketBinary))
    {
        authUserAction();
    } else {
        rejectUserAction();
    }
}

Authentication flow

Work in progress

When someone connects to the server they send a request to the server "Hey give me a network id" which is read by the server and if there is an authenticator set then it will run this piece of code in UDPServer.cs lines 542-545

The client will then get this challenge message and run this pieces of code in UDPClient.cs lines 439-447 and send back to the server the data you specify that will identify your player.

When the server gets the challenge response it will run this piece of code in UDPServer.cs lines 553-561 to check that what the client sent back is valid and the client can be allowed on the server and depending on what you do in verifyrepsonse you have two callbacks to call one to authorize the client the other to reject

Note the AuthUser and RejectUser callback methods in authenticator.VerifyResponse(this, currentPlayer, frame.StreamData, AuthUser, RejectUser); on line 559 of the UDPServer.cs file they are these two methods

Home

Getting Started
Network Contract Wizard (NCW)
Network Object
Remote Procedure Calls (RPCs)
Unity Integration
Basic Network Samples
Scene Navigation
NetWorker
Master Server
Web Server
Netcoding Design Patterns
Troubleshooting
Miscellaneous
Forge Networking Alloy
Steamworks

Clone this wiki locally