From 2ee6d61231d7fe4f8f8bc75737a21977fcb9ad7a Mon Sep 17 00:00:00 2001 From: tovjemam Date: Sat, 14 Mar 2026 22:45:06 +0100 Subject: [PATCH] Add messages on player join/leave --- src/game/game.cpp | 15 +++++++++++++++ src/game/game.hpp | 4 ++++ 2 files changed, 19 insertions(+) diff --git a/src/game/game.cpp b/src/game/game.cpp index 74e6cf4..a78d96e 100644 --- a/src/game/game.cpp +++ b/src/game/game.cpp @@ -1,5 +1,7 @@ #include "game.hpp" +#include + #include "player.hpp" #include "openworld.hpp" @@ -22,13 +24,26 @@ void game::Game::FinishFrame() void game::Game::PlayerJoined(Player& player) { player.SetWorld(default_world_); + + players_.insert(&player); + BroadcastChat(std::format("{}^r se připoojil jupí jupí jupííí", player.GetName())); } void game::Game::PlayerLeft(Player& player) { + players_.erase(&player); + BroadcastChat(std::format("{}^r se vodpojil zmrd", player.GetName())); } bool game::Game::PlayerInput(Player& player, PlayerInputType type, bool enabled) { return false; // not handled here } + +void game::Game::BroadcastChat(const std::string& text) +{ + for (auto player : players_) + { + player->SendChat(text); + } +} diff --git a/src/game/game.hpp b/src/game/game.hpp index c37bd27..1e492ec 100644 --- a/src/game/game.hpp +++ b/src/game/game.hpp @@ -1,6 +1,7 @@ #pragma once #include +#include #include "world.hpp" @@ -21,9 +22,12 @@ public: void PlayerLeft(Player& player); bool PlayerInput(Player& player, PlayerInputType type, bool enabled); +private: + void BroadcastChat(const std::string& text); private: std::shared_ptr default_world_; + std::set players_; };