Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Donald Haase
Cockatrice
Commits
5efb92e2
Commit
5efb92e2
authored
Jan 31, 2010
by
Max-Wilhelm Bruker
Browse files
game inactivity timeout
parent
a9f590e9
Changes
7
Hide whitespace changes
Inline
Side-by-side
common/server.h
View file @
5efb92e2
...
...
@@ -31,6 +31,9 @@ public:
void
closeOldSession
(
const
QString
&
playerName
);
virtual
QString
getLoginMessage
()
const
=
0
;
Server_Game
*
createGame
(
const
QString
&
description
,
const
QString
&
password
,
int
maxPlayers
,
bool
spectatorsAllowed
,
Server_ProtocolHandler
*
creator
);
virtual
int
getMaxGameInactivityTime
()
const
=
0
;
virtual
int
getMaxPlayerInactivityTime
()
const
=
0
;
private:
QMap
<
int
,
Server_Game
*>
games
;
QList
<
Server_ProtocolHandler
*>
clients
;
...
...
common/server_game.cpp
View file @
5efb92e2
...
...
@@ -28,7 +28,7 @@
#include
<QTimer>
Server_Game
::
Server_Game
(
Server_ProtocolHandler
*
_creator
,
int
_gameId
,
const
QString
&
_description
,
const
QString
&
_password
,
int
_maxPlayers
,
bool
_spectatorsAllowed
,
QObject
*
parent
)
:
QObject
(
parent
),
gameStarted
(
false
),
gameId
(
_gameId
),
description
(
_description
),
password
(
_password
),
maxPlayers
(
_maxPlayers
),
activePlayer
(
-
1
),
activePhase
(
-
1
),
spectatorsAllowed
(
_spectatorsAllowed
)
:
QObject
(
parent
),
gameStarted
(
false
),
gameId
(
_gameId
),
description
(
_description
),
password
(
_password
),
maxPlayers
(
_maxPlayers
),
activePlayer
(
-
1
),
activePhase
(
-
1
),
spectatorsAllowed
(
_spectatorsAllowed
)
,
inactivityCounter
(
0
)
{
creator
=
addPlayer
(
_creator
,
false
,
false
);
...
...
@@ -55,12 +55,25 @@ void Server_Game::pingClockTimeout()
QDateTime
now
=
QDateTime
::
currentDateTime
();
QList
<
ServerInfo_PlayerPing
*>
pingList
;
QMapIterator
<
int
,
Server_Player
*>
playerIterator
(
players
);
bool
allPlayersInactive
=
true
;
while
(
playerIterator
.
hasNext
())
{
Server_Player
*
player
=
playerIterator
.
next
().
value
();
int
pingTime
=
player
->
getProtocolHandler
()
?
player
->
getProtocolHandler
()
->
getLastCommandTime
().
secsTo
(
now
)
:
-
1
;
int
pingTime
;
if
(
player
->
getProtocolHandler
())
{
pingTime
=
player
->
getProtocolHandler
()
->
getLastCommandTime
().
secsTo
(
now
);
allPlayersInactive
=
false
;
}
else
pingTime
=
-
1
;
pingList
.
append
(
new
ServerInfo_PlayerPing
(
player
->
getPlayerId
(),
pingTime
));
}
sendGameEvent
(
new
Event_Ping
(
-
1
,
pingList
));
const
int
maxTime
=
static_cast
<
Server
*>
(
parent
())
->
getMaxGameInactivityTime
();
if
(
allPlayersInactive
)
{
if
((
++
inactivityCounter
>=
maxTime
)
&&
(
maxTime
>
0
))
deleteLater
();
}
else
inactivityCounter
=
0
;
}
int
Server_Game
::
getPlayerCount
()
const
...
...
common/server_game.h
View file @
5efb92e2
...
...
@@ -40,6 +40,7 @@ private:
int
maxPlayers
;
int
activePlayer
,
activePhase
;
bool
spectatorsAllowed
;
int
inactivityCounter
;
QTimer
*
pingClock
;
signals:
void
gameClosing
();
...
...
common/server_protocolhandler.cpp
View file @
5efb92e2
...
...
@@ -149,7 +149,7 @@ void Server_ProtocolHandler::processCommand(Command *command)
void
Server_ProtocolHandler
::
pingClockTimeout
()
{
if
(
lastCommandTime
.
secsTo
(
QDateTime
::
currentDateTime
())
>
10
)
if
(
lastCommandTime
.
secsTo
(
QDateTime
::
currentDateTime
())
>
server
->
getMaxPlayerInactivityTime
()
)
deleteLater
();
}
...
...
servatrice/servatrice.ini.example
View file @
5efb92e2
...
...
@@ -21,3 +21,6 @@ size=1
1\autojoin=true
1\joinmessage="This is the general chat channel. This message is only here to show that channels can have a join message."
[game]
max_game_inactivity_time=300
max_player_inactivity_time=15
servatrice/src/servatrice.cpp
View file @
5efb92e2
...
...
@@ -52,6 +52,9 @@ Servatrice::Servatrice(QObject *parent)
settings
->
endArray
();
loginMessage
=
settings
->
value
(
"messages/login"
).
toString
();
maxGameInactivityTime
=
settings
->
value
(
"game/max_game_inactivity_time"
).
toInt
();
maxPlayerInactivityTime
=
settings
->
value
(
"game/max_player_inactivity_time"
).
toInt
();
}
Servatrice
::~
Servatrice
()
...
...
servatrice/src/servatrice.h
View file @
5efb92e2
...
...
@@ -41,10 +41,14 @@ public:
bool
execSqlQuery
(
QSqlQuery
&
query
);
AuthenticationResult
checkUserPassword
(
const
QString
&
user
,
const
QString
&
password
);
QString
getLoginMessage
()
const
{
return
loginMessage
;
}
int
getMaxGameInactivityTime
()
const
{
return
maxGameInactivityTime
;
}
int
getMaxPlayerInactivityTime
()
const
{
return
maxPlayerInactivityTime
;
}
private:
QTcpServer
*
tcpServer
;
QString
loginMessage
;
QSettings
*
settings
;
int
maxGameInactivityTime
;
int
maxPlayerInactivityTime
;
};
#endif
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment