Added callback for when client disconnects

This commit is contained in:
Albin Corén 2018-03-28 17:34:42 +02:00
parent c7dd950954
commit 0622ca7a37

View File

@ -44,6 +44,7 @@ namespace MLAPI
public bool IsClientConnected; public bool IsClientConnected;
public Action OnClientConnectedCallback = null; public Action OnClientConnectedCallback = null;
public Action OnClientDisconnectCallback = null;
public NetworkingConfiguration NetworkConfig; public NetworkingConfiguration NetworkConfig;
@ -341,6 +342,8 @@ namespace MLAPI
} }
else else
{ {
if (OnClientDisconnectCallback != null)
OnClientDisconnectCallback.Invoke();
IsClientConnected = false; IsClientConnected = false;
} }
} }
@ -386,7 +389,12 @@ namespace MLAPI
if (isServer) if (isServer)
OnClientDisconnect(clientId); OnClientDisconnect(clientId);
else else
{
if (OnClientDisconnectCallback != null)
OnClientDisconnectCallback.Invoke();
IsClientConnected = false; IsClientConnected = false;
}
break; break;
} }
// Only do another iteration if: there are no more messages AND (there is no limit to max events or we have processed less than the maximum) // Only do another iteration if: there are no more messages AND (there is no limit to max events or we have processed less than the maximum)