// renamed from room.h #ifndef YC_LIB_CHAT_ROOM_H #define YC_LIB_CHAT_ROOM_H #include #include #include #include #include #include #include #include #include #include "lib/base.h" #include "chat_user.h" #include "object/room.h" #include "lib/database.h" namespace Yc { namespace Lib { class Server; class ChatRoom : public Base, public std::enable_shared_from_this { public: enum RoomType { none = 0, dice = 1, poker = 2, rounds = 4, password = 8 }; ChatRoom(std::shared_ptr parent, Json::Value roomParams); ~ChatRoom(); std::shared_ptr getServer() const { return _parent; } void run(); std::string name(); bool addUser(std::string userName, std::string color, std::string password, int socket); bool addUser(std::string userName, std::string color, std::string password, void* wsi); bool addUser(std::string userName, std::string color, std::string password, void* wsi, std::string token); bool addUser(std::shared_ptr user, std::string password); bool userNameExists(std::string userName); void removeUser(std::string _token, bool silent = false); void removeUser(std::shared_ptr user, bool silent = false); void removeUserDisconnected(std::shared_ptr userToRemove); void setStop(); void addMessage(ChatUser::MsgType type, const char *messageText, std::string userName = "", std::string color = ""); void addMessage(ChatUser::MsgType type, std::string messageText, std::string userName = "", std::string color = ""); void addMessage(ChatUser::MsgType type, Json::Value messageText, std::string userName = "", std::string color = ""); void setDatabase(std::shared_ptr database); RoomType type(); bool isType(RoomType type); bool canDice(); void sendToAllUsers(ChatUser::MsgType type, Json::Value message); unsigned int addDice(std::shared_ptr user, int diceValue); bool accessAllowed(std::string userName, std::string password); bool accessAllowed(std::string userName, std::string password, std::shared_ptr user); bool userIsInRoom(std::string userName); std::shared_ptr findUserByName(std::string userName); std::shared_ptr findUserByToken(std::string token); void addUserWhenQueueEmpty(std::shared_ptr user); bool userToNewRoom(std::shared_ptr user, std::string newRoom, std::string password); unsigned int flags(); Json::Value userList(); // Message structure for internal use struct Message { ChatUser::MsgType type; std::string messageTr; std::string userName; std::string color; }; // Refactored helper methods bool hasMessagesToProcess() const; void processMessageQueue(); void broadcastMessageToUsers(const Message& message); bool shouldSuppressMessageForUser(const Message& message, std::shared_ptr user) const; bool isDiceRoom() const; // Neue Würfel-Funktionen bool startDiceGame(int rounds, std::shared_ptr admin); bool rollDice(std::shared_ptr user, int diceValue); void endDiceGame(); bool isDiceGameRunning() const { return _diceGameRunning; } int getCurrentRound() const { return _currentRound; } int getTotalRounds() const { return _totalRounds; } // Raumliste neu laden void reloadRoomList(); private: struct DiceResult { std::string userName; int diceValue; std::chrono::steady_clock::time_point rollTime; bool valid; }; std::shared_ptr _parent; std::shared_ptr _database; std::string _name; std::string _password; std::vector _allowedUsers; RoomType _type; std::vector> _users; bool _blocked; bool _stop; std::queue _msgQueue; std::unique_ptr thread; bool _roundRunning; time_t _roundStart; time_t _lastRoundEnd; int _roundLength; std::vector, int>> _diceValues; Yc::Object::Room _room; // Neue Würfel-Spiel-Variablen bool _diceGameRunning; int _currentRound; int _totalRounds; std::chrono::steady_clock::time_point _roundStartTime; std::chrono::steady_clock::time_point _gameStartTime; std::map> _gameResults; // userName -> Runden-Ergebnisse std::map _hasRolledThisRound; // userName -> hat in dieser Runde gewürfelt std::thread _roundTimerThread; void _handleDice(); void _startDiceRound(); void _endDiceRound(); void _initRound(); void _showDiceRoundResults(); // Neue Würfel-Funktionen void _startRoundTimer(); void _endRoundTimer(); void _processRoundResults(); void _showGameResults(); void _resetRound(); bool _isUserAdmin(std::shared_ptr user) const; }; } // namespace Lib } // namespace Yc #endif // YC_LIB_CHAT_ROOM_H