Merge pull request #7 from Salanto/Simple-Commands

Implement /g, /need and /flip command
This commit is contained in:
scatterflower 2021-01-09 20:26:03 -06:00 committed by GitHub
commit c6758ea337
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 44 additions and 1 deletions

View File

@ -171,9 +171,13 @@ class AOClient : public QObject {
void cmdListUsers(int argc, QStringList argv);
void cmdLogout(int argc, QStringList argv);
void cmdPos(int argc, QStringList argv);
void cmdG(int argc, QStringList argv);
void cmdNeed(int argc, QStringList argv);
void cmdFlip(int argc, QStringList argv);
// Command helper functions
QStringList buildAreaList(int area_idx);
int genRand(int min, int max);
// Command function global variables
bool change_auth_started = false;
@ -202,7 +206,10 @@ class AOClient : public QObject {
{"removeperm", {ACLFlags.value("MODIFY_USERS"), 2, &AOClient::cmdRemovePerms}},
{"listusers", {ACLFlags.value("MODIFY_USERS"), 0, &AOClient::cmdListUsers}},
{"logout", {ACLFlags.value("NONE"), 0, &AOClient::cmdLogout}},
{"pos", {ACLFlags.value("NONE"), 1, &AOClient::cmdPos}}
{"pos", {ACLFlags.value("NONE"), 1, &AOClient::cmdPos}},
{"g", {ACLFlags.value("NONE"), 1, &AOClient::cmdG}},
{"need", {ACLFlags.value("NONE"), 1, &AOClient::cmdNeed}},
{"flip", {ACLFlags.value("NONE"), 0, &AOClient::cmdFlip}}
};
QString partial_packet;

View File

@ -371,6 +371,29 @@ void AOClient::cmdPos(int argc, QStringList argv)
sendServerMessage("Position changed to " + pos + ".");
}
void AOClient::cmdG(int argc, QStringList argv)
{
QString sender_name = ooc_name;
QString sender_message = argv.join(" ");
server->broadcast(AOPacket("CT", {"[G]" + sender_name, sender_message+ "."}));
return;
}
void AOClient::cmdNeed(int argc, QStringList argv)
{
QString sender_area = server->area_names.value(current_area);
QString sender_message = argv.join(" ");
server->broadcast(AOPacket("CT", {"=== Advert ===","[" + sender_area + "] needs " + sender_message+ "."}));
}
void AOClient::cmdFlip(int argc, QStringList argv)
{
QString sender_name = ooc_name;
QStringList faces = {"head","tails"};
QString face = faces[AOClient::genRand(0,1)];
sendServerMessage(sender_name + " flipped a coin and got " + face + ".");
}
QStringList AOClient::buildAreaList(int area_idx)
{
QStringList entries;
@ -390,3 +413,16 @@ QStringList AOClient::buildAreaList(int area_idx)
}
return entries;
}
int AOClient::genRand(int min, int max)
{
#if QT_VERSION < QT_VERSION_CHECK(5, 10, 0)
qsrand(QDateTime::currentMSecsSinceEpoch());
quint32 random_number = (qrand() % (max - min + 1)) + min;
return random_number;
#else
quint32 random_number = QRandomGenerator::system()->bounded(min, max + 1);
return random_number;
#endif
}