- Home /
Question by
leopripos · Sep 11, 2016 at 03:21 AM ·
networkingunity5
NetworkLobbyManager.OnLobbyStopHost() called when stop Server Only, Is this bug?
I created a class extending UnityEngine.Networking.NetworkLobbyManager bellow.
public class NetworkLobbyManager : UnityEngine.Networking.NetworkLobbyManager, ISingleton
{
/************************************* Start Server Callback ****************************/
#region Server Collback
/// <summary>
/// This is called on the host when a host is started.
/// </summary>
public override void OnLobbyStartHost()
{
Debug.Log("OnLobbyStartHost");
base.OnLobbyStartHost();
}
/// <summary>
/// This is called on the host when the host is stopped.
/// </summary>
public override void OnLobbyStopHost()
{
Debug.Log("OnLobbyStopHost");
base.OnLobbyStopHost();
}
/// <summary>
/// This is called on the server when the server is started - including when a host is started.
/// </summary>
public override void OnLobbyStartServer()
{
Debug.Log("OnLobbyStartServer");
base.OnLobbyStartServer();
}
/// <summary>
/// This is called on the server when a new client connects to the server.
/// </summary>
/// <param name="conn">The new connection.</param>
public override void OnLobbyServerConnect(NetworkConnection conn)
{
Debug.Log("OnLobbyServerConnect connectionId : " + conn.connectionId);
base.OnLobbyServerConnect(conn);
}
/// <summary>
/// This is called on the server when a client disconnects.
/// </summary>
/// <param name="conn" The connection that disconnected.></param>
public override void OnLobbyServerDisconnect(NetworkConnection conn)
{
Debug.Log("OnLobbyServerDisconnect connectionId : " + conn.connectionId);
base.OnLobbyServerDisconnect(conn);
}
/// <summary>
/// This allows customization of the creation of the GamePlayer object on the server.
/// By default the gamePlayerPrefab is used to create the game-player, but this function allows that behaviour to be customized.
/// The object returned from the function will be used to replace the lobby-player on the connection.
/// </summary>
/// <param name="conn">The connection the player object is for.</param>
/// <param name="playerControllerId">The controllerId of the player on the connnection.</param>
/// <returns>A new GamePlayer object.</returns>
public override GameObject OnLobbyServerCreateGamePlayer(NetworkConnection conn, short playerControllerId)
{
Debug.Log("OnLobbyServerCreateGamePlayer connectionId : " + conn.connectionId + ", playerConntrollerId : " + playerControllerId);
return base.OnLobbyServerCreateGamePlayer(conn, playerControllerId);
}
/// <summary>
/// This allows customization of the creation of the lobby-player object on the server.
/// By default the lobbyPlayerPrefab is used to create the lobby-player, but this function allows that behaviour to be customized.
/// </summary>
/// <param name="conn">The connection the player object is for.</param>
/// <param name="playerControllerId">The controllerId of the player.</param>
/// <returns>The new lobby-player object.</returns>
public override GameObject OnLobbyServerCreateLobbyPlayer(NetworkConnection conn, short playerControllerId)
{
Debug.Log("OnLobbyServerCreateLobbyPlayer connectionId : " + conn.connectionId + ", playerConntrollerId : " + playerControllerId);
return base.OnLobbyServerCreateLobbyPlayer(conn, playerControllerId);
}
/// <summary>
/// This is called on the server when all the players in the lobby are ready.
/// The default implementation of this function uses ServerChangeScene() to switch to the game player scene.
/// </summary>
public override void OnLobbyServerPlayersReady()
{
Debug.Log("OnLobbyServerPlayersReady");
base.OnLobbyServerPlayersReady();
}
/// <summary>
/// This is called on the server when a player is removed.
/// </summary>
/// <param name="conn">The connection the player object that removed.</param>
/// <param name="playerControllerId">The controllerId of the player that removed.</param>
public override void OnLobbyServerPlayerRemoved(NetworkConnection conn, short playerControllerId)
{
Debug.Log("OnLobbyServerPlayerRemoved connectionId : " + conn.connectionId + ", playerConntrollerId : " + playerControllerId);
base.OnLobbyServerPlayerRemoved(conn, playerControllerId);
}
/// <summary>
/// This is called on the server when a networked scene finishes loading.
/// </summary>
/// <param name="sceneName">Name of the new scene.</param>
public override void OnLobbyServerSceneChanged(string sceneName)
{
Debug.Log("OnLobbyServerSceneChanged sceneName : " + sceneName);
base.OnLobbyServerSceneChanged(sceneName);
}
/// <summary>
/// This is called on the server when it is told that a client has finished switching from the lobby scene to a game player scene.
/// When switching from the lobby, the lobby-player is replaced with a game-player object.
/// This callback function gives an opportunity to apply state from the lobby-player to the game-player object.
/// </summary>
/// <param name="lobbyPlayer">The lobby player object.</param>
/// <param name="gamePlayer">The game player object.</param>
/// <returns>False to not allow this player to replace the lobby player.</returns>
public override bool OnLobbyServerSceneLoadedForPlayer(GameObject lobbyPlayer, GameObject gamePlayer)
{
Debug.Log("OnLobbyServerSceneLoadedForPlayer lobbyPlayer : " + lobbyPlayer.GetInstanceID() + " gamePlayer : " + gamePlayer.GetInstanceID());
return base.OnLobbyServerSceneLoadedForPlayer(lobbyPlayer, gamePlayer);
}
#endregion
/************************************* End Server Callback ****************************/
/************************************* Start Client Callback ****************************/
#region Client Collback
/// <summary>
/// This is a hook to allow custom behaviour when the game client enters the lobby.
/// </summary>
public override void OnLobbyClientEnter()
{
Debug.Log("OnLobbyClientEnter");
base.OnLobbyClientEnter();
}
/// <summary>
/// This is a hook to allow custom behaviour when the game client exits the lobby.
/// </summary>
public override void OnLobbyClientExit()
{
Debug.Log("OnLobbyClientExit");
base.OnLobbyClientExit();
}
/// <summary>
/// This is called on the client when it connects to server.
/// </summary>
/// <param name="conn">The new connection</param>
public override void OnLobbyClientConnect(NetworkConnection conn)
{
Debug.Log("OnLobbyClientConnect connectionId : " + conn.connectionId);
base.OnLobbyClientConnect(conn);
}
/// <summary>
/// This is called on the client when disconnected from a server.
/// </summary>
/// <param name="conn">The connection that disconnected.</param>
public override void OnLobbyClientDisconnect(NetworkConnection conn)
{
Debug.Log("OnLobbyClientDisconnect connectionId : " + conn.connectionId);
base.OnLobbyClientDisconnect(conn);
}
/// <summary>
/// This is called on the client when a client is started.
/// </summary>
/// <param name="lobbyClient">The new network client</param>
public override void OnLobbyStartClient(NetworkClient lobbyClient)
{
Debug.Log("OnLobbyStartClient netowrkClient : " + lobbyClient.connection.connectionId);
base.OnLobbyStartClient(lobbyClient);
}
/// <summary>
/// This is called on the client when the client stops.
/// </summary>
public override void OnLobbyStopClient()
{
Debug.Log("OnLobbyStopClient");
base.OnLobbyStopClient();
}
/// <summary>
/// This is called on the client when the client is finished loading a new networked scene.
/// </summary>
/// <param name="conn">Connection</param>
public override void OnLobbyClientSceneChanged(NetworkConnection conn)
{
Debug.Log("OnLobbyClientSceneChanged connectionId : " + conn.connectionId);
base.OnLobbyClientSceneChanged(conn);
}
/// <summary>
/// Called on the client when adding a player to the lobby fails.
/// This could be because the lobby is full, or the connection is not allowed to have more players
/// </summary>
public override void OnLobbyClientAddPlayerFailed()
{
Debug.Log("OnLobbyClientAddPlayerFailed");
base.OnLobbyClientAddPlayerFailed();
}
#endregion
/************************************* End Client Callback ****************************/
}
But, the debug result like this : When Start Server Only, the result :
OnLobbyStartServer
When Stop the Server Only, the result:
OnLobbyStopHost
OnLobbyStopClient
OnLobbyClientExit
I am using Unity 5.4.0p4. Is this bug?
Comment
Best Answer
Answer by leopripos · Sep 11, 2016 at 03:37 AM
I think this is the cause, I found that NetworkManagerHUD implemented like this. So, it make it like a host.
if (NetworkServer.active || manager.IsClientConnected())
{
if (GUI.Button(new Rect(xpos, ypos, 200, 20), "Stop (X)"))
{
manager.StopHost();
}
ypos += spacing;
}
Your answer
![](https://koobas.hobune.stream/wayback/20220612092558im_/https://answers.unity.com/themes/thub/images/avi.jpg)