126 lines
3.8 KiB
Lua
126 lines
3.8 KiB
Lua
local PLUGIN = PLUGIN
|
|
util.AddNetworkString("ixWhitelistMenuOpen")
|
|
util.AddNetworkString("ixWhitelistMenuDataRequest")
|
|
util.AddNetworkString("ixWhitelistMenuData")
|
|
util.AddNetworkString("ixWhitelistMenuApply")
|
|
|
|
local function GetFactionData()
|
|
local data = {}
|
|
for k, v in pairs(ix.faction.indices) do
|
|
if v.Podr and v.Spec and v.Ranks then
|
|
data[k] = {
|
|
name = v.name,
|
|
Podr = v.Podr,
|
|
Spec = v.Spec,
|
|
Ranks = v.Ranks
|
|
}
|
|
end
|
|
end
|
|
return data
|
|
end
|
|
|
|
net.Receive("ixWhitelistMenuDataRequest", function(_, client)
|
|
if not PLUGIN:HasAccess(client) then
|
|
return
|
|
end
|
|
|
|
local players = {}
|
|
for _, ply in ipairs(player.GetAll()) do
|
|
if ply:Alive() and ply:GetCharacter() then
|
|
table.insert(players, {
|
|
steamID = ply:SteamID(),
|
|
name = ply:Name()
|
|
})
|
|
end
|
|
end
|
|
|
|
net.Start("ixWhitelistMenuData")
|
|
net.WriteTable(players)
|
|
net.WriteTable(GetFactionData())
|
|
net.Send(client)
|
|
end)
|
|
|
|
net.Receive("ixWhitelistMenuApply", function(_, client)
|
|
if not PLUGIN:HasAccess(client) then
|
|
return
|
|
end
|
|
|
|
local targetSteamID = net.ReadString()
|
|
local factionID = net.ReadUInt(16)
|
|
local podrID = net.ReadUInt(8)
|
|
local specID = net.ReadUInt(8)
|
|
local rankID = net.ReadUInt(8)
|
|
|
|
local target = nil
|
|
for _, ply in ipairs(player.GetAll()) do
|
|
if ply:SteamID() == targetSteamID then
|
|
target = ply
|
|
break
|
|
end
|
|
end
|
|
|
|
if not target or not target:GetCharacter() then
|
|
client:Notify("Игрок не найден.")
|
|
return
|
|
end
|
|
|
|
local faction = ix.faction.indices[factionID]
|
|
if not faction then
|
|
client:Notify("Фракция не найдена.")
|
|
return
|
|
end
|
|
|
|
if not faction.Podr[podrID] then
|
|
client:Notify("Подразделение не найдено.")
|
|
return
|
|
end
|
|
|
|
if not faction.Spec[specID] then
|
|
client:Notify("Специализация не найдена.")
|
|
return
|
|
end
|
|
|
|
local targetRanks = (faction.Podr[podrID] and faction.Podr[podrID].ranks) or faction.Ranks
|
|
if not (targetRanks and targetRanks[rankID]) then
|
|
client:Notify("Звание не найдено.")
|
|
return
|
|
end
|
|
|
|
if faction.Spec[specID].podr ~= podrID then
|
|
client:Notify("Специализация не соответствует подразделению.")
|
|
return
|
|
end
|
|
|
|
local char = target:GetCharacter()
|
|
char:SetFaction(factionID)
|
|
char:SetPodr(podrID)
|
|
char:SetSpec(specID)
|
|
char:SetRank(rankID)
|
|
|
|
-- Респавн игрока для применения изменений
|
|
target:Spawn()
|
|
|
|
client:Notify("Роль назначена: " .. target:Name())
|
|
target:Notify("Вам назначена новая роль!")
|
|
|
|
-- Логирование в систему серверных логов
|
|
local serverlogs = ix.plugin.list["serverlogs"]
|
|
if serverlogs then
|
|
local factionName = faction.name or "Неизвестно"
|
|
local podrName = faction.Podr[podrID] and faction.Podr[podrID].name or tostring(podrID)
|
|
local specName = faction.Spec[specID] and faction.Spec[specID].name or tostring(specID)
|
|
local rankName = targetRanks[rankID] and targetRanks[rankID].name or tostring(rankID)
|
|
|
|
local message = string.format("%s изменил роль игроку %s: Фракция: %s, Подразделение: %s, Спец: %s, Ранг: %s",
|
|
client:Nick(), target:Nick(), factionName, podrName, specName, rankName)
|
|
|
|
serverlogs:AddLog("CHARACTER_WHITELIST", message, target, {
|
|
admin = client:SteamID(),
|
|
faction = factionName,
|
|
podr = podrName,
|
|
spec = specName,
|
|
rank = rankName
|
|
})
|
|
end
|
|
end)
|