Example #1
0
    public void StartHost()
    {
        NetworkManager.Singleton.OnClientConnectedCallback += OnClientConnectedCallbak;
        NetworkManager.Singleton.StartHost();

        OnHostStarted?.Invoke();
    }
Example #2
0
 /// <summary>
 /// 运行服务
 /// </summary>
 /// <returns></returns>
 public async Task RunAsync()
 {
     _hostBuilder.UseConsoleLifetime();
     _host = _hostBuilder.Build();
     OnHostStarted?.Invoke(ServiceProvider);
     await _host.RunAsync();
 }
Example #3
0
    public void StartHostPhoton(string roomName)
    {
        var netManager = NetworkManager.Singleton;

        netManager.GetComponent <PhotonRealtimeTransport>().RoomName = roomName;

        NetworkManager.Singleton.OnClientConnectedCallback += OnClientConnectedCallback;
        NetworkManager.Singleton.StartHost();
        OnDisconnected += StopHost;
        OnHostStarted?.Invoke();
    }
Example #4
0
        private void StartInternal()
        {
            if (_process.IsProcessRunning)
            {
                throw new InvalidOperationException();
            }

            //
            // We try to start the goddamn host process in a loop until:
            // - The start & connection succeeds
            // - The IFailureHandler calls quit
            // - The number of restarts is 20
            //
            // If starting failed then we throw the last exception
            //
            List <Exception> exceptions  = null;
            const int        maxRestarts = 20;
            int          pid             = -1;
            ConnectionId connectionId    = ConnectionId.None;

            for (int currentRestart = 0; currentRestart < maxRestarts; ++currentRestart)
            {
                LoopResult instruction = StartOnce(currentRestart, out pid, out connectionId, ref exceptions);
                if (instruction == LoopResult.Stop)
                {
                    break;
                }
            }

            if (exceptions != null)
            {
                //
                // POINT OF FAILURE
                //

                _currentPid        = -1;
                _currentConnection = ConnectionId.None;
                throw new AggregateException("Unable to start & establish a connection with the host process",
                                             exceptions);
            }


            //
            // POINT OF NO FAILURE BELOW
            //

            lock (_syncRoot)
            {
                _currentPid        = pid;
                _currentConnection = connectionId;
            }

            try
            {
                OnHostStarted?.Invoke();
            }
            catch (Exception e)
            {
                Log.WarnFormat("The OnHostStarted event threw an exception, please don't do that: {0}", e);
            }
        }
Example #5
0
 private void QueueOnOnHostStarted()
 {
     OnHostStarted?.Invoke();
 }