Add runtime toggles for global and group chat - #236
Open
Zaldaryon wants to merge 1 commit into
Open
Conversation
Fixes #218. CmdStratumStaffCommands.OnPlayerChat already carried channelId and had a staff bypass; this adds a per-channel check ahead of that bypass so the exemption can actually be turned off. Chat.Global and Chat.Groups each get Enabled, AllowStaffBypass, and DisabledMessage. Defaults preserve current behavior. /chattoggle mirrors /lockchat and /slowmode, shares the ChatControl privilege, no new privilege or catalog entry. /stratum set works too with zero new command code.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #218.
What
Two independent runtime toggles,
Chat.Global.EnabledandChat.Groups.Enabled. Each channel also getsAllowStaffBypass(default on) and aDisabledMessageshown to a blocked sender. Config-backed, so it survives a restart, unlike/lockchatwhich is session state.No new command needed either,
/stratum set Chat.Global.Enabled falseworks today through the existing reflection path./announce,/staffbroadcast, and slash commands are untouched. They never go throughOnPlayerChat.Where it hooks and why
CmdStratumStaffCommands.OnPlayerChatalready runs the mute check, then an unconditional staff bypass, then the chat lock and slowmode checks. I put the new check between the mute check and the bypass, not after it. The bypass at that point returns unconditionally, so if the per-channel check came after it,AllowStaffBypass = falsewould be dead code, staff would always get through regardless of the setting.StratumChatConfig.ChannelFor(channelId)maps0to Global, any positive group id to Groups, and returns null for the negative server channels (ServerInfo, DamageLog, InfoLog, AllChatGroups). Those are server-to-client only, never reachable from a player chat packet, left alone.Kept it independent of the existing
Chat.Enabledflag. That one only gates role-prefix formatting. If the new toggles read it too, disabling formatting would silently re-enable a channel someone had turned off on purpose.A tradeoff worth flagging
The staff exemption reuses the existing
Commands.ChatControlprivilege (stratum.chatcontrol) instead of adding a new one. Simpler, no new config block, no new catalog entry, matches what/lockchat's bypass already uses. The cost: if an operator disables theChatControlcommand block entirely, the staff exemption goes with it, sincePlayerHasAccesschecks that block's ownEnabledflag. Recoverable from console (console callers always pass the check) or by hand-editingstratum.json. Same behavior/lockchatalready has, not a new failure mode, but worth knowing before merge.Testing
No test project in this repo, so this follows the usual live-boot convention.
dotnet build VintageStory.slnx -c Release, zero warnings on the touched files.dataPathboot, reachesRunGame, no fatal errors.stratum.jsonwritesChat.GlobalandChat.Groupswith correct defaults,ConfigVersionunchanged.stratum.json, setChat.Global.Enabled = falsewith a custom message, deleted theChat.Groupsblock outright, restarted. The custom Global value survived, the deleted Groups block came back with the right defaults throughEnsurePopulated./chattoggle global offwithAllowStaffBypassat its default (true): staff message still delivered/stratum set Chat.Global.AllowStaffBypass false, same account, same channel: message blocked, disabled message shown client-side/announcedelivered with global chat off, confirms it doesn't route through the hook/chattoggle statusand the on/off/toggle modes all exercised through the actual command, not just read from sourceThat last live pass caught a real bug before it shipped: the arg parser accepts
statusas a value for themodeargument too (/chattoggle global status), but the original handler only checked foron/offand fell through to the toggle branch for anything else,statusincluded. Typing/chattoggle global statusexpecting a read would have flipped the channel instead. Fixed by handlingmode == "status"as its own branch before the mutation path, verified against the same build.@trevorftp @tehtelev