add AFK system
This commit is contained in:
parent
4c5c40b497
commit
f0412e0e05
@ -53,7 +53,10 @@ class AOClient : public QObject {
|
|||||||
AOClient(Server* p_server, QTcpSocket* p_socket, QObject* parent = nullptr, int user_id = 0)
|
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(""),
|
: QObject(parent), id(user_id), remote_ip(p_socket->peerAddress()), password(""),
|
||||||
joined(false), current_area(0), current_char(""), socket(p_socket), server(p_server),
|
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;
|
||||||
|
connect(afk_timer, SIGNAL(timeout()), this, SLOT(onAfkTimeout()));
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Destructor for the AOClient instance.
|
* @brief Destructor for the AOClient instance.
|
||||||
@ -233,6 +236,18 @@ class AOClient : public QObject {
|
|||||||
*/
|
*/
|
||||||
bool is_gimped = false;
|
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:
|
public slots:
|
||||||
/**
|
/**
|
||||||
* @brief A slot for when the client disconnects from the server.
|
* @brief A slot for when the client disconnects from the server.
|
||||||
@ -261,6 +276,11 @@ class AOClient : public QObject {
|
|||||||
*/
|
*/
|
||||||
void sendPacket(QString header);
|
void sendPacket(QString header);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief A slot for when the client's AFK timer runs out.
|
||||||
|
*/
|
||||||
|
void onAfkTimeout();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/**
|
/**
|
||||||
* @brief The TCP socket used to communicate with the client.
|
* @brief The TCP socket used to communicate with the client.
|
||||||
@ -1546,6 +1566,15 @@ class AOClient : public QObject {
|
|||||||
*/
|
*/
|
||||||
void cmdAllowIniswap(int argc, QStringList argv);
|
void cmdAllowIniswap(int argc, QStringList argv);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Toggles whether this client is considered AFK.
|
||||||
|
*
|
||||||
|
* @details No arguments.
|
||||||
|
*
|
||||||
|
* @iscommand
|
||||||
|
*/
|
||||||
|
void cmdAfk(int argc, QStringList argv);
|
||||||
|
|
||||||
///@}
|
///@}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1785,10 +1814,11 @@ class AOClient : public QObject {
|
|||||||
{"undisemvowel", {ACLFlags.value("MUTE"), 1, &AOClient::cmdUnDisemvowel}},
|
{"undisemvowel", {ACLFlags.value("MUTE"), 1, &AOClient::cmdUnDisemvowel}},
|
||||||
{"shake", {ACLFlags.value("MUTE"), 1, &AOClient::cmdShake}},
|
{"shake", {ACLFlags.value("MUTE"), 1, &AOClient::cmdShake}},
|
||||||
{"unshake", {ACLFlags.value("MUTE"), 1, &AOClient::cmdUnShake}},
|
{"unshake", {ACLFlags.value("MUTE"), 1, &AOClient::cmdUnShake}},
|
||||||
{"forceimmediate", {ACLFlags.value("CM"), 1, &AOClient::cmdForceImmediate}},
|
{"forceimmediate", {ACLFlags.value("CM"), 0, &AOClient::cmdForceImmediate}},
|
||||||
{"force_noint_pres", {ACLFlags.value("CM"), 1, &AOClient::cmdForceImmediate}},
|
{"force_noint_pres", {ACLFlags.value("CM"), 0, &AOClient::cmdForceImmediate}},
|
||||||
{"allowiniswap", {ACLFlags.value("CM"), 1, &AOClient::cmdAllowIniswap}},
|
{"allowiniswap", {ACLFlags.value("CM"), 0, &AOClient::cmdAllowIniswap}},
|
||||||
{"allow_iniswap", {ACLFlags.value("CM"), 1, &AOClient::cmdAllowIniswap}},
|
{"allow_iniswap", {ACLFlags.value("CM"), 0, &AOClient::cmdAllowIniswap}},
|
||||||
|
{"afk", {ACLFlags.value("NONE"), 0, &AOClient::cmdAfk}},
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -232,6 +232,11 @@ class Server : public QObject {
|
|||||||
*/
|
*/
|
||||||
int max_dice;
|
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.
|
* @brief The server-wide global timer.
|
||||||
*/
|
*/
|
||||||
|
@ -77,6 +77,13 @@ void AOClient::handlePacket(AOPacket packet)
|
|||||||
return;
|
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) {
|
if (packet.contents.length() < info.minArgs) {
|
||||||
#ifdef NET_DEBUG
|
#ifdef NET_DEBUG
|
||||||
qDebug() << "Invalid packet args length. Minimum is" << info.minArgs << "but only" << packet.contents.length() << "were given.";
|
qDebug() << "Invalid packet args length. Minimum is" << info.minArgs << "but only" << packet.contents.length() << "were given.";
|
||||||
@ -313,7 +320,13 @@ bool AOClient::checkAuth(unsigned long long acl_mask)
|
|||||||
|
|
||||||
QString AOClient::getIpid() { return ipid; }
|
QString AOClient::getIpid() { return ipid; }
|
||||||
|
|
||||||
Server* AOClient::getServer() { return server; };
|
Server* AOClient::getServer() { return server; }
|
||||||
|
|
||||||
|
void AOClient::onAfkTimeout()
|
||||||
|
{
|
||||||
|
is_afk = true;
|
||||||
|
sendServerMessage("You are now AFK.");
|
||||||
|
}
|
||||||
|
|
||||||
AOClient::~AOClient() {
|
AOClient::~AOClient() {
|
||||||
socket->deleteLater();
|
socket->deleteLater();
|
||||||
|
@ -1537,6 +1537,13 @@ void AOClient::cmdAllowIniswap(int argc, QStringList argv)
|
|||||||
sendServerMessage("Iniswapping in this area is now " + state);
|
sendServerMessage("Iniswapping in this area is now " + state);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AOClient::cmdAfk(int argc, QStringList argv)
|
||||||
|
{
|
||||||
|
is_afk = !is_afk;
|
||||||
|
QString state = is_afk ? "now" : "no longer";
|
||||||
|
sendServerMessage("You are " + state + " AFK.");
|
||||||
|
}
|
||||||
|
|
||||||
QStringList AOClient::buildAreaList(int area_idx)
|
QStringList AOClient::buildAreaList(int area_idx)
|
||||||
{
|
{
|
||||||
QStringList entries;
|
QStringList entries;
|
||||||
@ -1564,6 +1571,8 @@ QStringList AOClient::buildAreaList(int area_idx)
|
|||||||
char_entry.insert(0, "[CM] ");
|
char_entry.insert(0, "[CM] ");
|
||||||
if (authenticated)
|
if (authenticated)
|
||||||
char_entry += " (" + client->getIpid() + "): " + client->ooc_name;
|
char_entry += " (" + client->getIpid() + "): " + client->ooc_name;
|
||||||
|
if (client->is_afk)
|
||||||
|
char_entry += " [AFK]";
|
||||||
entries.append(char_entry);
|
entries.append(char_entry);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -232,9 +232,13 @@ void Server::loadServerConfig()
|
|||||||
auth_type = config.value("auth","simple").toString();
|
auth_type = config.value("auth","simple").toString();
|
||||||
modpass = config.value("modpass","").toString();
|
modpass = config.value("modpass","").toString();
|
||||||
bool zalgo_tolerance_conversion_success;
|
bool zalgo_tolerance_conversion_success;
|
||||||
zalgo_tolerance = config.value("zalgo_tolerance", "3").toInt(&zalgo_tolerance_conversion_success);
|
zalgo_tolerance = config.value("zalgo_tolerance", "3").toInt(&zalgo_tolerance_conversion_success);
|
||||||
if (!zalgo_tolerance_conversion_success)
|
if (!zalgo_tolerance_conversion_success)
|
||||||
zalgo_tolerance = 3;
|
zalgo_tolerance = 3;
|
||||||
|
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();
|
config.endGroup();
|
||||||
|
|
||||||
//Load dice values
|
//Load dice values
|
||||||
|
Loading…
Reference in New Issue
Block a user