From fd7a22423fc4ff2f89f2ac883154ebf92f3ef47e Mon Sep 17 00:00:00 2001 From: Andyyy7666 <86536434+Andyyy7666@users.noreply.github.com> Date: Wed, 12 Jul 2023 04:53:00 +0200 Subject: [PATCH] refactor(server/main): warnings and identifiers --- server/main.lua | 44 ++++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/server/main.lua b/server/main.lua index d108d2c..f2e85eb 100644 --- a/server/main.lua +++ b/server/main.lua @@ -1,18 +1,19 @@ NDCore = {} ActivePlayers = {} PlayersInfo = {} +local resourceName = GetCurrentResourceName() local tempPlayersInfo = {} local databaseFiles = { "database/characters.sql", "database/vehicles.sql" } +local discordErrors = { + [400] = "Improper HTTP request", + [401] = "Discord bot token might be missing or incorrect", + [404] = "User might not be in the server", + [429] = "Discord bot rate limited" +} -AddEventHandler("playerDropped", function() - local src = source - local char = ActivePlayers[src] - if not char then return end - char:unload() -end) Config = { serverName = GetConvar("core:serverName", "Unconfigured ND-Core Server"), discordInvite = GetConvar("core:discordInvite", "https://discord.gg/Z9Mxu72zZ6"), @@ -32,33 +33,22 @@ Config = { groups = json.decode(GetConvar("core:groups", "[]")) } -SetConvarServerInfo("ND_Core", GetResourceMetadata(GetCurrentResourceName(), "version", 0) or "invalid") +SetConvarServerInfo("ND_Core", GetResourceMetadata(resourceName, "version", 0) or "invalid") SetConvarReplicated("inventory:framework", "nd") -local file = LoadResourceFile(GetCurrentResourceName(), "query.sql") -if file then - MySQL.query(file) -end - local function getIdentifierList(src) local list = {} for i=0, GetNumPlayerIdentifiers(src) do local identifier = GetPlayerIdentifier(src, i) if identifier then local colon = identifier:find(":") - list[identifierType] = identifier:sub(1, colon-1) + local identifierType = identifier:sub(1, colon-1) + list[identifierType] = identifier end end return list end -local discordErrors = { - [400] = "Improper HTTP request", - [401] = "Discord bot token might be missing or incorrect", - [404] = "User might not be in the server", - [429] = "Discord bot rate limited" -} - local function getDiscordInfo(discordUserId) local done = false local data @@ -66,7 +56,7 @@ local function getDiscordInfo(discordUserId) PerformHttpRequest(("https://discordapp.com/api/guilds/%s/members/%s"):format(Config.discordGuildId, discordUserId), function(errorCode, resultData, resultHeaders) if errorCode ~= 200 then done = true - return print(("Error %d: %s"):format(errorCode, discordErrors[errorCode])) + return print(("^3Warning: %d %s"):format(errorCode, discordErrors[errorCode])) end local result = json.decode(resultData) @@ -104,7 +94,7 @@ AddEventHandler("playerConnecting", function(name, setKickReason, deferrals) Wait(0) return end - discordInfo = getDiscordInfo(discordIdentifier:gsub("discord:")) + discordInfo = getDiscordInfo(discordIdentifier:gsub("discord:", "")) end deferrals.update("Connecting...") @@ -121,6 +111,16 @@ AddEventHandler("playerConnecting", function(name, setKickReason, deferrals) Wait(0) end end) + +AddEventHandler("playerDropped", function() + local src = source + local char = ActivePlayers[src] + if char then + char:unload() + end + PlayersInfo[src] = nil +end) + for i=1, #databaseFiles do local file = LoadResourceFile(resourceName, databaseFiles[i]) if file then