From 243ccc03f269ed10cf49f2db8568dc5abe076f74 Mon Sep 17 00:00:00 2001 From: Tom Gerrits Date: Mon, 30 Nov 2020 10:38:03 +0100 Subject: [PATCH] Add password user authenticator --- .../Networking/PasswordUserAuthenticator.cs | 66 +++++++++++++++++++ .../PasswordUserAuthenticator.cs.meta | 11 ++++ 2 files changed, 77 insertions(+) create mode 100644 ForgeUnity/Assets/BeardedManStudios/Scripts/Networking/Forge/Networking/PasswordUserAuthenticator.cs create mode 100644 ForgeUnity/Assets/BeardedManStudios/Scripts/Networking/Forge/Networking/PasswordUserAuthenticator.cs.meta 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: