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

Add password user authenticator #387

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
using System;
using BeardedManStudios;
using BeardedManStudios.Forge.Networking;

namespace BeardedManStudios.Forge.Networking
{
/// <summary>
/// Authenticates the user to the server through a password.
/// </summary>
internal sealed class PasswordUserAuthenticator : IUserAuthenticator
{
/// <summary>
/// The password to require.
/// </summary>
private readonly string password;

/// <summary>
/// Constructor.
/// </summary>
/// <param name="password">The password to require when connecting to the server.</param>
public PasswordUserAuthenticator(string password)
{
this.password = password;
}

/// <inheritdoc/>
public void IssueChallenge(
NetWorker networker,
NetworkingPlayer player,
Action<NetworkingPlayer, BMSByte> issueChallengeAction,
Action<NetworkingPlayer> skipAuthAction
)
{
issueChallengeAction(player, new BMSByte());
}

/// <inheritdoc/>
public void AcceptChallenge(
NetWorker networker,
BMSByte challenge,
Action<BMSByte> authServerAction,
Action rejectServerAction
)
{
authServerAction(ObjectMapper.BMSByte(password));
}

/// <inheritdoc/>
public void VerifyResponse(
NetWorker networker,
NetworkingPlayer player,
BMSByte response,
Action<NetworkingPlayer> authUserAction,
Action<NetworkingPlayer> rejectUserAction
)
{
string sentPassword = response.GetBasicType<string>();

if (sentPassword == password)
authUserAction(player);

else
rejectUserAction(player);
}
}
}

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