QtCraft API C++ classes QML types Handbook

QcClientSession Class

Client side of one connection: distributes the server's messages to its parts (the world mirror QcWorldMirror, the entity mirror, the screens), drives the local player's parts (clientcore/player: prediction, hand, animation, inventory) once per tick and sends their requests. More...

Header: #include <clientcore/session/QcClientSession.h>
Inherits: QObject

Public Types

State
TickMode

Public Functions

QcClientSession(std::unique_ptr<QcSessionThread> thread, std::unique_ptr<QcTransport> transport, QString playerName)
QcClientSession(const QcClientSession &)
QcClientSession(QcClientSession &&)
QcClientAdmin &admin()
const QcClientAdmin &admin() const
const QcClientAdvancements &advancements() const
QcClientAnvil &anvil()
const QcClientAnvil &anvil() const
const QcAppearance &appearance() const
bool attack()
QcBlockPrediction &blockPrediction()
const QcBlockPrediction &blockPrediction() const
QcCameraMode cameraMode() const
void cancelUse()
void clearRecentSounds()
void closeMachine()
std::shared_ptr<const QcContentRegistry> content() const
QcClientDebugSubscription &debug()
const QcClientDebugSubscription &debug() const
void disconnectFromServer()
const QcMsg::Disconnect &disconnectMessage() const
QString disconnectReason() const
bool dropItem(bool wholeStack)
QcClientEnchanting &enchanting()
const QcClientEnchanting &enchanting() const
QcSessionEnding ending() const
const QHash<quint32, QcClientEntity> &entities() const
QcClientEntities &entityMirror()
const QcClientEntities &entityMirror() const
QcClientGameMode &gameMode()
const QcClientGameMode &gameMode() const
const QcHandActions &hand() const
QcHandTimers handTimers(double alpha) const
QcHurtTilt::Tilt hurtTilt(double alpha) const
const QcPlayerInput &intent() const
const QcInventory &inventory() const
const QcClientInventory &inventoryMirror() const
bool isDead() const
std::optional<QcRoundTripSummary> latency() const
QcLinkStats &linkStats() const
QcEntityPose localPose(double alpha) const
const QcClientLogin &login() const
const QcClientMachineScreen &machine() const
const QcEntityMotion &playerMotion() const
QString playerName() const
const QList<QcMsg::PlayerList::Entry> &players() const
const QcPrediction &prediction() const
bool pressUse()
void releaseUse()
void requestPause(bool paused)
void resetCorrections()
void resetLatency()
void respawn()
void selectHotbarSlot(int slot)
void sendChat(const QString &text)
bool serverPaused() const
double serverSpeed() const
void setAppearance(const QcAppearance &appearance)
void setCameraMode(QcCameraMode mode)
void setContentLanguage(const QString &language)
void setCredentials(QcClientLogin::Credentials credentials)
void setIntent(const QcPlayerInput &intent)
void setMining(bool mining)
QcClientSignEditor &signEditor()
const QcClientSignEditor &signEditor() const
const QcClientSounds &sounds() const
void start(QcClientSession::TickMode mode = TickMode::Threaded)
QcClientSession::State state() const
QcClientStonecutter &stonecutter()
const QcClientStonecutter &stonecutter() const
void tick()
quint64 tickCount() const
QcTickTiming &tickTiming() const
QcClientTrading &trading()
const QcClientTrading &trading() const
bool useItem()
const QcClientVitals &vitals() const
const QcMsg::Welcome &welcome() const
const QcClientWorld *world() const
const QcWorldMirror &worldMirror() const
QcClientSession &operator=(QcClientSession &&)
QcClientSession &operator=(const QcClientSession &)

Signals

void actionRefused()
void advancementReached(const QString &advancement)
void advancementsChanged()
void airChanged()
void blockChanged(QcBlockPos pos, QcBlockId previous)
void chatReceived(const QString &text)
void chunkLoaded(QcChunkPos pos)
void chunkUnloaded(QcChunkPos pos)
void contentReady()
void craftingOpened(int size)
void disconnected(const QString &reason)
void experienceChanged()
void foodChanged()
void gameModeChanged()
void healthChanged()
void inventoryChanged()
void machineChanged()
void machineClosed()
void machineOpened()
void playerBlockChanged(QcBlockPos pos, QcBlockId previous)
void playersChanged()
void serverPauseChanged()
void soundCue(const QcSoundCue &cue)
void stateChanged(QcSessionStates::State state)
void ticked()

Detailed Description

GUI-free; the renderer, the UI and the control interface all observe a session. Its getters hand out the parts themselves; the session keeps what combines them, the player's actions and the signals (decisions E-530, E-717). Connection, ticks and prediction run in a tick core (QcSessionLink, E-560), timer-driven on a thread of its own; the session applies the core's ordered events in its own thread, between two frames.

Member Type Documentation

[alias] QcClientSession::State

The phase of the connection (QcSessionState); stateChanged() reports every change.

[alias] QcClientSession::TickMode

How the session ticks: on the tick thread, by a timer in this thread or by hand (tick()).

Member Function Documentation

QcClientSession::QcClientSession(std::unique_ptr<QcSessionThread> thread, std::unique_ptr<QcTransport> transport, QString playerName)

Ticks on thread, where transport was made (a TLS connection, decisions E-560, E-872).

[delete] QcClientSession::QcClientSession(const QcClientSession &)

Copy-constructs an instance of QcClientSession. This function is deleted.

[delete] QcClientSession::QcClientSession(QcClientSession &&)

Move-constructs an instance of QcClientSession. This function is deleted.

[signal] void QcClientSession::actionRefused()

The mode refused a mining or use of the player (adventure allow-lists); at most once every QcRefusalThrottle::reportTicks.

QcClientAdmin &QcClientSession::admin()

Returns the admin channel (decision E-848): what an operator follows and asks the server for.

const QcClientAdmin &QcClientSession::admin() const

Returns the admin channel, read-only.

[signal] void QcClientSession::advancementReached(const QString &advancement)

The server announced that the local player reached advancement just now (the toast).

const QcClientAdvancements &QcClientSession::advancements() const

Returns the progress in the adventure guide as the server last reported it (decision E-923).

[signal] void QcClientSession::advancementsChanged()

The progress in the adventure guide changed (advancements()).

[signal] void QcClientSession::airChanged()

The player's air under water changed (vitals()).

QcClientAnvil &QcClientSession::anvil()

Returns the anvil's screen the server opened (decision E-866).

const QcClientAnvil &QcClientSession::anvil() const

Returns the anvil's screen the server opened, read-only.

const QcAppearance &QcClientSession::appearance() const

Returns the look sent to the server.

See also setAppearance().

bool QcClientSession::attack()

Hits the targeted entity; returns false without one.

[signal] void QcClientSession::blockChanged(QcBlockPos pos, QcBlockId previous)

The server changed the block at pos; previous is the block before.

QcBlockPrediction &QcClientSession::blockPrediction()

Returns the block prediction (decision E-853): whether the blocks of the player's breaks and placements show before the server confirms them, and the number of the latest predicted action.

const QcBlockPrediction &QcClientSession::blockPrediction() const

Returns the block prediction, read-only.

QcCameraMode QcClientSession::cameraMode() const

Returns the view mode of the graphical client (also switchable through the control interface).

See also setCameraMode().

void QcClientSession::cancelUse()

Lets a drawn launcher go without a shot when the use button is released (cancelled).

[signal] void QcClientSession::chatReceived(const QString &text)

A chat line arrived; text is ready to show (content names in the content language).

[signal] void QcClientSession::chunkLoaded(QcChunkPos pos)

The chunk at pos arrived from the server.

[signal] void QcClientSession::chunkUnloaded(QcChunkPos pos)

The server unloaded the chunk at pos.

void QcClientSession::clearRecentSounds()

Forgets the recent sounds (control interface).

void QcClientSession::closeMachine()

Closes the open machine screen here and asks the server to close it; nothing open, nothing sent.

std::shared_ptr<const QcContentRegistry> QcClientSession::content() const

Returns the content the server sent, null until it arrived.

[signal] void QcClientSession::contentReady()

The server's content arrived; world() and content() are set.

[signal] void QcClientSession::craftingOpened(int size)

Emitted when the server opened a crafting table's grid of size x size slots.

QcClientDebugSubscription &QcClientSession::debug()

Returns the server's debug data: what is asked for and what arrived (QcClientDebugSubscription).

const QcClientDebugSubscription &QcClientSession::debug() const

Returns the server's debug data, read-only.

void QcClientSession::disconnectFromServer()

Sends Disconnect to the server and closes the connection; does nothing once disconnected.

const QcMsg::Disconnect &QcClientSession::disconnectMessage() const

Returns the server's Disconnect message (empty if the link broke or the client left).

QString QcClientSession::disconnectReason() const

Returns why the session ended: the server's Disconnect text (translated, E-094), the connection error, or "Connection closed"; empty while connected.

[signal] void QcClientSession::disconnected(const QString &reason)

The session ended; reason says why (disconnectReason()).

bool QcClientSession::dropItem(bool wholeStack)

Throws one item (or the whole stack with wholeStack) of the selected hotbar slot; nothing when there is none. Returns whether an item was thrown.

QcClientEnchanting &QcClientSession::enchanting()

Returns the enchanting table's screen the server opened (decision E-864).

const QcClientEnchanting &QcClientSession::enchanting() const

Returns the enchanting table's screen the server opened, read-only.

QcSessionEnding QcClientSession::ending() const

Returns why the connection ended; QcSessionEnding::None while connected.

const QHash<quint32, QcClientEntity> &QcClientSession::entities() const

Returns the mirrored entities by id, as the server last reported them.

QcClientEntities &QcClientSession::entityMirror()

Returns the mirror itself: the dying entities, its snapshot clock and buffering (decision E-271).

const QcClientEntities &QcClientSession::entityMirror() const

Returns the entity mirror itself, read-only.

[signal] void QcClientSession::experienceChanged()

The player's experience changed (vitals()).

[signal] void QcClientSession::foodChanged()

The player's food changed (vitals()).

QcClientGameMode &QcClientSession::gameMode()

Returns the game mode the server reported, its rules and the wish to fly (decisions E-282, E-284).

const QcClientGameMode &QcClientSession::gameMode() const

Returns the game mode the server reported, its rules and the wish to fly, read-only.

[signal] void QcClientSession::gameModeChanged()

The server reported a game mode (gameMode()).

const QcHandActions &QcClientSession::hand() const

Returns the hand: the block or entity the player looks at (updated every tick), mining progress.

QcHandTimers QcClientSession::handTimers(double alpha) const

Returns the timers of the hand animation (swing, use) at alpha within the current tick.

[signal] void QcClientSession::healthChanged()

The player's health changed (vitals()).

QcHurtTilt::Tilt QcClientSession::hurtTilt(double alpha) const

Returns the tilt of the view after a hit alpha into the current tick (decision E-971).

const QcPlayerInput &QcClientSession::intent() const

Returns the movement intent of the local player as last set with setIntent().

See also setIntent().

const QcInventory &QcClientSession::inventory() const

Returns the player's inventory as the server sent it.

[signal] void QcClientSession::inventoryChanged()

The inventory, equipment or the selected hotbar slot changed.

const QcClientInventory &QcClientSession::inventoryMirror() const

Returns the inventory, equipment and crafting grid as the server sent them; moving items and crafting are requests to the server.

bool QcClientSession::isDead() const

Returns whether the local player is dead (vitals()).

std::optional<QcRoundTripSummary> QcClientSession::latency() const

Returns the round trip to the server, measured with probes by the tick thread (decision E-886); std::nullopt before the first answer.

QcLinkStats &QcClientSession::linkStats() const

Returns the round trip of the inputs and bytes of the connection (health line, decision E-834).

QcEntityPose QcClientSession::localPose(double alpha) const

Returns the animation of the local player. alpha interpolates within the current tick.

const QcClientLogin &QcClientSession::login() const

Returns the login data and what the server reported about itself.

const QcClientMachineScreen &QcClientSession::machine() const

Returns the machine or chest screen the server opened (position, category, slots, progress).

[signal] void QcClientSession::machineChanged()

Contents or progress of the open machine changed.

[signal] void QcClientSession::machineClosed()

The machine screen closed, by the server or by closeMachine().

[signal] void QcClientSession::machineOpened()

The server opened a machine or chest screen (machine()).

[signal] void QcClientSession::playerBlockChanged(QcBlockPos pos, QcBlockId previous)

Emitted when the block at pos changed from previous because the local player's prediction set it, or the rollback of a refused one (decision E-853); meshed before the others.

const QcEntityMotion &QcClientSession::playerMotion() const

Returns the predicted state after the latest tick.

QString QcClientSession::playerName() const

Returns the name this session plays under (sent in Hello).

const QList<QcMsg::PlayerList::Entry> &QcClientSession::players() const

Returns everyone on the server (QcMsg::PlayerList).

[signal] void QcClientSession::playersChanged()

The list of players on the server changed (players()).

const QcPrediction &QcClientSession::prediction() const

Returns the predicted player (motion one tick earlier, pending inputs, corrections, the minecart ridden).

bool QcClientSession::pressUse()

The use button pressed: uses the item like useItem and, while held, again every QcHandActions::useRepeatTicks ticks until releaseUse or cancelUse (decision E-885). Returns what the first useItem() returns.

void QcClientSession::releaseUse()

The use button released: a drawn launcher shoots (decision E-425); cancelUse lets it go without one.

void QcClientSession::requestPause(bool paused)

Asks the server to pause (paused) while the pause menu is open, or to run on (decision E-877); the server only hears the local player of a world hosted in the game, and only while no one else is connected.

void QcClientSession::resetCorrections()

Forgets the largest correction so far, here and in the tick core (E-257).

