Added dice, added check for room access

This commit is contained in:
Torsten Schulz
2017-07-22 22:24:38 +02:00
parent b5b4c94f65
commit 105232a9e3
7 changed files with 188 additions and 18 deletions

36
room.h
View File

@@ -6,16 +6,26 @@
#include <user.h>
#include <queue>
#include <thread>
#include <future>
#include <utility>
#include <vector>
#include <base.h>
namespace Yc {
namespace Lib {
class Server;
class Room
{
class Room: public Base {
public:
Room(Server *parent, std::string name, std::string password = "", std::vector<std::string> allowedUsers = std::vector<std::string>());
enum RoomType {
none = 0,
dice = 1,
poker = 2,
rounds = 4
};
Room(Server *parent, Json::Value roomParams);
~Room();
void run();
std::string name();
@@ -24,7 +34,14 @@ namespace Yc {
bool userNameExists(std::string userName);
void removeUser(std::string _token);
void setStop();
void addMessage(User::MsgType type, std::string message, std::string userName = "", std::string color = "");
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;
@@ -37,11 +54,22 @@ namespace Yc {
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