/// <inheritdoc />
        public void ShutDown()
        {
            if (_shuttingDown || !_running)
            {
                return;
            }

            CommunicationClient.Send(ServerCommand.Disconnect, null);

            // Give the server time to receive the reconnect signal.
            Thread.Sleep(100);

            _shuttingDown = true;
            _commandWaitQueue.Release(new ServerCommandData(ServerCommand.Nop, new byte[0]));
        }
示例#2
0
        /// <summary>
        ///     Shuts down the server after the current callback has been processed.
        /// </summary>
        public void ShutDown()
        {
            if (_shuttingDown || !_running)
            {
                return;
            }

            CommunicationClient.Send(ServerCommand.Disconnect, null);

            // Give the server time to receive the reconnect signal.
            // TODO: Unexpected behaviour if called from outside a callback (because shuttingDown hook is inside callback handler).
            // TODO: This is an ugly fix.
            Thread.Sleep(100);
            _shuttingDown = true;
        }
        private void Send(ServerCommand command, IEnumerable <byte> data)
        {
            if (!IsOnMainThread)
            {
                throw new GameModeClientException("Cannot send data to the server from a thread other than the main thread.");
            }

            try
            {
                CommunicationClient.Send(command, data);
                _lastSend = DateTime.UtcNow;
            }
            catch (IOException e)
            {
                throw new ServerConnectionClosedException("The server connection has closed. Did the server shut down?", e);
            }
        }