diff --git a/ForgeUnity/Assets/BeardedManStudios/Scripts/Networking/Forge/Networking/PasswordUserAuthenticator.cs b/ForgeUnity/Assets/BeardedManStudios/Scripts/Networking/Forge/Networking/PasswordUserAuthenticator.cs new file mode 100644 index 00000000..6e11cb3f --- /dev/null +++ b/ForgeUnity/Assets/BeardedManStudios/Scripts/Networking/Forge/Networking/PasswordUserAuthenticator.cs @@ -0,0 +1,66 @@ +using System; +using BeardedManStudios; +using BeardedManStudios.Forge.Networking; + +namespace BeardedManStudios.Forge.Networking +{ + /// + /// Authenticates the user to the server through a password. + /// + internal sealed class PasswordUserAuthenticator : IUserAuthenticator + { + /// + /// The password to require. + /// + private readonly string password; + + /// + /// Constructor. + /// + /// The password to require when connecting to the server. + public PasswordUserAuthenticator(string password) + { + this.password = password; + } + + /// + public void IssueChallenge( + NetWorker networker, + NetworkingPlayer player, + Action issueChallengeAction, + Action skipAuthAction + ) + { + issueChallengeAction(player, new BMSByte()); + } + + /// + public void AcceptChallenge( + NetWorker networker, + BMSByte challenge, + Action authServerAction, + Action rejectServerAction + ) + { + authServerAction(ObjectMapper.BMSByte(password)); + } + + /// + public void VerifyResponse( + NetWorker networker, + NetworkingPlayer player, + BMSByte response, + Action authUserAction, + Action rejectUserAction + ) + { + string sentPassword = response.GetBasicType(); + + if (sentPassword == password) + authUserAction(player); + + else + rejectUserAction(player); + } + } +} diff --git a/ForgeUnity/Assets/BeardedManStudios/Scripts/Networking/Forge/Networking/PasswordUserAuthenticator.cs.meta b/ForgeUnity/Assets/BeardedManStudios/Scripts/Networking/Forge/Networking/PasswordUserAuthenticator.cs.meta new file mode 100644 index 00000000..679d6365 --- /dev/null +++ b/ForgeUnity/Assets/BeardedManStudios/Scripts/Networking/Forge/Networking/PasswordUserAuthenticator.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: aad506979d6256d4cbff1acb0ceee13c +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: