Skip to main content

Server

Struct Server 

Source
pub struct Server<'s> { /* private fields */ }
Expand description

The running server, as seen from one call the engine makes into a plugin.

Every other type in this crate is reached from here. A Server holds the engine’s and game server’s interface factories, the only objects in Source from which every interface is reachable, and resolves an interface each time an accessor is called. Interfaces are process-wide singletons, so each accessor returns the same object; resolving is a short string search. An accessor returns an InterfaceError if the module does not export its interface at the version these bindings were generated for.

The lifetime 's is the scope Server::new vouches for. Handles derived from a Server carry it, so none can outlive the callback that created it.

Implementations§

Source§

impl<'s> Server<'s>

Source

pub fn players( &self, ) -> Result<impl Iterator<Item = Player<'s>> + use<'s>, InterfaceError>

Iterates over the players in the game: the clients that have connected, from the first slot, whose edicts hold their entities. A player still connecting may have no entity yet, and is left out.

Fails if the engine does not export its interface, and yields nothing without a game server.

Source§

impl<'s> Server<'s>

Source

pub fn precache_decal( &self, decal: &CStr, preload: bool, ) -> Result<usize, PrecacheError>

Precaches a decal, such as decals/scorch1, and returns its index in the DECAL_PRECACHE table, as the game’s UTIL_PrecacheDecal does. A decal precached already keeps its index.

Source

pub fn precache_generic( &self, path: &CStr, preload: bool, ) -> Result<usize, PrecacheError>

Precaches a generic file, such as a particle definition, and returns its index in the GENERIC_PRECACHE table. A file precached already keeps its index.

Source

pub fn precache_model( &self, model: &CStr, preload: bool, ) -> Result<usize, PrecacheError>

Precaches a model, such as models/props_farm/box.mdl, and returns its index in the MODEL_PRECACHE table, which entities give as their model index. A model precached already keeps its index. With preload, the server loads the model at once, rather than as it is first used.

Source§

impl<'s> Server<'s>

Source

