public void UseExternalClient(QNetworkClient externalClient)
 {
     if (runInBackground)
     {
         Application.runInBackground = true;
     }
     if (externalClient != null)
     {
         client          = externalClient;
         isNetworkActive = true;
         RegisterClientMessages(client);
         OnStartClient(client);
     }
     else
     {
         OnStopClient();
         QClientScene.DestroyAllClientObjects();
         QClientScene.HandleClientDisconnect(client.connection);
         client = null;
         if (!string.IsNullOrEmpty(offlineScene))
         {
             ClientChangeScene(offlineScene, false);
         }
     }
     s_Address = networkAddress;
 }
 private QNetworkClient ConnectLocalClient()
 {
     QLog.Log($"NetworkManager StartHost port:{networkPort}");
     networkAddress = "localhost";
     client         = QClientScene.ConnectLocalServer();
     RegisterClientMessages(client);
     return(client);
 }
Exemplo n.º 3
0
        public override void OnStartClient(QNetworkClient _)
        {
            DebugLog.DebugWrite($"Setting defaultServerIP to {networkAddress}");
            var config = QSBCore.Helper.Config;

            config.SetSettingsValue("defaultServerIP", networkAddress);
            QSBCore.Helper.Storage.Save(config, Constants.ModConfigFileName);
        }
 public QNetworkClient StartClient(ConnectionConfig config, int hostPort)
 {
     InitializeSingleton();
     if (runInBackground)
     {
         Application.runInBackground = true;
     }
     isNetworkActive = true;
     if (m_GlobalConfig != null)
     {
         NetworkTransport.Init(m_GlobalConfig);
     }
     client = new QNetworkClient
     {
         hostPort = hostPort
     };
     if (config != null)
     {
         if (config.UsePlatformSpecificProtocols && Application.platform != RuntimePlatform.PS4 && Application.platform != RuntimePlatform.PSP2)
         {
             throw new ArgumentOutOfRangeException("Platform specific protocols are not supported on this platform");
         }
         client.Configure(config, 1);
     }
     else if (customConfig && m_ConnectionConfig != null)
     {
         m_ConnectionConfig.Channels.Clear();
         foreach (var channel in channels)
         {
             m_ConnectionConfig.AddChannel(channel);
         }
         if (m_ConnectionConfig.UsePlatformSpecificProtocols && Application.platform != RuntimePlatform.PS4 && Application.platform != RuntimePlatform.PSP2)
         {
             throw new ArgumentOutOfRangeException("Platform specific protocols are not supported on this platform");
         }
         client.Configure(m_ConnectionConfig, maxConnections);
     }
     RegisterClientMessages(client);
     if (string.IsNullOrEmpty(networkAddress))
     {
         QLog.Error("Must set the Network Address field in the manager");
         return(null);
     }
     if (useSimulator)
     {
         client.ConnectWithSimulator(networkAddress, networkPort, simulatedLatency, packetLossPercentage);
     }
     else
     {
         client.Connect(networkAddress, networkPort);
     }
     OnStartClient(client);
     s_Address = networkAddress;
     return(client);
 }
 public void StopClient()
 {
     OnStopClient();
     QLog.Log("NetworkManager StopClient");
     isNetworkActive = false;
     if (client != null)
     {
         client.Disconnect();
         client.Shutdown();
         client = null;
     }
     QClientScene.DestroyAllClientObjects();
     if (!string.IsNullOrEmpty(offlineScene))
     {
         ClientChangeScene(offlineScene, false);
     }
     CleanupNetworkIdentities();
 }
 internal void RegisterClientMessages(QNetworkClient client)
 {
     client.RegisterHandler(QMsgType.Connect, OnClientConnectInternal);
     client.RegisterHandler(QMsgType.Disconnect, OnClientDisconnectInternal);
     client.RegisterHandler(QMsgType.NotReady, OnClientNotReadyMessageInternal);
     client.RegisterHandler(QMsgType.Error, OnClientErrorInternal);
     client.RegisterHandler(QMsgType.Scene, OnClientSceneInternal);
     if (playerPrefab != null)
     {
         QClientScene.RegisterPrefab(playerPrefab);
     }
     foreach (var gameObject in spawnPrefabs)
     {
         if (gameObject != null)
         {
             QClientScene.RegisterPrefab(gameObject);
         }
     }
 }
 public virtual void OnStartClient(QNetworkClient client)
 {
 }