Skip to content

feat: raise OnTeamChanged for AppTeamChanged broadcasts - #107

Merged
HandyS11 merged 1 commit into
developfrom
feat/team-changed-broadcast
Jul 24, 2026
Merged

feat: raise OnTeamChanged for AppTeamChanged broadcasts#107
HandyS11 merged 1 commit into
developfrom
feat/team-changed-broadcast

Conversation

@HandyS11

Copy link
Copy Markdown
Owner

Problem

The AppBroadcast.team_changed variant (proto field 4, AppTeamChanged) was defined and code-generated, but RustPlus.ParseNotification had no branch for it — so every team-snapshot change broadcast fell straight through to Logger.LogUnknownBroadcast(broadcast) and was silently dropped. Unlike the five sibling broadcasts (EntityChanged, TeamMessage, ClanMessage, ClanChanged, CameraRays), the entire vertical slice was missing.

Fix

Mirrors the existing ClanChanged pattern end-to-end:

Area Change
Model New TeamChangedEventArg record — PlayerId (ulong) + TeamInfo?
Mapper New AppTeamChanged.ToTeamChangedEvent() (reuses existing ToTeamInfo())
Client New OnTeamChanged event + dispatch branch in ParseNotification
Contract OnTeamChanged declared on IRustPlus
Docs Added to the events table in rustplus-client.md
Sample LiveEvents console feature now subscribes to OnTeamChanged

Tests

  • TeamInfoMapperTests.ToTeamChangedEvent_MapsPlayerIdAndTeamInfo
  • RustPlusParseNotificationTests.TeamChanged_WithSubscriber_InvokesHandler
  • RustPlusParseNotificationTests.TeamChanged_NoSubscriber_DoesNotThrow

Both dispatch branches (subscriber / no-subscriber) and the mapper are covered.

Verification

  • dotnet build RustPlusApi.sln — clean (TreatWarningsAsErrors)
  • Unit tests pass on the net10.0 host (132 passed). The net8.0 runtime (netstandard2.0 build) isn't installed locally; CI covers both TFMs. The touched code has no #if forks.
  • ReSharper pre-push formatting check passed.

🤖 Generated with Claude Code

The AppBroadcast.team_changed variant (proto field 4) was defined and
code-generated but never handled in ParseNotification, so every team
snapshot change fell through to LogUnknownBroadcast and was silently
dropped.

Wire up the full slice, mirroring the existing ClanChanged pattern:
- TeamChangedEventArg (PlayerId + TeamInfo)
- AppTeamChanged.ToTeamChangedEvent() mapper (reuses ToTeamInfo)
- OnTeamChanged event on RustPlus and IRustPlus
- dispatch branch in ParseNotification

Also documents the event in the client reference table and subscribes
the console sample's LiveEvents to it. Adds unit tests covering the
mapper and both dispatch branches (subscriber + no-subscriber).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings July 24, 2026 09:43

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds first-class support for the AppBroadcast.team_changed (AppTeamChanged) broadcast in the core RustPlusApi client, exposing it as a new OnTeamChanged event with model mapping and unit test coverage (plus sample + docs updates).

Changes:

  • Introduced TeamChangedEventArg, AppTeamChanged.ToTeamChangedEvent(), and a new RustPlus.OnTeamChanged dispatch branch in ParseNotification.
  • Extended the public IRustPlus contract with OnTeamChanged, and updated docs + console sample to surface the new event.
  • Added unit tests covering both mapper correctness and subscriber/no-subscriber dispatch behavior.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
tests/RustPlusApi.UnitTests/TeamInfoMapperTests.cs Adds mapper test for AppTeamChanged → TeamChangedEventArg.
tests/RustPlusApi.UnitTests/RustPlusParseNotificationTests.cs Adds notification-dispatch tests for the new TeamChanged branch.
src/RustPlusApi/RustPlus.cs Adds OnTeamChanged event and dispatch branch in ParseNotification.
src/RustPlusApi/Interfaces/IRustPlus.cs Exposes OnTeamChanged on the public interface contract.
src/RustPlusApi/Extensions/AppTeamInfoToModel.cs Adds ToTeamChangedEvent() mapping extension.
src/RustPlusApi/Data/Events/TeamChangedEventArg.cs Introduces new event-arg type for team snapshot changes.
samples/RustPlus.ConsoleApp/Features/LiveEvents.cs Subscribes to and displays OnTeamChanged in the sample console app.
docs/articles/rustplus-client.md Documents the new public event in the events table.

Comment on lines +37 to +39
/// <summary>Raised when the team snapshot changes.</summary>
event EventHandler<TeamChangedEventArg>? OnTeamChanged;

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct that adding an interface member is source-breaking for external implementers, but this follows the established convention of the library: all seven existing broadcast events (OnEntityChanged, OnSmartDeviceTriggered, OnStorageMonitorTriggered, OnTeamChatReceived, OnClanChatReceived, OnClanChanged, OnCameraRaysReceived) are declared directly on IRustPlusOnEntityChanged was added the same way in #95. IRustPlus is the single canonical contract here; introducing a separate IRustPlusTeamChangedEvents would fragment it and break that consistency for no real gain while the package is still in beta. Keeping it on IRustPlus intentionally.

@@ -0,0 +1,11 @@
namespace RustPlusApi.Data.Events;

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a false positive — the code compiles as-is (clean build + all unit tests pass). TeamInfo lives in RustPlusApi.Data, and this file's namespace is RustPlusApi.Data.Events, a child namespace, so the parent RustPlusApi.Data is already in scope for name resolution. ClanChangedEventArg needs its explicit using RustPlusApi.Data.Clans only because ClanInfo sits in a sibling namespace, not an ancestor. Adding using RustPlusApi.Data; here would be a redundant using directive that the ReSharper cleanup profile strips. No change needed.

@HandyS11
HandyS11 merged commit 1edb2a5 into develop Jul 24, 2026
6 checks passed
@HandyS11
HandyS11 deleted the feat/team-changed-broadcast branch July 24, 2026 10:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants