/// <summary> /// Called from the MirrorPlayerBEventListener when destroyed to disconnect the associated NetworkID /// </summary> /// <param name="mirrorPlayerListener"> MirrorPlayerBEventListener to disconnect </param> /// <returns> Assigned NetworkID </returns> public void OnMirrorPlayerLeft(MirrorPlayerBEventListener mirrorPlayerListener, ENetworkID networkID) { // Is Local Player disconnected? if (networkID == LocalNetworkID) { // Is local player the server? if (LocalNetworkID == ENetworkID.HOST) { connectedNetworkIDs.Clear(); } LocalMirrorPlayerBEventListener = null; LocalNetworkID = ENetworkID.LOCAL; BEventManager.Instance.OnUpdatedNetworkState(ENetworkState.NOT_CONNECTED, this); BEventsCollection.NETWORK_ConnectionStoped.Invoke(new BEHandle(), true); } else if (LocalNetworkID == ENetworkID.HOST && IS_KEY_CONTAINED(connectedNetworkIDs, networkID)) { connectedNetworkIDs.Remove(networkID); Server_InformAllDisconnectedClient(networkID); } }
/// <summary> /// Called from a MirrorPlayerBEventListener when spawned to connect to the next available NetworkID /// </summary> /// <param name="mirrorPlayerListener"> New MirrorPlayerBEventListener </param> /// <returns> Assigned NetworkID </returns> public ENetworkID Server_OnNewMirrorPlayerJoined(MirrorPlayerBEventListener mirrorPlayerListener) { string ipAddress = ""; ENetworkID networkID = ENetworkID.NONE; if (IS_NOT_NULL(mirrorPlayerListener)) { ipAddress = mirrorPlayerListener.IpAdress; // Assign a NetworkID networkID = GetNextFreeNetworkNetworkID(); if (ARE_NOT_EQUAL(networkID, ENetworkID.NONE)) { LogConsole("Adding new Player Mirror Listener : " + networkID); connectedNetworkIDs.Add(networkID, mirrorPlayerListener); BEventsCollection.NETWORK_NewNetworkIDConnected.Invoke(new BEHandle <ENetworkID>(networkID)); Server_RefreshConnectedNetworkControllers(); } } // Validity Check if (networkID == ENetworkID.NONE) { LogConsoleWarning("No free Controller ID found for new connected Net Controller : " + ipAddress); } return(networkID); }
private void Server_InformAllDisconnectedClient(ENetworkID networkID) { foreach (KeyValuePair <ENetworkID, MirrorPlayerBEventListener> pair in connectedNetworkIDs) { MirrorPlayerBEventListener mirrorPlayerBEventListener = pair.Value; mirrorPlayerBEventListener.Rpc_OnClientDisconnected(networkID); } }
private void Server_RefreshConnectedNetworkControllers() // TODO : Replace by OnClientConnected? { foreach (KeyValuePair <ENetworkID, MirrorPlayerBEventListener> pair in connectedNetworkIDs) { MirrorPlayerBEventListener mirrorPlayerBEventListener = pair.Value; ENetworkID networkIDItr = pair.Key; LogConsole("Sending refresh for : " + networkIDItr); mirrorPlayerBEventListener.Server_RefreshAssignedNetworkID(networkIDItr); } }
public void Target_OnConnectedToHost(ENetworkID networkID, MirrorPlayerBEventListener mirrorPlayerBEventListener) { if (IS_NOT_NONE(networkID)) { LocalNetworkID = networkID; LocalMirrorPlayerBEventListener = mirrorPlayerBEventListener; BEventManager.Instance.OnUpdatedNetworkState(ENetworkState.CLIENT, this); BEventsCollection.NETWORK_ConnectedToHost.Invoke(new BEHandle <ENetworkID>(networkID)); } }
/// <summary> /// Called from the MirrorPlayerBEventListener on the server when spawned to connect to the next server NetworkID /// </summary> /// <param name="mirrorPlayerListener"> New MirrorPlayerBEventListener </param> public void Server_OnHostStarted(MirrorPlayerBEventListener mirrorPlayerListener) { if (IS_NOT_NULL(mirrorPlayerListener) && IS_KEY_NOT_CONTAINED(connectedNetworkIDs, ENetworkID.HOST)) { LocalNetworkID = ENetworkID.HOST; LogConsole("Adding Server Player Mirror Listener : " + LocalNetworkID); connectedNetworkIDs.Add(LocalNetworkID, mirrorPlayerListener); LocalMirrorPlayerBEventListener = mirrorPlayerListener; Server_RefreshConnectedNetworkControllers(); BEventManager.Instance.OnUpdatedNetworkState(ENetworkState.HOST, this); BEventsCollection.NETWORK_StartedHost.Invoke(new BEHandle()); BEventsCollection.NETWORK_NewNetworkIDConnected.Invoke(new BEHandle <ENetworkID>(LocalNetworkID)); } }