mirror of
https://github.com/lifestorm/wnsrc.git
synced 2025-12-17 05:43:46 +03:00
Upload
This commit is contained in:
63
addons/sam-master/lua/sam/config/cl_config.lua
Normal file
63
addons/sam-master/lua/sam/config/cl_config.lua
Normal file
@@ -0,0 +1,63 @@
|
||||
--[[
|
||||
| This file was obtained through the combined efforts
|
||||
| of Madbluntz & Plymouth Antiquarian Society.
|
||||
|
|
||||
| Credits: lifestorm, Gregory Wayne Rossel JR.,
|
||||
| Maloy, DrPepper10 @ RIP, Atle!
|
||||
|
|
||||
| Visit for more: https://plymouth.thetwilightzone.ru/
|
||||
--]]
|
||||
|
||||
if SAM_LOADED then return end
|
||||
|
||||
local sam = sam
|
||||
local mp = sam.mp
|
||||
local config = sam.config
|
||||
|
||||
function config.set(key, value, force)
|
||||
if not sam.isstring(key) then
|
||||
error("invalid setting name")
|
||||
end
|
||||
|
||||
if not mp.packers[sam.type(value)] then
|
||||
error("not supported value type")
|
||||
end
|
||||
|
||||
if not force and config.get(key) == value then return end
|
||||
sam.netstream.Start("Config.Set", key, value)
|
||||
end
|
||||
|
||||
function config.get(key, default)
|
||||
local value = sam.get_global("Config")[key]
|
||||
if value ~= nil then
|
||||
return value
|
||||
end
|
||||
return default
|
||||
end
|
||||
|
||||
local menu_settings = {}
|
||||
function config.add_menu_setting(title, func)
|
||||
local i = #menu_settings + 1
|
||||
for k, v in ipairs(menu_settings) do
|
||||
if v.title == title then
|
||||
i = k
|
||||
break
|
||||
end
|
||||
end
|
||||
menu_settings[i] = {
|
||||
title = title,
|
||||
func = func,
|
||||
}
|
||||
end
|
||||
|
||||
function config.get_menu_settings()
|
||||
return menu_settings
|
||||
end
|
||||
|
||||
hook.Add("SAM.ChangedGlobalVar", "SAM.CheckLoadedConfig", function(key, value)
|
||||
if key == "Config" then
|
||||
config.loaded = true
|
||||
hook.Call("SAM.LoadedConfig", nil, value)
|
||||
hook.Remove("SAM.ChangedGlobalVar", "SAM.CheckLoadedConfig")
|
||||
end
|
||||
end)
|
||||
61
addons/sam-master/lua/sam/config/sh_config.lua
Normal file
61
addons/sam-master/lua/sam/config/sh_config.lua
Normal file
@@ -0,0 +1,61 @@
|
||||
--[[
|
||||
| This file was obtained through the combined efforts
|
||||
| of Madbluntz & Plymouth Antiquarian Society.
|
||||
|
|
||||
| Credits: lifestorm, Gregory Wayne Rossel JR.,
|
||||
| Maloy, DrPepper10 @ RIP, Atle!
|
||||
|
|
||||
| Visit for more: https://plymouth.thetwilightzone.ru/
|
||||
--]]
|
||||
|
||||
if SAM_LOADED then return end
|
||||
|
||||
local sam = sam
|
||||
local config = sam.config
|
||||
|
||||
sam.permissions.add("manage_config", nil, "superadmin")
|
||||
|
||||
local updates = {}
|
||||
function config.hook(keys, func)
|
||||
for i = #keys, 1, -1 do
|
||||
keys[keys[i]] = true
|
||||
keys[i] = nil
|
||||
end
|
||||
|
||||
local id = table.insert(updates, {
|
||||
keys = keys,
|
||||
func = func
|
||||
})
|
||||
|
||||
if config.loaded then
|
||||
func()
|
||||
end
|
||||
|
||||
return id
|
||||
end
|
||||
|
||||
function config.get_updated(key, default)
|
||||
local setting = {}
|
||||
config.hook({key}, function()
|
||||
setting.value = config.get(key, default)
|
||||
end)
|
||||
return setting
|
||||
end
|
||||
|
||||
function config.remove_hook(key)
|
||||
updates[key] = nil
|
||||
end
|
||||
|
||||
hook.Add("SAM.LoadedConfig", "RunHooks", function()
|
||||
for k, v in pairs(updates) do
|
||||
v.func()
|
||||
end
|
||||
end)
|
||||
|
||||
hook.Add("SAM.UpdatedConfig", "RunHooks", function(key, value, old)
|
||||
for k, v in pairs(updates) do
|
||||
if v.keys[key] then
|
||||
v.func(value, old)
|
||||
end
|
||||
end
|
||||
end)
|
||||
109
addons/sam-master/lua/sam/config/sv_config.lua
Normal file
109
addons/sam-master/lua/sam/config/sv_config.lua
Normal file
@@ -0,0 +1,109 @@
|
||||
--[[
|
||||
| This file was obtained through the combined efforts
|
||||
| of Madbluntz & Plymouth Antiquarian Society.
|
||||
|
|
||||
| Credits: lifestorm, Gregory Wayne Rossel JR.,
|
||||
| Maloy, DrPepper10 @ RIP, Atle!
|
||||
|
|
||||
| Visit for more: https://plymouth.thetwilightzone.ru/
|
||||
--]]
|
||||
|
||||
if SAM_LOADED then return end
|
||||
|
||||
local sam = sam
|
||||
local SQL = sam.SQL
|
||||
local mp = sam.mp
|
||||
local config = sam.config
|
||||
|
||||
local _config = {}
|
||||
|
||||
function config.sync()
|
||||
sam.set_global("Config", _config, true)
|
||||
end
|
||||
|
||||
local to_hex
|
||||
do
|
||||
local byte = string.byte
|
||||
local gsub = string.gsub
|
||||
local format = string.format
|
||||
|
||||
local hex = function(c)
|
||||
return format("%02X", byte(c))
|
||||
end
|
||||
|
||||
function to_hex(text)
|
||||
return (gsub(text, ".", hex))
|
||||
end
|
||||
end
|
||||
|
||||
function config.set(key, value, force)
|
||||
if not sam.isstring(key) then
|
||||
error("invalid setting name")
|
||||
end
|
||||
|
||||
if not mp.packers[sam.type(value)] then
|
||||
error("not supported value type")
|
||||
end
|
||||
|
||||
local old = _config[key]
|
||||
if not force and value == old then return end
|
||||
|
||||
SQL.FQuery([[
|
||||
REPLACE INTO
|
||||
`sam_config`(
|
||||
`key`,
|
||||
`value`
|
||||
)
|
||||
VALUES
|
||||
({1}, X{2})
|
||||
]], {key, to_hex(mp.pack(value))})
|
||||
|
||||
_config[key] = value
|
||||
config.sync()
|
||||
sam.hook_call("SAM.UpdatedConfig", key, value, old)
|
||||
end
|
||||
|
||||
function config.get(key, default)
|
||||
local value = _config[key]
|
||||
if value ~= nil then
|
||||
return value
|
||||
end
|
||||
return default
|
||||
end
|
||||
|
||||
config.sync()
|
||||
|
||||
hook.Add("SAM.DatabaseLoaded", "LoadConfig", function()
|
||||
SQL.Query([[
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
`sam_config`
|
||||
]], function(sam_config)
|
||||
for _, v in ipairs(sam_config) do
|
||||
_config[v.key] = mp.unpack(v.value)
|
||||
end
|
||||
|
||||
config.loaded = true
|
||||
config.sync()
|
||||
hook.Call("SAM.LoadedConfig", nil, _config)
|
||||
end):wait()
|
||||
end)
|
||||
|
||||
sam.netstream.Hook("Config.Set", function(ply, key, value)
|
||||
config.set(key, value)
|
||||
|
||||
value = tostring(value)
|
||||
|
||||
if value == "" then
|
||||
sam.player.send_message(nil, "{A} changed {S Blue} setting to: {S_2 Red}", {
|
||||
A = ply, S = key, S_2 = "none"
|
||||
})
|
||||
else
|
||||
sam.player.send_message(nil, "{A} changed {S Blue} setting to: {S_2}", {
|
||||
A = ply, S = key, S_2 = value
|
||||
})
|
||||
end
|
||||
end, function(ply)
|
||||
return ply:HasPermission("manage_config")
|
||||
end)
|
||||
Reference in New Issue
Block a user