QcServer Class
Authoritative game server. More...
| Header: | #include <server/core/QcServer.h> |
| Inherits: | QObject |
Public Types
| enum class | ClientOrigin { Remote, Local } |
Public Functions
| QcServer(const QcServer &) | |
| QcServer(QcServer &&) | |
| void | addClient(std::unique_ptr<QcTransport> transport, QcServer::ClientOrigin origin = ClientOrigin::Remote) |
| quint64 | autosaveCount() const |
| QcBlockEntities & | blockEntities() |
| const QcBlockUpdateQueue & | blockUpdates() const |
| QcMinecartManager & | carts() |
| QcChunkLoading & | chunkLoading() |
| QcCircuitState & | circuitState() |
| int | clientCount() const |
| QcServerCommands & | commands() |
| const QcServerConfig & | config() const |
| const QcServerCreatures & | creatures() const |
| const QcServerPersistence::DamagedFile & | damagedFile() const |
| void | disconnectRemoteClients() |
| QcEntities & | entities() |
| const QcEntities & | entities() const |
| QcFallingBlockManager & | fallingBlocks() |
| QcFireQueue & | fires() |
| QcHealthSample | health() |
| QcHopperQueue & | hopperQueue() |
| QcItemEntityManager & | items() |
| bool | keepInventory() const |
| QcLiquidFlow & | liquids() |
| const QcMachineRules & | machineRules() const |
| QcMapStore & | maps() |
| QcMobManager & | mobs() |
| const QcMovingBlocks & | movingBlocks() const |
| void | noteContents(QcBlockPos pos) |
| const QStringList & | openWarnings() const |
| QcStatus | openWorld() |
| QcExperienceOrbManager & | orbs() |
| const QcServerPause & | pause() const |
| QcPlantManager & | plants() |
| void | resetTickTimes() |
| void | runConsoleCommand(const QString &line, const QcCommandSource::Output &output) |
| QcStatus | save() |
| void | saveInBackground() |
| void | setKeepInventory(bool keep) |
| void | setLoginSettings(const QcLoginSettings &login) |
| void | setWorldTime(double seconds) |
| QcArmourStandManager & | stands() |
| void | start() |
| QcStatus | stop() |
| QcServerSystems & | systems() |
| void | tick() |
| const QcTickControl & | tickControl() const |
| quint64 | tickCount() const |
| const QcTickPhaseTimer & | tickPhases() const |
| QcTickScheduler & | tickScheduler() |
| const QcTickSystems & | tickSystems() const |
| QcTickStats::Summary | tickTimes() const |
| double | timeSpeed() const |
| void | waitForStorage() |
| QcServerWorld & | world() |
| bool | worldInUse() const |
| double | worldTime() const |
| bool | worldTooOld() const |
| QcServer & | operator=(QcServer &&) |
| QcServer & | operator=(const QcServer &) |
Signals
| void | clientCountChanged(int count) |
| void | stopRequested() |
Static Public Members
| const int | craftingGridSlot |
| const int | maxBlockUpdatesPerTick |
| const double | playerMaxHealth |
Detailed Description
Owns the world and all game logic and talks to clients only through protocol messages: it runs the tick and hands messages to its parts. Lives in one thread; all functions must be called from that thread, except tickTimes() and resetTickTimes().
Member Type Documentation
enum class QcServer::ClientOrigin
Where a client connects from.
Local clients are those of the in-process host (single player: the one who opened the world, who is the operator anyway); they join without a login and their chat lines and commands are not rate limited (decision E-091, supplement). Everything else is Remote: it logs in (decision E-252) and is fully limited.
| Constant | Value | Description |
|---|---|---|
QcServer::ClientOrigin::Remote | 0 | A network client. |
QcServer::ClientOrigin::Local | 1 | The player of the in-process host. |
Member Function Documentation
[delete] QcServer::QcServer(const QcServer &)
Copy-constructs an instance of QcServer. This function is deleted.
[delete] QcServer::QcServer(QcServer &&)
Move-constructs an instance of QcServer. This function is deleted.
void QcServer::addClient(std::unique_ptr<QcTransport> transport, QcServer::ClientOrigin origin = ClientOrigin::Remote)
Adds a client connected through transport from origin; a remote one logs in first.
quint64 QcServer::autosaveCount() const
Returns the autosaves since the server started.
QcBlockEntities &QcServer::blockEntities()
Returns the state that belongs to single blocks (decision E-357).
const QcBlockUpdateQueue &QcServer::blockUpdates() const
Returns the queues of block updates and their counters (pending, waiting, processed, dropped).
QcMinecartManager &QcServer::carts()
Returns the table of the minecarts.
QcChunkLoading &QcServer::chunkLoading()
Returns which chunks are loaded and how they come and go (decisions E-374 to E-377).
QcCircuitState &QcServer::circuitState()
Returns the state of the Signal Dust circuits.
int QcServer::clientCount() const
Returns the number of clients, those still logging in included.
[signal] void QcServer::clientCountChanged(int count)
The number of clients changed to count.
QcServerCommands &QcServer::commands()
Returns the command layer (chat, console, admin channel).
const QcServerConfig &QcServer::config() const
Returns the configuration.
const QcServerCreatures &QcServer::creatures() const
Returns the creatures in the tick: guardians and crumbling (decisions E-591, E-593) for tests.
const QcServerPersistence::DamagedFile &QcServer::damagedFile() const
Returns whether openWorld() failed on a damaged per-region file, and which.
void QcServer::disconnectRemoteClients()
Ends the connections of all network clients with a reason (the host stopped sharing the world); the local player stays. They are saved with the next tick like any who leave.
QcEntities &QcServer::entities()
Returns every entity of the world (decision E-364) and the tables of the kinds.
const QcEntities &QcServer::entities() const
Returns every entity of the world and the tables of the kinds, read-only.
QcFallingBlockManager &QcServer::fallingBlocks()
Returns the table of the falling blocks.
QcFireQueue &QcServer::fires()
Returns the queue of the burning fires (decision E-392).
QcHealthSample QcServer::health()
Returns the players, loaded chunks, creatures and items, the network traffic of the clients and the tick durations since the previous call for the health line (decision E-834); server thread only.
QcHopperQueue &QcServer::hopperQueue()
Returns the queue of the Signal Hoppers.
QcItemEntityManager &QcServer::items()
Returns the table of the dropped items.
bool QcServer::keepInventory() const
Returns the game rule keepInventory of the world.
See also setKeepInventory().
QcLiquidFlow &QcServer::liquids()
Returns the flow of liquids.
const QcMachineRules &QcServer::machineRules() const
Returns the rules of machines.
QcMapStore &QcServer::maps()
Returns the maps of the world (decision E-799).
QcMobManager &QcServer::mobs()
Returns the table of the creatures.
const QcMovingBlocks &QcServer::movingBlocks() const
Returns the blocks a piston slides.
void QcServer::noteContents(QcBlockPos pos)
The contents of the container or machine at pos changed (set by a test or tool): comparators reading it and hoppers next to it look again.
const QStringList &QcServer::openWarnings() const
Returns the problems found while opening the world (missing mods, unknown blocks); it still opened.
QcStatus QcServer::openWorld()
Opens or creates the world directory given in the config (no-op without one). Must succeed before start(); returns an error with a readable message for damaged or mismatching saves.
QcExperienceOrbManager &QcServer::orbs()
Returns the table of the experience orbs (decision E-398).
const QcServerPause &QcServer::pause() const
Returns whether the tick loop pauses (decision E-877): tick() runs only the players' upkeep then.
QcPlantManager &QcServer::plants()
Returns the growing plants.
void QcServer::resetTickTimes()
Forgets the tick times recorded so far; safe from other threads (benchmark).
void QcServer::runConsoleCommand(const QString &line, const QcCommandSource::Output &output)
Runs line of the server console (decision E-247); the replies go to output.
QcStatus QcServer::save()
Writes all players, world info, changed chunks, entities, machines, chests and pending updates. A failing part does not keep the others from being written; returns the first error. No-op without a world directory.
void QcServer::saveInBackground()
Saves in the background like an autosave (tests and measurements).
void QcServer::setKeepInventory(bool keep)
Sets the game rule keepInventory of the world to keep.
See also keepInventory().
void QcServer::setLoginSettings(const QcLoginSettings &login)
Changes the login settings for network players to login (a world opened to the LAN, decision E-252).
void QcServer::setWorldTime(double seconds)
Sets the world time to seconds (at least 0) and tells every playing client.
See also worldTime().
QcArmourStandManager &QcServer::stands()
Returns the table of the armour stands.
void QcServer::start()
Starts the tick loop: the first tick is due one interval from now.
QcStatus QcServer::stop()
Saves, then disconnects every client; returns the result of saving.
[signal] void QcServer::stopRequested()
/stop from the console: the host should stop the server.
QcServerSystems &QcServer::systems()
Returns the gameplay systems: fire, burning, health, weather, minecarts, experience, projectiles and circuits.
void QcServer::tick()
Runs one simulation tick immediately (used by tests and by the tick timer).
const QcTickControl &QcServer::tickControl() const
Returns whether the world is frozen and the steps left (/tick); server thread only.
quint64 QcServer::tickCount() const
Returns the ticks counted since the server started.
const QcTickPhaseTimer &QcServer::tickPhases() const
Returns the time per phase of the latest ticks (decision E-225); server thread only.
QcTickScheduler &QcServer::tickScheduler()
Returns the tick schedule: rate and sprints (/tick, decision E-249); server thread only.
const QcTickSystems &QcServer::tickSystems() const
Returns the systems of the tick in their order (decision E-700); server thread only.
QcTickStats::Summary QcServer::tickTimes() const
Returns the duration and lateness of the timed ticks; safe to read and reset from other threads (benchmark).
double QcServer::timeSpeed() const
Returns the server ticks per tick of a client's clock, sent with WorldTime: the tick rate / 20, during a sprint the larger of sprint and tick rate / 20, at most QcMsg::WorldTime::maxSpeed; 0 while frozen or paused (decisions E-249, E-877).
void QcServer::waitForStorage()
Waits until everything handed to the world's storage is written (autosaves run in the background, decision E-373).
QcServerWorld &QcServer::world()
Returns the world: chunks, blocks and what belongs to them.
bool QcServer::worldInUse() const
Returns whether openWorld() failed because another server has the world open.
double QcServer::worldTime() const
Returns the seconds since the world was created (the day/night cycle).
See also setWorldTime().
bool QcServer::worldTooOld() const
Returns whether openWorld() failed because the world comes from an older development version.
[delete] QcServer &QcServer::operator=(QcServer &&)
Move-assigns other to this QcServer instance. This function is deleted.
[delete] QcServer &QcServer::operator=(const QcServer &)
Copy-assigns other to this QcServer instance. This function is deleted.
Member Variable Documentation
const int QcServer::craftingGridSlot
The first slot of the crafting grid in inventory moves (QcMsg::MoveInventoryItem).
const int QcServer::maxBlockUpdatesPerTick
Neighbour updates per tick at most by default (QcServerLimits::blockUpdatesPerTick).
const double QcServer::playerMaxHealth
The health of a player at full health (QcServerClient::maxHealth).