VoltMod
C++23 framework for CS2 server plugins
Loading...
Searching...
No Matches
VoltMod::GameEvents Class Reference

Creates, fires and listens to game events. More...

#include <GameEvents.hpp>

Inheritance diagram for VoltMod::GameEvents:

Public Member Functions

 GameEvents (Interfaces &interfaces, const Bindings &bindings)
 ~GameEvents () override
 GameEvents (const GameEvents &)=delete
GameEvents & operator= (const GameEvents &)=delete
Status Available () const
IGameEvent * CreateEvent (std::string_view name)
bool FireEvent (IGameEvent *event, bool broadcast=true)
void FreeEvent (IGameEvent *event)
template<class TEvent>
Subscription On (std::function< void(const TEvent &)> handler)
void RemoveAllListeners ()
void OnServerStartup ()
IGameEventListener2 * GetClientLegacyListener (int slot) const
bool ClientListensTo (int slot, std::string_view eventName) const
void FireGameEvent (IGameEvent *event) override

Detailed Description

Creates, fires and listens to game events.

Definition at line 22 of file GameEvents.hpp.

Constructor & Destructor Documentation

◆ GameEvents() [1/2]

VoltMod::GameEvents::GameEvents ( Interfaces & interfaces,
const Bindings & bindings )

Reads IGameEventManager2 into interfaces. Both must outlive this service.

Definition at line 14 of file GameEvents.cpp.

Referenced by GameEvents(), and operator=().

◆ ~GameEvents()

VoltMod::GameEvents::~GameEvents ( )
override

Definition at line 31 of file GameEvents.cpp.

References RemoveAllListeners().

◆ GameEvents() [2/2]

VoltMod::GameEvents::GameEvents ( const GameEvents & )
delete

References GameEvents().

Member Function Documentation

◆ Available()

Status VoltMod::GameEvents::Available ( ) const

An error when the event manager did not resolve.

Definition at line 37 of file GameEvents.cpp.

References VoltMod::Error::Engine(), and VoltMod::Error::Unsupported().

◆ ClientListensTo()

bool VoltMod::GameEvents::ClientListensTo ( int slot,
std::string_view eventName ) const

Whether slot's client listens to eventName; a vanilla client takes only what its HUD needs, so an extra one can mean injected code.

Definition at line 60 of file GameEvents.cpp.

References GetClientLegacyListener().

◆ CreateEvent()

IGameEvent * VoltMod::GameEvents::CreateEvent ( std::string_view name)

Definition at line 72 of file GameEvents.cpp.

◆ FireEvent()

bool VoltMod::GameEvents::FireEvent ( IGameEvent * event,
bool broadcast = true )

Definition at line 84 of file GameEvents.cpp.

◆ FireGameEvent()

void VoltMod::GameEvents::FireGameEvent ( IGameEvent * event)
override

Definition at line 178 of file GameEvents.cpp.

◆ FreeEvent()

void VoltMod::GameEvents::FreeEvent ( IGameEvent * event)

Definition at line 95 of file GameEvents.cpp.

◆ GetClientLegacyListener()

IGameEventListener2 * VoltMod::GameEvents::GetClientLegacyListener ( int slot) const

slot's client listener: an event fired at it reaches that client alone. Null without a client or when the GetLegacyGameEventListener signature did not bind.

Definition at line 50 of file GameEvents.cpp.

References VoltMod::IsValidSlot().

Referenced by ClientListensTo().

◆ On()

template<class TEvent>
Subscription VoltMod::GameEvents::On ( std::function< void(const TEvent &)> handler)
inlinenodiscard

Subscribe to TEvent, a struct from <VoltMod/Events/EventTypes.hpp>, while the returned Subscription lives. An event whose Slot is invalid never reaches handler.

Definition at line 41 of file GameEvents.hpp.

References VoltMod::IsValidSlot().

◆ OnServerStartup()

void VoltMod::GameEvents::OnServerStartup ( )

Re-attach every event that still has a handler: map startup resets the engine's listeners.

Definition at line 128 of file GameEvents.cpp.

References VoltMod::Log::Info(), and VoltMod::Log::Warn().

◆ operator=()

GameEvents & VoltMod::GameEvents::operator= ( const GameEvents & )
delete

References GameEvents().

◆ RemoveAllListeners()

void VoltMod::GameEvents::RemoveAllListeners ( )

Remove every handler and detach from the engine.

Definition at line 163 of file GameEvents.cpp.

Referenced by ~GameEvents().


The documentation for this class was generated from the following files: