diff --git a/include/aoclient.h b/include/aoclient.h index 530efd5..76bc7e7 100644 --- a/include/aoclient.h +++ b/include/aoclient.h @@ -197,6 +197,7 @@ class AOClient : public QObject { void cmdSetBackground(int argc, QStringList argv); void cmdBgLock(int argc, QStringList argv); void cmdBgUnlock(int argc, QStringList argv); + void cmdStatus(int argc, QStringList argv); // Moderation void cmdMods(int argc, QStringList argv); void cmdBan(int argc, QStringList argv); @@ -278,6 +279,7 @@ class AOClient : public QObject { {"toggleglobal", {ACLFlags.value("NONE"), 0, &AOClient::cmdToggleGlobal}}, {"mods", {ACLFlags.value("NONE"), 0, &AOClient::cmdMods}}, {"help", {ACLFlags.value("NONE"), 0, &AOClient::cmdHelp}}, + {"status", {ACLFlags.value("NONE"), 1, &AOClient::cmdStatus}}, }; QString partial_packet; diff --git a/include/area_data.h b/include/area_data.h index 1697ec6..f26311d 100644 --- a/include/area_data.h +++ b/include/area_data.h @@ -28,7 +28,8 @@ #include class Logger; -class AreaData { +class AreaData : public QObject { + Q_OBJECT public: AreaData(QStringList p_characters, QString p_name, int p_index); @@ -43,7 +44,16 @@ class AreaData { QMap characters_taken; QList evidence; int player_count; - QString status; + enum Status { + IDLE, + RP, + CASING, + LOOKING_FOR_PLAYERS, + RECESS, + GAMING + }; + Q_ENUM(Status); + Status status; QList owners; QList invited; enum LockStatus { @@ -51,6 +61,7 @@ class AreaData { LOCKED, SPECTATABLE }; + Q_ENUM(LockStatus); LockStatus locked; QString background; bool is_protected; diff --git a/src/aoclient.cpp b/src/aoclient.cpp index 5a7f3ac..167e919 100644 --- a/src/aoclient.cpp +++ b/src/aoclient.cpp @@ -215,42 +215,38 @@ void AOClient::arup(ARUPType type, bool broadcast) QStringList arup_data; arup_data.append(QString::number(type)); for (AreaData* area : server->areas) { - if (type == ARUPType::PLAYER_COUNT) { - arup_data.append(QString::number(area->player_count)); - } - else if (type == ARUPType::STATUS) { - arup_data.append(area->status); - } - else if (type == ARUPType::CM) { - if (area->owners.isEmpty()) - arup_data.append("FREE"); - else { - QStringList area_owners; - for (int owner_id : area->owners) { - AOClient* owner = server->getClientByID(owner_id); - area_owners.append("[" + QString::number(owner->id) + "] " + owner->current_char); + switch(type) { + case ARUPType::PLAYER_COUNT: { + arup_data.append(QString::number(area->player_count)); + break; + } + case ARUPType::STATUS: { + QString area_status = QVariant::fromValue(area->status).toString().replace("_", "-"); + arup_data.append(area_status); + break; + } + case ARUPType::CM: { + if (area->owners.isEmpty()) + arup_data.append("FREE"); + else { + QStringList area_owners; + for (int owner_id : area->owners) { + AOClient* owner = server->getClientByID(owner_id); + area_owners.append("[" + QString::number(owner->id) + "] " + owner->current_char); + } + arup_data.append(area_owners.join(", ")); } - arup_data.append(area_owners.join(", ")); + break; + } + case ARUPType::LOCKED: { + QString lock_status = QVariant::fromValue(area->locked).toString(); + arup_data.append(lock_status); + break; + } + default: { + return; } } - else if (type == ARUPType::LOCKED) { - QString lock_status; - switch (area->locked) { - case AreaData::LockStatus::FREE: - lock_status = "FREE"; - break; - case AreaData::LockStatus::LOCKED: - lock_status = "LOCKED"; - break; - case AreaData::LockStatus::SPECTATABLE: - lock_status = "SPECTATABLE"; - break; - default: - break; - } - arup_data.append(lock_status); - } - else return; } if (broadcast) server->broadcast(AOPacket("ARUP", arup_data)); diff --git a/src/area_data.cpp b/src/area_data.cpp index 0036af3..bfffba6 100644 --- a/src/area_data.cpp +++ b/src/area_data.cpp @@ -32,7 +32,7 @@ AreaData::AreaData(QStringList characters, QString p_name, int p_index) areas_ini.endGroup(); player_count = 0; locked = FREE; - status = "FREE"; + status = IDLE; def_hp = 10; pro_hp = 10; document = "No document."; diff --git a/src/commands.cpp b/src/commands.cpp index 68ca736..1b32529 100644 --- a/src/commands.cpp +++ b/src/commands.cpp @@ -723,13 +723,35 @@ void AOClient::cmdHelp(int argc, QStringList argv) QMap::const_iterator i; for (i = commands.constBegin(); i!= commands.constEnd(); ++i) { CommandInfo info = i.value(); - if (checkAuth(info.acl_mask)) { + if (checkAuth(info.acl_mask)) { // if we are allowed to use this command entries << "/" + i.key(); } } sendServerMessage(entries.join("\n")); } +void AOClient::cmdStatus(int argc, QStringList argv) { + AreaData* area = server->areas[current_area]; + QString arg = argv[0].toLower(); + if (arg == "idle") + area->status = AreaData::IDLE; + else if (arg == "rp") + area->status = AreaData::RP; + else if (arg == "casing") + area->status = AreaData::CASING; + else if (arg == "looking-for-players" || arg == "lfp") + area->status = AreaData::LOOKING_FOR_PLAYERS; + else if (arg == "recess") + area->status = AreaData::RECESS; + else if (arg == "gaming") + area->status = AreaData::GAMING; + else { + sendServerMessage("That does not look like a valid status. Valid statuses are idle, rp, casing, lfp, recess, gaming"); + return; + } + arup(ARUPType::STATUS, true); +} + QStringList AOClient::buildAreaList(int area_idx) { QStringList entries;