diff --git a/src/gamemodes/amongus/gamemode/cl_net.moon b/src/gamemodes/amongus/gamemode/cl_net.moon index 1b1edf9..03e5394 100644 --- a/src/gamemodes/amongus/gamemode/cl_net.moon +++ b/src/gamemodes/amongus/gamemode/cl_net.moon @@ -499,3 +499,24 @@ net.Receive "NMW AU Flow", -> switch net.ReadUInt GAMEMODE.FlowSize when GAMEMODE.FlowTypes.GameChatNotification chat.AddText Color(220, 32, 32), "[Among Us] ", Color(255, 255, 0), tostring TRANSLATE "chat.noTalkingDuringGame" + +skipSync = {} +for _, cvar in ipairs GAMEMODE.replicatedWritableCvars + cvars.AddChangeCallback GAMEMODE.ConVars[cvar]\GetName!, ((cvar, oldValue, newValue) -> + if skipSync[cvar] + skipSync[cvar] = false + elseif CAMI.PlayerHasAccess LocalPlayer!, GAMEMODE.PRIV_CHANGE_SETTINGS + net.Start "AU ChangeCvar" + net.WriteString cvar + net.WriteString newValue + net.SendToServer! + else + print "Only admins can change ConVar #{cvar}" + skipSync[cvar] = true + RunConsoleCommand cvar, oldValue + ), "SendToServer" + +net.Receive "AU ChangeCvar", (len, ply) -> + cvar = net.ReadString! + skipSync[cvar] = true + RunConsoleCommand cvar, net.ReadString! \ No newline at end of file diff --git a/src/gamemodes/amongus/gamemode/shared.moon b/src/gamemodes/amongus/gamemode/shared.moon index ae49bf3..b3aab9e 100644 --- a/src/gamemodes/amongus/gamemode/shared.moon +++ b/src/gamemodes/amongus/gamemode/shared.moon @@ -17,7 +17,8 @@ GM.WorkshopID = "{{CI_WORKSHOP_ID}}" GM.Version = "manual-build" if GM.Version == "{{" .. "CI_GAMEMODE_VERSION}}" GM.WorkshopID = nil if GM.WorkshopID == "{{" .. "CI_WORKSHOP_ID}}" -flags = bit.bor FCVAR_ARCHIVE, FCVAR_REPLICATED +flags = FCVAR_ARCHIVE +flagsRep = bit.bor FCVAR_ARCHIVE, FCVAR_REPLICATED --- Table of all ConVars the game mode is using. -- These are tracked and cannot be changed during the round. @@ -45,7 +46,7 @@ flags = bit.bor FCVAR_ARCHIVE, FCVAR_REPLICATED -- @field ForceAutoWarmup (Bool) Should the automated round management be forced? GM.ConVars = ImposterCount: CreateConVar "au_max_imposters" , 1 , flags, "", 1, 10 - MinPlayers: CreateConVar "au_min_players" , 3 , flags, "", 3, 128 + MinPlayers: CreateConVar "au_min_players" , 3 , flagsRep, "", 3, 128 KillCooldown: CreateConVar "au_kill_cooldown" , 20, flags, "", 1, 60 KillDistanceMod: CreateConVar "au_killdistance_mod", 1 , flags, "", 1, 3 ConfirmEjects: CreateConVar "au_confirm_ejects" , 1 , flags, "", 0, 1 @@ -65,19 +66,42 @@ GM.ConVars = TasksCommon: CreateConVar "au_tasks_common" , 1, flags, "", 0, 5 TasksVisual: CreateConVar "au_tasks_enable_visual", 0, flags, "", 0, 1 - DistributeTasksToBots: CreateConVar "au_debug_bot_tasks" , 0, flags, "", 0, 1 - MeetingBotVote: CreateConVar "au_debug_bot_vote" , 0, flags, "", 0, 1 + DistributeTasksToBots: CreateConVar "au_debug_bot_tasks" , 0, flagsRep, "", 0, 1 + MeetingBotVote: CreateConVar "au_debug_bot_vote" , 0, flagsRep, "", 0, 1 TimeLimit: CreateConVar "au_time_limit", 600, flags, "", 0, 1200 - Countdown: CreateConVar "au_countdown" , 5 , flags, "", 1, 10 + Countdown: CreateConVar "au_countdown" , 5 , flagsRep, "", 1, 10 - WarmupTime: CreateConVar "au_warmup_time" , 60, flags, "", 0, 120 - ForceAutoWarmup: CreateConVar "au_warmup_force_auto", 0 , flags, "", 0, 1 + WarmupTime: CreateConVar "au_warmup_time" , 60, flagsRep, "", 0, 120 + ForceAutoWarmup: CreateConVar "au_warmup_force_auto", 0 , flagsRep, "", 0, 1 PlayerModel: CreateConVar "au_player_model", "models/amongus/player/player.mdl", - flags, "" + flagsRep, "" CorpseModel: CreateConVar "au_corpse_model", "models/amongus/player/corpse.mdl", - flags, "" + flagsRep, "" + +GM.replicatedWritableCvars = { + "ImposterCount" + "KillCooldown" + "TimeLimit" + "KillDistanceMod" + "AllTalk" + "TaskbarUpdates" + "PlayerSpeedMod" + + "MeetingsPerPlayer" + "MeetingCooldown" + "VoteTime" + "VotePreTime" + "VotePostTime" + "ConfirmEjects" + "VoteAnonymous" + + "TasksShort" + "TasksLong" + "TasksCommon" + "TasksVisual" +} --- Enum of all colors players can get. -- @table GM.Colors diff --git a/src/gamemodes/amongus/gamemode/sv_net.moon b/src/gamemodes/amongus/gamemode/sv_net.moon index e8bea95..178ac28 100644 --- a/src/gamemodes/amongus/gamemode/sv_net.moon +++ b/src/gamemodes/amongus/gamemode/sv_net.moon @@ -3,6 +3,7 @@ -- @module sv_net util.AddNetworkString "NMW AU Flow" +util.AddNetworkString "AU ChangeCvar" --- Sends the game state update. -- @param ply Player entity. @@ -422,6 +423,7 @@ net.Receive "NMW AU Flow", (len, ply) -> ply\SetPlayerColor GAMEMODE.Colors[preferred]\ToVector! GAMEMODE\Net_UpdateGameState ply + GAMEMODE\Net_SyncGameSettings ply -- -- Player has closed the task window. @@ -532,3 +534,34 @@ GM.SetOnAutoPilot = (newState) => -- @return You guessed it again. GM.SetFullyInitializedPlayerCount = (newCount) => SetGlobalInt "NMW AU FullyInitializedPlayers", newCount + +GM.Net_SyncGameSettings = (ply) => + for _, cvar in ipairs GAMEMODE.replicatedWritableCvars + net.Start "AU ChangeCvar" + net.WriteString GAMEMODE.ConVars[cvar]\GetName! + net.WriteString GAMEMODE.ConVars[cvar]\GetString! + net.Send ply + +skipSync = {} +for _, cvar in ipairs GAMEMODE.replicatedWritableCvars + cvars.AddChangeCallback GAMEMODE.ConVars[cvar]\GetName!, ((cvar, oldValue, newValue) -> + if skipSync[cvar] + skipSync[cvar] = false + else + net.Start "AU ChangeCvar" + net.WriteString cvar + net.WriteString newValue + net.Broadcast! + ), "SendToClient" + +net.Receive "AU ChangeCvar", (len, ply) -> + isWritableCvar = (cvarName) -> + for _, cvar in ipairs GAMEMODE.replicatedWritableCvars + if GAMEMODE.ConVars[cvar]\GetName! == cvarName + return true + return false + + cvar = net.ReadString! + if CAMI.PlayerHasAccess(ply, GAMEMODE.PRIV_CHANGE_SETTINGS) and isWritableCvar(cvar) + skipSync[cvar] = true + RunConsoleCommand cvar, net.ReadString! \ No newline at end of file diff --git a/src/gamemodes/amongus/gamemode/vgui/vgui_showhelp.moon b/src/gamemodes/amongus/gamemode/vgui/vgui_showhelp.moon index 3f128c6..e38b4a9 100644 --- a/src/gamemodes/amongus/gamemode/vgui/vgui_showhelp.moon +++ b/src/gamemodes/amongus/gamemode/vgui/vgui_showhelp.moon @@ -340,7 +340,7 @@ return vgui.RegisterTable { .Paint = (_, w, h) -> draw.RoundedBox cornerRadiusBase * 1.5, 0, 0, w, h, entryColor - element = if (CAMI.PlayerHasAccess LocalPlayer!, GAMEMODE.PRIV_CHANGE_SETTINGS) and LocalPlayer!\GetNWBool "NMW AU Host" + element = if CAMI.PlayerHasAccess LocalPlayer!, GAMEMODE.PRIV_CHANGE_SETTINGS -- Show the admin stuffs to admins. switch type when "Int", "Time", "Mod" @@ -360,7 +360,14 @@ return vgui.RegisterTable { depressed = false .OnDepressed = -> depressed = true - .OnReleased = -> depressed = false + .OnReleased = -> + depressed = false + if conVarName == "sv_alltalk" + -- sending value here to server because sv_alltalk doesn't callback on client (https://github.com/Facepunch/garrysmod-issues/issues/3503) + net.Start "AU ChangeCvar" + net.WriteString conVarName + net.WriteString \GetChecked() and "0" or "1" + net.SendToServer! .Paint = (_, w, h) -> depressedPadding = w * 0.025