Expose team changes and settings to APIs#46
Conversation
- 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.
Extremelyd1
left a comment
There was a problem hiding this comment.
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.
…ce and applied naming fixes.
|
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 |
|
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 |
|
@Liparakis do you want to implement those additions from @BobbyTheCatfish still in this PR before I review? |
Extremelyd1
left a comment
There was a problem hiding this comment.
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.
- 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
Extremelyd1
left a comment
There was a problem hiding this comment.
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.

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:IClientManager.Idso addons can access the local player's assigned network ID on the client.IClientManager.ServerSettingsso addons can read the current shared gameplay settings on the client.IServerSettingsthroughOnChanged, which is now the single client-side settings change hook.OnTeamChangedto bothIClientPlayerandIServerPlayer.ClientPlayerDataandServerPlayerDataso team property changes raiseOnTeamChanged.ClientPlayerDatausingSelfId.ClientPlayerData.Teamis also updated, makingIClientPlayer.OnTeamChangedwork for self as well as remote players.Why
The goal of the PR is to support four addon use cases cleanly: