Skip to content

Commit

Permalink
fix: add nullable to event invokes (#554)
Browse files Browse the repository at this point in the history
  • Loading branch information
uweeby committed Jan 27, 2021
1 parent a0e416b commit 8236614
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 24 deletions.
4 changes: 2 additions & 2 deletions Assets/Mirror/Runtime/NetworkClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ async UniTaskVoid OnConnected()
// the handler may want to send messages to the client
// thus we should set the connected state before calling the handler
connectState = ConnectState.Connected;
Connected.Invoke(Connection);
Connected?.Invoke(Connection);

// start processing messages
try
Expand All @@ -235,7 +235,7 @@ async UniTaskVoid OnConnected()
{
Cleanup();

Disconnected.Invoke();
Disconnected?.Invoke();
}
}

Expand Down
16 changes: 8 additions & 8 deletions Assets/Mirror/Runtime/NetworkIdentity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -653,12 +653,12 @@ internal void StartServer()
{
if (logger.LogEnabled()) logger.Log("OnStartServer " + this + " NetId:" + NetId + " SceneId:" + sceneId);

OnStartServer.Invoke();
OnStartServer?.Invoke();
}

internal void StopServer()
{
OnStopServer.Invoke();
OnStopServer?.Invoke();
}

bool clientStarted;
Expand All @@ -668,7 +668,7 @@ internal void StartClient()
return;
clientStarted = true;

OnStartClient.Invoke();
OnStartClient?.Invoke();
}

bool localPlayerStarted;
Expand All @@ -678,7 +678,7 @@ internal void StartLocalPlayer()
return;
localPlayerStarted = true;

OnStartLocalPlayer.Invoke();
OnStartLocalPlayer?.Invoke();
}

bool hadAuthority;
Expand All @@ -693,12 +693,12 @@ internal void NotifyAuthority()

internal void StartAuthority()
{
OnStartAuthority.Invoke();
OnStartAuthority?.Invoke();
}

internal void StopAuthority()
{
OnStopAuthority.Invoke();
OnStopAuthority?.Invoke();
}

internal void OnSetHostVisibility(bool visible)
Expand Down Expand Up @@ -733,7 +733,7 @@ internal bool OnCheckObserver(INetworkConnection conn)

internal void StopClient()
{
OnStopClient.Invoke();
OnStopClient?.Invoke();
}

// random number that is unlikely to appear in a regular data stream
Expand Down Expand Up @@ -906,7 +906,7 @@ internal void HandleRemoteCall(Skeleton skeleton, int componentIndex, NetworkRea
if (componentIndex >= 0 && componentIndex < NetworkBehaviours.Length)
{
NetworkBehaviour invokeComponent = NetworkBehaviours[componentIndex];
skeleton.Invoke(reader, invokeComponent, senderConnection, replyId);
skeleton?.Invoke(reader, invokeComponent, senderConnection, replyId);
}
else
{
Expand Down
8 changes: 4 additions & 4 deletions Assets/Mirror/Runtime/NetworkSceneManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ internal void ClientNotReadyMessage(INetworkConnection conn, NotReadyMessage msg
/// <param name="sceneOperation">Scene operation that's about to happen</param>
internal void OnClientChangeScene(string scenePath, SceneOperation sceneOperation)
{
ClientChangeScene.Invoke(scenePath, sceneOperation);
ClientChangeScene?.Invoke(scenePath, sceneOperation);
}

/// <summary>
Expand All @@ -160,7 +160,7 @@ internal void OnClientChangeScene(string scenePath, SceneOperation sceneOperatio
/// <param name="sceneOperation">Scene operation that was just happen</param>
internal void OnClientSceneChanged(string scenePath, SceneOperation sceneOperation)
{
ClientSceneChanged.Invoke(scenePath, sceneOperation);
ClientSceneChanged?.Invoke(scenePath, sceneOperation);

if (pendingAdditiveSceneList.Count > 0 && client && !client.IsLocalClient)
{
Expand Down Expand Up @@ -240,7 +240,7 @@ internal void OnServerChangeScene(string scenePath, SceneOperation operation)
{
logger.Log("OnServerChangeScene");

ServerChangeScene.Invoke(scenePath, operation);
ServerChangeScene?.Invoke(scenePath, operation);
}

/// <summary>
Expand All @@ -253,7 +253,7 @@ internal void OnServerSceneChanged(string scenePath, SceneOperation operation)

server.SendToAll(new SceneReadyMessage());

ServerSceneChanged.Invoke(scenePath, operation);
ServerSceneChanged?.Invoke(scenePath, operation);
}

#endregion
Expand Down
12 changes: 6 additions & 6 deletions Assets/Mirror/Runtime/NetworkServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public void Disconnect()
{
if (LocalClient != null)
{
OnStopHost.Invoke();
OnStopHost?.Invoke();
LocalClient.Disconnect();
}

Expand Down Expand Up @@ -204,7 +204,7 @@ private void TransportStarted()
logger.Log("Server started listening");
Active = true;
// (useful for loading & spawning stuff from database etc.)
Started.Invoke();
Started?.Invoke();
}

private void TransportConnected(IConnection connection)
Expand Down Expand Up @@ -232,7 +232,7 @@ public UniTask StartHost(NetworkClient client)
// call OnStartHost AFTER SetupServer. this way we can use
// NetworkServer.Spawn etc. in there too. just like OnStartServer
// is called after the server is actually properly started.
OnStartHost.Invoke();
OnStartHost?.Invoke();

logger.Log("NetworkServer StartHost");
return task;
Expand Down Expand Up @@ -263,7 +263,7 @@ private void Cleanup()
Connected.RemoveListener(OnAuthenticated);
}

Stopped.Invoke();
Stopped?.Invoke();
initialized = false;
Active = false;
}
Expand Down Expand Up @@ -388,7 +388,7 @@ async UniTaskVoid ConnectionAcceptedAsync(INetworkConnection conn)
AddConnection(conn);

// let everyone know we just accepted a connection
Connected.Invoke(conn);
Connected?.Invoke(conn);

// now process messages until the connection closes
try
Expand All @@ -412,7 +412,7 @@ void OnDisconnected(INetworkConnection connection)

RemoveConnection(connection);

Disconnected.Invoke(connection);
Disconnected?.Invoke(connection);

connection.DestroyOwnedObjects();
connection.Identity = null;
Expand Down
4 changes: 2 additions & 2 deletions Assets/Mirror/Runtime/Transport/Kcp/KcpTransport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public override UniTask ListenAsync()
socket.Bind(new IPEndPoint(IPAddress.IPv6Any, Port));

// transport started
Started.Invoke();
Started?.Invoke();

ListenCompletionSource = AutoResetUniTaskCompletionSource.Create();
return ListenCompletionSource.Task;
Expand Down Expand Up @@ -125,7 +125,7 @@ private async UniTaskVoid ServerHandshake(EndPoint endpoint, byte[] data, int ms
await connection.HandshakeAsync();

// once handshake is completed, then the connection has been accepted
Connected.Invoke(connection);
Connected?.Invoke(connection);
}

private readonly HashSet<HashCash> used = new HashSet<HashCash>();
Expand Down
4 changes: 2 additions & 2 deletions Assets/Mirror/Runtime/Transport/MultiplexTransport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ public void Start()
{
foreach (Transport t in transports)
{
t.Connected.AddListener(c => Connected.Invoke(c));
t.Started.AddListener(() => Started.Invoke());
t.Connected.AddListener(c => Connected?.Invoke(c));
t.Started.AddListener(() => Started?.Invoke());
}
}

Expand Down

0 comments on commit 8236614

Please sign in to comment.