-
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
base: master
Are you sure you want to change the base?
Changes from 14 commits
7cd7faa
42e5100
31a17a5
67c6bc2
f823c91
153daf4
6a797df
51fd143
c54be4d
1763a70
748088f
0517e83
2422a67
4ed5c2b
44f58ac
8f49d43
35a51ff
6004ba6
4250710
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| using Content.Shared.Dataset; | ||
| using Robust.Shared.Prototypes; | ||
|
|
||
| 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> | ||
| /// Localized dataset used when speaking | ||
| /// </summary> | ||
| [DataField] | ||
| public ProtoId<LocalizedDatasetPrototype> Dataset = "ExceptionSpeechDataset"; | ||
|
|
||
| /// <summary> | ||
| /// The next time the entity can say another error. | ||
| /// </summary> | ||
| [DataField] | ||
| public TimeSpan? NextTimeCanSpeak; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This needs to use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I also added the auto pause fields which I think are also needed - let me know if they aren't (The documentation kina makes them sound like they should be added?) |
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| using Content.Server.Chat.Systems; | ||
| using Content.Server.Speech; | ||
| using Content.Shared.Chat; | ||
| using Robust.Shared.Prototypes; | ||
| 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 IRobustRandom _random = default!; | ||
| [Dependency] private readonly IPrototypeManager _proto = default!; | ||
|
|
||
| // Special log handler that just saves the latest error. | ||
| private SpeakOnExceptionLogHandler _logHandler = default!; | ||
|
|
||
| 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) ]); | ||
| } | ||
|
|
||
| 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) | ||
| { | ||
| _chat.TrySendInGameICMessage(uid, CensorMessage(comp), InGameICChatType.Speak, ChatTransmitRange.Normal, true); | ||
|
|
||
| comp.NextTimeCanSpeak += comp.SpeechCooldown; | ||
| } | ||
|
|
||
| // If the log changes when you're in cooldown, you still want to update the log so it won't trigger immediately | ||
| comp.LastLog = log; | ||
| } | ||
| } | ||
|
|
||
| private void OnTransformSpeech(Entity<SpeakOnExceptionComponent> ent, ref TransformSpeechEvent args) | ||
| { | ||
| if (_random.Prob(ent.Comp.ChanceSpeakNoAccent)) | ||
| args.Cancel(); | ||
| } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will apply to all speech, not just error messages, no? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep I think it will! Changed it due to #39734 (comment) - but apparently I did that for a reason but I got myself confused and got rid of it 😆 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is not mentioned in the PR description and I do not think this is a good feature to have. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It now works proplerly - I personally think its fun. |
||
|
|
||
| private string CensorMessage(SpeakOnExceptionComponent comp) | ||
| { | ||
| return Loc.GetString(_random.Pick(_proto.Index(comp.Dataset).Values)); | ||
| } | ||
|
|
||
| public override void Shutdown() | ||
| { | ||
| _log.RootSawmill.RemoveHandler(_logHandler); | ||
| } | ||
| } | ||
|
|
||
| // 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; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| exception-censored-1 = called `Option::unwrap()` on a `None` value` | ||
| exception-censored-2 = SyntaxError: invalid syntax | ||
| exception-censored-3 = java.lang.NullPointerException: Cannot invoke "com.spacestation14.ss14.Cat.meow(java.lang.String)" because the return value of "com.spacestation14.robusttoolbox.Utils.getCatSound()" is null | ||
| exception-censored-4 = Error: Can't open display: :3 | ||
| exception-censored-5 = Segmentation fault (core dumped) | ||
| exception-censored-6 = cat-speech-dataset-120 | ||
| exception-censored-7 = Can't resolve "Robust.Shared.GameObjects.MetaDataComponent" on entity 5233063! | ||
| exception-censored-8 = Uncaught ReferenceError: meow is not defined | ||
| exception-censored-9 = TabError: inconsistent use of tabs and spaces in indentation | ||
| exception-censored-10 = code.dm:3:error: meow: undefined proc | ||
| exception-censored-11 = Failed to wipe mind: Exception |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| - type: localizedDataset | ||
| id: ExceptionSpeechDataset | ||
| values: | ||
| prefix: exception-censored- | ||
| count: 11 |
Uh oh!
There was an error while loading. Please reload this page.