Merge pull request #73 from AttorneyOnline/afk

Add an AFK system, and /afk
This commit is contained in:
Marisa P 2021-04-15 14:32:15 -05:00 committed by GitHub
commit fd5882b675
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 75 additions and 10 deletions

View File

@ -53,7 +53,11 @@ class AOClient : public QObject {
AOClient(Server* p_server, QTcpSocket* p_socket, QObject* parent = nullptr, int user_id = 0)
: QObject(parent), id(user_id), remote_ip(p_socket->peerAddress()), password(""),
joined(false), current_area(0), current_char(""), socket(p_socket), server(p_server),
is_partial(false), last_wtce_time(0) {};
is_partial(false), last_wtce_time(0) {
afk_timer = new QTimer;
afk_timer->setSingleShot(true);
connect(afk_timer, SIGNAL(timeout()), this, SLOT(onAfkTimeout()));
};
/**
* @brief Destructor for the AOClient instance.
@ -239,6 +243,18 @@ class AOClient : public QObject {
*/
bool is_gimped = false;
/**
* @brief If true, the client will be marked as AFK in /getarea. Automatically applied when a configurable
* amount of time has passed since the last interaction, or manually applied by /afk.
*/
bool is_afk = false;
/**
* @brief Timer for tracking user interaction. Automatically restarted whenever a user interacts (i.e. sends any packet besides CH)
*/
QTimer* afk_timer;
public slots:
/**
* @brief A slot for when the client disconnects from the server.
@ -267,6 +283,11 @@ class AOClient : public QObject {
*/
void sendPacket(QString header);
/**
* @brief A slot for when the client's AFK timer runs out.
*/
void onAfkTimeout();
private:
/**
* @brief The TCP socket used to communicate with the client.
@ -1560,6 +1581,15 @@ class AOClient : public QObject {
*/
void cmdAllowIniswap(int argc, QStringList argv);
/**
* @brief Toggles whether this client is considered AFK.
*
* @details No arguments.
*
* @iscommand
*/
void cmdAfk(int argc, QStringList argv);
///@}
/**
@ -1799,10 +1829,11 @@ class AOClient : public QObject {
{"undisemvowel", {ACLFlags.value("MUTE"), 1, &AOClient::cmdUnDisemvowel}},
{"shake", {ACLFlags.value("MUTE"), 1, &AOClient::cmdShake}},
{"unshake", {ACLFlags.value("MUTE"), 1, &AOClient::cmdUnShake}},
{"forceimmediate", {ACLFlags.value("CM"), 1, &AOClient::cmdForceImmediate}},
{"force_noint_pres", {ACLFlags.value("CM"), 1, &AOClient::cmdForceImmediate}},
{"allowiniswap", {ACLFlags.value("CM"), 1, &AOClient::cmdAllowIniswap}},
{"allow_iniswap", {ACLFlags.value("CM"), 1, &AOClient::cmdAllowIniswap}},
{"forceimmediate", {ACLFlags.value("CM"), 0, &AOClient::cmdForceImmediate}},
{"force_noint_pres", {ACLFlags.value("CM"), 0, &AOClient::cmdForceImmediate}},
{"allowiniswap", {ACLFlags.value("CM"), 0, &AOClient::cmdAllowIniswap}},
{"allow_iniswap", {ACLFlags.value("CM"), 0, &AOClient::cmdAllowIniswap}},
{"afk", {ACLFlags.value("NONE"), 0, &AOClient::cmdAfk}},
};
/**

View File

@ -232,6 +232,11 @@ class Server : public QObject {
*/
int max_dice;
/**
* @brief The amount of time in seconds to wait before marking a user AFK.
*/
int afk_timeout;
/**
* @brief The server-wide global timer.
*/

View File

@ -77,6 +77,13 @@ void AOClient::handlePacket(AOPacket packet)
return;
}
if (packet.header != "CH") {
if (is_afk)
sendServerMessage("You are no longer AFK.");
is_afk = false;
afk_timer->start(server->afk_timeout * 1000);
}
if (packet.contents.length() < info.minArgs) {
#ifdef NET_DEBUG
qDebug() << "Invalid packet args length. Minimum is" << info.minArgs << "but only" << packet.contents.length() << "were given.";
@ -314,7 +321,14 @@ bool AOClient::checkAuth(unsigned long long acl_mask)
QString AOClient::getIpid() { return ipid; }
Server* AOClient::getServer() { return server; };
Server* AOClient::getServer() { return server; }
void AOClient::onAfkTimeout()
{
if (!is_afk)
sendServerMessage("You are now AFK.");
is_afk = true;
}
AOClient::~AOClient() {
socket->deleteLater();

View File

@ -1537,6 +1537,12 @@ void AOClient::cmdAllowIniswap(int argc, QStringList argv)
sendServerMessage("Iniswapping in this area is now " + state);
}
void AOClient::cmdAfk(int argc, QStringList argv)
{
is_afk = true;
sendServerMessage("You are now AFK.");
}
QStringList AOClient::buildAreaList(int area_idx)
{
QStringList entries;
@ -1564,6 +1570,8 @@ QStringList AOClient::buildAreaList(int area_idx)
char_entry.insert(0, "[CM] ");
if (authenticated)
char_entry += " (" + client->getIpid() + "): " + client->ooc_name;
if (client->is_afk)
char_entry += " [AFK]";
entries.append(char_entry);
}
}

View File

@ -230,10 +230,17 @@ void Server::loadServerConfig()
auth_type = config.value("auth","simple").toString();
modpass = config.value("modpass","").toString();
bool zalgo_tolerance_conversion_success;
zalgo_tolerance = config.value("zalgo_tolerance", "3").toInt(&zalgo_tolerance_conversion_success);
if (!zalgo_tolerance_conversion_success)
zalgo_tolerance = 3;
maximum_statements = config.value("maximum_statements", 10).toInt();
zalgo_tolerance = config.value("zalgo_tolerance", "3").toInt(&zalgo_tolerance_conversion_success);
if (!zalgo_tolerance_conversion_success)
zalgo_tolerance = 3;
bool maximum_statements_conversion_success;
maximum_statements = config.value("maximum_statements", "10").toInt(&maximum_statements_conversion_success);
if (!maximum_statements_conversion_success)
maximum_statements = 10;
bool afk_timeout_conversion_success;
afk_timeout = config.value("afk_timeout", "300").toInt(&afk_timeout_conversion_success);
if (!afk_timeout_conversion_success)
afk_timeout = 300;
config.endGroup();
//Load dice values