From 49bad39ec13e1b2c878c8e45b8faa395f7c59d52 Mon Sep 17 00:00:00 2001 From: in1tiate Date: Fri, 5 Mar 2021 23:53:36 -0600 Subject: [PATCH 1/6] nonfunctional initial commit --- include/aoclient.h | 4 ++ include/area_data.h | 4 +- include/server.h | 3 ++ src/area_data.cpp | 8 ++++ src/commands.cpp | 95 +++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 113 insertions(+), 1 deletion(-) diff --git a/include/aoclient.h b/include/aoclient.h index d5175f7..64e1f63 100644 --- a/include/aoclient.h +++ b/include/aoclient.h @@ -64,6 +64,7 @@ class AOClient : public QObject { {"BGLOCK", 1ULL << 2}, {"MODIFY_USERS", 1ULL << 3}, {"CM", 1ULL << 4}, + {"GLOBAL_TIMER", 1ULL << 5}, {"SUPER", ~0ULL} }; @@ -198,11 +199,13 @@ class AOClient : public QObject { void cmdRollP(int argc, QStringList argv); void cmdDoc(int argc, QStringList argv); void cmdClearDoc(int argc, QStringList argv); + void cmdTimer(int argc, QStringList argv); // Messaging/Client void cmdPos(int argc, QStringList argv); void cmdG(int argc, QStringList argv); // Command helper functions + QString getAreaTimer(int area_idx, QTimer* timer); QStringList buildAreaList(int area_idx); int genRand(int min, int max); void diceThrower(int argc, QStringList argv, RollType Type); @@ -249,6 +252,7 @@ class AOClient : public QObject { {"lock", {ACLFlags.value("CM"), 0, &AOClient::cmdLock}}, {"spectatable", {ACLFlags.value("CM"), 0, &AOClient::cmdSpectatable}}, {"unlock", {ACLFlags.value("CM"), 0, &AOClient::cmdUnLock}}, + {"timer", {ACLFlags.value("NONE"), 0, &AOClient::cmdTimer}}, }; QString partial_packet; diff --git a/include/area_data.h b/include/area_data.h index 13d30d7..1697ec6 100644 --- a/include/area_data.h +++ b/include/area_data.h @@ -24,6 +24,8 @@ #include #include #include +#include +#include class Logger; class AreaData { @@ -35,7 +37,7 @@ class AreaData { QString description; QString image; }; - + QList timers; QString name; int index; QMap characters_taken; diff --git a/include/server.h b/include/server.h index 1aca99f..ae7db9c 100644 --- a/include/server.h +++ b/include/server.h @@ -32,6 +32,7 @@ #include #include #include +#include class AOClient; class DBManager; @@ -64,6 +65,8 @@ class Server : public QObject { DBManager* db_manager; QString server_name; + QTimer* timer; + signals: public slots: diff --git a/src/area_data.cpp b/src/area_data.cpp index a444c0a..5f3706e 100644 --- a/src/area_data.cpp +++ b/src/area_data.cpp @@ -43,4 +43,12 @@ AreaData::AreaData(QStringList characters, QString p_name, int p_index) if (log_size == 0) log_size = 500; logger = new Logger(log_size, this); + QTimer* timer1; + timers.append(timer1); + QTimer* timer2; + timers.append(timer2); + QTimer* timer3; + timers.append(timer3); + QTimer* timer4; + timers.append(timer4); } diff --git a/src/commands.cpp b/src/commands.cpp index 253c94c..9210575 100644 --- a/src/commands.cpp +++ b/src/commands.cpp @@ -554,6 +554,88 @@ void AOClient::cmdUnLock(int argc, QStringList argv) arup(ARUPType::LOCKED, true); } +void AOClient::cmdTimer(int argc, QStringList argv) +{ + AreaData* area = server->areas[current_area]; + + if (argc == 0) { + QStringList timers; + timers.append("Currently active timers:"); + QTimer* global_timer = server->timer; + if (global_timer->isActive()) { + QTime current_time(0, 0, 0, global_timer->remainingTime()); + timers.append("Global timer is at " + current_time.toString("hh:mm:ss.zzz")); + } + for (AreaData* area : server->areas) { + for (QTimer* timer : area->timers) { + timers.append(getAreaTimer(area->index, timer)); + } + } + sendServerMessage(timers.join("\n")); + return; + } + bool ok; + int timer_id = argv[0].toInt(&ok); + if (!ok || timer_id < 0 || timer_id > 4) { + sendServerMessage("Invalid timer ID. Timer ID must be a whole number between 0 and 4."); + return; + } + + if (argc == 1) { + if (timer_id == 0) { + QTimer* global_timer = server->timer; + if (global_timer->isActive()) { + QTime current_time(0, 0, 0, global_timer->remainingTime()); + sendServerMessage("Global timer is at " + current_time.toString("hh:mm:ss.zzz")); + return; + } + } + else { + QTimer* timer = area->timers[timer_id - 1]; + sendServerMessage(getAreaTimer(area->index, timer)); + return; + } + } + + QTimer* requested_timer; + if (timer_id == 0) { + if (!checkAuth(ACLFlags.value("GLOBAL_TIMER"))) { + sendServerMessage("You are not authorized to alter the global timer."); + return; + } + requested_timer = server->timer; + } + else + requested_timer = area->timers[timer_id - 1]; + QTime requested_time = QTime::fromString(argv[1], "hh:mm:ss"); + if (requested_time.isValid()) { + requested_timer->setInterval(QTime(0,0).msecsTo(requested_time)); + requested_timer->start(); + sendServerMessage("Set timer " + QString::number(timer_id) + " to " + argv[1] + "."); + sendPacket("TI", {QString::number(timer_id), QString::number(0), QString::number(QTime(0,0).msecsTo(requested_time))}); + return; + } + else { + if (argv[1] == "start") { + requested_timer->start(); + sendServerMessage("Started timer " + QString::number(timer_id) + "."); + sendPacket("TI", {QString::number(timer_id), QString::number(0), QString::number(requested_timer->remainingTime())}); + } + else if (argv[1] == "pause" || argv[1] == "stop") { + requested_timer->setInterval(requested_timer->remainingTime()); + requested_timer->stop(); + sendServerMessage("Stopped timer " + QString::number(timer_id) + "."); + sendPacket("TI", {QString::number(timer_id), QString::number(1), QString::number(requested_timer->remainingTime())}); + } + else if (argv[1] == "hide" || argv[1] == "unset") { + requested_timer->setInterval(0); + requested_timer->stop(); + sendServerMessage("Hid timer " + QString::number(timer_id) + "."); + sendPacket("TI", {QString::number(timer_id), QString::number(3)}); + } + } +} + QStringList AOClient::buildAreaList(int area_idx) { QStringList entries; @@ -657,3 +739,16 @@ void AOClient::diceThrower(int argc, QStringList argv, RollType type) default : break; } } + +QString AOClient::getAreaTimer(int area_idx, QTimer* timer) +{ + AreaData* area = server->areas[area_idx]; + if (timer->isActive()) { + QTime current_time (0,0,0,timer->remainingTime()); + return "Timer " + QString::number(area->timers.indexOf(timer) + 1) + " is at " + current_time.toString("hh:mm:ss.zzz"); + } + else { + return "Timer " + QString::number(area->timers.indexOf(timer) + 1) + "is inactive."; + } +} + From e65caf2a59f2b0fc839b69b94a1f91fac84681d1 Mon Sep 17 00:00:00 2001 From: in1tiate Date: Sat, 6 Mar 2021 00:00:50 -0600 Subject: [PATCH 2/6] probably initializing the timers would be a good idea --- src/area_data.cpp | 8 ++++---- src/server.cpp | 1 + 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/area_data.cpp b/src/area_data.cpp index 5f3706e..a2d9373 100644 --- a/src/area_data.cpp +++ b/src/area_data.cpp @@ -43,12 +43,12 @@ AreaData::AreaData(QStringList characters, QString p_name, int p_index) if (log_size == 0) log_size = 500; logger = new Logger(log_size, this); - QTimer* timer1; + QTimer* timer1 = new QTimer(); timers.append(timer1); - QTimer* timer2; + QTimer* timer2 = new QTimer(); timers.append(timer2); - QTimer* timer3; + QTimer* timer3 = new QTimer(); timers.append(timer3); - QTimer* timer4; + QTimer* timer4 = new QTimer(); timers.append(timer4); } diff --git a/src/server.cpp b/src/server.cpp index e5d728e..b9acff4 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -24,6 +24,7 @@ Server::Server(int p_port, int p_ws_port, QObject* parent) : QObject(parent) port = p_port; ws_port = p_ws_port; + timer = new QTimer(); player_count = 0; From 2e3a16c9b0ea65f2700134642aac5932e6b99720 Mon Sep 17 00:00:00 2001 From: in1tiate Date: Sat, 6 Mar 2021 00:16:39 -0600 Subject: [PATCH 3/6] send packet to show timer --- src/commands.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/commands.cpp b/src/commands.cpp index 9210575..133007a 100644 --- a/src/commands.cpp +++ b/src/commands.cpp @@ -566,10 +566,8 @@ void AOClient::cmdTimer(int argc, QStringList argv) QTime current_time(0, 0, 0, global_timer->remainingTime()); timers.append("Global timer is at " + current_time.toString("hh:mm:ss.zzz")); } - for (AreaData* area : server->areas) { - for (QTimer* timer : area->timers) { - timers.append(getAreaTimer(area->index, timer)); - } + for (QTimer* timer : area->timers) { + timers.append(getAreaTimer(area->index, timer)); } sendServerMessage(timers.join("\n")); return; @@ -585,7 +583,7 @@ void AOClient::cmdTimer(int argc, QStringList argv) if (timer_id == 0) { QTimer* global_timer = server->timer; if (global_timer->isActive()) { - QTime current_time(0, 0, 0, global_timer->remainingTime()); + QTime current_time = QTime(0, 0, 0, global_timer->remainingTime()); sendServerMessage("Global timer is at " + current_time.toString("hh:mm:ss.zzz")); return; } @@ -612,6 +610,7 @@ void AOClient::cmdTimer(int argc, QStringList argv) requested_timer->setInterval(QTime(0,0).msecsTo(requested_time)); requested_timer->start(); sendServerMessage("Set timer " + QString::number(timer_id) + " to " + argv[1] + "."); + sendPacket("TI", {QString::number(timer_id), QString::number(2)}); sendPacket("TI", {QString::number(timer_id), QString::number(0), QString::number(QTime(0,0).msecsTo(requested_time))}); return; } @@ -619,6 +618,7 @@ void AOClient::cmdTimer(int argc, QStringList argv) if (argv[1] == "start") { requested_timer->start(); sendServerMessage("Started timer " + QString::number(timer_id) + "."); + sendPacket("TI", {QString::number(timer_id), QString::number(2)}); sendPacket("TI", {QString::number(timer_id), QString::number(0), QString::number(requested_timer->remainingTime())}); } else if (argv[1] == "pause" || argv[1] == "stop") { @@ -744,11 +744,11 @@ QString AOClient::getAreaTimer(int area_idx, QTimer* timer) { AreaData* area = server->areas[area_idx]; if (timer->isActive()) { - QTime current_time (0,0,0,timer->remainingTime()); + QTime current_time = QTime(0,0,0,timer->remainingTime()); return "Timer " + QString::number(area->timers.indexOf(timer) + 1) + " is at " + current_time.toString("hh:mm:ss.zzz"); } else { - return "Timer " + QString::number(area->timers.indexOf(timer) + 1) + "is inactive."; + return "Timer " + QString::number(area->timers.indexOf(timer) + 1) + " is inactive."; } } From 6cf135a9759e6dd3beb4c76cc1e04d8b3136a4f6 Mon Sep 17 00:00:00 2001 From: in1tiate Date: Sat, 6 Mar 2021 00:25:16 -0600 Subject: [PATCH 4/6] it works! *evil laugh* --- src/commands.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/commands.cpp b/src/commands.cpp index 133007a..7b6f7e0 100644 --- a/src/commands.cpp +++ b/src/commands.cpp @@ -619,13 +619,13 @@ void AOClient::cmdTimer(int argc, QStringList argv) requested_timer->start(); sendServerMessage("Started timer " + QString::number(timer_id) + "."); sendPacket("TI", {QString::number(timer_id), QString::number(2)}); - sendPacket("TI", {QString::number(timer_id), QString::number(0), QString::number(requested_timer->remainingTime())}); + sendPacket("TI", {QString::number(timer_id), QString::number(0), QString::number(QTime(0,0).msecsTo(QTime(0,0).addMSecs(requested_timer->remainingTime())))}); } else if (argv[1] == "pause" || argv[1] == "stop") { requested_timer->setInterval(requested_timer->remainingTime()); requested_timer->stop(); sendServerMessage("Stopped timer " + QString::number(timer_id) + "."); - sendPacket("TI", {QString::number(timer_id), QString::number(1), QString::number(requested_timer->remainingTime())}); + sendPacket("TI", {QString::number(timer_id), QString::number(1), QString::number(QTime(0,0).msecsTo(QTime(0,0).addMSecs(requested_timer->interval())))}); } else if (argv[1] == "hide" || argv[1] == "unset") { requested_timer->setInterval(0); @@ -744,7 +744,7 @@ QString AOClient::getAreaTimer(int area_idx, QTimer* timer) { AreaData* area = server->areas[area_idx]; if (timer->isActive()) { - QTime current_time = QTime(0,0,0,timer->remainingTime()); + QTime current_time = QTime(0,0).addMSecs(timer->remainingTime()); return "Timer " + QString::number(area->timers.indexOf(timer) + 1) + " is at " + current_time.toString("hh:mm:ss.zzz"); } else { From 18efacb8861f8ed0a700a20eadb1508de855d568 Mon Sep 17 00:00:00 2001 From: in1tiate Date: Sat, 6 Mar 2021 00:41:10 -0600 Subject: [PATCH 5/6] set timers when you join and change areas --- src/aoclient.cpp | 10 ++++++++++ src/commands.cpp | 2 +- src/packets.cpp | 17 +++++++++++++++++ 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/aoclient.cpp b/src/aoclient.cpp index 344eebf..7d3a90c 100644 --- a/src/aoclient.cpp +++ b/src/aoclient.cpp @@ -130,6 +130,16 @@ void AOClient::changeArea(int new_area) server->areas[current_area]->characters_taken[current_char] = true; server->updateCharsTaken(server->areas[current_area]); } + for (QTimer* timer : server->areas[current_area]->timers) { + int timer_id = server->areas[current_area]->timers.indexOf(timer) + 1; + if (timer->isActive()) { + sendPacket("TI", {QString::number(timer_id), QString::number(2)}); + sendPacket("TI", {QString::number(timer_id), QString::number(0), QString::number(QTime(0,0).msecsTo(QTime(0,0).addMSecs(timer->remainingTime())))}); + } + else { + sendPacket("TI", {QString::number(timer_id), QString::number(3)}); + } + } sendServerMessage("You moved to area " + server->area_names[current_area]); if (server->areas[current_area]->locked == AreaData::LockStatus::SPECTATABLE) sendServerMessage("Area " + server->area_names[current_area] + " is spectate-only; to chat IC you will need to be invited by the CM."); diff --git a/src/commands.cpp b/src/commands.cpp index 7b6f7e0..6abee2f 100644 --- a/src/commands.cpp +++ b/src/commands.cpp @@ -563,7 +563,7 @@ void AOClient::cmdTimer(int argc, QStringList argv) timers.append("Currently active timers:"); QTimer* global_timer = server->timer; if (global_timer->isActive()) { - QTime current_time(0, 0, 0, global_timer->remainingTime()); + QTime current_time = QTime(0,0).addMSecs(global_timer->remainingTime()); timers.append("Global timer is at " + current_time.toString("hh:mm:ss.zzz")); } for (QTimer* timer : area->timers) { diff --git a/src/packets.cpp b/src/packets.cpp index 3bc7f30..619849d 100644 --- a/src/packets.cpp +++ b/src/packets.cpp @@ -143,6 +143,23 @@ void AOClient::pktSelectChar(AreaData* area, int argc, QStringList argv, AOPacke server->updateCharsTaken(area); sendPacket("PV", {QString::number(id), "CID", argv[1]}); fullArup(); + if (server->timer->isActive()) { + sendPacket("TI", {QString::number(0), QString::number(2)}); + sendPacket("TI", {QString::number(0), QString::number(0), QString::number(QTime(0,0).msecsTo(QTime(0,0).addMSecs(server->timer->remainingTime())))}); + } + else { + sendPacket("TI", {QString::number(0), QString::number(3)}); + } + for (QTimer* timer : area->timers) { + int timer_id = area->timers.indexOf(timer) + 1; + if (timer->isActive()) { + sendPacket("TI", {QString::number(timer_id), QString::number(2)}); + sendPacket("TI", {QString::number(timer_id), QString::number(0), QString::number(QTime(0,0).msecsTo(QTime(0,0).addMSecs(timer->remainingTime())))}); + } + else { + sendPacket("TI", {QString::number(timer_id), QString::number(3)}); + } + } } void AOClient::pktIcChat(AreaData* area, int argc, QStringList argv, AOPacket packet) From 89fda682786c3303e1cddbb14c9e72b8e9e22ecf Mon Sep 17 00:00:00 2001 From: in1tiate <32779090+in1tiate@users.noreply.github.com> Date: Sat, 6 Mar 2021 11:00:36 -0600 Subject: [PATCH 6/6] switch timers to CM-locked --- include/aoclient.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/aoclient.h b/include/aoclient.h index 64e1f63..2a549d5 100644 --- a/include/aoclient.h +++ b/include/aoclient.h @@ -252,7 +252,7 @@ class AOClient : public QObject { {"lock", {ACLFlags.value("CM"), 0, &AOClient::cmdLock}}, {"spectatable", {ACLFlags.value("CM"), 0, &AOClient::cmdSpectatable}}, {"unlock", {ACLFlags.value("CM"), 0, &AOClient::cmdUnLock}}, - {"timer", {ACLFlags.value("NONE"), 0, &AOClient::cmdTimer}}, + {"timer", {ACLFlags.value("CM"), 0, &AOClient::cmdTimer}}, }; QString partial_packet;