mirror of
https://github.com/ND-Framework/ND_Core.git
synced 2026-08-17 22:06:02 +01:00
refactor(server/main): warnings and identifiers
This commit is contained in:
@@ -1,18 +1,19 @@
|
|||||||
NDCore = {}
|
NDCore = {}
|
||||||
ActivePlayers = {}
|
ActivePlayers = {}
|
||||||
PlayersInfo = {}
|
PlayersInfo = {}
|
||||||
|
local resourceName = GetCurrentResourceName()
|
||||||
local tempPlayersInfo = {}
|
local tempPlayersInfo = {}
|
||||||
local databaseFiles = {
|
local databaseFiles = {
|
||||||
"database/characters.sql",
|
"database/characters.sql",
|
||||||
"database/vehicles.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 = {
|
Config = {
|
||||||
serverName = GetConvar("core:serverName", "Unconfigured ND-Core Server"),
|
serverName = GetConvar("core:serverName", "Unconfigured ND-Core Server"),
|
||||||
discordInvite = GetConvar("core:discordInvite", "https://discord.gg/Z9Mxu72zZ6"),
|
discordInvite = GetConvar("core:discordInvite", "https://discord.gg/Z9Mxu72zZ6"),
|
||||||
@@ -32,33 +33,22 @@ Config = {
|
|||||||
groups = json.decode(GetConvar("core:groups", "[]"))
|
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")
|
SetConvarReplicated("inventory:framework", "nd")
|
||||||
|
|
||||||
local file = LoadResourceFile(GetCurrentResourceName(), "query.sql")
|
|
||||||
if file then
|
|
||||||
MySQL.query(file)
|
|
||||||
end
|
|
||||||
|
|
||||||
local function getIdentifierList(src)
|
local function getIdentifierList(src)
|
||||||
local list = {}
|
local list = {}
|
||||||
for i=0, GetNumPlayerIdentifiers(src) do
|
for i=0, GetNumPlayerIdentifiers(src) do
|
||||||
local identifier = GetPlayerIdentifier(src, i)
|
local identifier = GetPlayerIdentifier(src, i)
|
||||||
if identifier then
|
if identifier then
|
||||||
local colon = identifier:find(":")
|
local colon = identifier:find(":")
|
||||||
list[identifierType] = identifier:sub(1, colon-1)
|
local identifierType = identifier:sub(1, colon-1)
|
||||||
|
list[identifierType] = identifier
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return list
|
return list
|
||||||
end
|
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 function getDiscordInfo(discordUserId)
|
||||||
local done = false
|
local done = false
|
||||||
local data
|
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)
|
PerformHttpRequest(("https://discordapp.com/api/guilds/%s/members/%s"):format(Config.discordGuildId, discordUserId), function(errorCode, resultData, resultHeaders)
|
||||||
if errorCode ~= 200 then
|
if errorCode ~= 200 then
|
||||||
done = true
|
done = true
|
||||||
return print(("Error %d: %s"):format(errorCode, discordErrors[errorCode]))
|
return print(("^3Warning: %d %s"):format(errorCode, discordErrors[errorCode]))
|
||||||
end
|
end
|
||||||
|
|
||||||
local result = json.decode(resultData)
|
local result = json.decode(resultData)
|
||||||
@@ -104,7 +94,7 @@ AddEventHandler("playerConnecting", function(name, setKickReason, deferrals)
|
|||||||
Wait(0)
|
Wait(0)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
discordInfo = getDiscordInfo(discordIdentifier:gsub("discord:"))
|
discordInfo = getDiscordInfo(discordIdentifier:gsub("discord:", ""))
|
||||||
end
|
end
|
||||||
|
|
||||||
deferrals.update("Connecting...")
|
deferrals.update("Connecting...")
|
||||||
@@ -121,6 +111,16 @@ AddEventHandler("playerConnecting", function(name, setKickReason, deferrals)
|
|||||||
Wait(0)
|
Wait(0)
|
||||||
end
|
end
|
||||||
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
|
for i=1, #databaseFiles do
|
||||||
local file = LoadResourceFile(resourceName, databaseFiles[i])
|
local file = LoadResourceFile(resourceName, databaseFiles[i])
|
||||||
if file then
|
if file then
|
||||||
|
|||||||
Reference in New Issue
Block a user