Skip to main content

Client

Struct Client 

Source
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

Source

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.

Source

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).

Source

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).

Source

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).

Source

pub fn connector(self, connector: Connector) -> Client

How to open the TCP connection (SOCKS5 proxy, proxy policy, timeouts).

Source

pub fn settings(self, settings: ClientSettings) -> Client

Client settings sent after joining.

Source

pub fn brand(self, brand: Option<String>) -> Client

The client brand sent after joining (None: send none).

Source

pub fn sensitivity(self, sensitivity: f32) -> Client

Mouse sensitivity (options.txt value, 0 … 1) for rotation steps.

Source

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.

Source

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.

Source

pub fn silent_hold(self, d: Duration) -> Client

The behaviour is frozen after this long without data from the server (default 1.5 s).

Source

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).

Source

pub fn login_timeout(self, d: Duration) -> Client

Connecting plus login must finish within this time (default 30 s).

Source

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).

Source

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.

Source

pub fn shared_chunks(self, cache: &SharedChunks) -> Client

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);
}
Source

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.

Source

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.

Source

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).

Source

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.

Source

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.

Source

pub fn address(&self) -> &TargetAddr

The server address.

Source

pub fn version(&self) -> GameVersion

The protocol version.

Source

pub fn account(&self) -> &Account

The account.

Source

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.

Source

pub async fn run_until<B, S>( &self, behavior: &mut B, shutdown: S, ) -> Result<SessionEnd, ClientError>
where B: Behavior, S: Future<Output = ()>,

Like Client::run, but also ends cleanly (the behaviour is stopped, the socket shut down) when shutdown completes.

Trait Implementations§

Source§

impl Clone for Client

Source§

fn clone(&self) -> Client

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Client

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl !RefUnwindSafe for Client

§

impl !UnwindSafe for Client

§

impl Forget for Client

§

impl Freeze for Client
where *const u8 is !null: Freeze, PhantomData<u8>: Freeze, *const ArcInner<MicrosoftAuth> is !null: Freeze, PhantomData<ArcInner<MicrosoftAuth>>: Freeze, *const ArcInner<dyn Fn(&TargetAddr) -> Route + Sync + Send> is !null: Freeze, PhantomData<ArcInner<dyn Fn(&TargetAddr) -> Route + Sync + Send>>: Freeze, *const ArcInner<dyn Resolve> is !null: Freeze, PhantomData<ArcInner<dyn Resolve>>: Freeze, *const ArcInner<Inner> is !null: Freeze, PhantomData<ArcInner<Inner>>: Freeze, *const ArcInner<Mutex<Option<Arc<ProfileKeys>>>> is !null: Freeze, PhantomData<ArcInner<Mutex<Option<Arc<ProfileKeys>>>>>: Freeze,

§

impl Move for Client

§

impl Send for Client
where RawVecInner: Send, Arc<MicrosoftAuth>: Send, Arc<dyn Fn(&TargetAddr) -> Route + Sync + Send>: Send, Arc<dyn Resolve>: Send, Arc<Inner>: Send, Arc<Mutex<Option<Arc<ProfileKeys>>>>: Send,

§

impl Sync for Client
where RawVecInner: Sync, Arc<MicrosoftAuth>: Sync, Arc<dyn Fn(&TargetAddr) -> Route + Sync + Send>: Sync, Arc<dyn Resolve>: Sync, Arc<Inner>: Sync, Arc<Mutex<Option<Arc<ProfileKeys>>>>: Sync,

§

impl Unpin for Client

§

impl UnsafeUnpin for Client
where *const u8 is !null: UnsafeUnpin, PhantomData<u8>: UnsafeUnpin, *const ArcInner<MicrosoftAuth> is !null: UnsafeUnpin, PhantomData<ArcInner<MicrosoftAuth>>: UnsafeUnpin, *const ArcInner<dyn Fn(&TargetAddr) -> Route + Sync + Send> is !null: UnsafeUnpin, PhantomData<ArcInner<dyn Fn(&TargetAddr) -> Route + Sync + Send>>: UnsafeUnpin, *const ArcInner<dyn Resolve> is !null: UnsafeUnpin, PhantomData<ArcInner<dyn Resolve>>: UnsafeUnpin, *const ArcInner<Inner> is !null: UnsafeUnpin, PhantomData<ArcInner<Inner>>: UnsafeUnpin, *const ArcInner<Mutex<Option<Arc<ProfileKeys>>>> is !null: UnsafeUnpin, PhantomData<ArcInner<Mutex<Option<Arc<ProfileKeys>>>>>: UnsafeUnpin,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromRef<T> for T
where T: Clone,

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
Source§

impl<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more