From 3f148c9c669dfb13be9cc0d551bd345e193c0d09 Mon Sep 17 00:00:00 2001 From: Salanto Date: Sat, 9 Jan 2021 14:50:43 +0100 Subject: [PATCH 1/4] Add /g command --- include/aoclient.h | 4 +++- src/commands.cpp | 8 ++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/include/aoclient.h b/include/aoclient.h index 20baef2..7fe4993 100644 --- a/include/aoclient.h +++ b/include/aoclient.h @@ -171,6 +171,7 @@ 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); // Command helper functions QStringList buildAreaList(int area_idx); @@ -202,7 +203,8 @@ 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}} }; QString partial_packet; diff --git a/src/commands.cpp b/src/commands.cpp index 4a66c4e..a81d062 100644 --- a/src/commands.cpp +++ b/src/commands.cpp @@ -371,6 +371,14 @@ 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; +} + QStringList AOClient::buildAreaList(int area_idx) { QStringList entries; From 296426d16390baaf76300dea1c9ff147e3a50ab6 Mon Sep 17 00:00:00 2001 From: Salanto Date: Sat, 9 Jan 2021 22:24:32 +0100 Subject: [PATCH 2/4] Add /need command --- include/aoclient.h | 4 +++- src/commands.cpp | 7 +++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/include/aoclient.h b/include/aoclient.h index 7fe4993..85064e0 100644 --- a/include/aoclient.h +++ b/include/aoclient.h @@ -172,6 +172,7 @@ class AOClient : public QObject { void cmdLogout(int argc, QStringList argv); void cmdPos(int argc, QStringList argv); void cmdG(int argc, QStringList argv); + void cmdNeed(int argc, QStringList argv); // Command helper functions QStringList buildAreaList(int area_idx); @@ -204,7 +205,8 @@ class AOClient : public QObject { {"listusers", {ACLFlags.value("MODIFY_USERS"), 0, &AOClient::cmdListUsers}}, {"logout", {ACLFlags.value("NONE"), 0, &AOClient::cmdLogout}}, {"pos", {ACLFlags.value("NONE"), 1, &AOClient::cmdPos}}, - {"g", {ACLFlags.value("NONE"), 1, &AOClient::cmdG}} + {"g", {ACLFlags.value("NONE"), 1, &AOClient::cmdG}}, + {"need", {ACLFlags.value("NONE"), 1, &AOClient::cmdNeed}} }; QString partial_packet; diff --git a/src/commands.cpp b/src/commands.cpp index a81d062..f0ad57b 100644 --- a/src/commands.cpp +++ b/src/commands.cpp @@ -379,6 +379,13 @@ void AOClient::cmdG(int argc, QStringList argv) 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})); +} + QStringList AOClient::buildAreaList(int area_idx) { QStringList entries; From fd1baacd3df2474ffdc612217cb2750c4c6c843f Mon Sep 17 00:00:00 2001 From: Salanto Date: Sun, 10 Jan 2021 02:58:39 +0100 Subject: [PATCH 3/4] Add /flip command ; Add AOClient::genRand(min, max) Also added some punctuation for /g and /need --- include/aoclient.h | 5 ++++- src/commands.cpp | 25 +++++++++++++++++++++++-- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/include/aoclient.h b/include/aoclient.h index 85064e0..9df70ea 100644 --- a/include/aoclient.h +++ b/include/aoclient.h @@ -173,9 +173,11 @@ class AOClient : public QObject { 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; @@ -206,7 +208,8 @@ class AOClient : public QObject { {"logout", {ACLFlags.value("NONE"), 0, &AOClient::cmdLogout}}, {"pos", {ACLFlags.value("NONE"), 1, &AOClient::cmdPos}}, {"g", {ACLFlags.value("NONE"), 1, &AOClient::cmdG}}, - {"need", {ACLFlags.value("NONE"), 1, &AOClient::cmdNeed}} + {"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 f0ad57b..9772eae 100644 --- a/src/commands.cpp +++ b/src/commands.cpp @@ -375,7 +375,7 @@ 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})); + server->broadcast(AOPacket("CT", {"[G]" + sender_name, sender_message+ "."})); return; } @@ -383,7 +383,15 @@ 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})); + 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) @@ -405,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()); + quint16 random_number = (qrand() % (max - min + 1)) + min; + return random_number; + +#else + quint32 random_number = QRandomGenerator::system()->bounded(min, max + 1); + return random_number; +#endif +} From 6241b3d6cbb63499b1425900c4696cbfff09e3ec Mon Sep 17 00:00:00 2001 From: Salanto Date: Sun, 10 Jan 2021 03:17:49 +0100 Subject: [PATCH 4/4] Fix spacing, Replace quint16 with quint32 in ::genRand() --- include/aoclient.h | 2 +- src/commands.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/include/aoclient.h b/include/aoclient.h index 9df70ea..bcd63f0 100644 --- a/include/aoclient.h +++ b/include/aoclient.h @@ -177,7 +177,7 @@ class AOClient : public QObject { // Command helper functions QStringList buildAreaList(int area_idx); - int genRand(int min, int max); + int genRand(int min, int max); // Command function global variables bool change_auth_started = false; diff --git a/src/commands.cpp b/src/commands.cpp index 9772eae..aa84f9f 100644 --- a/src/commands.cpp +++ b/src/commands.cpp @@ -418,7 +418,7 @@ int AOClient::genRand(int min, int max) { #if QT_VERSION < QT_VERSION_CHECK(5, 10, 0) qsrand(QDateTime::currentMSecsSinceEpoch()); - quint16 random_number = (qrand() % (max - min + 1)) + min; + quint32 random_number = (qrand() % (max - min + 1)) + min; return random_number; #else