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
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue