diff --git a/README.md b/README.md new file mode 100644 index 0000000..0be17fd --- /dev/null +++ b/README.md @@ -0,0 +1,18 @@ +# Raccoon Whitelisting +## What is Raccoon Whitelisting? +Raccoon Whitelisting is a new whitelist script, created by TheRaccoon (PeEcEeChIP) for an easy-to-use Discord whitelist. This script uses [Badger's](https://github.com/JaredScar) [Discord API Script](https://github.com/JaredScar/Badger_Discord_API), refraining from having to make another Discord bot token, and grab role ID's, making this whitelist script easier to use for anybody. + +## Configuration +``` +-- Change your server whitelist configurations here. +Configure = { +DiscordKick = 'We couldn\'t detect the desktop client of Discord, please check if your Discord is open.', -- Sends message to the user if they're Discord is not open. +WhitelistKick = 'We\'re sorry, but this server has been whitelisted. Please join the Discord and check how to be whitelisted.', -- Sends message to the user if they're not whitelisted in the server. +RoleIDKick = 'Sorry, but we couldn\'t detect your Role ID\'s. If this problem persist\'s please contact the server developer/development team.', +svname = 'Server Name', +Whitelisted = { -- Roles that you assigned in Badgers API that should pass the whitelist, make sure each role is listed with a comma. + "Whitelisted Role #1", + "Whitelisted Role #2", + "Whitelisted Role #3", +}, +}``` \ No newline at end of file diff --git a/fxmanifest.lua b/fxmanifest.lua new file mode 100644 index 0000000..e23ec46 --- /dev/null +++ b/fxmanifest.lua @@ -0,0 +1,13 @@ +fx_version "cerulean" +game "gta5" + +-- Define the resource metadata +name "Raccoon-Whitelist" +description "A simple whitelist script that utilizes Badger's new API" +author "TheRaccoon#1023 (PeEcEeChIP)" +version "v0.1.0" + + +server_script "settings.lua" +server_script "server.lua" +server_script "version_check.lua" diff --git a/server.lua b/server.lua new file mode 100644 index 0000000..f209957 --- /dev/null +++ b/server.lua @@ -0,0 +1,71 @@ +function ExtractIdentifiers(src) + local identifiers = { + discord = "" + } + + --Loop Identifiers + for i = 0, GetNumPlayerIdentifiers(src) - 1 do + local id = GetPlayerIdentifier(src, i) + + + if string.find(id, "discord") then + identifiers.discord = id + end + end + return identifiers +end + +roleList = Configure.Whitelisted; + +AddEventHandler("playerConnecting", function(name, setCallback, deferrals) + local Configure = Configure + deferrals.defer() + local src = source + local identifierDiscord = ""; + deferrals.update("Checking Your Server Permissions For " .. Configure.svname) + + Citizen.Wait(0); + + for k, v in ipairs(GetPlayerIdentifiers(src)) do + if string.sub(v, 1, string.len("discord:")) == "discord:" then + identifierDiscord = v + end + end + local isWhitelisted = false; + if identifierDiscord then + local roleIDs = exports.Badger_Discord_API:GetDiscordRoles(src) + if not (roleIDs == false) then + for i = 1, #roleList do + for j = 1, #roleIDs do + if exports.Badger_Discord_API:CheckEqual(roleList[i], roleIDs[j]) then + print("[Raccoon-Whitelist] (playerConnecting) Allowing " .. GetPlayerName(src) .. " to join with the role " .. roleList[i]) + print("[Raccoon-Whitelist] (playerConnecting) Player " .. GetPlayerName(src) .. " Attempted to connect with Raccoon-Whitelist, They were allowed entry") + isWhitelisted = true; + else + if isWhitelisted == false then + isWhitelisted = false; + end + end + end + end + else + print("[Raccoon-Whitelist] (playerConnecting) Player " .. GetPlayerName(src) .. " We could not get your Role ID\'s, failed to connect.") + print("[Raccoon-Whitelist] (playerConnecting) Player " .. GetPlayerName(src) .. " Attempted to connect with Raccoon-Whitelist, connection has failed.") + deferrals.done(Configure.RoleIDKick) + CancelEvent() + return; + end + else + print("[Raccoon-Whitelist] (playerConnecting) Declined connection from " .. GetPlayerName(src) .. " because they did not have Discord open") + print("[Raccoon-Whitelist] (playerConnecting) Player " .. GetPlayerName(src) .. " Attempted to connect with Raccoon-Whitelist, connection has failed.") + deferrals.done(Configure.DiscordKick) + CancelEvent() + return; + end + if isWhitelisted then + deferrals.done(); + else + deferrals.done(Configure.WhitelistKick); + CancelEvent() + end +end) diff --git a/settings.lua b/settings.lua new file mode 100644 index 0000000..97b3b36 --- /dev/null +++ b/settings.lua @@ -0,0 +1,12 @@ +-- Change your server whitelist configurations here. +Configure = { + DiscordKick = 'We couldn\'t detect the desktop client of Discord, please check if your Discord is open.', -- Sends message to the user if they're Discord is not open. + WhitelistKick = 'We\'re sorry, but this server has been whitelisted. Please join the Discord and check how to be whitelisted.', -- Sends message to the user if they're not whitelisted in the server. + RoleIDKick = 'Sorry, but we couldn\'t detect your Role ID\'s. If this problem persist\'s please contact the server developer/development team.', + svname = 'Server Name', + Whitelisted = { -- Roles that you assigned in Badgers API that should pass the whitelist, ALSO Make sure that **each** role ends with a comma! + "Whitelisted Role #1", + "Whitelisted Role #2", + "Whitelisted Role #3", + }, + } \ No newline at end of file diff --git a/version_check.lua b/version_check.lua new file mode 100644 index 0000000..ee1d038 --- /dev/null +++ b/version_check.lua @@ -0,0 +1,47 @@ +local label = +[[ + // + || ____ _ ____ _ __ ___ __ + || / __ \____ _______________ ____ ____ | | / / /_ (_) /____ / (_)____/ /_ + || / /_/ / __ `/ ___/ ___/ __ \/ __ \/ __ \ | | /| / / __ \/ / __/ _ \/ / / ___/ __/ + || / _, _/ /_/ / /__/ /__/ /_/ / /_/ / / / / | |/ |/ / / / / / /_/ __/ / (__ ) /_ + || /_/ |_|\__,_/\___/\___/\____/\____/_/ /_/ |__/|__/_/ /_/_/\__/\___/_/_/____/\__/ + || Created by TheRaccoon#1023 + ||]] +Citizen.CreateThread(function() + local CurrentVersion = GetResourceMetadata(GetCurrentResourceName(), 'version', 0) + if not CurrentVersion then + print('^1Raccoon-Whitelist Version Check Failed!^7') + end + + function VersionCheckHTTPRequest() + PerformHttpRequest('https://raw.githubusercontent.com/PeEcEeChIP/version-history/version/raccoon-whitelist.json', VersionCheck, 'GET') + end + + function VersionCheck(err, response, headers) + Citizen.Wait(3000) + if err == 200 then + local Data = json.decode(response) + if CurrentVersion ~= Data.NewestVersion then + print( label ) + print(' || \n || Raccoon-Whitelist is outdated!') + print(' || Current version: ^2' .. Data.NewestVersion .. '^7') + print(' || Your version: ^1' .. CurrentVersion .. '^7') + print(' || Please download the lastest version from ^5' .. Data.DownloadLocation .. '^7') + if Data.Changes ~= '' then + print(' || \n || ^5Changes: ^7' .. Data.Changes .. "\n^0 \\\\\n") + end + else + print( label ) + print(' || ^2Raccoon-Whitelist is up to date!\n^0 ||\n \\\\\n') + end + else + print( label ) + print(' || ^1There was an error getting the latest version information, if the issue persists contact TheRaccoon#1023 on Discord.\n^0 ||\n \\\\\n') + end + + SetTimeout(60000000, VersionCheckHTTPRequest) + end + + VersionCheckHTTPRequest() +end)