Added dice, added check for room access
This commit is contained in:
25
user.cpp
25
user.cpp
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user