From efcadd4734ed4c0d2c6bc1678deed85cd2671cdc Mon Sep 17 00:00:00 2001
From: Andyyy7666 <86536434+Andyyy7666@users.noreply.github.com>
Date: Wed, 10 Aug 2022 00:18:14 +0200
Subject: [PATCH] fix(CharacterSelection/js): Removed duplicated code
---
ND_CharacterSelection/source/server.lua | 10 +-
ND_CharacterSelection/source/ui/script.js | 228 ----------------------
ND_Core/server/functions.lua | 3 +-
3 files changed, 6 insertions(+), 235 deletions(-)
diff --git a/ND_CharacterSelection/source/server.lua b/ND_CharacterSelection/source/server.lua
index 39f7812..2fcca79 100644
--- a/ND_CharacterSelection/source/server.lua
+++ b/ND_CharacterSelection/source/server.lua
@@ -5,12 +5,12 @@ NDCore = exports["ND_Core"]:GetCoreObject()
function validateDepartment(player, department)
local departmentExists = config.departments[department]
if departmentExists then
- local discordUserId = string.gsub(NDCore.Functions.GetPlayerIdentifierFromType("discord", player), "discord:", "")
- local roles = NDCore.Functions.GetUserDiscordInfo(discordUserId).roles
+ local discordUserId = NDCore.Functions.GetPlayerIdentifierFromType("discord", player):gsub("discord:", "")
+ local discordInfo = NDCore.Functions.GetUserDiscordInfo(discordUserId)
-- validate that the player actually has the role that they selected on the client.
for _, roleId in pairs(departmentExists) do
- if roles[roleId] or roleId == 0 or roleId == "0" then
+ if roleId == 0 or roleId == "0" or (discordInfo and discordInfo.roles[roleId]) then
return true
end
end
@@ -53,6 +53,7 @@ AddEventHandler("ND_CharacterSelection:checkPerms", function()
local discordUserId = NDCore.Functions.GetPlayerIdentifierFromType("discord", player):gsub("discord:", "")
local allowedRoles = {}
local discordInfo = NDCore.Functions.GetUserDiscordInfo(discordUserId)
+
-- Check if the players discord roles will grant them permission to the department.
for dept, roleTable in pairs(config.departments) do
for _, roleId in pairs(roleTable) do
@@ -61,6 +62,5 @@ AddEventHandler("ND_CharacterSelection:checkPerms", function()
end
end
end
-
TriggerClientEvent("ND_CharacterSelection:permsChecked", player, allowedRoles)
-end)
+end)
\ No newline at end of file
diff --git a/ND_CharacterSelection/source/ui/script.js b/ND_CharacterSelection/source/ui/script.js
index e6d7b80..bd7250a 100644
--- a/ND_CharacterSelection/source/ui/script.js
+++ b/ND_CharacterSelection/source/ui/script.js
@@ -213,234 +213,6 @@ $(function() {
return;
});
- $("#quitGameButton").click(function() {
- exitGameMenu(true)
- return;
- });
- $("#exitGameCancel").click(function() {
- exitGameMenu(false)
- return;
- });
- $("#exitGameConfirm").click(function() {
- $.post(`https://${GetParentResourceName()}/exitGame`);
- return;
- });
-});
-$(function() {
- function display(bool) {
- if (bool) {
- $("body").show();
- } else {
- $("body").hide();
- }
- }
- function characterCreatorMenu(bool) {
- if (bool) {
- $("#characterCreator").fadeIn("slow");
- $("#characterEditor, #exitGameMenu, #deleteCharacterMenu, #spawnLocation").hide();
- return;
- }
- $("#characterCreator").fadeOut("slow");
- }
- function characterEditorMenu(bool) {
- if (bool) {
- $("#characterEditor").fadeIn("slow");
- $("#characterCreator, #exitGameMenu, #deleteCharacterMenu, #spawnLocation").hide();
- return;
- }
- $("#characterEditor").fadeOut("slow");
- }
- function exitGameMenu(bool) {
- if (bool) {
- $("#exitGameMenu").fadeIn("slow");
- $("#characterCreator, #characterEditor, #deleteCharacterMenu, #spawnLocation").hide();
- return;
- }
- $("#exitGameMenu").fadeOut("slow");
- }
- function confirmDeleteMenu(bool) {
- if (bool) {
- $("#deleteCharacterMenu").fadeIn("slow");
- $("#characterCreator, #characterEditor, #exitGameMenu, #spawnLocation").hide();
- return;
- }
- $("#deleteCharacterMenu").fadeOut("slow");
- }
- function spawnMenu(bool) {
- if (bool) {
- $("#spawnLocation").fadeIn("slow");
- $("#characterCreator, #characterEditor, #exitGameMenu, #deleteCharacterMenu").hide();
- return;
- }
- $("#spawnLocation").fadeOut("slow");
- }
-
- window.addEventListener("message", function(event) {
- const item = event.data;
- if (item.type === "ui") {
- if (item.status) {
- $("#serverName").text(item.serverName);
- $("body").css("background-image", "url(" + item.background + ")");
- display(true);
- } else {
- display(false);
- }
- }
-
- $("#playerAmount").text(item.characterAmount);
-
- if (item.type === "setSpawns") {
- $("#spawnMenuContainer").empty();
- setTimeout(function(){
- $("#tpDoNot").data("id", item.id);
- $("#spawnMenuContainer").append(``);
- $(".spawnButtons").click(function() {
- $.post(`https://${GetParentResourceName()}/tpToLocation`, JSON.stringify({
- x: $(this).data("x"),
- y: $(this).data("y"),
- z: $(this).data("z")
- }));
- spawnMenu(false);
- setTimeout(function(){
- $("#spawnMenuContainer").empty();
- }, 550);
- return;
- });
- $("#tpDoNot").click(function() {
- $.post(`https://${GetParentResourceName()}/tpDoNot`, JSON.stringify({
- id: $("#tpDoNot").data("id")
- }));
- spawnMenu(false)
- setTimeout(function(){
- $("#spawnMenuContainer").empty();
- }, 550);
- return;
- });
- }, 10);
- }
-
- if (item.type === "givePerms") {
- JSON.parse(item.deptRoles).forEach((dept) => {
- $(".departments").append($("