Files
yourchat/room.h
2017-07-22 22:24:38 +02:00

79 lines
2.4 KiB
C++

#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>
namespace Yc {
namespace Lib {
class Server;
class Room: public Base {
public:
enum RoomType {
none = 0,
dice = 1,
poker = 2,
rounds = 4
};
Room(Server *parent, Json::Value roomParams);
~Room();
void run();
std::string name();
bool addUser(std::string userName, std::string color, std::string password, int socket);
bool addUser(User *user, std::string password);
bool userNameExists(std::string userName);
void removeUser(std::string _token);
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 = "");
RoomType type();
bool isType(RoomType type);
bool canDice();
unsigned int addDice(User *user, int diceValue);
bool accessAllowed(std::string userName, std::string password);
private:
struct Message {
User::MsgType type;
std::string messageTr;
std::string userName;
std::string color;
};
Server *_parent;
std::string _name;
std::string _password;
std::vector<std::string> _allowedUsers;
RoomType _type;
std::vector<User*> _users;
bool _blocked;
bool _stop;
std::queue<Message> _msgQueue;
std::thread *thread;
bool _roundRunning;
time_t _roundStart;
time_t _lastRoundEnd;
int _roundLength;
std::vector<std::pair<User *, int>> _diceValues;
void _handleDice();
void _startDiceRound();
void _endDiceRound();
void _initRound();
void _showDiceRoundResults();
};
} // namespace Lib
} // namespace Yc
#endif // YC_LIB_ROOM_H