Merge pull request #1313 from woogerboy21/update_pingtime
Update Client & Server ping time
This commit is contained in:
commit
13011180f7
8 changed files with 231 additions and 210 deletions
|
@ -1,7 +1,7 @@
|
|||
#include <QTimer>
|
||||
#include <QThread>
|
||||
#include "remoteclient.h"
|
||||
|
||||
#include "settingscache.h"
|
||||
#include "pending_command.h"
|
||||
#include "pb/commands.pb.h"
|
||||
#include "pb/session_commands.pb.h"
|
||||
|
@ -16,8 +16,10 @@ static const unsigned int protocolVersion = 14;
|
|||
RemoteClient::RemoteClient(QObject *parent)
|
||||
: AbstractClient(parent), timeRunning(0), lastDataReceived(0), messageInProgress(false), handshakeStarted(false), messageLength(0)
|
||||
{
|
||||
|
||||
int keepalive = settingsCache->getKeepAlive();
|
||||
timer = new QTimer(this);
|
||||
timer->setInterval(1000);
|
||||
timer->setInterval(keepalive * 1000);
|
||||
connect(timer, SIGNAL(timeout()), this, SLOT(ping()));
|
||||
|
||||
socket = new QTcpSocket(this);
|
||||
|
@ -309,9 +311,10 @@ void RemoteClient::ping()
|
|||
}
|
||||
}
|
||||
|
||||
int keepalive = settingsCache->getKeepAlive();
|
||||
int maxTime = timeRunning - lastDataReceived;
|
||||
emit maxPingTime(maxTime, maxTimeout);
|
||||
if (maxTime >= maxTimeout) {
|
||||
if (maxTime >= (keepalive * maxTimeout)) {
|
||||
disconnectFromServer();
|
||||
emit serverTimeout();
|
||||
} else {
|
||||
|
|
|
@ -6,6 +6,7 @@ SettingsCache::SettingsCache()
|
|||
settings = new QSettings(this);
|
||||
|
||||
lang = settings->value("personal/lang").toString();
|
||||
keepalive = settings->value("personal/keepalive", 5).toInt();
|
||||
|
||||
deckPath = settings->value("paths/decks").toString();
|
||||
replaysPath = settings->value("paths/replays").toString();
|
||||
|
|
|
@ -97,6 +97,7 @@ private:
|
|||
bool spectatorsNeedPassword;
|
||||
bool spectatorsCanTalk;
|
||||
bool spectatorsCanSeeEverything;
|
||||
int keepalive;
|
||||
public:
|
||||
SettingsCache();
|
||||
const QByteArray &getMainWindowGeometry() const { return mainWindowGeometry; }
|
||||
|
@ -167,6 +168,7 @@ public:
|
|||
bool getSpectatorsNeedPassword() const { return spectatorsNeedPassword; }
|
||||
bool getSpectatorsCanTalk() const { return spectatorsCanTalk; }
|
||||
bool getSpectatorsCanSeeEverything() const { return spectatorsCanSeeEverything; }
|
||||
int getKeepAlive() const { return keepalive; }
|
||||
public slots:
|
||||
void setMainWindowGeometry(const QByteArray &_mainWindowGeometry);
|
||||
void setLang(const QString &_lang);
|
||||
|
|
|
@ -56,6 +56,7 @@ public:
|
|||
virtual QString getLoginMessage() const { return QString(); }
|
||||
|
||||
virtual bool getGameShouldPing() const { return false; }
|
||||
virtual int getPingClockInterval() const { return 0; }
|
||||
virtual int getMaxGameInactivityTime() const { return 9999999; }
|
||||
virtual int getMaxPlayerInactivityTime() const { return 9999999; }
|
||||
virtual int getMessageCountingInterval() const { return 0; }
|
||||
|
|
|
@ -342,22 +342,31 @@ void Server_ProtocolHandler::processCommandContainer(const CommandContainer &con
|
|||
|
||||
void Server_ProtocolHandler::pingClockTimeout()
|
||||
{
|
||||
|
||||
int cmdcountinterval = server->getCommandCountingInterval();
|
||||
int msgcountinterval = server->getMessageCountingInterval();
|
||||
int pingclockinterval = server->getPingClockInterval();
|
||||
|
||||
int interval = server->getMessageCountingInterval();
|
||||
if (interval > 0) {
|
||||
if(pingclockinterval > 0) {
|
||||
messageSizeOverTime.prepend(0);
|
||||
if (messageSizeOverTime.size() > server->getMessageCountingInterval())
|
||||
if (messageSizeOverTime.size() > (msgcountinterval / pingclockinterval))
|
||||
messageSizeOverTime.removeLast();
|
||||
messageCountOverTime.prepend(0);
|
||||
if (messageCountOverTime.size() > server->getMessageCountingInterval())
|
||||
if (messageCountOverTime.size() > (msgcountinterval / pingclockinterval))
|
||||
messageCountOverTime.removeLast();
|
||||
}
|
||||
}
|
||||
|
||||
interval = server->getCommandCountingInterval();
|
||||
if (interval > 0) {
|
||||
if (pingclockinterval > 0) {
|
||||
commandCountOverTime.prepend(0);
|
||||
if (commandCountOverTime.size() > server->getCommandCountingInterval())
|
||||
if (commandCountOverTime.size() > (cmdcountinterval / pingclockinterval))
|
||||
commandCountOverTime.removeLast();
|
||||
}
|
||||
}
|
||||
|
||||
if (timeRunning - lastDataReceived > server->getMaxPlayerInactivityTime())
|
||||
prepareDestroy();
|
||||
|
|
|
@ -38,6 +38,14 @@ logfile=server.log
|
|||
; it won't be logged. Default is empty; example: "kittens,ponies,faires"
|
||||
logfilters=""
|
||||
|
||||
; Set the time interval in seconds that servatrice will use to communicate with each connected client
|
||||
; to verify the client has not timed out. Defaults is 1 seconds
|
||||
clientkeepalive=1
|
||||
|
||||
; Maximum time in seconds a player can stay inactive with there client not even responding to pings, before is
|
||||
; considered disconnected; default is 15
|
||||
max_player_inactivity_time=15
|
||||
|
||||
|
||||
[authentication]
|
||||
|
||||
|
@ -178,10 +186,6 @@ roomlist\1\game_types\3\name="GameType3"
|
|||
|
||||
[game]
|
||||
|
||||
; Maximum time in seconds a player can stay inactive, with his client hot even responding to pings, before is
|
||||
; considered disconnected; default is 15
|
||||
max_player_inactivity_time=15
|
||||
|
||||
; Maximum time in seconds all players in a game can stay inactive before the game is automatically closed;
|
||||
; default is 120
|
||||
max_game_inactivity_time=120
|
||||
|
|
|
@ -273,8 +273,8 @@ bool Servatrice::initServer()
|
|||
updateLoginMessage();
|
||||
|
||||
maxGameInactivityTime = settingsCache->value("game/max_game_inactivity_time", 120).toInt();
|
||||
maxPlayerInactivityTime = settingsCache->value("game/max_player_inactivity_time", 15).toInt();
|
||||
|
||||
maxPlayerInactivityTime = settingsCache->value("server/max_player_inactivity_time", 15).toInt();
|
||||
pingClockInterval = settingsCache->value("server/clientkeepalive", 1).toInt();
|
||||
maxUsersPerAddress = settingsCache->value("security/max_users_per_address", 4).toInt();
|
||||
messageCountingInterval = settingsCache->value("security/message_counting_interval", 10).toInt();
|
||||
maxMessageCountPerInterval = settingsCache->value("security/max_message_count_per_interval", 15).toInt();
|
||||
|
@ -345,7 +345,7 @@ bool Servatrice::initServer()
|
|||
|
||||
pingClock = new QTimer(this);
|
||||
connect(pingClock, SIGNAL(timeout()), this, SIGNAL(pingClockTimeout()));
|
||||
pingClock->start(1000);
|
||||
pingClock->start(pingClockInterval * 1000);
|
||||
|
||||
int statusUpdateTime = settingsCache->value("server/statusupdate", 15000).toInt();
|
||||
statusUpdateClock = new QTimer(this);
|
||||
|
|
|
@ -115,7 +115,7 @@ private:
|
|||
QMutex txBytesMutex, rxBytesMutex;
|
||||
quint64 txBytes, rxBytes;
|
||||
int maxGameInactivityTime, maxPlayerInactivityTime;
|
||||
int maxUsersPerAddress, messageCountingInterval, maxMessageCountPerInterval, maxMessageSizePerInterval, maxGamesPerUser, commandCountingInterval, maxCommandCountPerInterval;
|
||||
int maxUsersPerAddress, messageCountingInterval, maxMessageCountPerInterval, maxMessageSizePerInterval, maxGamesPerUser, commandCountingInterval, maxCommandCountPerInterval, pingClockInterval;
|
||||
|
||||
QString shutdownReason;
|
||||
int shutdownMinutes;
|
||||
|
@ -137,6 +137,7 @@ public:
|
|||
QString getServerName() const { return serverName; }
|
||||
QString getLoginMessage() const { QMutexLocker locker(&loginMessageMutex); return loginMessage; }
|
||||
bool getGameShouldPing() const { return true; }
|
||||
int getPingClockInterval() const { return pingClockInterval; }
|
||||
int getMaxGameInactivityTime() const { return maxGameInactivityTime; }
|
||||
int getMaxPlayerInactivityTime() const { return maxPlayerInactivityTime; }
|
||||
int getMaxUsersPerAddress() const { return maxUsersPerAddress; }
|
||||
|
|
Loading…
Reference in a new issue