void QcClientSession::resetLatency()

Forgets the round trips so far, e.g. those of the busy start (tests); the probes go on.

void QcClientSession::respawn()

Asks the server to respawn the player; only while the player is dead.

void QcClientSession::selectHotbarSlot(int slot)

Selects the hotbar slot and reports the change with inventoryChanged().

void QcClientSession::sendChat(const QString &text)

Sends text as a chat line, trimmed; blank text sends nothing.

[signal] void QcClientSession::serverPauseChanged()

The server's ticks paused or resumed (serverPaused()).

bool QcClientSession::serverPaused() const

Returns whether the server's ticks pause (QcMsg::ServerPause): the player's own prediction rests too.

double QcClientSession::serverSpeed() const

Returns the server's ticks per normal tick as the world shows them (QcMsg::WorldTime::speed: more in a sprint, 0 under /tick freeze), 0 while it pauses even before its WorldTime arrives: the clock of the animated textures (QcAnimationClock, decision E-878).

void QcClientSession::setAppearance(const QcAppearance &appearance)

Sets the look appearance sent to the server; set before start() or at any time later.

See also appearance().

void QcClientSession::setCameraMode(QcCameraMode mode)

Sets the view mode of the graphical client.

See also cameraMode().

void QcClientSession::setContentLanguage(const QString &language)

Sets the language chat lines show content names in (a creature's kind, decision E-873).

void QcClientSession::setCredentials(QcClientLogin::Credentials credentials)

Sets the login data credentials for a network server (E-252), set before start(); server name and MOTD after it.

void QcClientSession::setIntent(const QcPlayerInput &intent)

Sets the movement intent applied on every tick until changed. The sequence number is set by the session. Non-finite values are replaced, ranges clamped and yaw wrapped into [0, 360).

See also intent().

void QcClientSession::setMining(bool mining)

While mining, the targeted block is mined; progress runs from 0 to 1 and resets on target change. In creative mode a press breaks the aimed block at once (with the block prediction, E-853).

QcClientSignEditor &QcClientSession::signEditor()

Returns the editor of a sign the server opened (decision E-766).

const QcClientSignEditor &QcClientSession::signEditor() const

Returns the editor of a sign the server opened, read-only.

[signal] void QcClientSession::soundCue(const QcSoundCue &cue)

Emitted with a sound cue to play now.

const QcClientSounds &QcClientSession::sounds() const

Returns the recent sounds (server and own) and the ambience levels around the player, faded towards the surroundings every tick.

void QcClientSession::start(QcClientSession::TickMode mode = TickMode::Threaded)

Sends Hello and starts ticking on the tick thread, by a timer in this thread or by hand, as mode says.

QcClientSession::State QcClientSession::state() const

Returns the phase of the connection.

[signal] void QcClientSession::stateChanged(QcSessionStates::State state)

The phase of the connection changed to state.

QcClientStonecutter &QcClientSession::stonecutter()

Returns the stonecutter screen the server opened (decision E-785).

const QcClientStonecutter &QcClientSession::stonecutter() const

Returns the stonecutter screen the server opened, read-only.

void QcClientSession::tick()

Advances the client by one tick (TickMode::Manual only; otherwise a timer ticks).

quint64 QcClientSession::tickCount() const

Returns the number of ticks the client ran since the start.

QcTickTiming &QcClientSession::tickTiming() const

Returns the punctuality of the timer-driven ticks (decision E-560); empty with TickMode::Manual. Safe to read and reset while the tick thread runs.

[signal] void QcClientSession::ticked()

The client ran a tick (also while the player is dead).

QcClientTrading &QcClientSession::trading()

Returns the trading screen of a villager the server opened, and trading with it (decision E-414).

const QcClientTrading &QcClientSession::trading() const

Returns the trading screen the server opened, read-only.

bool QcClientSession::useItem()

Uses the held item on the targeted block face (places blocks). Returns false without a target.

const QcClientVitals &QcClientSession::vitals() const

Returns health, food and experience as the server last reported them.

const QcMsg::Welcome &QcClientSession::welcome() const

Returns the server's Welcome: world, seed, view distance streamed to us and our entity (all zero before it came).

const QcClientWorld *QcClientSession::world() const

Returns the blocks of the world mirror, null until the content arrived.

const QcWorldMirror &QcClientSession::worldMirror() const

Returns the world as the server sends it: content, blocks, chunk extras, world time, weather.

[delete] QcClientSession &QcClientSession::operator=(QcClientSession &&)

Move-assigns other to this QcClientSession instance. This function is deleted.

[delete] QcClientSession &QcClientSession::operator=(const QcClientSession &)

Copy-assigns other to this QcClientSession instance. This function is deleted.