-
-
Notifications
You must be signed in to change notification settings - Fork 306
Basic Authentication
[WORK IN PROGRESS] This page is a 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
Summarized:
- Implement
IUserAuthenticator
. - Use
SetAuthenticator
to set the new authenticator before callingConnect
on your networker.
Most users of Forge have a Unity project that serves both as client and server. In that case you can simply implement all methods of the interface and use it for both ends.
If you have a stand-alone non-Unity server, you only need to implement some methods for the server and some for the client. Each method below shows what is necessary.
- Needed on the client: No.
- Needed on the server: Yes.
public void IssueChallenge(NetWorker networker, NetworkingPlayer player, Action<NetworkingPlayer, BMSByte> issueChallengeAction, Action<NetworkingPlayer> skipAuthAction)
{
issueChallengeAction(player, new BMSByte());
}
- Needed on the client: Yes.
- Needed on the server: No.
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);
}
- Needed on the client: No.
- Needed on the server: Yes.
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();
}
}
You can find an example of password authentication in this pull request.
Getting Started
Network Contract Wizard (NCW)
Remote Procedure Calls (RPCs)
Unity Integration
Basic Network Samples
Scene Navigation
Master Server
Netcoding Design Patterns
Troubleshooting
Miscellaneous
-
Connection Cycle Events
-
Rewinding
-
Network Logging
-
Working with Multiple Sockets
-
Modify Master and Standalone servers
-
NAT Hole Punching
-
UDP LAN Discovery
-
Offline Mode
-
Ping Pong
-
Lobby System
-
Upgrading Forge Remastered to Develop branch or different version
-
Forge Networking Classic to Remastered Migration Guide
-
Script to easily use Forge Networking from sources
-
Run Two Unity Instances with Shared Assets for Easiest Dedicated Client Workflow