Refactor project structure: replace User class with ChatUser, integrate Database class, and update CMake configuration for new files

This commit is contained in:
Torsten Schulz (local)
2025-08-11 14:48:45 +02:00
parent 89956bd01a
commit b81f2de10f
14 changed files with 644 additions and 44 deletions

29
room.h
View File

@@ -1,20 +1,23 @@
#ifndef YC_LIB_ROOM_H
#define YC_LIB_ROOM_H
#include <vector>
#include <string>
#include <user.h>
#include <queue>
#include <thread>
#include <future>
#include <utility>
#include <vector>
#include <base.h>
#include "chat_user.h"
namespace Yc {
namespace Lib {
class Server;
class Server;
class Room: public Base, public std::enable_shared_from_this<Room> {
public:
@@ -31,27 +34,27 @@ namespace Yc {
void run();
std::string name();
bool addUser(std::string userName, std::string color, std::string password, int socket);
bool addUser(std::shared_ptr<User> user, std::string password);
bool addUser(std::shared_ptr<ChatUser> user, std::string password);
bool userNameExists(std::string userName);
void removeUser(std::string _token, bool silent = false);
void removeUser(std::shared_ptr<User> user, bool silent = false);
void removeUser(std::shared_ptr<ChatUser> user, bool silent = false);
void setStop();
void addMessage(User::MsgType type, const char* messageText, std::string userName = "", std::string color = "");
void addMessage(User::MsgType type, std::string messageText, std::string userName = "", std::string color = "");
void addMessage(User::MsgType type, Json::Value messageText, std::string userName = "", std::string color = "");
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 = "");
RoomType type();
bool isType(RoomType type);
bool canDice();
unsigned int addDice(std::shared_ptr<User> user, int diceValue);
unsigned int addDice(std::shared_ptr<ChatUser> user, int diceValue);
bool accessAllowed(std::string userName, std::string password);
bool userIsInRoom(std::string userName);
void addUserWhenQueueEmpty(std::shared_ptr<User> user);
bool userToNewRoom(std::shared_ptr<User> user, std::string newRoom, std::string password);
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();
private:
struct Message {
User::MsgType type;
ChatUser::MsgType type;
std::string messageTr;
std::string userName;
std::string color;
@@ -62,7 +65,7 @@ namespace Yc {
std::string _password;
std::vector<std::string> _allowedUsers;
RoomType _type;
std::vector<std::shared_ptr<User>> _users;
std::vector<std::shared_ptr<ChatUser>> _users;
bool _blocked;
bool _stop;
std::queue<Message> _msgQueue;
@@ -71,7 +74,7 @@ namespace Yc {
time_t _roundStart;
time_t _lastRoundEnd;
int _roundLength;
std::vector<std::pair<std::shared_ptr<User>, int>> _diceValues;
std::vector<std::pair<std::shared_ptr<ChatUser>, int>> _diceValues;
void _handleDice();
void _startDiceRound();
void _endDiceRound();