Skip to content

Commit

Permalink
Add OnPlayerJoin and OnPlayerLeft events to API
Browse files Browse the repository at this point in the history
  • Loading branch information
limoka committed Mar 18, 2022
1 parent 52b3b98 commit 75589c2
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 0 deletions.
13 changes: 13 additions & 0 deletions NebulaAPI/NebulaModAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,19 @@ public static IMultiplayerSession MultiplayerSession
/// </summary>
public static Action<int> OnPlanetLoadFinished;

/// <summary>
/// Subscribe to receive even when a new player joins the game.
/// The event fires right after the player starts to load in the save data
/// <see cref="IPlayerData"/>> player - info about the player
/// </summary>
public static Action<IPlayerData> OnPlayerJoinedGame;

/// <summary>
/// Subscribe to receive even when a new player leaves the game
/// <see cref="IPlayerData"/>> player - info about the player
/// </summary>
public static Action<IPlayerData> OnPlayerLeftGame;

private void Awake()
{
nebulaIsInstalled = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ public override void ProcessPacket(LobbyRequest packet, NebulaConnection conn)
}

Multiplayer.Session.World.OnPlayerJoining(player.Data.Username);
NebulaModAPI.OnPlayerJoinedGame?.Invoke(player.Data);

// Make sure that each player that is currently in the game receives that a new player as join so they can create its RemotePlayerCharacter
PlayerJoining pdata = new PlayerJoining((PlayerData)player.Data.CreateCopyWithoutMechaData()); // Remove inventory from mecha data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public override void ProcessPacket(StartGameMessage packet, NebulaConnection con
}

Multiplayer.Session.World.OnPlayerJoining(player.Data.Username);
NebulaModAPI.OnPlayerJoinedGame?.Invoke(player.Data);

// Make sure that each player that is currently in the game receives that a new player as join so they can create its RemotePlayerCharacter
PlayerJoining pdata = new PlayerJoining((PlayerData)player.Data.CreateCopyWithoutMechaData()); // Remove inventory from mecha data
Expand Down
1 change: 1 addition & 0 deletions NebulaNetwork/PlayerManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ public void PlayerDisconnected(INebulaConnection conn)
if (player != null)
{
SendPacketToOtherPlayers(new PlayerDisconnected(player.Id), player);
NebulaModAPI.OnPlayerLeftGame?.Invoke(player.Data);
Multiplayer.Session.World.DestroyRemotePlayerModel(player.Id);
using (threadSafe.availablePlayerIds.GetLocked(out Queue<ushort> availablePlayerIds))
{
Expand Down

0 comments on commit 75589c2

Please sign in to comment.