Füge Unterstützung für Würfelspiele hinzu und verbessere Debugging-Optionen
- Implementiere neue Funktionen in der ChatRoom-Klasse für das Starten, Rollen und Beenden von Würfelspielen. - Füge eine Option zur Aktivierung von Debug-Logging in CMake hinzu, um die Entwicklung zu erleichtern. - Aktualisiere die ChatUser-Klasse, um die Interaktion mit dem Würfelspiel zu ermöglichen. - Verbessere die Socket-Verwaltung im Server, um WebSocket-Verbindungen zu unterstützen und die Handhabung von Anfragen zu optimieren. - Aktualisiere die Konfiguration, um die neue Funktionalität zu unterstützen und die Benutzererfahrung zu verbessern.
This commit is contained in:
@@ -9,6 +9,8 @@
|
||||
#include <future>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <chrono>
|
||||
|
||||
#include "lib/base.h"
|
||||
#include "chat_user.h"
|
||||
@@ -53,10 +55,22 @@ namespace Yc
|
||||
unsigned int addDice(std::shared_ptr<ChatUser> user, int diceValue);
|
||||
bool accessAllowed(std::string userName, std::string password);
|
||||
bool userIsInRoom(std::string userName);
|
||||
std::shared_ptr<ChatUser> findUserByName(std::string userName);
|
||||
void addUserWhenQueueEmpty(std::shared_ptr<ChatUser> user);
|
||||
bool userToNewRoom(std::shared_ptr<ChatUser> user, std::string newRoom, std::string password);
|
||||
unsigned int flags();
|
||||
Json::Value userList();
|
||||
|
||||
// Neue Würfel-Funktionen
|
||||
bool startDiceGame(int rounds, std::shared_ptr<ChatUser> admin);
|
||||
bool rollDice(std::shared_ptr<ChatUser> 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 Message
|
||||
@@ -67,6 +81,14 @@ namespace Yc
|
||||
std::string color;
|
||||
};
|
||||
|
||||
struct DiceResult
|
||||
{
|
||||
std::string userName;
|
||||
int diceValue;
|
||||
std::chrono::steady_clock::time_point rollTime;
|
||||
bool valid;
|
||||
};
|
||||
|
||||
std::shared_ptr<Server> _parent;
|
||||
std::string _name;
|
||||
std::string _password;
|
||||
@@ -83,11 +105,30 @@ namespace Yc
|
||||
int _roundLength;
|
||||
std::vector<std::pair<std::shared_ptr<ChatUser>, 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<std::string, std::vector<DiceResult>> _gameResults; // userName -> Runden-Ergebnisse
|
||||
std::map<std::string, bool> _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<ChatUser> user) const;
|
||||
};
|
||||
|
||||
} // namespace Lib
|
||||
|
||||
Reference in New Issue
Block a user