-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Exception now meows when an error occurs on the server #39734
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
Open
beck-thompson
wants to merge
19
commits into
space-wizards:master
Choose a base branch
from
beck-thompson:exceptoin-exception
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+169
−2
Open
Changes from 3 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
7cd7faa
Exception now meows when an error occurs
beck-thompson 42e5100
tweaks
beck-thompson 31a17a5
Add to real mouse
beck-thompson 67c6bc2
1984 :pensive:
beck-thompson f823c91
Sussy entity effect
beck-thompson 153daf4
Comment
beck-thompson 6a797df
More errors
beck-thompson 51fd143
Other fixes
beck-thompson c54be4d
opps
beck-thompson 1763a70
Merge conflict
beck-thompson 748088f
fixes
beck-thompson 0517e83
cleanup
beck-thompson 2422a67
Cleanup
beck-thompson 4ed5c2b
Merge conflicts
beck-thompson 44f58ac
Remove saving last message
beck-thompson 8f49d43
runtime as well!
beck-thompson 35a51ff
Make logger private, clean up error has occured to boolean instead of…
beck-thompson 6004ba6
Add auto pause and time offset serializer
beck-thompson 4250710
Properly block accent when speaking (sometimes)
beck-thompson File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| namespace Content.Server.RuntimeFun; | ||
|
|
||
| /// <summary> | ||
| /// Entities with this component will speak everytime an error occurs. They will say the exception | ||
| /// </summary> | ||
| [RegisterComponent] | ||
| public sealed partial class SpeakOnExceptionComponent : Component | ||
| { | ||
| /// <summary> | ||
| /// The last log that was spoken, used to ensure you don't repeat logs | ||
| /// </summary> | ||
| [DataField] | ||
| public string? LastLog; | ||
|
|
||
| /// <summary> | ||
| /// Minimum time between error speech events. | ||
| /// </summary> | ||
| [DataField] | ||
| public TimeSpan SpeechCooldown = TimeSpan.FromMinutes(1); | ||
|
|
||
| /// <summary> | ||
| /// The chance to speak without an accent. | ||
| /// </summary> | ||
| [DataField] | ||
| public float ChanceSpeakNoAccent = 0.005f; | ||
|
|
||
| /// <summary> | ||
| /// The next time the entity can say another error. | ||
| /// </summary> | ||
| [DataField] | ||
| public TimeSpan? NextTimeCanSpeak; | ||
|
|
||
| /// <summary> | ||
| /// If this component is currently trying to block accents from working. | ||
| /// </summary> | ||
| public bool BlockAccent; | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| using System.Threading; | ||
| using Content.Server.Chat.Systems; | ||
| using Content.Server.Speech; | ||
| using Content.Shared.CCVar; | ||
| using Robust.Shared.Configuration; | ||
| using Robust.Shared.Random; | ||
| using Robust.Shared.Timing; | ||
| using Serilog.Events; | ||
|
|
||
| namespace Content.Server.RuntimeFun; | ||
|
|
||
| public sealed class SpeakOnExceptionSystem : EntitySystem | ||
beck-thompson marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| { | ||
| [Dependency] private readonly ILogManager _log = default!; | ||
| [Dependency] private readonly ChatSystem _chat = default!; | ||
| [Dependency] private readonly IGameTiming _timing = default!; | ||
| [Dependency] private readonly IConfigurationManager _config = default!; | ||
| [Dependency] private readonly IRobustRandom _random = default!; | ||
|
|
||
| // Special log handler that just saves the latest error. | ||
| private SpeakOnExceptionLogHandler _logHandler = default!; | ||
|
|
||
| private bool _censor; | ||
|
|
||
| public override void Initialize() | ||
| { | ||
| base.Initialize(); | ||
|
|
||
| _logHandler = new SpeakOnExceptionLogHandler(); | ||
| _log.RootSawmill.AddHandler(_logHandler); | ||
beck-thompson marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| SubscribeLocalEvent<SpeakOnExceptionComponent, MapInitEvent>(OnMapInit); | ||
| SubscribeLocalEvent<SpeakOnExceptionComponent, TransformSpeechEvent>(OnTransformSpeech, before: [ typeof(AccentSystem) ]); | ||
|
|
||
| Subs.CVar(_config, CCVars.CensorExceptionsInChat, x => _censor = x, true); | ||
| } | ||
|
|
||
| private void OnMapInit(Entity<SpeakOnExceptionComponent> ent, ref MapInitEvent args) | ||
| { | ||
| ent.Comp.NextTimeCanSpeak = _timing.CurTime; | ||
|
|
||
| // Make sure you don't speak when spawned if an error already occured | ||
| ent.Comp.LastLog = _logHandler.LastLog; | ||
| } | ||
|
|
||
| public override void Update(float frameTime) | ||
| { | ||
| var log = _logHandler.LastLog; | ||
| if (log == null) | ||
| return; | ||
beck-thompson marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
beck-thompson marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| var query = EntityQueryEnumerator<SpeakOnExceptionComponent>(); | ||
|
|
||
| while (query.MoveNext(out var uid, out var comp)) | ||
| { | ||
| if (_timing.CurTime >= comp.NextTimeCanSpeak && log != comp.LastLog) | ||
| { | ||
| if (_random.Prob(comp.ChanceSpeakNoAccent)) | ||
| comp.BlockAccent = true; | ||
|
|
||
| _chat.TrySendInGameICMessage(uid, TryCensorMessage(log), InGameICChatType.Speak, ChatTransmitRange.Normal); | ||
| comp.BlockAccent = false; | ||
beck-thompson marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| comp.NextTimeCanSpeak += comp.SpeechCooldown; | ||
| } | ||
|
|
||
| // If the log changes when your in cooldown, you still want to update the log so it won't trigger immediately | ||
beck-thompson marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| comp.LastLog = log; | ||
| } | ||
| } | ||
|
|
||
| private void OnTransformSpeech(Entity<SpeakOnExceptionComponent> ent, ref TransformSpeechEvent args) | ||
| { | ||
| args.Cancelled |= ent.Comp.BlockAccent; | ||
| } | ||
|
|
||
| private string TryCensorMessage(string message) | ||
| { | ||
| return _censor ? Loc.GetString("speak-on-exception-censor-text") : message; | ||
| } | ||
| } | ||
|
|
||
| // Log handler for SpeakOnException entities. | ||
| public sealed class SpeakOnExceptionLogHandler : ILogHandler | ||
beck-thompson marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| { | ||
| // Last error log that occured | ||
| public string? LastLog; | ||
beck-thompson marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| public void Log(string sawmillName, LogEvent message) | ||
| { | ||
| if (message.Exception == null) | ||
| return; | ||
|
|
||
| LastLog = message.Exception.Message; | ||
| } | ||
| } | ||
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
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
1 change: 1 addition & 0 deletions
1
Resources/Locale/en-US/speak-on-exception/speak-on-exception.ftl
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| speak-on-exception-censor-text = 1984 |
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.