RobustToolbox icon indicating copy to clipboard operation
RobustToolbox copied to clipboard

Add `SharedOnlyEventAttribute` and analyzer

Open Tayrtahn opened this issue 4 months ago • 3 comments

Adds an attribute that can be applied to event structs/classes to indicate that they should only be subscribed to in Shared code. Subscriptions to the event in Server-only code will raise a warning.

Applying the attribute to GetVerbsEvent: Screenshot 2025-08-03 at 6 34 31 PM

Warning on a server-only subscription: Screenshot 2025-08-03 at 3 53 17 PM

The attribute also has an optional parameter, AllowClientOnly which defaults to true. If true, subscriptions are also allowed in Client-only code. In most potential use cases (verbs, examines), Client-only subscriptions are fine.

This feature was requested by @slarticodefast to help enforce https://github.com/space-wizards/space-station-14/issues/39286 - subscribing to GetVerbsEvent in server-only code causes the verbs menu to jump around, because it is first populated client-side with Client and Shared verbs, then gets rebuilt when the server sends its version containing new entries. This is a major annoyance for players, and has caused problems where admins accidentally trigger actions on players while trying to use examining verbs on them.

Tayrtahn avatar Aug 03 '25 22:08 Tayrtahn

Good freakin shit man!

VerinSenpai avatar Aug 03 '25 23:08 VerinSenpai

This engine clearly needs more cool analyzers. Awesome.

TornadoTechnology avatar Aug 05 '25 04:08 TornadoTechnology

Would it not make more sense to have an attribute that worked with bitflags? Like [NetworkSideOnly(Shared | Client)]?

Yeah, I was thinking that too. Figured I'd do it this way first and upgrade to that if desired. I'll get on it.

Tayrtahn avatar Aug 05 '25 14:08 Tayrtahn