Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Made it possible to change gamesettings in the f1-menu on dedicated servers #90

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions src/gamemodes/amongus/gamemode/cl_net.moon
Original file line number Diff line number Diff line change
Expand Up @@ -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!
42 changes: 33 additions & 9 deletions src/gamemodes/amongus/gamemode/shared.moon
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
33 changes: 33 additions & 0 deletions src/gamemodes/amongus/gamemode/sv_net.moon
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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!
11 changes: 9 additions & 2 deletions src/gamemodes/amongus/gamemode/vgui/vgui_showhelp.moon
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand Down