R-Type
Distributed multiplayer game engine in C++
Loading...
Searching...
No Matches
server::GameruleBroadcaster Class Reference

Utility class to send gamerule updates to clients. More...

#include <GameruleBroadcaster.hpp>

Collaboration diagram for server::GameruleBroadcaster:
Collaboration graph

Public Member Functions

 GameruleBroadcaster ()=default
 
 ~GameruleBroadcaster ()=default
 

Static Public Member Functions

static void sendAllGamerules (IPeer *peer, const GameRules &rules)
 Send all gamerules to a single client.
 
static void sendGamerule (IPeer *peer, GameruleKey key, float value)
 Send a single gamerule update to a single client (type-safe)
 
static void sendGamerule (IPeer *peer, const std::string &key, float value)
 Send a single gamerule update to a single client (string version)
 
static void broadcastGamerule (const std::vector< IPeer * > &peers, GameruleKey key, float value)
 Broadcast a single gamerule update to multiple clients (type-safe)
 
static void broadcastGamerule (const std::vector< IPeer * > &peers, const std::string &key, float value)
 Broadcast a single gamerule update to multiple clients (string version)
 
static void broadcastGamerules (const std::vector< IPeer * > &peers, const std::unordered_map< GameruleKey, float > &gamerules)
 Broadcast multiple gamerule updates to multiple clients (type-safe)
 
static void broadcastGamerules (const std::vector< IPeer * > &peers, const std::unordered_map< std::string, float > &gamerules)
 Broadcast multiple gamerule updates to multiple clients (string version)
 
static void sendGamerulePacket (IPeer *peer, const RType::Messages::S2C::GamerulePacket &packet)
 Send a pre-built gamerule packet to a single client.
 

Detailed Description

Utility class to send gamerule updates to clients.

This class helps the server synchronize game constants with clients. It can send individual gamerules or batch multiple updates together.

The class provides type-safe methods using GameruleKey enum to prevent typos and string-based methods for flexibility with custom/dynamic keys.

Usage: // Type-safe with enum (recommended) GameruleBroadcaster::sendGamerule(peer, GameruleKey::PLAYER_SPEED, 250.0f); GameruleBroadcaster::broadcastGamerule(peers, GameruleKey::PLAYER_HEALTH, 150.0f);

// String-based (for custom keys) GameruleBroadcaster::sendGamerule(peer, "custom.value", 42.0f);

Definition at line 41 of file GameruleBroadcaster.hpp.

Constructor & Destructor Documentation

◆ GameruleBroadcaster()

server::GameruleBroadcaster::GameruleBroadcaster ( )
default

◆ ~GameruleBroadcaster()

server::GameruleBroadcaster::~GameruleBroadcaster ( )
default

Member Function Documentation

◆ broadcastGamerule() [1/2]

static void server::GameruleBroadcaster::broadcastGamerule ( const std::vector< IPeer * > &  peers,
const std::string &  key,
float  value 
)
inlinestatic

Broadcast a single gamerule update to multiple clients (string version)

Parameters
peersThe peers to send to
keyThe gamerule key string
valueThe gamerule value

Definition at line 118 of file GameruleBroadcaster.hpp.

References RType::Messages::S2C::GamerulePacket::addGamerule(), and sendGamerulePacket().

Here is the call graph for this function:

◆ broadcastGamerule() [2/2]

static void server::GameruleBroadcaster::broadcastGamerule ( const std::vector< IPeer * > &  peers,
GameruleKey  key,
float  value 
)
inlinestatic

Broadcast a single gamerule update to multiple clients (type-safe)

Parameters
peersThe peers to send to
keyThe gamerule key enum
valueThe gamerule value

Definition at line 108 of file GameruleBroadcaster.hpp.

References broadcastGamerule(), and GameruleKeys::toString().

Referenced by broadcastGamerule().

Here is the call graph for this function:

◆ broadcastGamerules() [1/2]

static void server::GameruleBroadcaster::broadcastGamerules ( const std::vector< IPeer * > &  peers,
const std::unordered_map< GameruleKey, float > &  gamerules 
)
inlinestatic

Broadcast multiple gamerule updates to multiple clients (type-safe)

Parameters
peersThe peers to send to
gamerulesMap of gamerule enum-value pairs

Definition at line 135 of file GameruleBroadcaster.hpp.

References RType::Messages::S2C::GamerulePacket::addGamerule(), sendGamerulePacket(), and GameruleKeys::toString().

Here is the call graph for this function:

◆ broadcastGamerules() [2/2]

static void server::GameruleBroadcaster::broadcastGamerules ( const std::vector< IPeer * > &  peers,
const std::unordered_map< std::string, float > &  gamerules 
)
inlinestatic

Broadcast multiple gamerule updates to multiple clients (string version)

Parameters
peersThe peers to send to
gamerulesMap of gamerule string-value pairs

Definition at line 155 of file GameruleBroadcaster.hpp.

References RType::Messages::S2C::GamerulePacket::addGamerule(), and sendGamerulePacket().

Here is the call graph for this function:

◆ sendAllGamerules()

static void server::GameruleBroadcaster::sendAllGamerules ( IPeer peer,
const GameRules rules 
)
inlinestatic

◆ sendGamerule() [1/2]

static void server::GameruleBroadcaster::sendGamerule ( IPeer peer,
const std::string &  key,
float  value 
)
inlinestatic

Send a single gamerule update to a single client (string version)

Parameters
peerThe peer to send to
keyThe gamerule key string
valueThe gamerule value

Definition at line 93 of file GameruleBroadcaster.hpp.

References RType::Messages::S2C::GamerulePacket::addGamerule(), and sendGamerulePacket().

Here is the call graph for this function:

◆ sendGamerule() [2/2]

static void server::GameruleBroadcaster::sendGamerule ( IPeer peer,
GameruleKey  key,
float  value 
)
inlinestatic

Send a single gamerule update to a single client (type-safe)

Parameters
peerThe peer to send to
keyThe gamerule key enum
valueThe gamerule value

Definition at line 83 of file GameruleBroadcaster.hpp.

References sendGamerule(), and GameruleKeys::toString().

Referenced by Server::_sendGameStartToRoom(), and sendGamerule().

Here is the call graph for this function:

◆ sendGamerulePacket()

static void server::GameruleBroadcaster::sendGamerulePacket ( IPeer peer,
const RType::Messages::S2C::GamerulePacket packet 
)
inlinestatic

Send a pre-built gamerule packet to a single client.

Parameters
peerThe peer to send to
packetThe gamerule packet to send

Definition at line 175 of file GameruleBroadcaster.hpp.

References NetworkMessages::createMessage(), createPacket(), RELIABLE, NetworkMessages::S2C_GAMERULE_UPDATE, IPeer::send(), and RType::Messages::S2C::GamerulePacket::serialize().

Referenced by broadcastGamerule(), broadcastGamerules(), broadcastGamerules(), sendAllGamerules(), and sendGamerule().

Here is the call graph for this function:

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