QcLocalServerHost Class
Runs a QcServer in its own thread inside the game process (single player) and hands out in-process client transports. More...
| Header: | #include <worlds/QcLocalServerHost.h> |
| Inherits: | QObject |
Public Types
| struct | EntityCounts |
Public Functions
| QcLocalServerHost(QcServerConfig config, std::shared_ptr<const QcContentRegistry> content, std::unique_ptr<QcWorldGenerator> generator, QObject *parent = nullptr) | |
| QcLocalServerHost(const QcWorldStart &start, std::shared_ptr<const QcContentRegistry> content, std::unique_ptr<QcWorldGenerator> generator, QObject *parent = nullptr) | |
| QcLocalServerHost(const QcLocalServerHost &) | |
| QcLocalServerHost(QcLocalServerHost &&) | |
| std::unique_ptr<QcTransport> | connectClient() |
| const QcDamagedFile & | damagedFile() const |
| QcLocalServerHost::EntityCounts | entityCounts() |
| QcHealthSample | health() |
| QcResult<quint16> | listen(const QcNetworkConfig &config, const std::optional<QcLoginSettings> &login = std::nullopt) |
| quint16 | listeningPort() const |
| void | resetTickTimes() |
| QStringList | runConsoleCommand(const QString &line) |
| QcStatus | save() |
| QcStatus | shutdown() |
| QString | startError() const |
| void | stopListening() |
| QcTickSummary | tickStats() const |
| bool | worldInUse() const |
| bool | worldTooOld() const |
| QcLocalServerHost & | operator=(QcLocalServerHost &&) |
| QcLocalServerHost & | operator=(const QcLocalServerHost &) |
Signals
| void | stopRequested() |
Static Public Members
| const qint64 | stalledTickNs |
Detailed Description
Owned and used by the GUI/main thread.
Member Function Documentation
QcLocalServerHost::QcLocalServerHost(QcServerConfig config, std::shared_ptr<const QcContentRegistry> content, std::unique_ptr<QcWorldGenerator> generator, QObject *parent = nullptr)
Opens a world with the server configuration config (headless tool and tests, which include server/core/QcServerConfig.h), content and generator; parent is the QObject parent.
QcLocalServerHost::QcLocalServerHost(const QcWorldStart &start, std::shared_ptr<const QcContentRegistry> content, std::unique_ptr<QcWorldGenerator> generator, QObject *parent = nullptr)
Opens the world start describes, with the server's rules for a world of this process: the view distance one chunk ring beyond the player's, the default game mode only for an unsaved world. The server uses content and generator; parent is the QObject parent.
[delete] QcLocalServerHost::QcLocalServerHost(const QcLocalServerHost &)
Copy-constructs an instance of QcLocalServerHost. This function is deleted.
[delete] QcLocalServerHost::QcLocalServerHost(QcLocalServerHost &&)
Move-constructs an instance of QcLocalServerHost. This function is deleted.
std::unique_ptr<QcTransport> QcLocalServerHost::connectClient()
Connects a new client and returns its transport, which belongs to the caller's thread. Clients of the host are local players (QcServer::ClientOrigin::Local: chat is not rate limited, debug data is sent).
const QcDamagedFile &QcLocalServerHost::damagedFile() const
Returns the damaged per-region file that kept the world from opening (decision E-366).
QcLocalServerHost::EntityCounts QcLocalServerHost::entityCounts()
Returns the entity counts, counted in the server thread (blocks until done); all -1 when no world is open.
QcHealthSample QcLocalServerHost::health()
Returns the server's part of the health line (decision E-834): players, chunks, entities, network traffic and the tick times since the previous call (blocks until the server thread counted); empty when no world is open, and when a tick has run for longer than stalledTickNs: then it logs a warning with the phase that finished last instead of waiting for the server thread.
QcResult<quint16> QcLocalServerHost::listen(const QcNetworkConfig &config, const std::optional<QcLoginSettings> &login = std::nullopt)
Lets network clients join as well (decision E-251): a listener in the server thread, the local player stays in-process. Returns the port in use; listening again replaces the listener. config sets up the listener; login replaces the login settings of the server's configuration. Returns an error when no world is open or the port cannot be opened.
quint16 QcLocalServerHost::listeningPort() const
Returns the port of the listener, 0 when not listening.
void QcLocalServerHost::resetTickTimes()
Clears the tick statistics that tickStats() reports, so a measurement starts afresh.
QStringList QcLocalServerHost::runConsoleCommand(const QString &line)
Runs line as a line of the server console in the server thread (decision E-247) and returns the replies as English text (blocks until done).
QcStatus QcLocalServerHost::save()
Saves the world now (blocks until done); returns an error when it fails.
QcStatus QcLocalServerHost::shutdown()
Stops the server (which saves) and joins its thread; returns an error when saving failed. Safe to call more than once; later calls return success.
QString QcLocalServerHost::startError() const
Returns an empty string when the world opened; otherwise the reason, and the host serves no clients.
void QcLocalServerHost::stopListening()
Closes the listener and disconnects the network players ("The host stopped sharing the world"); the local player plays on.
[signal] void QcLocalServerHost::stopRequested()
The console asked to stop the server (/stop); the owner shuts the host down.
QcTickSummary QcLocalServerHost::tickStats() const
Returns the server tick durations, lateness and skipped ticks so far (benchmark); zero when no world is open.
bool QcLocalServerHost::worldInUse() const
Returns whether the world could not open because another server (window or process) has it open.
bool QcLocalServerHost::worldTooOld() const
Returns whether the world could not open because it comes from an older development version (decision E-356).
[delete] QcLocalServerHost &QcLocalServerHost::operator=(QcLocalServerHost &&)
Move-assigns other to this QcLocalServerHost instance. This function is deleted.
[delete] QcLocalServerHost &QcLocalServerHost::operator=(const QcLocalServerHost &)
Copy-assigns other to this QcLocalServerHost instance. This function is deleted.