Idle Client Timeout Functionality

Added the functionality client side to log users out of servers if they
are idle for more than 1 hour without joining either a game or room.
Sending a message (room/game/private) or performing a game action.
This commit is contained in:
woogerboy21 2016-10-09 13:55:07 -04:00
parent e4127fead3
commit 7af2f3f057
15 changed files with 70 additions and 3 deletions

View file

@ -30,12 +30,17 @@ RemoteClient::RemoteClient(QObject *parent)
timer->setInterval(keepalive * 1000);
connect(timer, SIGNAL(timeout()), this, SLOT(ping()));
int idlekeepalive = settingsCache->getIdleKeepAlive();
idleTimer = new QTimer(this);
idleTimer->setInterval(idlekeepalive * 1000);
connect(idleTimer, SIGNAL(timeout()), this, SLOT(doIdleTimeOut()));
connect(this, SIGNAL(resetIdleTimerClock()), idleTimer, SLOT(start()));
socket = new QTcpSocket(this);
socket->setSocketOption(QAbstractSocket::LowDelayOption, 1);
connect(socket, SIGNAL(connected()), this, SLOT(slotConnected()));
connect(socket, SIGNAL(readyRead()), this, SLOT(readData()));
connect(socket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(slotSocketError(QAbstractSocket::SocketError)));
connect(this, SIGNAL(serverIdentificationEventReceived(const Event_ServerIdentification &)), this, SLOT(processServerIdentificationEvent(const Event_ServerIdentification &)));
connect(this, SIGNAL(connectionClosedEventReceived(Event_ConnectionClosed)), this, SLOT(processConnectionClosedEvent(Event_ConnectionClosed)));
connect(this, SIGNAL(sigConnectToServer(QString, unsigned int, QString, QString)), this, SLOT(doConnectToServer(QString, unsigned int, QString, QString)));
@ -61,6 +66,7 @@ void RemoteClient::slotConnected()
{
timeRunning = lastDataReceived = 0;
timer->start();
idleTimer->start();
// dirty hack to be compatible with v14 server
sendCommandContainer(CommandContainer());
@ -302,6 +308,7 @@ void RemoteClient::doActivateToServer(const QString &_token)
void RemoteClient::doDisconnectFromServer()
{
timer->stop();
idleTimer->stop();
messageInProgress = false;
handshakeStarted = false;
@ -379,4 +386,15 @@ QString RemoteClient::getSrvClientID(const QString _hostname)
}
QString uniqueServerClientID = QCryptographicHash::hash(srvClientID.toUtf8(), QCryptographicHash::Sha1).toHex().right(15);
return uniqueServerClientID;
}
void RemoteClient::doIdleTimeOut()
{
doDisconnectFromServer();
emit idleTimeout();
}
void RemoteClient::resetIdleTimer()
{
emit resetIdleTimerClock();
}