feat: allow servers to disable rainbow for everyone (to help prevent reported crashes)

This commit is contained in:
James Ross 2021-01-23 22:34:02 +00:00
parent ba3be84ac9
commit 0c48d224bf
No known key found for this signature in database
GPG Key ID: 49E8B07166BE49AB
4 changed files with 40 additions and 22 deletions

View File

@ -28,6 +28,7 @@
## Server owners
* `sbox_maxtextscreens` controls the maximum amount of text screens that each player can spawn. This defaults to 1. This cvar only exists on the server, so make sure it's set via RCON, or in something like server.cfg.
* `ss_enable_rainbow` controls whether players on your server can use the rainbow effect. Set this to `0` in your `server.cfg` to prevent anyone from using rainbow effects.
* Set `ss_call_to_home 1` on your server to provide anonymous analytics including your operating system, version of the addon, and rough, anonymised geo-location. This is entirely optional and used solely to put a smile on my face.
* To install this onto your server, follow the instructions [listed here](https://wiki.garrysmod.com/page/Workshop_for_Dedicated_Servers).

View File

@ -11,14 +11,19 @@ local function checkAdmin(ply)
return canAdmin
end
-- allow servers to disable rainbow effect for everyone
CreateConVar("ss_enable_rainbow", 1, {FCVAR_NOTIFY, FCVAR_REPLICATED}, "Determines whether rainbow textscreens will render for all clients. When disabled, rainbow screens will render as solid white.", 0, 1)
if SERVER then
AddCSLuaFile()
AddCSLuaFile("textscreens_config.lua")
include("textscreens_config.lua")
CreateConVar("sbox_maxtextscreens", "1", {FCVAR_NOTIFY, FCVAR_REPLICATED})
CreateConVar("ss_call_to_home", 0, {FCVAR_NOTIFY, FCVAR_REPLICATED})
CreateConVar("sbox_maxtextscreens", "1", {FCVAR_NOTIFY, FCVAR_REPLICATED}, "Determines the maximum number of textscreens users can spawn.")
CreateConVar("ss_call_to_home", 0, {FCVAR_NOTIFY, FCVAR_REPLICATED}, "Determines whether anonymous usage analytics can be sent to the addon author.", 0, 1)
local version = "1.17.3"
--local rainbow_enabled = cvars.Number('ss_enable_rainbow', 1)
local version = "1.18.0"
local function GetOS()
if system.IsLinux() then return "linux" end

View File

@ -3,6 +3,7 @@ include("shared.lua")
local render_convar_range = CreateClientConVar("ss_render_range", 1500, true, false, "Determines the render range for Textscreens. Default 1500")
local render_rainbow = CreateClientConVar("ss_render_rainbow", 1, true, false, "Determines if rainbow screens are rendered. If disabled (0), will render as solid white. Default enabled (1)", 0, 1)
local render_range = render_convar_range:GetInt() * render_convar_range:GetInt() --We multiply this is that we can use DistToSqr instead of Distance so we don't need to workout the square root all the time
local rainbow_enabled = cvars.Number("ss_enable_rainbow", 1)
local textscreenFonts = textscreenFonts
local screenInfo = {}
local shouldDrawBoth = false
@ -45,6 +46,12 @@ cvars.AddChangeCallback("ss_render_rainbow", function(convar_name, value_old, va
render_rainbow = tonumber(value_new)
end, "3D2DScreens")
-- TODO: https://github.com/Facepunch/garrysmod-issues/issues/3740
-- cvars.AddChangeCallback("ss_enable_rainbow", function(convar_name, value_old, value_new)
-- print('ss_enable_rainbow changed: '.. value_new)
-- rainbow_enabled = tonumber(value_new)
-- end, "3D2DScreens")
function ENT:Initialize()
self:SetMaterial("models/effects/vol_light001")
self:SetRenderMode(RENDERMODE_NONE)
@ -78,10 +85,10 @@ local function Draw3D2D(ang, pos, camangle, data)
if data[i][RAINBOW] ~= nil and data[i][RAINBOW] ~= 0 then
for j = 1, #data[i][TEXT] do
--Color
if render_rainbow ~= 0 then
if rainbow_enabled == 1 and render_rainbow ~= 0 then
surface.SetTextColor(HSVToColor((CurTime() * 60 + (j * 5)) % 360, 1, 1))
else
-- Render as solid white if ss_render_rainbow is disabled
-- Render as solid white if ss_render_rainbow is disabled or server disabled via ss_enable_rainbow
surface.SetTextColor(255, 255, 255)
end
--Text

View File

@ -8,6 +8,7 @@ local labels = {}
local sliders = {}
local rainbowCheckboxes = {}
local textscreenFonts = textscreenFonts
local rainbow_enabled = cvars.Number("ss_enable_rainbow", 1)
for i = 1, 5 do
TOOL.ClientConVar["text" .. i] = ""
@ -77,7 +78,7 @@ function TOOL:LeftClick(tr)
-- font
tonumber(self:GetClientInfo("font" .. i)) or 1,
tonumber(self:GetClientInfo("rainbow" .. i)) or 0
rainbow_enabled == 1 and tonumber(self:GetClientInfo("rainbow" .. i)) or 0
)
end
@ -104,7 +105,7 @@ function TOOL:RightClick(tr)
-- font
tonumber(self:GetClientInfo("font" .. i)) or 1,
tonumber(self:GetClientInfo("rainbow" .. i)) or 0
rainbow_enabled and tonumber(self:GetClientInfo("rainbow" .. i)) or 0
)
end
@ -217,11 +218,13 @@ function TOOL.BuildCPanel(CPanel)
ResetFont({1, 2, 3, 4, 5}, false)
end)
menu:AddOption("Reset rainbow", function()
for i = 1, 5 do
rainbowCheckboxes[i]:SetValue(0)
end
end)
if rainbow_enabled == 1 then
menu:AddOption("Reset rainbow", function()
for i = 1, 5 do
rainbowCheckboxes[i]:SetValue(0)
end
end)
end
menu:AddOption("Reset everything", function()
for i = 1, 5 do
@ -234,7 +237,9 @@ function TOOL.BuildCPanel(CPanel)
RunConsoleCommand("textscreen_text" .. i, "")
RunConsoleCommand("textscreen_font" .. i, 1)
textBox[i]:SetValue("")
rainbowCheckboxes[i]:SetValue(0)
if rainbow_enabled == 1 then
rainbowCheckboxes[i]:SetValue(0)
end
end
ResetFont({1, 2, 3, 4, 5}, true)
end)
@ -337,15 +342,15 @@ function TOOL.BuildCPanel(CPanel)
Multiplier = 255
})
print("textscreen_rainbow" .. i)
print(GetConVar("textscreen_rainbow" .. i):GetInt())
rainbowCheckboxes[i] = vgui.Create("DCheckBoxLabel")
rainbowCheckboxes[i]:SetText("Rainbow Text")
rainbowCheckboxes[i]:SetTextColor(Color(0,0,0,255))
rainbowCheckboxes[i]:SetConVar("textscreen_rainbow" .. i)
rainbowCheckboxes[i]:SetTooltip("Enable for rainbow text")
rainbowCheckboxes[i]:SetValue(GetConVar("textscreen_rainbow" .. i):GetInt())
CPanel:AddItem(rainbowCheckboxes[i])
if rainbow_enabled == 1 then
rainbowCheckboxes[i] = vgui.Create("DCheckBoxLabel")
rainbowCheckboxes[i]:SetText("Rainbow Text")
rainbowCheckboxes[i]:SetTextColor(Color(0,0,0,255))
rainbowCheckboxes[i]:SetConVar("textscreen_rainbow" .. i)
rainbowCheckboxes[i]:SetTooltip("Enable for rainbow text")
rainbowCheckboxes[i]:SetValue(GetConVar("textscreen_rainbow" .. i):GetInt())
CPanel:AddItem(rainbowCheckboxes[i])
end
sliders[i] = vgui.Create("DNumSlider")
sliders[i]:SetText("Font size")