Skip to content

Expose team changes and settings to APIs#46

Merged
Extremelyd1 merged 21 commits intoExtremelyd1:mainfrom
Liparakis:main
Apr 6, 2026
Merged

Expose team changes and settings to APIs#46
Extremelyd1 merged 21 commits intoExtremelyd1:mainfrom
Liparakis:main

Conversation

@Liparakis
Copy link
Copy Markdown
Contributor

@Liparakis Liparakis commented Mar 31, 2026

What Changed

This PR adds addon-facing client/server API hooks around shared multiplayer state and removes a couple of rough edges from the initial implementation.

Main changes since 4d6c01f:

  • Added IClientManager.Id so addons can access the local player's assigned network ID on the client.
  • Added IClientManager.ServerSettings so addons can read the current shared gameplay settings on the client.
  • Exposed change notifications on IServerSettings through OnChanged, which is now the single client-side settings change hook.
  • Added OnTeamChanged to both IClientPlayer and IServerPlayer.
  • Updated ClientPlayerData and ServerPlayerData so team property changes raise OnTeamChanged.
  • Updated the client connect path to create/store the local ClientPlayerData using SelfId.
  • Updated the local team-change path so the local player's ClientPlayerData.Team is also updated, making IClientPlayer.OnTeamChanged work for self as well as remote players.

Why

The goal of the PR is to support four addon use cases cleanly:

  • read server settings on the client
  • react when server settings change
  • react when a player changes team
  • read the local player's own ID on the client

- Add `Id` property to `IClientManager` for local player identification.
- Add `OnChanged` event to `IServerSettings` to track server-side setting updates on the client.
- Add `OnTeamChanged` event to `IClientPlayer` for per-player team tracking.
- Update `ServerManager` to include the connecting player's ID and username in the initial `ServerInfo` handshake.
- Implement automatic local ID resolution in `ClientManager` upon successful connection.
@Liparakis Liparakis marked this pull request as draft March 31, 2026 09:42
@Liparakis Liparakis closed this Mar 31, 2026
@Liparakis Liparakis reopened this Mar 31, 2026
@Liparakis Liparakis marked this pull request as ready for review March 31, 2026 12:51
Copy link
Copy Markdown
Owner

@Extremelyd1 Extremelyd1 left a comment

Choose a reason for hiding this comment

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

Thanks for the PR, changes to the API are always welcome.
I've left a few comments about simple things, but I would like you to revert exposing the local player's network ID as discussed, since it is unnecessary.

@Liparakis Liparakis requested a review from Extremelyd1 April 6, 2026 11:15
@Liparakis
Copy link
Copy Markdown
Contributor Author

I reverted the UserID exposure and applied the fixes you requested. Also i implemented an Interface under the API which allows addon to read ModSettings and Subscribe to the ChangedEvent.

@BobbyTheCatfish
Copy link
Copy Markdown
Contributor

Just a thought, maybe there should be an event on ClientManager for when your own team changes? And maybe an event for when any player's team changes so that you don't have to hook each player individually? Something like OwnTeamChangeEvent and PlayerTeamChangeEvent, (but with better names ofc)?

@Extremelyd1
Copy link
Copy Markdown
Owner

@Liparakis do you want to implement those additions from @BobbyTheCatfish still in this PR before I review?

@Liparakis
Copy link
Copy Markdown
Contributor Author

@Extremelyd1 Extremelyd1 removed their request for review April 6, 2026 15:34
@Liparakis Liparakis requested a review from Extremelyd1 April 6, 2026 16:09
Copy link
Copy Markdown
Owner

@Extremelyd1 Extremelyd1 left a comment

Choose a reason for hiding this comment

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

A couple of comments for some unintended behaviour.

Also, when reading Bobby's comment I thought that it might be better if we either move the TeamChangedEvent from IServerPlayer (on the server-side) to IServerManager and have it be an Action<IServerPlayer, Team> so it is easier to deal with.
Then, you can also hook team changes server-side in general, without having to hook every individual player. Otherwise, if an addon needs to deal with team changes globally they'd need to hook PlayerConnectEvent, then hook the TeamChangedEvent. And probably for cleanup, you'd need to hook PlayerDisconnectEvent also to remove the hook on TeamChangedEvent for the player. Otherwise, GC won't kick in because of references.

@Liparakis Liparakis requested a review from Extremelyd1 April 6, 2026 17:32
- Move team change event to dedicated player manager
- Remove redundant access modifiers
- Remove team change event from client player data
- Inherit documentation from interface
- Change naming of added events
- Make Team property in client manager obsolete
- Remove empty spaces in reason message
Copy link
Copy Markdown
Owner

@Extremelyd1 Extremelyd1 left a comment

Choose a reason for hiding this comment

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

I've done some additional cleanup.
Most impactful is that I've moved the team change events on the client-side to a separate interface IPlayerManager that more closely resembles the underlying implementation.

@Extremelyd1 Extremelyd1 changed the title Property Observation & API Exposure Expose team changes and settings to APIs Apr 6, 2026
@Extremelyd1 Extremelyd1 merged commit 6b67a98 into Extremelyd1:main Apr 6, 2026
3 checks passed
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.

3 participants