@@ -257,7 +257,7 @@ public async Task<IReadOnlyList<MonumentSnapshot>> GetMonumentsAsync(
257257 return null ;
258258 }
259259
260- return await live . Connection . GetSmartSwitchInfoAsync ( entityId , _options . HeartbeatTimeout , cancellationToken )
260+ return await live . Connection . GetSmartDeviceInfoAsync ( entityId , _options . HeartbeatTimeout , cancellationToken )
261261 . ConfigureAwait ( false ) ;
262262 }
263263
@@ -467,20 +467,20 @@ void OnTeamMessage(object? sender, TeamChatLine line)
467467 var dims = await connection . GetMapDimensionsAsync ( _options . HeartbeatTimeout , ct ) . ConfigureAwait ( false ) ;
468468 var rigs = await GetRigPositionsAsync ( key . Server , connection , ct ) . ConfigureAwait ( false ) ;
469469
470- #pragma warning disable RCS1163 // Unused 'sender': required by the EventHandler<ulong > delegate shape.
471- void OnSmartSwitch ( object ? sender , ulong entityId )
470+ #pragma warning disable RCS1163 // Unused 'sender': required by the EventHandler<SmartDeviceTrigger > delegate shape.
471+ void OnSmartDevice ( object ? sender , SmartDeviceTrigger trigger )
472472 {
473- // Fire-and-forget: PublishSwitchStateAsync catches everything internally, so the discarded task never
474- // surfaces an unobserved exception. Switch triggers are low-volume, so unbounded concurrency is fine.
475- _ = PublishSwitchStateAsync ( key , connection , entityId ) ;
473+ // Fire-and-forget: PublishDeviceTriggerAsync catches everything internally, so the discarded task never
474+ // surfaces an unobserved exception. Device triggers are low-volume, so unbounded concurrency is fine.
475+ _ = PublishDeviceTriggerAsync ( key , trigger ) ;
476476 }
477477#pragma warning restore RCS1163
478478
479479 var tracker = new TeamStateTracker ( ) ;
480480 connection . TeamMessageReceived += OnTeamMessage ;
481- connection . SmartSwitchTriggered += OnSmartSwitch ;
481+ connection . SmartDeviceTriggered += OnSmartDevice ;
482482 _liveSockets [ key ] = new LiveSocket ( connection , activeSteamId , tracker ) ;
483- await PrimeSwitchesAsync ( key , connection , ct ) . ConfigureAwait ( false ) ;
483+ await PrimeDevicesAsync ( key , connection , ct ) . ConfigureAwait ( false ) ;
484484 using var pollCts = CancellationTokenSource . CreateLinkedTokenSource ( ct ) ;
485485 var markerPoll = Task . Run ( ( ) => PollMarkersAsync ( key , connection , dims , rigs , tracker , pollCts . Token ) ,
486486 CancellationToken . None ) ;
@@ -521,7 +521,7 @@ await PublishStatusAsync(key, ConnectionStatus.Connected, beat.PlayerCount, cred
521521
522522 _liveSockets . TryRemove ( key , out _ ) ;
523523 connection . TeamMessageReceived -= OnTeamMessage ;
524- connection . SmartSwitchTriggered -= OnSmartSwitch ;
524+ connection . SmartDeviceTriggered -= OnSmartDevice ;
525525 }
526526 }
527527
@@ -799,7 +799,7 @@ private async Task PublishTeamMessageAsync((ulong Guild, Guid Server) key, ulong
799799 }
800800 }
801801
802- private async Task PrimeSwitchesAsync (
802+ private async Task PrimeDevicesAsync (
803803 ( ulong Guild , Guid Server ) key ,
804804 IRustServerConnection connection ,
805805 CancellationToken ct )
@@ -823,7 +823,7 @@ private async Task PrimeSwitchesAsync(
823823#pragma warning restore CA1031
824824 {
825825 // Best-effort: a store/DB failure must not crash the connected loop or block the heartbeat.
826- LogSwitchListFailed ( logger , ex , key . Server ) ;
826+ LogDeviceListFailed ( logger , ex , key . Server ) ;
827827 return ;
828828 }
829829
@@ -834,7 +834,7 @@ private async Task PrimeSwitchesAsync(
834834 // Best-effort per switch: one failure must not crash the connected loop or block the heartbeat.
835835 try
836836 {
837- await PublishSwitchStateAsync ( key , connection , sw . EntityId ) . ConfigureAwait ( false ) ;
837+ await PublishDevicePrimeAsync ( key , connection , sw . EntityId ) . ConfigureAwait ( false ) ;
838838 }
839839 catch ( OperationCanceledException )
840840 {
@@ -844,12 +844,47 @@ private async Task PrimeSwitchesAsync(
844844 catch ( Exception ex )
845845#pragma warning restore CA1031
846846 {
847- LogSwitchPrimeFailed ( logger , ex , sw . EntityId , key . Server ) ;
847+ LogDevicePrimeFailed ( logger , ex , sw . EntityId , key . Server ) ;
848848 }
849849 }
850850 }
851851
852- private async Task PublishSwitchStateAsync (
852+ /// <summary>Trigger path: IsActive is carried on the broadcast arg — no re-read.</summary>
853+ /// <param name="key">The (guild, server) routing key.</param>
854+ /// <param name="trigger">The device trigger carrying the entity id and active state.</param>
855+ private async Task PublishDeviceTriggerAsync (
856+ ( ulong Guild , Guid Server ) key ,
857+ SmartDeviceTrigger trigger )
858+ {
859+ if ( _disposed )
860+ {
861+ return ;
862+ }
863+
864+ try
865+ {
866+ await eventBus . PublishAsync (
867+ new SmartDeviceTriggeredEvent ( key . Guild , key . Server , trigger . EntityId , trigger . IsActive ) ,
868+ _shutdown . Token )
869+ . ConfigureAwait ( false ) ;
870+ }
871+ catch ( OperationCanceledException )
872+ {
873+ // Shutting down.
874+ }
875+ #pragma warning disable CA1031 // Broad catch: a device publish failure must not crash the socket callback.
876+ catch ( Exception ex )
877+ #pragma warning restore CA1031
878+ {
879+ LogDevicePublishFailed ( logger , ex , trigger . EntityId , key . Server ) ;
880+ }
881+ }
882+
883+ /// <summary>Prime path: read state on connect (also primes the socket's interest), then publish.</summary>
884+ /// <param name="key">The (guild, server) routing key.</param>
885+ /// <param name="connection">The live connection used to read device state.</param>
886+ /// <param name="entityId">The entity id of the device to prime.</param>
887+ private async Task PublishDevicePrimeAsync (
853888 ( ulong Guild , Guid Server ) key ,
854889 IRustServerConnection connection ,
855890 ulong entityId )
@@ -862,22 +897,22 @@ private async Task PublishSwitchStateAsync(
862897 try
863898 {
864899 var isActive = await connection
865- . GetSmartSwitchInfoAsync ( entityId , _options . HeartbeatTimeout , _shutdown . Token )
900+ . GetSmartDeviceInfoAsync ( entityId , _options . HeartbeatTimeout , _shutdown . Token )
866901 . ConfigureAwait ( false ) ;
867902 await eventBus . PublishAsync (
868- new SwitchStateChangedEvent ( key . Guild , key . Server , entityId , isActive ?? false ) ,
903+ new SmartDeviceTriggeredEvent ( key . Guild , key . Server , entityId , isActive ?? false ) ,
869904 _shutdown . Token )
870905 . ConfigureAwait ( false ) ;
871906 }
872907 catch ( OperationCanceledException )
873908 {
874909 // Shutting down.
875910 }
876- #pragma warning disable CA1031 // Broad catch: a switch publish failure must not crash the socket callback.
911+ #pragma warning disable CA1031 // Broad catch: a device prime failure must not crash the socket callback.
877912 catch ( Exception ex )
878913#pragma warning restore CA1031
879914 {
880- LogSwitchPublishFailed ( logger , ex , entityId , key . Server ) ;
915+ LogDevicePublishFailed ( logger , ex , entityId , key . Server ) ;
881916 }
882917 }
883918
@@ -897,16 +932,16 @@ await eventBus.PublishAsync(
897932 private static partial void LogPublishTeamMessageFailed ( ILogger logger , Exception exception , Guid serverId ) ;
898933
899934 [ LoggerMessage ( Level = LogLevel . Warning ,
900- Message = "Listing smart switches to prime on server {ServerId} failed; priming skipped for this connection." ) ]
901- private static partial void LogSwitchListFailed ( ILogger logger , Exception exception , Guid serverId ) ;
935+ Message = "Listing smart devices to prime on server {ServerId} failed; priming skipped for this connection." ) ]
936+ private static partial void LogDeviceListFailed ( ILogger logger , Exception exception , Guid serverId ) ;
902937
903- [ LoggerMessage ( Level = LogLevel . Warning , Message = "Priming smart switch {EntityId} on server {ServerId} failed." ) ]
938+ [ LoggerMessage ( Level = LogLevel . Warning , Message = "Priming smart device {EntityId} on server {ServerId} failed." ) ]
904939 private static partial void
905- LogSwitchPrimeFailed ( ILogger logger , Exception exception , ulong entityId , Guid serverId ) ;
940+ LogDevicePrimeFailed ( ILogger logger , Exception exception , ulong entityId , Guid serverId ) ;
906941
907942 [ LoggerMessage ( Level = LogLevel . Warning ,
908- Message = "Publishing a smart-switch state for entity {EntityId} on server {ServerId} failed." ) ]
909- private static partial void LogSwitchPublishFailed ( ILogger logger ,
943+ Message = "Publishing a smart-device state for entity {EntityId} on server {ServerId} failed." ) ]
944+ private static partial void LogDevicePublishFailed ( ILogger logger ,
910945 Exception exception ,
911946 ulong entityId ,
912947 Guid serverId ) ;
0 commit comments