Untitled

mail@pastecode.io avatar
unknown
csharp
2 years ago
3.6 kB
2
Indexable
Never
using System;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using Rage;
using DiscordRPC;
using System.Reflection;

namespace PanosCommon.Utils
{
    internal static class AlternateAuthentification
    {
        readonly static string licensesFile = "https://raw.githubusercontent.com/Panos1221/Licenses/main/FireCallouts.txt";

        internal static bool Authentified = false;

        [Obfuscation(Exclude = false, Feature = "-rename")]
        [STAThread()]
        [Rage.Attributes.ConsoleCommand("Try verifying your license", Name = "PanosCommonVerifyLicense")]
        internal static void Initialize()
        {
            try
            {
                string id = "724743398862618715";
                DiscordRpcClient client = new DiscordRpcClient(id);
                client.OnReady += Client_OnReady;
                client.Initialize();
            }
            catch(Exception ex)
            {
                Game.LogTrivial($"[PanosCommon] Exception: {ex}");
            }
        }

        private static void Client_OnReady(object sender, DiscordRPC.Message.ReadyMessage args)
        {
            Game.LogTrivial($"Inside Client_OnReady");

            var id = args.User.ID;
            string encryptedID;
            using (SHA256 sha256Hash = SHA256.Create())
            {
                // ComputeHash - returns byte array  
                byte[] bytes = sha256Hash.ComputeHash(Encoding.UTF8.GetBytes(Convert.ToString(id)));

                // Convert byte array to a string   
                StringBuilder builder = new StringBuilder();
                for (int i = 0; i < bytes.Length; i++)
                {
                    builder.Append(bytes[i].ToString("x2"));
                }
                encryptedID = builder.ToString();
            }

            Game.LogTrivial($"[PanosCommon] User ID: {id} Encrypted ID: {encryptedID}");
            string result = WebDownloader.DownloadString(licensesFile, out bool success, true);
            if (success)
            {
                Game.LogTrivial($"[PanosCommon] Web request result: {result}");
                var premiumUsers = result.Split('\n');
                if (premiumUsers.Any(userID => userID == encryptedID))
                {
                    Game.LogTrivial("[PanosCommon] You are successfully verified to use Fire Callouts. Thank you for your support!");
                    Authentified = true;
                    EntryPoint.beta = true;
                }
                else
                {
                    Game.LogTrivial("[PanosCommon] You do not have a valid license for Fire Callouts. Make sure to check your membership status at https://www.patreon.com/panos1221. The plugin will unload now");
                    //Game.UnloadActivePlugin();
                }
            }
            else
            {

                Game.LogTrivial("[PanosCommon] An error occured while checking for donor status. Make sure you're connected to the Internet and Discord (the application) is running. The plugin will unload now");
                //Game.UnloadActivePlugin();
            }
        }

        [Obfuscation(Exclude = false, Feature = "-rename")]
        [Rage.Attributes.ConsoleCommand()]
        public static void CheckFireCalloutsLicenseStatus()
        {
            string validity = Authentified ? "Valid" : "Invalid";
            Game.LogTrivial($"[PanosCommon] License status: {validity}");
        }
    }
}