pub struct Client { /* private fields */ }Expand description
A configured client: where to connect, which version, which account, and how.
One Client can run any number of sessions one after another (reconnects); run several
clients concurrently for several bots (one per process, or many tasks in one process —
a failing session never affects another).
Implementations§
Source§impl Client
impl Client
Sourcepub fn new(
address: TargetAddr,
version: GameVersion,
account: Account,
) -> Client
pub fn new( address: TargetAddr, version: GameVersion, account: Account, ) -> Client
A client with vanilla defaults: direct connection (see Client::connector),
brand vanilla, sensitivity 0.5, 30 s read timeout.
Sourcepub fn signed_chat(self, on: bool) -> Client
pub fn signed_chat(self, on: bool) -> Client
Signed chat on encrypted (online-mode) connections, 1.19.3+ (default on, like vanilla):
the client gets the account’s profile key pair (with the microsoft feature from the
Minecraft services, or the one given to Client::profile_keys), announces a chat
session after each join and signs chat messages and signable command arguments. Off:
everything is sent unsigned (servers with enforce-secure-profile then refuse chat).
Offline-mode connections never sign (vanilla has no key pair there).
Sourcepub fn follow_transfers(self, on: bool) -> Client
pub fn follow_transfers(self, on: bool) -> Client
Follow server transfers (1.20.5+ transfer, default off): the client closes the
connection and logs in to the target with the transfer intent, carrying the cookies the
server stored, within the same Client::run (the behaviour stops and starts again, as
on a reconnect; at most 8 transfers in a row). Off, the session ends with
SessionEnd::Transferred and the application decides (vanilla always follows; a
library should not let a server move a bot to any host, through its proxy, unasked).
Sourcepub fn profile_keys(self, keys: ProfileKeys) -> Client
pub fn profile_keys(self, keys: ProfileKeys) -> Client
Uses this profile key pair for signed chat instead of fetching one (for example a pair kept from an earlier run; it must belong to the account’s profile id).
Sourcepub fn connector(self, connector: Connector) -> Client
pub fn connector(self, connector: Connector) -> Client
How to open the TCP connection (SOCKS5 proxy, proxy policy, timeouts).
Sourcepub fn settings(self, settings: ClientSettings) -> Client
pub fn settings(self, settings: ClientSettings) -> Client
Client settings sent after joining.
Sourcepub fn brand(self, brand: Option<String>) -> Client
pub fn brand(self, brand: Option<String>) -> Client
The client brand sent after joining (None: send none).
Sourcepub fn sensitivity(self, sensitivity: f32) -> Client
pub fn sensitivity(self, sensitivity: f32) -> Client
Mouse sensitivity (options.txt value, 0 … 1) for rotation steps.
Sourcepub fn turn_rate(self, yaw: f64, pitch: f64) -> Client
pub fn turn_rate(self, yaw: f64, pitch: f64) -> Client
The aim’s turn rate cap: at most yaw / pitch degrees per tick (defaults
Rotation::MAX_YAW_PER_TICK 14° /
Rotation::MAX_PITCH_PER_TICK 10.5°).
Every turn stays a whole number of mouse counts of the Client::sensitivity. The cap
is a behaviour choice, not vanilla (a mouse has none; players turn 30–60° in a tick in
fights); values that are not finite and positive keep the default.
Sourcepub fn gui_releases_keys(self, on: bool) -> Client
pub fn gui_releases_keys(self, on: bool) -> Client
A screen (an open window, the player inventory) releases the movement keys, like
vanilla (default on): every version’s setScreen calls KeyBinding.unpressAll, and
the screen takes the keyboard, so while it is open the player walks, jumps, sneaks and
sprints as if no key were held (a sprint ends on the next movement step, a sneak too).
The held Controls apply again once it closes (1.12+ re-read the
held keys then; on 1.8 it is the same as pressing them again). Off: the controls apply
through screens (not vanilla; Grim checks clicking and closing while moving).
1.16.5’s own inventory screen passes key presses through (passEvents): a movement key
pressed while it is open applies (let go of a key held through the opening and press
it again to walk). The OS key repeat of a key held through the opening is not modelled:
it stays released, a vanilla-possible input. 1.8.9 and 1.12.2 screens take every key.
Grim’s MultiActionsC / MultiActionsD flag a click or a close while the server sees a
sprint (also where vanilla allows it): let go of the sprint before clicking.
Sourcepub fn silent_hold(self, d: Duration) -> Client
pub fn silent_hold(self, d: Duration) -> Client
The behaviour is frozen after this long without data from the server (default 1.5 s).
Sourcepub fn read_timeout(self, d: Duration) -> Client
pub fn read_timeout(self, d: Duration) -> Client
The session fails after this long without data from the server (default 30 s, like vanilla’s read timeout).
Sourcepub fn login_timeout(self, d: Duration) -> Client
pub fn login_timeout(self, d: Duration) -> Client
Connecting plus login must finish within this time (default 30 s).
Sourcepub fn record(self, path: impl Into<PathBuf>) -> Client
pub fn record(self, path: impl Into<PathBuf>) -> Client
Records every session’s movement in the oracle’s replay format (every version; the file
is overwritten by each session; MC=<row> oracle/run.sh replay --in <file> runs it in
vanilla). For debugging anticheat flags against vanilla. What the format cannot carry is
written as ghast_note lines (explosion pushes, block changes after a column was first
seen, gliding on 1.12.2, entity pushes and collisions, riding on 26.x).
Sourcepub fn world_config(self, config: WorldConfig) -> Client
pub fn world_config(self, config: WorldConfig) -> Client
What the world keeps besides block states. Default: nothing (no light, no biomes:
the bot does not need them, and they cost memory and decoding time). A viewer that
draws the world can turn them on; crate::WorldView::column gives the data.
Share the block storage of chunk sections with every other client given the same
store (see ghast_world::SharedChunks): bots in the same area then hold one copy of
each identical section instead of one each. Reads stay as fast as without it; a block
change copies only the section it touches, for this bot only. Opt-in (default: every
bot owns its sections). Used by the modern versions (26.1 – 26.3); the older versions
ignore it.
use ghast_client::{Account, Client, GameVersion, world::SharedChunks};
let cache = SharedChunks::new(); // one store for all bots of the process
let mut clients = Vec::new();
for i in 0..10 {
let client = Client::new(
"localhost:25565".parse()?,
GameVersion::V26_2,
Account::offline(&format!("Bot{i}"))?,
)
.shared_chunks(&cache);
clients.push(client);
}Sourcepub fn hold_turn_on_action(self, on: bool) -> Client
pub fn hold_turn_on_action(self, on: bool) -> Client
Keep the look still on a tick that dug or placed when this tick’s turn would take the crosshair off the clicked block, or that used an item without a block when the new look would pick one (on by default). Grim’s RotationPlace re-checks a dig / place / item use with the look of the movement packet that follows it; holding the mouse for one tick is what a player does anyway. The held turn continues on the next tick the behaviour aims.
Sourcepub fn entity_push(self, on: bool) -> Client
pub fn entity_push(self, on: bool) -> Client
Whether other entities push the player (default on, like vanilla). Pushes happen only
with entity tracking (Interests::ENTITIES or Interests::ENTITY_TRACKING):
without it the client knows no entities, so nothing pushes the bot and the crosshair
sees blocks only. With it, on 1.12.2, 1.16.5 and 26.1+ mobs, players and boats around
the player push it in the client’s entity tick; the 1.8.9 client is never pushed by the
client (the switch is a no-op there). Off is not vanilla: a vanilla client always applies
these pushes itself; off keeps entity tracking (crosshair, attack, interact) without
them. A behaviour can switch it at run time with TickContext::set_entity_push.
Sourcepub fn force_step_position(self, on: bool) -> Client
pub fn force_step_position(self, on: bool) -> Client
Not vanilla (Grim 2.3 compatibility, off by default): on a tick whose feet height changed (a step-up or landing) but whose move stayed under the 0.03-block resend threshold, send the position anyway. Vanilla sends only the look / on-ground there, which Grim 2.3.73 sets back (soul sand → grass hops).
Sourcepub fn force_step_position_mode(self, mode: ForceStepPosition) -> Client
pub fn force_step_position_mode(self, mode: ForceStepPosition) -> Client
Not vanilla: Client::force_step_position with a choice of rule, e.g.
ForceStepPosition::StepUpOnly, which forces the
position only on step-ups (on ground after the move, feet higher) and leaves sub-0.03
falls and landings vanilla.
Sourcepub fn accept_required_resource_packs(self, on: bool) -> Client
pub fn accept_required_resource_packs(self, on: bool) -> Client
Server resource packs (1.20.3+): optional packs are always declined (the client never shows the prompt); a pack the server requires is reported accepted and loaded when this is on (default), declined otherwise (the server then usually disconnects). Nothing is downloaded.
1.8 – 1.16 packs carry no “required” flag, so this decides for every pack: on, it is
reported accepted then loaded (the vanilla client with the server’s packs enabled),
off, declined. A pack the vanilla client could not load (a level:// world pack, or on
1.12+ a URL its check rejects) is reported “failed download” either way.
Sourcepub fn address(&self) -> &TargetAddr
pub fn address(&self) -> &TargetAddr
The server address.
Sourcepub fn version(&self) -> GameVersion
pub fn version(&self) -> GameVersion
The protocol version.
Sourcepub async fn run<B>(&self, behavior: &mut B) -> Result<SessionEnd, ClientError>where
B: Behavior,
pub async fn run<B>(&self, behavior: &mut B) -> Result<SessionEnd, ClientError>where
B: Behavior,
Runs one session with behavior until the server ends it, the behaviour quits or an
error occurs.
Sourcepub async fn run_until<B, S>(
&self,
behavior: &mut B,
shutdown: S,
) -> Result<SessionEnd, ClientError>
pub async fn run_until<B, S>( &self, behavior: &mut B, shutdown: S, ) -> Result<SessionEnd, ClientError>
Like Client::run, but also ends cleanly (the behaviour is stopped, the socket shut
down) when shutdown completes.