mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-13 01:24:46 -07:00
improved packet loss handling
This commit is contained in:
parent
657f97680a
commit
d6083a85c7
6 changed files with 26 additions and 19 deletions
|
|
@ -58,7 +58,6 @@ void Server_Game::pingClockTimeout()
|
|||
{
|
||||
++secondsElapsed;
|
||||
|
||||
QDateTime now = QDateTime::currentDateTime();
|
||||
QList<ServerInfo_PlayerPing *> pingList;
|
||||
QMapIterator<int, Server_Player *> playerIterator(players);
|
||||
bool allPlayersInactive = true;
|
||||
|
|
@ -66,7 +65,7 @@ void Server_Game::pingClockTimeout()
|
|||
Server_Player *player = playerIterator.next().value();
|
||||
int pingTime;
|
||||
if (player->getProtocolHandler()) {
|
||||
pingTime = player->getProtocolHandler()->getLastCommandTime().secsTo(now);
|
||||
pingTime = player->getProtocolHandler()->getLastCommandTime();
|
||||
allPlayersInactive = false;
|
||||
} else
|
||||
pingTime = -1;
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@
|
|||
#include <QDateTime>
|
||||
|
||||
Server_ProtocolHandler::Server_ProtocolHandler(Server *_server, QObject *parent)
|
||||
: QObject(parent), server(_server), authState(PasswordWrong), acceptsUserListChanges(false), acceptsRoomListChanges(false), userInfo(0), lastCommandTime(QDateTime::currentDateTime())
|
||||
: QObject(parent), server(_server), authState(PasswordWrong), acceptsUserListChanges(false), acceptsRoomListChanges(false), userInfo(0), timeRunning(0), lastDataReceived(0)
|
||||
{
|
||||
connect(server, SIGNAL(pingClockTimeout()), this, SLOT(pingClockTimeout()));
|
||||
}
|
||||
|
|
@ -58,8 +58,6 @@ void Server_ProtocolHandler::playerRemovedFromGame(Server_Game *game)
|
|||
|
||||
ResponseCode Server_ProtocolHandler::processCommandHelper(Command *command, CommandContainer *cont)
|
||||
{
|
||||
lastCommandTime = QDateTime::currentDateTime();
|
||||
|
||||
RoomCommand *roomCommand = qobject_cast<RoomCommand *>(command);
|
||||
if (roomCommand) {
|
||||
qDebug() << "received RoomCommand: roomId =" << roomCommand->getRoomId();
|
||||
|
|
@ -159,6 +157,8 @@ ResponseCode Server_ProtocolHandler::processCommandHelper(Command *command, Comm
|
|||
|
||||
void Server_ProtocolHandler::processCommandContainer(CommandContainer *cont)
|
||||
{
|
||||
lastDataReceived = timeRunning;
|
||||
|
||||
const QList<Command *> &cmdList = cont->getCommandList();
|
||||
ResponseCode finalResponseCode = RespOk;
|
||||
for (int i = 0; i < cmdList.size(); ++i) {
|
||||
|
|
@ -219,8 +219,9 @@ void Server_ProtocolHandler::pingClockTimeout()
|
|||
messageCountOverTime.removeLast();
|
||||
}
|
||||
|
||||
if (lastCommandTime.secsTo(QDateTime::currentDateTime()) > server->getMaxPlayerInactivityTime())
|
||||
if (timeRunning - lastDataReceived > server->getMaxPlayerInactivityTime())
|
||||
deleteLater();
|
||||
++timeRunning;
|
||||
}
|
||||
|
||||
void Server_ProtocolHandler::enqueueProtocolItem(ProtocolItem *item)
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ protected:
|
|||
private:
|
||||
QList<ProtocolItem *> itemQueue;
|
||||
QList<int> messageSizeOverTime, messageCountOverTime;
|
||||
QDateTime lastCommandTime;
|
||||
int timeRunning, lastDataReceived;
|
||||
QTimer *pingClock;
|
||||
|
||||
virtual DeckList *getDeckFromDatabase(int deckId) = 0;
|
||||
|
|
@ -101,8 +101,8 @@ public:
|
|||
void setUserInfo(ServerInfo_User *_userInfo) { userInfo = _userInfo; }
|
||||
const QMap<QString, ServerInfo_User *> &getBuddyList() const { return buddyList; }
|
||||
const QMap<QString, ServerInfo_User *> &getIgnoreList() const { return ignoreList; }
|
||||
const QDateTime &getLastCommandTime() const { return lastCommandTime; }
|
||||
|
||||
int getLastCommandTime() const { return timeRunning - lastDataReceived; }
|
||||
void processCommandContainer(CommandContainer *cont);
|
||||
virtual void sendProtocolItem(ProtocolItem *item, bool deleteItem = true) = 0;
|
||||
void enqueueProtocolItem(ProtocolItem *item);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue