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

View File

@@ -27,7 +27,7 @@ namespace Yc {
User::~User() {
delete thread;
_parent->addMessage(User::system, "leaved_chat", _name, _color);
_parent->addMessage(User::system, std::string("leaved_chat"), _name, _color);
}
std::string User::name() const {
@@ -42,6 +42,10 @@ namespace Yc {
return (toValidate == this);
}
void User::sendMsg(MsgType type, const char *message, std::string userName, std::string color) {
sendMsg(type, std::string(message), userName, color);
}
void User::sendMsg(MsgType type, std::string message , std::string userName, std::string color) {
Json::Value sendMessage;
sendMessage["type"] = type;
@@ -103,6 +107,25 @@ namespace Yc {
Json::Value jsonTree = getJsonTree(message);
if (jsonTree["type"].asString() == "message") {
_parent->addMessage(User::message, jsonTree["message"].asString(), _name, _color);
} else if (jsonTree["type"].asString() == "dice") {
doDice();
} else if (jsonTree["type"].asString() == "scream") {
_parent->addMessage(User::scream, jsonTree["message"].asString(), _name, _color);
} else if (jsonTree["type"].asString() == "do") {
_parent->addMessage(User::dosomething, jsonTree["message"].asString(), _name, _color);
}
}
void User::doDice() {
switch (_parent->addDice(this, (rand() % 6) + 1)) {
case 1:
sendMsg(system, "dice_not_possible", "", "");
break;
case 2:
sendMsg(system, "dice_allready_done", "", "");
break;
default:
break;
}
}
} // namespace Lib