mirror of
https://github.com/ND-Framework/ND_Core.git
synced 2026-08-17 05:56:01 +01:00
feat(server): lan identifer
Create fake identifier when using sv_lan
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
|
||||
---@return table
|
||||
function NDCore.getPlayer(src)
|
||||
|
||||
@@ -26,7 +26,8 @@ Config = {
|
||||
adminDiscordRoles = json.decode(GetConvar("core:adminDiscordRoles", "[]")),
|
||||
groupRoles = json.decode(GetConvar("core:groupRoles", "[]")),
|
||||
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)
|
||||
@@ -43,6 +44,11 @@ local function getIdentifierList(src)
|
||||
list[identifierType] = identifier
|
||||
end
|
||||
end
|
||||
|
||||
if Config.sv_lan then
|
||||
list[Config.characterIdentifier] = NDCore.getPlayerIdentifierByType(src, Config.characterIdentifier)
|
||||
end
|
||||
|
||||
return list
|
||||
end
|
||||
|
||||
@@ -52,6 +58,10 @@ AddEventHandler("playerJoining", function(oldId)
|
||||
PlayersInfo[src] = tempPlayersInfo[oldTempId]
|
||||
tempPlayersInfo[oldTempId] = nil
|
||||
|
||||
if Config.sv_lan then
|
||||
lib.addPrincipal(("player.%s"):format(src), "group.admin")
|
||||
end
|
||||
|
||||
if Config.multiCharacter then return end
|
||||
Wait(3000)
|
||||
|
||||
@@ -103,7 +113,7 @@ AddEventHandler("playerConnecting", function(name, setKickReason, deferrals)
|
||||
|
||||
if mainIdentifier and Config.discordBotToken ~= "false" and Config.discordGuildId ~= "false" then
|
||||
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))
|
||||
Wait(0)
|
||||
end
|
||||
@@ -112,6 +122,17 @@ AddEventHandler("playerConnecting", function(name, setKickReason, deferrals)
|
||||
deferrals.update("Connecting...")
|
||||
Wait(0)
|
||||
|
||||
if Config.sv_lan then
|
||||
tempPlayersInfo[tempSrc] = {
|
||||
identifiers = {
|
||||
[Config.characterIdentifier] = "sv_lan"
|
||||
},
|
||||
discord = discordInfo
|
||||
}
|
||||
deferrals.done()
|
||||
return
|
||||
end
|
||||
|
||||
if mainIdentifier then
|
||||
tempPlayersInfo[tempSrc] = {
|
||||
identifiers = identifiers,
|
||||
|
||||
@@ -426,7 +426,7 @@ end
|
||||
---@param info table
|
||||
---@return table
|
||||
function NDCore.newCharacter(src, info)
|
||||
local identifier = GetPlayerIdentifierByType(src, Config.characterIdentifier)
|
||||
local identifier = NDCore.getPlayerIdentifierByType(src, Config.characterIdentifier)
|
||||
if not identifier then return end
|
||||
|
||||
local charInfo = {
|
||||
@@ -468,7 +468,7 @@ end
|
||||
function NDCore.fetchCharacter(id, src)
|
||||
local result
|
||||
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
|
||||
result = MySQL.query.await("SELECT * FROM nd_characters WHERE charid = ?", {id})
|
||||
end
|
||||
@@ -497,7 +497,7 @@ end
|
||||
---@return table
|
||||
function NDCore.fetchAllCharacters(src)
|
||||
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
|
||||
local info = result[i]
|
||||
|
||||
Reference in New Issue
Block a user