improve arup function, add /status

This commit is contained in:
in1tiate 2021-03-10 19:39:46 -06:00
parent a792c063ee
commit 556fe9a0b1
5 changed files with 68 additions and 37 deletions

View File

@ -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;

View File

@ -28,7 +28,8 @@
#include <QElapsedTimer>
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<QString, bool> characters_taken;
QList<Evidence> evidence;
int player_count;
QString status;
enum Status {
IDLE,
RP,
CASING,
LOOKING_FOR_PLAYERS,
RECESS,
GAMING
};
Q_ENUM(Status);
Status status;
QList<int> owners;
QList<int> invited;
enum LockStatus {
@ -51,6 +61,7 @@ class AreaData {
LOCKED,
SPECTATABLE
};
Q_ENUM(LockStatus);
LockStatus locked;
QString background;
bool is_protected;

View File

@ -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));

View File

@ -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.";

View File

@ -723,13 +723,35 @@ void AOClient::cmdHelp(int argc, QStringList argv)
QMap<QString, CommandInfo>::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;