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
69fce1fb
Commit
69fce1fb
authored
Apr 18, 2011
by
Max-Wilhelm Bruker
Browse files
thread fixes
parent
e6fc2011
Changes
7
Hide whitespace changes
Inline
Side-by-side
common/server.cpp
View file @
69fce1fb
...
...
@@ -101,7 +101,9 @@ void Server::broadcastRoomUpdate()
QMutexLocker
locker
(
&
serverMutex
);
Server_Room
*
room
=
static_cast
<
Server_Room
*>
(
sender
());
QList
<
ServerInfo_Room
*>
eventRoomList
;
room
->
roomMutex
.
lock
();
eventRoomList
.
append
(
new
ServerInfo_Room
(
room
->
getId
(),
room
->
getName
(),
room
->
getDescription
(),
room
->
getGames
().
size
(),
room
->
size
(),
room
->
getAutoJoin
()));
room
->
roomMutex
.
unlock
();
Event_ListRooms
*
event
=
new
Event_ListRooms
(
eventRoomList
);
for
(
int
i
=
0
;
i
<
clients
.
size
();
++
i
)
...
...
common/server_game.cpp
View file @
69fce1fb
...
...
@@ -31,6 +31,8 @@
Server_Game
::
Server_Game
(
Server_ProtocolHandler
*
_creator
,
int
_gameId
,
const
QString
&
_description
,
const
QString
&
_password
,
int
_maxPlayers
,
const
QList
<
int
>
&
_gameTypes
,
bool
_onlyBuddies
,
bool
_onlyRegistered
,
bool
_spectatorsAllowed
,
bool
_spectatorsNeedPassword
,
bool
_spectatorsCanTalk
,
bool
_spectatorsSeeEverything
,
Server_Room
*
_room
)
:
QObject
(),
room
(
_room
),
creatorInfo
(
new
ServerInfo_User
(
_creator
->
getUserInfo
())),
gameStarted
(
false
),
gameId
(
_gameId
),
description
(
_description
),
password
(
_password
),
maxPlayers
(
_maxPlayers
),
gameTypes
(
_gameTypes
),
activePlayer
(
-
1
),
activePhase
(
-
1
),
onlyBuddies
(
_onlyBuddies
),
onlyRegistered
(
_onlyRegistered
),
spectatorsAllowed
(
_spectatorsAllowed
),
spectatorsNeedPassword
(
_spectatorsNeedPassword
),
spectatorsCanTalk
(
_spectatorsCanTalk
),
spectatorsSeeEverything
(
_spectatorsSeeEverything
),
inactivityCounter
(
0
),
secondsElapsed
(
0
),
gameMutex
(
QMutex
::
Recursive
)
{
connect
(
this
,
SIGNAL
(
sigStartGameIfReady
()),
this
,
SLOT
(
doStartGameIfReady
()),
Qt
::
QueuedConnection
);
addPlayer
(
_creator
,
false
,
false
);
if
(
room
->
getServer
()
->
getGameShouldPing
())
{
...
...
@@ -111,7 +113,7 @@ int Server_Game::getSpectatorCount() const
return
result
;
}
void
Server_Game
::
s
tartGameIfReady
()
void
Server_Game
::
doS
tartGameIfReady
()
{
QMutexLocker
locker
(
&
gameMutex
);
...
...
@@ -159,6 +161,11 @@ void Server_Game::startGameIfReady()
nextTurn
();
}
void
Server_Game
::
startGameIfReady
()
{
emit
sigStartGameIfReady
();
}
void
Server_Game
::
stopGameIfFinished
()
{
QMutexLocker
locker
(
&
gameMutex
);
...
...
@@ -214,6 +221,7 @@ Server_Player *Server_Game::addPlayer(Server_ProtocolHandler *handler, bool spec
int
playerId
=
keyList
.
isEmpty
()
?
0
:
(
keyList
.
last
()
+
1
);
Server_Player
*
newPlayer
=
new
Server_Player
(
this
,
playerId
,
handler
->
getUserInfo
(),
spectator
,
handler
);
newPlayer
->
moveToThread
(
thread
());
sendGameEvent
(
new
Event_Join
(
newPlayer
->
getProperties
()));
players
.
insert
(
playerId
,
newPlayer
);
...
...
common/server_game.h
View file @
69fce1fb
...
...
@@ -54,8 +54,10 @@ private:
QTimer
*
pingClock
;
signals:
void
gameClosing
();
void
sigStartGameIfReady
();
private
slots
:
void
pingClockTimeout
();
void
doStartGameIfReady
();
public:
mutable
QMutex
gameMutex
;
Server_Game
(
Server_ProtocolHandler
*
_creator
,
int
_gameId
,
const
QString
&
_description
,
const
QString
&
_password
,
int
_maxPlayers
,
const
QList
<
int
>
&
_gameTypes
,
bool
_onlyBuddies
,
bool
_onlyRegistered
,
bool
_spectatorsAllowed
,
bool
_spectatorsNeedPassword
,
bool
_spectatorsCanTalk
,
bool
_spectatorsSeeEverything
,
Server_Room
*
parent
);
...
...
common/server_player.cpp
View file @
69fce1fb
...
...
@@ -29,6 +29,12 @@ Server_Player::~Server_Player()
clearZones
();
}
void
Server_Player
::
moveToThread
(
QThread
*
thread
)
{
QObject
::
moveToThread
(
thread
);
userInfo
->
moveToThread
(
thread
);
}
int
Server_Player
::
newCardId
()
{
QMutexLocker
locker
(
&
game
->
gameMutex
);
...
...
common/server_player.h
View file @
69fce1fb
...
...
@@ -43,6 +43,7 @@ private:
public:
Server_Player
(
Server_Game
*
_game
,
int
_playerId
,
ServerInfo_User
*
_userInfo
,
bool
_spectator
,
Server_ProtocolHandler
*
_handler
);
~
Server_Player
();
void
moveToThread
(
QThread
*
thread
);
Server_ProtocolHandler
*
getProtocolHandler
()
const
{
return
handler
;
}
void
setProtocolHandler
(
Server_ProtocolHandler
*
_handler
)
{
playerMutex
.
lock
();
handler
=
_handler
;
playerMutex
.
unlock
();
}
...
...
common/server_protocolhandler.cpp
View file @
69fce1fb
...
...
@@ -821,6 +821,7 @@ ResponseCode Server_ProtocolHandler::cmdCreateToken(Command_CreateToken *cmd, Co
y
=
0
;
Server_Card
*
card
=
new
Server_Card
(
cmd
->
getCardName
(),
player
->
newCardId
(),
x
,
y
);
card
->
moveToThread
(
player
->
thread
());
card
->
setPT
(
cmd
->
getPt
());
card
->
setColor
(
cmd
->
getColor
());
card
->
setAnnotation
(
cmd
->
getAnnotation
());
...
...
common/server_room.cpp
View file @
69fce1fb
...
...
@@ -103,6 +103,8 @@ void Server_Room::removeGame()
QMutexLocker
locker
(
&
roomMutex
);
Server_Game
*
game
=
static_cast
<
Server_Game
*>
(
sender
());
QMutexLocker
gameLocker
(
&
game
->
gameMutex
);
broadcastGameListUpdate
(
game
);
games
.
remove
(
game
->
getGameId
());
...
...
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