pub const unsafe fn new<S: ?Sized>( engine: InterfaceFactory, game_server: InterfaceFactory, game: Game, _scope: &'s S, ) -> Self

Wraps the running server’s interface factories for the scope 's.

This is the only function the rest of the crate’s safety rests on.

§Safety

For all of 's:

  1. engine and game_server are the CreateInterface functions of the running server’s engine and game-server modules, neither of which is unloaded.
  2. The game DLL was built for game.
  3. 's lies within a single call from the engine into the plugin, on the server’s main thread. No frame, level change, or shutdown completes during it, so the edict table, entity list, and string pools stay allocated.
  4. Code that runs during 's, including engine, game, and other plugins’ code reached through calls made in 's, frees entities only through the engine’s deferred deletion (UTIL_Remove), never immediately (UTIL_RemoveImmediate, RemoveEntityImmediate, or RemoveEdict). This includes map scripts (VScript) the game runs during 's, and rules out restarting the round, which frees nearly every entity. The crate’s safe functions refuse the calls known to break this whatever the map does, such as inputs that run code the caller chooses or spawn entity templates.
  5. Even if it is unregistered, a console command or variable that the ICvar registry lists at any point during 's stays allocated, with its name unchanged, until 's ends, and the module that declared it stays loaded. As in 4, this includes code reached through calls made in 's, such as another plugin’s change callback that unloads a plugin: unloading a Metamod:Source plugin unmaps the commands and variables it declared, and unloading a SourceMod plugin can free the commands it created, with their names.
Source

pub fn bot_manager(&self) -> Result<BotManager<'s>, InterfaceError>

IBotManager, which creates bots.

Source

pub fn console_print(&self, message: &CStr)

Prints to the server console, which rcon’s redirection also receives.

This goes through tier0’s Msg, as the game’s own console commands do. If tier0 cannot be found, it falls back to ICvar::ConsolePrintf, which only listen servers display.

Source

pub fn cvar(&self) -> Result<Cvar<'s>, InterfaceError>

ICvar, the console variable and command registry.

Source

pub const fn engine_factory(&self) -> InterfaceFactory

The engine module’s interface factory, as passed to Server::new.

Source

pub fn engine_replay(&self) -> Result<EngineReplay<'s>, InterfaceError>

IEngineReplay, the engine’s services for its replay system, which recalculate the server’s tags.

That the engine exports it as EngineReplay001 is inferred from the header, which declares that version, and from TF2’s client library, which requests it from the engine; the engine is not public. Like every interface, it fails should the engine not export it.

Source

pub fn engine_sound(&self) -> Result<EngineSound<'s>, InterfaceError>

IEngineSound, the server’s sound system.

Source

pub fn engine_trace(&self) -> Result<EngineTrace<'s>, InterfaceError>

IEngineTrace, which traces rays and queries world contents.

Source

pub fn find_interface<T>( &self, module: Module, version: &CStr, ) -> Result<NonNull<T>, InterfaceError>

Looks up an interface this crate does not wrap.

The pointer is valid for 's if version names an interface that the module implements as a singleton, which almost all are. Dereferencing it requires T to match that interface. Returns an InterfaceError if the module does not export version.

Source

pub const fn game(&self) -> Game

The game the server runs.

Source

pub fn game_events(&self) -> Result<GameEventManager<'s>, InterfaceError>

IGameEventManager2, which creates, fires, and listens for game events.

Source

pub const fn game_server_factory(&self) -> InterfaceFactory

The game server module’s interface factory, as passed to Server::new.

Source

pub fn model_info(&self) -> Result<ModelInfo<'s>, InterfaceError>

IVModelInfo, the server’s model registry.

Source

pub fn network_string_tables( &self, ) -> Result<NetworkStringTables<'s>, InterfaceError>

INetworkStringTableContainer, the server’s network string tables.

Source

pub fn player_info_manager( &self, ) -> Result<PlayerInfoManager<'s>, InterfaceError>

IPlayerInfoManager, which exposes player state and the engine globals.

Source

pub fn plugin_helpers(&self) -> Result<PluginHelpers<'s>, InterfaceError>

IServerPluginHelpers, services for server plugins.

Source

pub fn server_game_clients( &self, ) -> Result<ServerGameClients<'s>, InterfaceError>

IServerGameClients, the game’s handling of connected clients.

Source

pub fn server_game_dll(&self) -> Result<ServerGameDll<'s>, InterfaceError>

IServerGameDLL, implemented by the game’s CServerGameDLL.

Source

pub fn server_game_ents(&self) -> Result<ServerGameEnts<'s>, InterfaceError>

IServerGameEnts, which converts between entities and edicts.

Source

pub fn server_game_tags(&self) -> Result<ServerGameTags<'s>, InterfaceError>

IServerGameTags, the game’s list of the console variables that tag the server.

Source

pub fn server_tools(&self) -> Result<ServerTools<'s>, InterfaceError>

IServerTools, which enumerates and manipulates entities.

Source

pub fn valve_engine(&self) -> Result<ValveEngine<'s>, InterfaceError>

IVEngineServer, the engine’s services for the game server.

Source

pub fn voice_server(&self) -> Result<VoiceServer<'s>, InterfaceError>

IVoiceServer, which routes voice between clients.

Source§

impl<'s> Server<'s>

Source

pub fn game_coordinator(&self) -> Option<GameCoordinator<'s>>

The game server’s connection to the GC, or None while the Steam game server is not running, such as before the first map starts.

Steam creates the connection when the game server first asks for it, as the game does once logged on to Steam, and then returns the same object until it shuts down; see the module documentation.

Trait Implementations§

Source§

impl<'s> Clone for Server<'s>

Source§

fn clone(&self) -> Self

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<'s> Copy for Server<'s>

Source§

impl<'s> Debug for Server<'s>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'s> !Send for Server<'s>

§

impl<'s> !Sync for Server<'s>

§

impl<'s> Freeze for Server<'s>

§

impl<'s> RefUnwindSafe for Server<'s>

§

impl<'s> Unpin for Server<'s>

§

impl<'s> UnsafeUnpin for Server<'s>

§

impl<'s> UnwindSafe for Server<'s>

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