|
R-Type
Distributed multiplayer game engine in C++
|
Utility class to send gamerule updates to clients. More...
#include <GameruleBroadcaster.hpp>

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. | |
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.
|
default |
|
default |
|
inlinestatic |
Broadcast a single gamerule update to multiple clients (string version)
| peers | The peers to send to |
| key | The gamerule key string |
| value | The gamerule value |
Definition at line 118 of file GameruleBroadcaster.hpp.
References RType::Messages::S2C::GamerulePacket::addGamerule(), and sendGamerulePacket().

|
inlinestatic |
Broadcast a single gamerule update to multiple clients (type-safe)
| peers | The peers to send to |
| key | The gamerule key enum |
| value | The gamerule value |
Definition at line 108 of file GameruleBroadcaster.hpp.
References broadcastGamerule(), and GameruleKeys::toString().
Referenced by broadcastGamerule().

|
inlinestatic |
Broadcast multiple gamerule updates to multiple clients (type-safe)
| peers | The peers to send to |
| gamerules | Map of gamerule enum-value pairs |
Definition at line 135 of file GameruleBroadcaster.hpp.
References RType::Messages::S2C::GamerulePacket::addGamerule(), sendGamerulePacket(), and GameruleKeys::toString().

|
inlinestatic |
Broadcast multiple gamerule updates to multiple clients (string version)
| peers | The peers to send to |
| gamerules | Map of gamerule string-value pairs |
Definition at line 155 of file GameruleBroadcaster.hpp.
References RType::Messages::S2C::GamerulePacket::addGamerule(), and sendGamerulePacket().

|
inlinestatic |
Send all gamerules to a single client.
| peer | The peer to send to |
| rules | The game rules to send |
This is typically called when a player first connects to ensure they have all the correct game constants.
Definition at line 54 of file GameruleBroadcaster.hpp.
References RType::Messages::S2C::GamerulePacket::addGamerule(), server::GameRules::getDefaultPlayerDamage(), server::GameRules::getDefaultPlayerFireRate(), server::GameRules::getDefaultPlayerHealth(), server::GameRules::getDefaultPlayerSpeed(), server::GameRules::getPlayerSpawnX(), server::GameRules::getPlayerSpawnY(), PLAYER_DAMAGE, PLAYER_FIRE_RATE, PLAYER_HEALTH, PLAYER_SPAWN_X, PLAYER_SPAWN_Y, PLAYER_SPEED, sendGamerulePacket(), and GameruleKeys::toString().
Referenced by Server::_handleHandshakeRequest(), Server::_sendGameStartToRoom(), and Server::_sendGameStartToSpectator().

|
inlinestatic |
Send a single gamerule update to a single client (string version)
| peer | The peer to send to |
| key | The gamerule key string |
| value | The gamerule value |
Definition at line 93 of file GameruleBroadcaster.hpp.
References RType::Messages::S2C::GamerulePacket::addGamerule(), and sendGamerulePacket().

|
inlinestatic |
Send a single gamerule update to a single client (type-safe)
| peer | The peer to send to |
| key | The gamerule key enum |
| value | The gamerule value |
Definition at line 83 of file GameruleBroadcaster.hpp.
References sendGamerule(), and GameruleKeys::toString().
Referenced by Server::_sendGameStartToRoom(), and sendGamerule().

|
inlinestatic |
Send a pre-built gamerule packet to a single client.
| peer | The peer to send to |
| packet | The 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().
