Merge pull request #12 from AttorneyOnline/feature/timers
Add support for 2.9 timers
This commit is contained in:
commit
505c729f7f
@ -64,6 +64,7 @@ class AOClient : public QObject {
|
|||||||
{"BGLOCK", 1ULL << 2},
|
{"BGLOCK", 1ULL << 2},
|
||||||
{"MODIFY_USERS", 1ULL << 3},
|
{"MODIFY_USERS", 1ULL << 3},
|
||||||
{"CM", 1ULL << 4},
|
{"CM", 1ULL << 4},
|
||||||
|
{"GLOBAL_TIMER", 1ULL << 5},
|
||||||
{"SUPER", ~0ULL}
|
{"SUPER", ~0ULL}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -198,11 +199,13 @@ class AOClient : public QObject {
|
|||||||
void cmdRollP(int argc, QStringList argv);
|
void cmdRollP(int argc, QStringList argv);
|
||||||
void cmdDoc(int argc, QStringList argv);
|
void cmdDoc(int argc, QStringList argv);
|
||||||
void cmdClearDoc(int argc, QStringList argv);
|
void cmdClearDoc(int argc, QStringList argv);
|
||||||
|
void cmdTimer(int argc, QStringList argv);
|
||||||
// Messaging/Client
|
// Messaging/Client
|
||||||
void cmdPos(int argc, QStringList argv);
|
void cmdPos(int argc, QStringList argv);
|
||||||
void cmdG(int argc, QStringList argv);
|
void cmdG(int argc, QStringList argv);
|
||||||
|
|
||||||
// Command helper functions
|
// Command helper functions
|
||||||
|
QString getAreaTimer(int area_idx, QTimer* timer);
|
||||||
QStringList buildAreaList(int area_idx);
|
QStringList buildAreaList(int area_idx);
|
||||||
int genRand(int min, int max);
|
int genRand(int min, int max);
|
||||||
void diceThrower(int argc, QStringList argv, RollType Type);
|
void diceThrower(int argc, QStringList argv, RollType Type);
|
||||||
@ -249,6 +252,7 @@ class AOClient : public QObject {
|
|||||||
{"lock", {ACLFlags.value("CM"), 0, &AOClient::cmdLock}},
|
{"lock", {ACLFlags.value("CM"), 0, &AOClient::cmdLock}},
|
||||||
{"spectatable", {ACLFlags.value("CM"), 0, &AOClient::cmdSpectatable}},
|
{"spectatable", {ACLFlags.value("CM"), 0, &AOClient::cmdSpectatable}},
|
||||||
{"unlock", {ACLFlags.value("CM"), 0, &AOClient::cmdUnLock}},
|
{"unlock", {ACLFlags.value("CM"), 0, &AOClient::cmdUnLock}},
|
||||||
|
{"timer", {ACLFlags.value("CM"), 0, &AOClient::cmdTimer}},
|
||||||
};
|
};
|
||||||
|
|
||||||
QString partial_packet;
|
QString partial_packet;
|
||||||
|
@ -24,6 +24,8 @@
|
|||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QSettings>
|
#include <QSettings>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
#include <QTimer>
|
||||||
|
#include <QElapsedTimer>
|
||||||
|
|
||||||
class Logger;
|
class Logger;
|
||||||
class AreaData {
|
class AreaData {
|
||||||
@ -35,7 +37,7 @@ class AreaData {
|
|||||||
QString description;
|
QString description;
|
||||||
QString image;
|
QString image;
|
||||||
};
|
};
|
||||||
|
QList<QTimer*> timers;
|
||||||
QString name;
|
QString name;
|
||||||
int index;
|
int index;
|
||||||
QMap<QString, bool> characters_taken;
|
QMap<QString, bool> characters_taken;
|
||||||
|
@ -32,6 +32,7 @@
|
|||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QTcpServer>
|
#include <QTcpServer>
|
||||||
#include <QTcpSocket>
|
#include <QTcpSocket>
|
||||||
|
#include <QTimer>
|
||||||
|
|
||||||
class AOClient;
|
class AOClient;
|
||||||
class DBManager;
|
class DBManager;
|
||||||
@ -64,6 +65,8 @@ class Server : public QObject {
|
|||||||
DBManager* db_manager;
|
DBManager* db_manager;
|
||||||
QString server_name;
|
QString server_name;
|
||||||
|
|
||||||
|
QTimer* timer;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
@ -130,6 +130,16 @@ void AOClient::changeArea(int new_area)
|
|||||||
server->areas[current_area]->characters_taken[current_char] = true;
|
server->areas[current_area]->characters_taken[current_char] = true;
|
||||||
server->updateCharsTaken(server->areas[current_area]);
|
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]);
|
sendServerMessage("You moved to area " + server->area_names[current_area]);
|
||||||
if (server->areas[current_area]->locked == AreaData::LockStatus::SPECTATABLE)
|
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.");
|
sendServerMessage("Area " + server->area_names[current_area] + " is spectate-only; to chat IC you will need to be invited by the CM.");
|
||||||
|
@ -43,4 +43,12 @@ AreaData::AreaData(QStringList characters, QString p_name, int p_index)
|
|||||||
if (log_size == 0)
|
if (log_size == 0)
|
||||||
log_size = 500;
|
log_size = 500;
|
||||||
logger = new Logger(log_size, this);
|
logger = new Logger(log_size, this);
|
||||||
|
QTimer* timer1 = new QTimer();
|
||||||
|
timers.append(timer1);
|
||||||
|
QTimer* timer2 = new QTimer();
|
||||||
|
timers.append(timer2);
|
||||||
|
QTimer* timer3 = new QTimer();
|
||||||
|
timers.append(timer3);
|
||||||
|
QTimer* timer4 = new QTimer();
|
||||||
|
timers.append(timer4);
|
||||||
}
|
}
|
||||||
|
@ -554,6 +554,88 @@ void AOClient::cmdUnLock(int argc, QStringList argv)
|
|||||||
arup(ARUPType::LOCKED, true);
|
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 = 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) {
|
||||||
|
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 = QTime(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(2)});
|
||||||
|
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(2)});
|
||||||
|
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(QTime(0,0).msecsTo(QTime(0,0).addMSecs(requested_timer->interval())))});
|
||||||
|
}
|
||||||
|
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 AOClient::buildAreaList(int area_idx)
|
||||||
{
|
{
|
||||||
QStringList entries;
|
QStringList entries;
|
||||||
@ -657,3 +739,16 @@ void AOClient::diceThrower(int argc, QStringList argv, RollType type)
|
|||||||
default : break;
|
default : break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString AOClient::getAreaTimer(int area_idx, QTimer* timer)
|
||||||
|
{
|
||||||
|
AreaData* area = server->areas[area_idx];
|
||||||
|
if (timer->isActive()) {
|
||||||
|
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 {
|
||||||
|
return "Timer " + QString::number(area->timers.indexOf(timer) + 1) + " is inactive.";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -143,6 +143,23 @@ void AOClient::pktSelectChar(AreaData* area, int argc, QStringList argv, AOPacke
|
|||||||
server->updateCharsTaken(area);
|
server->updateCharsTaken(area);
|
||||||
sendPacket("PV", {QString::number(id), "CID", argv[1]});
|
sendPacket("PV", {QString::number(id), "CID", argv[1]});
|
||||||
fullArup();
|
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)
|
void AOClient::pktIcChat(AreaData* area, int argc, QStringList argv, AOPacket packet)
|
||||||
|
@ -24,6 +24,7 @@ Server::Server(int p_port, int p_ws_port, QObject* parent) : QObject(parent)
|
|||||||
|
|
||||||
port = p_port;
|
port = p_port;
|
||||||
ws_port = p_ws_port;
|
ws_port = p_ws_port;
|
||||||
|
timer = new QTimer();
|
||||||
|
|
||||||
player_count = 0;
|
player_count = 0;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user