diff --git a/include/aoclient.h b/include/aoclient.h index 20baef2..bcd63f0 100644 --- a/include/aoclient.h +++ b/include/aoclient.h @@ -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; diff --git a/src/commands.cpp b/src/commands.cpp index 4a66c4e..aa84f9f 100644 --- a/src/commands.cpp +++ b/src/commands.cpp @@ -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 +}