mirror of
https://github.com/ND-Framework/ND_Core.git
synced 2026-08-17 05:56:01 +01:00
Merge pull request #77 from ND-Framework/feat/lan-identifier
feat(server): lan identifer
This commit is contained in:
@@ -1,3 +1,10 @@
|
|||||||
|
function NDCore.getPlayerIdentifierByType(src, indentifierType)
|
||||||
|
if Config.sv_lan then
|
||||||
|
return ("%s:sv_lan"):format(indentifierType)
|
||||||
|
end
|
||||||
|
return GetPlayerIdentifierByType(src, indentifierType)
|
||||||
|
end
|
||||||
|
|
||||||
---@param src number
|
---@param src number
|
||||||
---@return table
|
---@return table
|
||||||
function NDCore.getPlayer(src)
|
function NDCore.getPlayer(src)
|
||||||
|
|||||||
@@ -26,7 +26,8 @@ Config = {
|
|||||||
adminDiscordRoles = json.decode(GetConvar("core:adminDiscordRoles", "[]")),
|
adminDiscordRoles = json.decode(GetConvar("core:adminDiscordRoles", "[]")),
|
||||||
groupRoles = json.decode(GetConvar("core:groupRoles", "[]")),
|
groupRoles = json.decode(GetConvar("core:groupRoles", "[]")),
|
||||||
multiCharacter = false,
|
multiCharacter = false,
|
||||||
compatibility = json.decode(GetConvar("core:compatibility", "[]"))
|
compatibility = json.decode(GetConvar("core:compatibility", "[]")),
|
||||||
|
sv_lan = GetConvar("sv_lan", "false") == "true",
|
||||||
}
|
}
|
||||||
|
|
||||||
SetConvarServerInfo("Discord", Config.discordInvite)
|
SetConvarServerInfo("Discord", Config.discordInvite)
|
||||||
@@ -43,6 +44,11 @@ local function getIdentifierList(src)
|
|||||||
list[identifierType] = identifier
|
list[identifierType] = identifier
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if Config.sv_lan then
|
||||||
|
list[Config.characterIdentifier] = NDCore.getPlayerIdentifierByType(src, Config.characterIdentifier)
|
||||||
|
end
|
||||||
|
|
||||||
return list
|
return list
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -52,6 +58,10 @@ AddEventHandler("playerJoining", function(oldId)
|
|||||||
PlayersInfo[src] = tempPlayersInfo[oldTempId]
|
PlayersInfo[src] = tempPlayersInfo[oldTempId]
|
||||||
tempPlayersInfo[oldTempId] = nil
|
tempPlayersInfo[oldTempId] = nil
|
||||||
|
|
||||||
|
if Config.sv_lan then
|
||||||
|
lib.addPrincipal(("player.%s"):format(src), "group.admin")
|
||||||
|
end
|
||||||
|
|
||||||
if Config.multiCharacter then return end
|
if Config.multiCharacter then return end
|
||||||
Wait(3000)
|
Wait(3000)
|
||||||
|
|
||||||
@@ -103,7 +113,7 @@ AddEventHandler("playerConnecting", function(name, setKickReason, deferrals)
|
|||||||
|
|
||||||
if mainIdentifier and Config.discordBotToken ~= "false" and Config.discordGuildId ~= "false" then
|
if mainIdentifier and Config.discordBotToken ~= "false" and Config.discordGuildId ~= "false" then
|
||||||
discordInfo = checkDiscordIdentifier(identifiers)
|
discordInfo = checkDiscordIdentifier(identifiers)
|
||||||
if not discordInfo and Config.discordMemeberRequired then
|
if not discordInfo and Config.discordMemeberRequired and not Config.sv_lan then
|
||||||
deferrals.done(("Your discord was not found, join our discord here: %s."):format(Config.discordInvite))
|
deferrals.done(("Your discord was not found, join our discord here: %s."):format(Config.discordInvite))
|
||||||
Wait(0)
|
Wait(0)
|
||||||
end
|
end
|
||||||
@@ -112,6 +122,17 @@ AddEventHandler("playerConnecting", function(name, setKickReason, deferrals)
|
|||||||
deferrals.update("Connecting...")
|
deferrals.update("Connecting...")
|
||||||
Wait(0)
|
Wait(0)
|
||||||
|
|
||||||
|
if Config.sv_lan then
|
||||||
|
tempPlayersInfo[tempSrc] = {
|
||||||
|
identifiers = {
|
||||||
|
[Config.characterIdentifier] = "sv_lan"
|
||||||
|
},
|
||||||
|
discord = discordInfo
|
||||||
|
}
|
||||||
|
deferrals.done()
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
if mainIdentifier then
|
if mainIdentifier then
|
||||||
tempPlayersInfo[tempSrc] = {
|
tempPlayersInfo[tempSrc] = {
|
||||||
identifiers = identifiers,
|
identifiers = identifiers,
|
||||||
|
|||||||
@@ -426,7 +426,7 @@ end
|
|||||||
---@param info table
|
---@param info table
|
||||||
---@return table
|
---@return table
|
||||||
function NDCore.newCharacter(src, info)
|
function NDCore.newCharacter(src, info)
|
||||||
local identifier = GetPlayerIdentifierByType(src, Config.characterIdentifier)
|
local identifier = NDCore.getPlayerIdentifierByType(src, Config.characterIdentifier)
|
||||||
if not identifier then return end
|
if not identifier then return end
|
||||||
|
|
||||||
local charInfo = {
|
local charInfo = {
|
||||||
@@ -468,7 +468,7 @@ end
|
|||||||
function NDCore.fetchCharacter(id, src)
|
function NDCore.fetchCharacter(id, src)
|
||||||
local result
|
local result
|
||||||
if src then
|
if src then
|
||||||
result = MySQL.query.await("SELECT * FROM nd_characters WHERE charid = ? and identifier = ?", {id, GetPlayerIdentifierByType(src, Config.characterIdentifier)})
|
result = MySQL.query.await("SELECT * FROM nd_characters WHERE charid = ? and identifier = ?", {id, NDCore.getPlayerIdentifierByType(src, Config.characterIdentifier)})
|
||||||
else
|
else
|
||||||
result = MySQL.query.await("SELECT * FROM nd_characters WHERE charid = ?", {id})
|
result = MySQL.query.await("SELECT * FROM nd_characters WHERE charid = ?", {id})
|
||||||
end
|
end
|
||||||
@@ -497,7 +497,7 @@ end
|
|||||||
---@return table
|
---@return table
|
||||||
function NDCore.fetchAllCharacters(src)
|
function NDCore.fetchAllCharacters(src)
|
||||||
local characters = {}
|
local characters = {}
|
||||||
local result = MySQL.query.await("SELECT * FROM nd_characters WHERE identifier = ?", {GetPlayerIdentifierByType(src, Config.characterIdentifier)})
|
local result = MySQL.query.await("SELECT * FROM nd_characters WHERE identifier = ?", {NDCore.getPlayerIdentifierByType(src, Config.characterIdentifier)})
|
||||||
|
|
||||||
for i=1, #result do
|
for i=1, #result do
|
||||||
local info = result[i]
|
local info = result[i]
|
||||||
|
|||||||
Reference in New Issue
Block a user