Skip to content

Commit

Permalink
feat: IsConnecting and IsConnected helper methods to NetworkPlayer
Browse files Browse the repository at this point in the history
  • Loading branch information
James-Frowen committed Jul 9, 2024
1 parent c76b88a commit d722758
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 10 deletions.
28 changes: 20 additions & 8 deletions Assets/Mirage/Runtime/INetworkPlayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,28 @@ public interface IObjectOwner
/// </summary>
public interface INetworkPlayer : IMessageSender, IVisibilityTracker, IObjectOwner, ISceneLoader
{
SocketLayer.IEndPoint Address { get; }
SocketLayer.IConnection Connection { get; }
IConnection Connection { get; }

/// <summary>
/// The IP address / URL / FQDN associated with the connection.
/// Can be useful for a game master to do IP Bans etc.
/// <para>
/// Best used to get concrete Endpoint type based on the <see cref="SocketFactory"/> being used
/// </para>
/// </summary>
IEndPoint Address { get; }

/// <summary>Connect called on client, but server has not replied yet</summary>
bool IsConnecting { get; }

/// <summary>Server and Client are connected and can send messages</summary>
bool IsConnected { get; }

PlayerAuthentication Authentication { get; }
void SetAuthentication(PlayerAuthentication authentication, bool allowReplace = false);
bool IsAuthenticated { get; }
/// <summary>
/// True if this Player is the local player on the server or client
/// </summary>

/// <summary>True if this Player is the local player on the server or client</summary>
bool IsHost { get; }

void Disconnect();
Expand All @@ -136,9 +150,7 @@ public interface INetworkPlayer : IMessageSender, IVisibilityTracker, IObjectOwn

public interface ISceneLoader
{
/// <summary>
/// Scene is fully loaded and we now can do things with player.
/// </summary>
/// <summary>Scene is fully loaded and we now can do things with player.</summary>
bool SceneIsReady { get; set; }
}
}
2 changes: 1 addition & 1 deletion Assets/Mirage/Runtime/NetworkIdentity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -950,7 +950,7 @@ internal void AddObserver(INetworkPlayer player)
return;
}

if (logger.LogEnabled()) logger.Log($"Adding '{player.Connection.EndPoint}' as an observer for {gameObject}");
if (logger.LogEnabled()) logger.Log($"Adding '{player}' as an observer for {gameObject}");
observers.Add(player);
player.AddToVisList(this);

Expand Down
11 changes: 10 additions & 1 deletion Assets/Mirage/Runtime/NetworkPlayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,22 @@ public void SetAuthentication(PlayerAuthentication authentication, bool allowRep
/// </summary>
public bool HasCharacter => Identity != null;

public IConnection Connection => _connection;

/// <summary>
/// The IP address / URL / FQDN associated with the connection.
/// Can be useful for a game master to do IP Bans etc.
/// <para>
/// Best used to get concrete Endpoint type based on the <see cref="SocketFactory"/> being used
/// </para>
/// </summary>
public IEndPoint Address => _connection.EndPoint;

public IConnection Connection => _connection;
/// <summary>Connect called on client, but server has not replied yet</summary>
public bool IsConnecting => _connection.State == ConnectionState.Connecting;

/// <summary>Server and Client are connected and can send messages</summary>
public bool IsConnected => _connection.State == ConnectionState.Connected;

/// <summary>
/// List of all networkIdentity that this player can see
Expand Down

0 comments on commit d722758

Please sign in to comment.