lsft/sv_lsft.txt

185 lines
5.3 KiB
Text
Raw Normal View History

2021-12-14 20:11:04 -05:00
--@name Logan's Starfall Toolkit
--@author logan2611
--@server
--@include lsft/cl_lsft.txt
--@includedir lsft/modules/server
--@includedir lsft/modules/shared
--@clientmain lsft/cl_lsft.txt
-- SPAWN THIS ONE
--[[
_ ____ _____ _____
| | / ___|| ___|_ _|
| | _____ \___ \| |_ | |
| |___ |_____| ___) | _| | |
|_____| |____/|_| |_|
--]]
--[[
TODO: Literally everything
TODO: Update checker
TODO: On module load, grab default config values. Write changed values
TODO: Client can request config values
prop.createSent(chip():getPos()+Vector(0,0,90),Angle(0,0,0),"Seat_Airboat",true)
--]]
--[[
hook.add("PlayerSay", "CommandCheck", function(ply, str)
if ply==owner() and string.find(str,"^!") then
end
end)
--]]
-- Main Module (Mostly loading modules and stuff)
core = {}
core.modules = {
core = {
version = 0.1,
commands = {
help = function() print("hi") end,
colors = function() print(""..core:get_config("core","color_logo")) end,
},
},
}
core.config = {}
core.defaultconfig = {
core = {
command_prefix = "!n",
color_logo = Color(255,200,50),
color_text = Color(200,200,200),
color_info = Color(50,150,255),
color_warning = Color(255,150,50),
color_error = Color(255,50,50)
},
}
log = {
ERROR=0,
WARNING=1,
INFO=2,
TEXT=3
}
function core:init(config)
-- If the streamed config exists and has stuff in it, use it instead of the empty one
if config != nil and #config > 0 then
core.config = config
end
core:load_modules()
core.color_logo = core:get_config("core","color_logo")
core.color_text = core:get_config("core","color_text")
core.color_info = core:get_config("core","color_info")
core.color_warning = core:get_config("core","color_warning")
core.color_error = core:get_config("core","color_error")
core:log(log.INFO, "Loaded v"..core.modules.core.version.." successfully")
return true
end
function core:get_config(...)
local args = {...}
local cur = core.config
for arg in pairs(args) do
for i,v in pairs(cur) do
if i == args[arg] then
if type(v) == "table" then
--cur = cur[i]
cur = v
continue
else
return v
end
end
end
end
local cur = core.defaultconfig
for arg in pairs(args) do
for i,v in pairs(cur) do
if i == args[arg] then
if type(v) == "table" then
--cur = cur[i]
cur = v
continue
else
return v
end
end
end
end
error("Config value requested, but no current or default entry exists!")
end
function core:load_modules()
dodir("lsft/modules/server")
dodir("lsft/modules/shared")
hook.add("PlayerSay", "CommandCheck", function(ply, str)
local prefix = core:get_config("core","command_prefix")
if ply == owner() and string.find(str, "^"..prefix) then
local command = string.sub(string.explode(" ", str)[1], #prefix+1)
for i, v in pairs(core.modules) do
for commandin, commandfunc in pairs(v["commands"]) do
if command == commandin then
commandfunc()
return ""
end
end
end
--print(core.color_logo, "[L-SFT] ", core.color_error, "Error: \""..command.."\" is not a valid command!")
core:log(log.ERROR, "\""..command.."\" is not a valid command!")
return ""
end
end)
end
function core:log(...)
local args = {...}
local loglevel = args[1]
local message = { unpack(args, 2, #args) }
local color = Color(0,0,0)
if loglevel == log.ERROR then color = core.color_error
elseif loglevel == log.WARNING then color = core.color_warning
elseif loglevel == log.INFO then color = core.color_info
elseif loglevel == log.TEXT then color = core.color_text
end
print(core.defaultconfig.core.color_logo, "[L-SFT] ", color, unpack(message))
end
net.receive("LSFT-Config-Read", function(len, ply)
if ply == owner() then
-- Colors settings aren't loaded yet, so use dumb printing method with default colors (Don't ever do this >:c)
--print(core.defaultconfig.core.color_logo, "[L-SFT] ", core.defaultconfig.core.color_info, "Downloading configuration: 0%")
timer.create("ConfigProgress", 0.25, 0, function()
print(core.defaultconfig.core.color_logo, "[L-SFT] ", core.defaultconfig.core.color_info, "Downloading configuration: ", math.round(net.getStreamProgress() * 100, 2), "%")
end)
net.readStream(function(data)
timer.remove("ConfigProgress")
core:init(json.decode(data))
end)
else
print(core.defaultconfig.core.color_logo, "[L-SFT] ", core.defaultconfig.core.color_error, ply:getName().." is trying to give us a config")
end
end)
net.receive("LSFT-Get-Config", function()
core:getConfig(unpack(net.readTable()))
end)