mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-04-27 07:48:01 -07:00
Rework idle timeout, now server side (#2259)
* Server side idle timeout Initial commit for server side idle timeout counter. This adds a new int value that is updated when room/game/mod/admin commands occur and is checked during the regular ping timout function that if the users new "idle" value exceeds the idleclienttimeout value defined in the servers configuration file the user is logged out. The user will receive a warning at the 90% time frame mark about being idle. * Use round instead of ceil Travis fix for older xcode issue's. * Fixed requested items Mis-spelleed function, added header, added warning message sent check value. Also corrected the protobuf declaration file for event_notifyuser * Moved bool to protected * Re-Ordered Declarations * Removed most stylistic items Resolved most noted things. * Remove client side idle timeout Removed client side idle timeout functionality
This commit is contained in:
parent
1cebe030f6
commit
6962777ded
23 changed files with 65 additions and 86 deletions
|
|
@ -20,6 +20,7 @@ void FeatureSet::initalizeFeatureList(QMap<QString, bool> &featureList) {
|
|||
featureList.insert("room_chat_history", false);
|
||||
featureList.insert("client_warnings", false);
|
||||
featureList.insert("mod_log_lookup", false);
|
||||
featureList.insert("idle_client", false);
|
||||
}
|
||||
|
||||
void FeatureSet::enableRequiredFeature(QMap<QString, bool> &featureList, QString featureName){
|
||||
|
|
|
|||
|
|
@ -3,8 +3,10 @@ import "session_event.proto";
|
|||
message Event_NotifyUser {
|
||||
|
||||
enum NotificationType {
|
||||
UNKNOWN = 0; // Default enum value if no "type" is defined when used
|
||||
PROMOTED = 1;
|
||||
WARNING = 2;
|
||||
IDLEWARNING = 3;
|
||||
}
|
||||
|
||||
extend SessionEvent {
|
||||
|
|
|
|||
|
|
@ -64,6 +64,7 @@ public:
|
|||
virtual bool getClientIDRequiredEnabled() const { return false; }
|
||||
virtual bool getRegOnlyServerEnabled() const { return false; }
|
||||
virtual bool getMaxUserLimitEnabled() const { return false; }
|
||||
virtual int getIdleClientTimeout() const { return 0; }
|
||||
virtual int getClientKeepAlive() const { return 0; }
|
||||
virtual int getMaxGameInactivityTime() const { return 9999999; }
|
||||
virtual int getMaxPlayerInactivityTime() const { return 9999999; }
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
#include <QDebug>
|
||||
#include <QDateTime>
|
||||
#include <math.h>
|
||||
#include "server_protocolhandler.h"
|
||||
#include "server_database_interface.h"
|
||||
#include "server_room.h"
|
||||
|
|
@ -19,6 +20,7 @@
|
|||
#include "pb/event_game_joined.pb.h"
|
||||
#include "pb/event_room_say.pb.h"
|
||||
#include "pb/serverinfo_user.pb.h"
|
||||
#include "pb/event_notify_user.pb.h"
|
||||
#include <google/protobuf/descriptor.h>
|
||||
#include "featureset.h"
|
||||
|
||||
|
|
@ -31,8 +33,11 @@ Server_ProtocolHandler::Server_ProtocolHandler(Server *_server, Server_DatabaseI
|
|||
authState(NotLoggedIn),
|
||||
acceptsUserListChanges(false),
|
||||
acceptsRoomListChanges(false),
|
||||
idleClientWarningSent(false),
|
||||
timeRunning(0),
|
||||
lastDataReceived(0)
|
||||
lastDataReceived(0),
|
||||
lastActionReceived(0)
|
||||
|
||||
{
|
||||
connect(server, SIGNAL(pingClockTimeout()), this, SLOT(pingClockTimeout()));
|
||||
}
|
||||
|
|
@ -171,6 +176,8 @@ Response::ResponseCode Server_ProtocolHandler::processRoomCommandContainer(const
|
|||
if (!room)
|
||||
return Response::RespNotInRoom;
|
||||
|
||||
resetIdleTimer();
|
||||
|
||||
Response::ResponseCode finalResponseCode = Response::RespOk;
|
||||
for (int i = cont.room_command_size() - 1; i >= 0; --i) {
|
||||
Response::ResponseCode resp = Response::RespInvalidCommand;
|
||||
|
|
@ -240,6 +247,8 @@ Response::ResponseCode Server_ProtocolHandler::processGameCommandContainer(const
|
|||
if (!player)
|
||||
return Response::RespNotInRoom;
|
||||
|
||||
resetIdleTimer();
|
||||
|
||||
int commandCountingInterval = server->getCommandCountingInterval();
|
||||
int maxCommandCountPerInterval = server->getMaxCommandCountPerInterval();
|
||||
GameEventStorage ges;
|
||||
|
|
@ -280,6 +289,8 @@ Response::ResponseCode Server_ProtocolHandler::processModeratorCommandContainer(
|
|||
if (!(userInfo->user_level() & ServerInfo_User::IsModerator))
|
||||
return Response::RespLoginNeeded;
|
||||
|
||||
resetIdleTimer();
|
||||
|
||||
Response::ResponseCode finalResponseCode = Response::RespOk;
|
||||
for (int i = cont.moderator_command_size() - 1; i >= 0; --i) {
|
||||
Response::ResponseCode resp = Response::RespInvalidCommand;
|
||||
|
|
@ -301,6 +312,8 @@ Response::ResponseCode Server_ProtocolHandler::processAdminCommandContainer(cons
|
|||
if (!(userInfo->user_level() & ServerInfo_User::IsAdmin))
|
||||
return Response::RespLoginNeeded;
|
||||
|
||||
resetIdleTimer();
|
||||
|
||||
Response::ResponseCode finalResponseCode = Response::RespOk;
|
||||
for (int i = cont.admin_command_size() - 1; i >= 0; --i) {
|
||||
Response::ResponseCode resp = Response::RespInvalidCommand;
|
||||
|
|
@ -373,6 +386,24 @@ void Server_ProtocolHandler::pingClockTimeout()
|
|||
|
||||
if (timeRunning - lastDataReceived > server->getMaxPlayerInactivityTime())
|
||||
prepareDestroy();
|
||||
|
||||
if (QString::fromStdString(userInfo->privlevel()).toLower() == "none") {
|
||||
if ((server->getIdleClientTimeout() > 0) && (idleClientWarningSent)) {
|
||||
if (timeRunning - lastActionReceived > server->getIdleClientTimeout()) {
|
||||
prepareDestroy();
|
||||
}
|
||||
}
|
||||
|
||||
if (((timeRunning - lastActionReceived) >= ceil(server->getIdleClientTimeout() *.9)) && (!idleClientWarningSent)) {
|
||||
Event_NotifyUser event;
|
||||
event.set_type(Event_NotifyUser::IDLEWARNING);
|
||||
SessionEvent *se = prepareSessionEvent(event);
|
||||
sendProtocolItem(*se);
|
||||
delete se;
|
||||
idleClientWarningSent = true;
|
||||
}
|
||||
}
|
||||
|
||||
++timeRunning;
|
||||
}
|
||||
|
||||
|
|
@ -728,3 +759,9 @@ Response::ResponseCode Server_ProtocolHandler::cmdJoinGame(const Command_JoinGam
|
|||
|
||||
return room->processJoinGameCommand(cmd, rc, this);
|
||||
}
|
||||
|
||||
void Server_ProtocolHandler::resetIdleTimer()
|
||||
{
|
||||
lastActionReceived = timeRunning;
|
||||
idleClientWarningSent = false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -52,10 +52,11 @@ protected:
|
|||
AuthenticationResult authState;
|
||||
bool acceptsUserListChanges;
|
||||
bool acceptsRoomListChanges;
|
||||
bool idleClientWarningSent;
|
||||
virtual void logDebugMessage(const QString & /* message */) { }
|
||||
private:
|
||||
QList<int> messageSizeOverTime, messageCountOverTime, commandCountOverTime;
|
||||
int timeRunning, lastDataReceived;
|
||||
int timeRunning, lastDataReceived, lastActionReceived;
|
||||
QTimer *pingClock;
|
||||
|
||||
virtual void transmitProtocolItem(const ServerMessage &item) = 0;
|
||||
|
|
@ -81,6 +82,8 @@ private:
|
|||
virtual Response::ResponseCode processExtendedModeratorCommand(int /* cmdType */, const ModeratorCommand & /* cmd */, ResponseContainer & /* rc */) { return Response::RespFunctionNotAllowed; }
|
||||
Response::ResponseCode processAdminCommandContainer(const CommandContainer &cont, ResponseContainer &rc);
|
||||
virtual Response::ResponseCode processExtendedAdminCommand(int /* cmdType */, const AdminCommand & /* cmd */, ResponseContainer & /* rc */) { return Response::RespFunctionNotAllowed; }
|
||||
|
||||
void resetIdleTimer();
|
||||
private slots:
|
||||
void pingClockTimeout();
|
||||
public slots:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue