Skip to main content

Plugin

Trait Plugin 

Source
pub trait Plugin: Default + 'static {
Show 23 methods // Provided methods fn init(&mut self, config: &str) -> Result<Registration, String> { ... } fn reload(&mut self, config: &str) -> Result<(), String> { ... } fn shutdown(&mut self, reason: &str) { ... } fn route(&mut self, connection: Connection) -> RouteDecision { ... } fn login(&mut self, ctx: Context) -> Action { ... } fn initial_server(&mut self, ctx: Context) -> Action { ... } fn before_transfer(&mut self, ctx: Context) -> Action { ... } fn command(&mut self, ctx: Context) -> Action { ... } fn suggest(&mut self, ctx: Context) -> Vec<Suggestion> { ... } fn status(&mut self, ping: Ping) -> Option<StatusOverride> { ... } fn http(&mut self, request: HttpRequest) -> Option<HttpResponse> { ... } fn chat(&mut self, attempt: ChatAttempt) -> Action { ... } fn kick(&mut self, ctx: Context) -> Action { ... } fn join(&mut self, ctx: Context) { ... } fn after_transfer(&mut self, ctx: Context) { ... } fn disconnect(&mut self, ctx: Context) { ... } fn message(&mut self, message: BusMessage) { ... } fn timer(&mut self, handle: u64) { ... } fn event(&mut self, event: RiftEvent) { ... } fn dialog(&mut self, response: DialogResponse) { ... } fn job_done(&mut self, handle: u64, outcome: Result<Vec<u8>, String>) { ... } fn work_init(&mut self, config: &str) -> Result<(), String> { ... } fn work(&mut self, payload: Vec<u8>) -> Result<Vec<u8>, String> { ... }
}
Expand description

A Rift plugin. Implement the hooks you need and pass the type to export!.

The instance is created with Default before Plugin::init; see the crate documentation for how state is kept.

Provided Methods§

Source

fn init(&mut self, config: &str) -> Result<Registration, String>

Called once per instance with the plugin’s configuration as JSON ({} without one). Create timers and bus subscriptions here.

Source

fn reload(&mut self, config: &str) -> Result<(), String>

The configuration changed and the manifest sets hot_reload = true.

Source

fn shutdown(&mut self, reason: &str)

The instance is about to be dropped.

Source

fn route(&mut self, connection: Connection) -> RouteDecision

A TCP connection was accepted, before any bytes are read.

Source

fn login(&mut self, ctx: Context) -> Action

A player authenticated. Accepts continue and deny.

Source

fn initial_server(&mut self, ctx: Context) -> Action

Choose the first backend. Accepts continue, deny and server.

Source

fn before_transfer(&mut self, ctx: Context) -> Action

A transfer is about to happen. Accepts continue and deny.

Source

fn command(&mut self, ctx: Context) -> Action

A registered command ran; ctx.command is its name, also when an alias was typed, and ctx.args the text after it. Accepts continue, message, server, queue and leave-queue.

For a command registered with CommandSpec::console, ctx.console tells that the operator console runs it: there is no player then (ctx.uuid is empty and ctx.name is CONSOLE), and a message answer is shown to the operator.

Source

fn suggest(&mut self, ctx: Context) -> Vec<Suggestion>

Complete an argument of a command registered with SuggestKind::Dynamic.

Source

fn status(&mut self, ping: Ping) -> Option<StatusOverride>

A server-list ping; return the fields to replace.

Source

fn http(&mut self, request: HttpRequest) -> Option<HttpResponse>

An authenticated request to /ext or /ext/* on the web server.

Source

fn chat(&mut self, attempt: ChatAttempt) -> Action

A player sent a chat message, or a command that neither Rift nor a plugin owns, and the backend has not seen it yet. Accepts continue, which lets it through unchanged, and deny, which drops it and shows the player the text.

Delivered only when Registration::hooks lists Hook::Chat; see the crate documentation for what that requires of the proxy. For a command, attempt.ctx.command is the root name and attempt.ctx.args the rest.

Source

fn kick(&mut self, ctx: Context) -> Action

A backend kicked a player in play: ctx.server is the backend and ctx.reason its reason without formatting. continue leaves it to network.on_kick, deny disconnects the player with the text and server moves them there.

Delivered only when Registration::hooks lists Hook::Kick.

Source

fn join(&mut self, ctx: Context)

A player joined.

Source

fn after_transfer(&mut self, ctx: Context)

A transfer finished (see ctx.success).

Source

fn disconnect(&mut self, ctx: Context)

A session closed (see ctx.reason).

Source

fn message(&mut self, message: BusMessage)

A message arrived on a subscription made with bus::subscribe.

Source

fn timer(&mut self, handle: u64)

A timer made with timers::every or timers::after fired.

Source

fn event(&mut self, event: RiftEvent)

A Rift event (rift.events.*).

Source

fn dialog(&mut self, response: DialogResponse)

A player clicked a plugin action of a dialog this plugin showed with players::show_dialog. Delivered without being listed in Registration::hooks.

Source

fn job_done(&mut self, handle: u64, outcome: Result<Vec<u8>, String>)

A job started with background::run finished: handle is the one run returned and outcome what Plugin::work returned on the worker, or why the job failed. Delivered without being listed in Registration::hooks.

Source

fn work_init(&mut self, config: &str) -> Result<(), String>

Background workers only: called once per worker before its first job, with the plugin’s configuration as JSON.

A worker is a separate instance of the component. self is a fresh Default value that only work_init and Plugin::work ever see; Plugin::init is never called on it.

Source

fn work(&mut self, payload: Vec<u8>) -> Result<Vec<u8>, String>

Background workers only: one job queued with background::run. It may block; the plugin’s hooks keep running meanwhile. The result reaches Plugin::job_done on the plugin’s main instance.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§