public virtual void OnServerRemovePlayer(QNetworkConnection conn, QPlayerController player) { if (player.Gameobject != null) { QNetworkServer.Destroy(player.Gameobject); } }
private void FinishLoadScene() { if (client != null) { if (s_ClientReadyConnection != null) { clientLoadedScene = true; OnClientConnect(s_ClientReadyConnection); s_ClientReadyConnection = null; } } else { QLog.Error("FinishLoadScene client is null"); } if (QNetworkServer.active) { QNetworkServer.SpawnObjects(); OnServerSceneChanged(networkSceneName); } if (IsClientConnected() && client != null) { RegisterClientMessages(client); OnClientSceneChanged(client.connection); } }
public QNetworkIdentity ReadNetworkIdentity() { var networkInstanceId = ReadNetworkId(); QNetworkIdentity result; if (networkInstanceId.IsEmpty()) { result = null; } else { var gameObject = QNetworkServer.active ? QNetworkServer.FindLocalObject(networkInstanceId) : QClientScene.FindLocalObject(networkInstanceId); if (gameObject == null) { Debug.Log($"ReadNetworkIdentity netId:{networkInstanceId}go: null"); result = null; } else { result = gameObject.GetComponent <QNetworkIdentity>(); } } return(result); }
public virtual void OnServerDisconnect(QNetworkConnection conn) { QNetworkServer.DestroyPlayersForConnection(conn); if (conn.LastError != NetworkError.Ok) { QLog.Error($"ServerDisconnected due to error: {conn.LastError}"); } }
internal void RemoveFromVisList(QNetworkIdentity uv, bool isDestroyed) { VisList.Remove(uv); if (!isDestroyed) { QNetworkServer.HideForConnection(uv, this); } }
public virtual void OnServerReady(QNetworkConnection conn) { if (conn.PlayerControllers.Count == 0) { QLog.Warning("Ready with no player object"); } QNetworkServer.SetClientReady(conn); }
public void SendToAll(T message) { if (!QSBNetworkManager.Instance.IsReady) { return; } QNetworkServer.SendToAll(_eventType, message); }
internal void RegisterServerMessages() { QNetworkServer.RegisterHandler(QMsgType.Connect, OnServerConnectInternal); QNetworkServer.RegisterHandler(QMsgType.Disconnect, OnServerDisconnectInternal); QNetworkServer.RegisterHandler(QMsgType.Ready, OnServerReadyMessageInternal); QNetworkServer.RegisterHandler(QMsgType.AddPlayer, OnServerAddPlayerMessageInternal); QNetworkServer.RegisterHandler(QMsgType.RemovePlayer, OnServerRemovePlayerMessageInternal); QNetworkServer.RegisterHandler(QMsgType.Error, OnServerErrorInternal); }
public override void OnServerAddPlayer(QNetworkConnection connection, short playerControllerId) // Called on the server when a client joins { DebugLog.DebugWrite($"OnServerAddPlayer {playerControllerId}", MessageType.Info); base.OnServerAddPlayer(connection, playerControllerId); QNetworkServer.SpawnWithClientAuthority(Instantiate(_shipPrefab), connection); QNetworkServer.SpawnWithClientAuthority(Instantiate(_cameraPrefab), connection); QNetworkServer.SpawnWithClientAuthority(Instantiate(_probePrefab), connection); QNetworkServer.SpawnWithClientAuthority(Instantiate(_stickPrefab), connection); }
protected void SendRPCInternal(QNetworkWriter writer, int channelId, string rpcName) { if (!IsServer) { QLog.Warning("ClientRpc call on un-spawned object"); return; } writer.FinishMessage(); QNetworkServer.SendWriterToReady(gameObject, writer, channelId); }
private void Init() { if (QNetworkServer.handlers.Keys.Contains(_eventType)) { QNetworkServer.handlers.Remove(_eventType); QNetworkManager.singleton.client.handlers.Remove(_eventType); } QNetworkServer.RegisterHandler(_eventType, OnServerReceiveMessageHandler); QNetworkManager.singleton.client.RegisterHandler(_eventType, OnClientReceiveMessageHandler); }
protected void SendEventInternal(QNetworkWriter writer, int channelId, string eventName) { if (!QNetworkServer.active) { QLog.Error($"Tried to send event {eventName} on channel {channelId} but QSBNetworkServer isn't active."); return; } writer.FinishMessage(); QNetworkServer.SendWriterToReady(gameObject, writer, channelId); }
private bool StartServer(ConnectionConfig config, int maxConnections) { InitializeSingleton(); OnStartServer(); if (runInBackground) { Application.runInBackground = true; } QNetworkCRC.scriptCRCCheck = scriptCRCCheck; QNetworkServer.useWebSockets = useWebSockets; if (m_GlobalConfig != null) { NetworkTransport.Init(m_GlobalConfig); } if (customConfig && m_ConnectionConfig != null && config == null) { m_ConnectionConfig.Channels.Clear(); foreach (var channel in channels) { m_ConnectionConfig.AddChannel(channel); } QNetworkServer.Configure(m_ConnectionConfig, this.maxConnections); } if (config != null) { QNetworkServer.Configure(config, maxConnections); } if (serverBindToIP && !string.IsNullOrEmpty(serverBindAddress)) { if (!QNetworkServer.Listen(serverBindAddress, networkPort)) { QLog.FatalError($"StartServer listen on {serverBindAddress} failed."); return(false); } } else if (!QNetworkServer.Listen(networkPort)) { QLog.FatalError("StartServer listen failed."); return(false); } RegisterServerMessages(); QLog.Log($"NetworkManager StartServer port:{networkPort}"); isNetworkActive = true; var name = SceneManager.GetSceneAt(0).name; if (!string.IsNullOrEmpty(onlineScene) && onlineScene != name && onlineScene != offlineScene) { ServerChangeScene(onlineScene); } else { QNetworkServer.SpawnObjects(); } return(true); }
private void BuildOrbs() { QSBWorldSync.OldOrbList.Clear(); QSBWorldSync.OldOrbList = Resources.FindObjectsOfTypeAll <NomaiInterfaceOrb>().ToList(); if (QSBCore.IsServer) { QSBWorldSync.OrbSyncList.ForEach(x => QNetworkServer.Destroy(x.gameObject)); QSBWorldSync.OrbSyncList.Clear(); QSBWorldSync.OldOrbList.ForEach(x => QNetworkServer.Spawn(Instantiate(QSBNetworkManager.Instance.OrbPrefab))); } DebugLog.DebugWrite($"Finished orb build with {QSBWorldSync.OldOrbList.Count} orbs.", MessageType.Success); }
public void StopServer() { if (QNetworkServer.active) { OnStopServer(); QLog.Log("NetworkManager StopServer"); isNetworkActive = false; QNetworkServer.Shutdown(); if (!string.IsNullOrEmpty(offlineScene)) { ServerChangeScene(offlineScene); } CleanupNetworkIdentities(); } }
public virtual void ServerChangeScene(string newSceneName) { if (string.IsNullOrEmpty(newSceneName)) { QLog.Error("ServerChangeScene empty scene name"); } else { QLog.Log($"ServerChangeScene {newSceneName}"); QNetworkServer.SetAllClientsNotReady(); networkSceneName = newSceneName; s_LoadingSceneAsync = SceneManager.LoadSceneAsync(newSceneName); var msg = new QStringMessage(networkSceneName); QNetworkServer.SendToAll(39, msg); } }
private void OnServerAddPlayerInternal(QNetworkConnection conn, short playerControllerId) { if (playerPrefab == null) { QLog.FatalError("The PlayerPrefab is empty on the QSBNetworkManager. Please setup a PlayerPrefab object."); } else if (playerPrefab.GetComponent <QNetworkIdentity>() == null) { QLog.FatalError("The PlayerPrefab does not have a QSBNetworkIdentity. Please add a QSBNetworkIdentity to the player prefab."); } else if (playerControllerId < conn.PlayerControllers.Count && conn.PlayerControllers[playerControllerId].IsValid && conn.PlayerControllers[playerControllerId].Gameobject != null) { QLog.Warning("There is already a player at that playerControllerId for this connections."); } else { var player = Instantiate(playerPrefab, Vector3.zero, Quaternion.identity); QNetworkServer.AddPlayerForConnection(conn, player, playerControllerId); } }
public GameObject ReadGameObject() { var networkInstanceId = ReadNetworkId(); GameObject result; if (networkInstanceId.IsEmpty()) { result = null; } else { var gameObject = QNetworkServer.active ? QNetworkServer.FindLocalObject(networkInstanceId) : QClientScene.FindLocalObject(networkInstanceId); if (gameObject == null) { Debug.Log($"ReadGameObject netId:{networkInstanceId}go: null"); } result = gameObject; } return(result); }
protected virtual void Dispose(bool disposing) { if (!m_Disposed && m_Channels != null) { foreach (var channel in m_Channels) { channel.Dispose(); } } m_Channels = null; if (ClientOwnedObjects != null) { foreach (var netId in ClientOwnedObjects) { var gameObject = QNetworkServer.FindLocalObject(netId); if (gameObject != null) { gameObject.GetComponent <QNetworkIdentity>().ClearClientOwner(); } } } ClientOwnedObjects = null; m_Disposed = true; }
public static void HandleTransform(QNetworkMessage netMsg) { var networkInstanceId = netMsg.Reader.ReadNetworkId(); var gameObject = QNetworkServer.FindLocalObject(networkInstanceId); if (gameObject == null) { QLog.Warning("Received NetworkTransform data for GameObject that doesn't exist"); } else { var component = gameObject.GetComponent <QNetworkTransform>(); if (component == null) { QLog.Warning("HandleTransform null target"); } else if (!component.LocalPlayerAuthority) { QLog.Warning("HandleTransform no localPlayerAuthority"); } else if (netMsg.Connection.ClientOwnedObjects == null) { QLog.Warning("HandleTransform object not owned by connection"); } else if (netMsg.Connection.ClientOwnedObjects.Contains(networkInstanceId)) { component.UnserializeModeTransform(netMsg.Reader, false); component.LastSyncTime = Time.time; } else { QLog.Warning( $"HandleTransform netId:{networkInstanceId} is not for a valid player"); } } }
public QULocalConnectionToServer(QNetworkServer localServer) { address = "localServer"; m_LocalServer = localServer; }
internal void AddToVisList(QNetworkIdentity uv) { VisList.Add(uv); QNetworkServer.ShowForConnection(uv, this); }