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>
impl<'s> Server<'s>
Sourcepub fn players(
&self,
) -> Result<impl Iterator<Item = Player<'s>> + use<'s>, InterfaceError>
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>
impl<'s> Server<'s>
Sourcepub fn precache_decal(
&self,
decal: &CStr,
preload: bool,
) -> Result<usize, PrecacheError>
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.
Sourcepub fn precache_generic(
&self,
path: &CStr,
preload: bool,
) -> Result<usize, PrecacheError>
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.
Sourcepub fn precache_model(
&self,
model: &CStr,
preload: bool,
) -> Result<usize, PrecacheError>
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>
impl<'s> Server<'s>
Sourcepub const unsafe fn new<S: ?Sized>(
engine: InterfaceFactory,
game_server: InterfaceFactory,
game: Game,
_scope: &'s S,
) -> Self
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:
engineandgame_serverare theCreateInterfacefunctions of the running server’s engine and game-server modules, neither of which is unloaded.- The game DLL was built for
game. 'slies 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.- 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, orRemoveEdict). 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. - Even if it is unregistered, a console command or variable that the
ICvarregistry lists at any point during'sstays allocated, with its name unchanged, until'sends, 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.
Sourcepub fn bot_manager(&self) -> Result<BotManager<'s>, InterfaceError>
pub fn bot_manager(&self) -> Result<BotManager<'s>, InterfaceError>
IBotManager, which creates bots.
Sourcepub fn console_print(&self, message: &CStr)
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.
Sourcepub fn cvar(&self) -> Result<Cvar<'s>, InterfaceError>
pub fn cvar(&self) -> Result<Cvar<'s>, InterfaceError>
ICvar, the console variable and command registry.
Sourcepub const fn engine_factory(&self) -> InterfaceFactory
pub const fn engine_factory(&self) -> InterfaceFactory
The engine module’s interface factory, as passed to Server::new.
Sourcepub fn engine_replay(&self) -> Result<EngineReplay<'s>, InterfaceError>
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.
Sourcepub fn engine_sound(&self) -> Result<EngineSound<'s>, InterfaceError>
pub fn engine_sound(&self) -> Result<EngineSound<'s>, InterfaceError>
IEngineSound, the server’s sound system.
Sourcepub fn engine_trace(&self) -> Result<EngineTrace<'s>, InterfaceError>
pub fn engine_trace(&self) -> Result<EngineTrace<'s>, InterfaceError>
IEngineTrace, which traces rays and queries world contents.
Sourcepub fn find_interface<T>(
&self,
module: Module,
version: &CStr,
) -> Result<NonNull<T>, InterfaceError>
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.
Sourcepub fn game_events(&self) -> Result<GameEventManager<'s>, InterfaceError>
pub fn game_events(&self) -> Result<GameEventManager<'s>, InterfaceError>
IGameEventManager2, which creates, fires, and listens for game events.
Sourcepub const fn game_server_factory(&self) -> InterfaceFactory
pub const fn game_server_factory(&self) -> InterfaceFactory
The game server module’s interface factory, as passed to
Server::new.
Sourcepub fn model_info(&self) -> Result<ModelInfo<'s>, InterfaceError>
pub fn model_info(&self) -> Result<ModelInfo<'s>, InterfaceError>
IVModelInfo, the server’s model registry.
Sourcepub fn network_string_tables(
&self,
) -> Result<NetworkStringTables<'s>, InterfaceError>
pub fn network_string_tables( &self, ) -> Result<NetworkStringTables<'s>, InterfaceError>
INetworkStringTableContainer, the server’s network string tables.
Sourcepub fn player_info_manager(
&self,
) -> Result<PlayerInfoManager<'s>, InterfaceError>
pub fn player_info_manager( &self, ) -> Result<PlayerInfoManager<'s>, InterfaceError>
IPlayerInfoManager, which exposes player state and the engine globals.
Sourcepub fn plugin_helpers(&self) -> Result<PluginHelpers<'s>, InterfaceError>
pub fn plugin_helpers(&self) -> Result<PluginHelpers<'s>, InterfaceError>
IServerPluginHelpers, services for server plugins.
Sourcepub fn server_game_clients(
&self,
) -> Result<ServerGameClients<'s>, InterfaceError>
pub fn server_game_clients( &self, ) -> Result<ServerGameClients<'s>, InterfaceError>
IServerGameClients, the game’s handling of connected clients.
Sourcepub fn server_game_dll(&self) -> Result<ServerGameDll<'s>, InterfaceError>
pub fn server_game_dll(&self) -> Result<ServerGameDll<'s>, InterfaceError>
IServerGameDLL, implemented by the game’s CServerGameDLL.
Sourcepub fn server_game_ents(&self) -> Result<ServerGameEnts<'s>, InterfaceError>
pub fn server_game_ents(&self) -> Result<ServerGameEnts<'s>, InterfaceError>
IServerGameEnts, which converts between entities and edicts.
IServerGameTags, the game’s list of the console variables that tag
the server.
Sourcepub fn server_tools(&self) -> Result<ServerTools<'s>, InterfaceError>
pub fn server_tools(&self) -> Result<ServerTools<'s>, InterfaceError>
IServerTools, which enumerates and manipulates entities.
Sourcepub fn valve_engine(&self) -> Result<ValveEngine<'s>, InterfaceError>
pub fn valve_engine(&self) -> Result<ValveEngine<'s>, InterfaceError>
IVEngineServer, the engine’s services for the game server.
Sourcepub fn voice_server(&self) -> Result<VoiceServer<'s>, InterfaceError>
pub fn voice_server(&self) -> Result<VoiceServer<'s>, InterfaceError>
IVoiceServer, which routes voice between clients.
Source§impl<'s> Server<'s>
impl<'s> Server<'s>
Sourcepub fn game_coordinator(&self) -> Option<GameCoordinator<'s>>
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.