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
00029eee
Commit
00029eee
authored
Feb 11, 2013
by
Max-Wilhelm Bruker
Browse files
Server_Room optimisation
parent
de3055be
Changes
3
Show whitespace changes
Inline
Side-by-side
common/server_protocolhandler.cpp
View file @
00029eee
...
@@ -552,8 +552,6 @@ Response::ResponseCode Server_ProtocolHandler::cmdCreateGame(const Command_Creat
...
@@ -552,8 +552,6 @@ Response::ResponseCode Server_ProtocolHandler::cmdCreateGame(const Command_Creat
if
(
gameId
==
-
1
)
if
(
gameId
==
-
1
)
return
Response
::
RespInternalError
;
return
Response
::
RespInternalError
;
QMutexLocker
roomLocker
(
&
room
->
gamesMutex
);
if
(
server
->
getMaxGamesPerUser
()
>
0
)
if
(
server
->
getMaxGamesPerUser
()
>
0
)
if
(
room
->
getGamesCreatedByUser
(
QString
::
fromStdString
(
userInfo
->
name
()))
>=
server
->
getMaxGamesPerUser
())
if
(
room
->
getGamesCreatedByUser
(
QString
::
fromStdString
(
userInfo
->
name
()))
>=
server
->
getMaxGamesPerUser
())
return
Response
::
RespContextError
;
return
Response
::
RespContextError
;
...
...
common/server_room.cpp
View file @
00029eee
...
@@ -30,7 +30,7 @@ Server_Room::~Server_Room()
...
@@ -30,7 +30,7 @@ Server_Room::~Server_Room()
gamesMutex
.
unlock
();
gamesMutex
.
unlock
();
usersLock
.
lockForWrite
();
usersLock
.
lockForWrite
();
user
List
.
clear
();
user
s
.
clear
();
usersLock
.
unlock
();
usersLock
.
unlock
();
}
}
...
@@ -64,10 +64,11 @@ const ServerInfo_Room &Server_Room::getInfo(ServerInfo_Room &result, bool comple
...
@@ -64,10 +64,11 @@ const ServerInfo_Room &Server_Room::getInfo(ServerInfo_Room &result, bool comple
gamesMutex
.
unlock
();
gamesMutex
.
unlock
();
usersLock
.
lockForRead
();
usersLock
.
lockForRead
();
result
.
set_player_count
(
user
List
.
size
()
+
externalUsers
.
size
());
result
.
set_player_count
(
user
s
.
size
()
+
externalUsers
.
size
());
if
(
complete
)
{
if
(
complete
)
{
for
(
int
i
=
0
;
i
<
userList
.
size
();
++
i
)
QMapIterator
<
QString
,
Server_ProtocolHandler
*>
userIterator
(
users
);
result
.
add_user_list
()
->
CopyFrom
(
userList
[
i
]
->
copyUserInfo
(
false
));
while
(
userIterator
.
hasNext
())
result
.
add_user_list
()
->
CopyFrom
(
userIterator
.
next
().
value
()
->
copyUserInfo
(
false
));
if
(
includeExternalData
)
{
if
(
includeExternalData
)
{
QMapIterator
<
QString
,
ServerInfo_User_Container
>
externalUserIterator
(
externalUsers
);
QMapIterator
<
QString
,
ServerInfo_User_Container
>
externalUserIterator
(
externalUsers
);
while
(
externalUserIterator
.
hasNext
())
while
(
externalUserIterator
.
hasNext
())
...
@@ -101,7 +102,7 @@ void Server_Room::addClient(Server_ProtocolHandler *client)
...
@@ -101,7 +102,7 @@ void Server_Room::addClient(Server_ProtocolHandler *client)
sendRoomEvent
(
prepareRoomEvent
(
event
));
sendRoomEvent
(
prepareRoomEvent
(
event
));
usersLock
.
lockForWrite
();
usersLock
.
lockForWrite
();
user
List
.
append
(
client
);
user
s
.
insert
(
QString
::
fromStdString
(
client
->
getUserInfo
()
->
name
()),
client
);
usersLock
.
unlock
();
usersLock
.
unlock
();
ServerInfo_Room
roomInfo
;
ServerInfo_Room
roomInfo
;
...
@@ -111,7 +112,7 @@ void Server_Room::addClient(Server_ProtocolHandler *client)
...
@@ -111,7 +112,7 @@ void Server_Room::addClient(Server_ProtocolHandler *client)
void
Server_Room
::
removeClient
(
Server_ProtocolHandler
*
client
)
void
Server_Room
::
removeClient
(
Server_ProtocolHandler
*
client
)
{
{
usersLock
.
lockForWrite
();
usersLock
.
lockForWrite
();
user
List
.
remove
At
(
userList
.
indexOf
(
client
));
user
s
.
remove
(
QString
::
fromStdString
(
client
->
getUserInfo
()
->
name
()
));
usersLock
.
unlock
();
usersLock
.
unlock
();
Event_LeaveRoom
event
;
Event_LeaveRoom
event
;
...
@@ -210,8 +211,11 @@ void Server_Room::say(const QString &userName, const QString &s, bool sendToIsl)
...
@@ -210,8 +211,11 @@ void Server_Room::say(const QString &userName, const QString &s, bool sendToIsl)
void
Server_Room
::
sendRoomEvent
(
RoomEvent
*
event
,
bool
sendToIsl
)
void
Server_Room
::
sendRoomEvent
(
RoomEvent
*
event
,
bool
sendToIsl
)
{
{
usersLock
.
lockForRead
();
usersLock
.
lockForRead
();
for
(
int
i
=
0
;
i
<
userList
.
size
();
++
i
)
{
userList
[
i
]
->
sendProtocolItem
(
*
event
);
QMapIterator
<
QString
,
Server_ProtocolHandler
*>
userIterator
(
users
);
while
(
userIterator
.
hasNext
())
userIterator
.
next
().
value
()
->
sendProtocolItem
(
*
event
);
}
usersLock
.
unlock
();
usersLock
.
unlock
();
if
(
sendToIsl
)
if
(
sendToIsl
)
...
@@ -229,8 +233,7 @@ void Server_Room::broadcastGameListUpdate(const ServerInfo_Game &gameInfo, bool
...
@@ -229,8 +233,7 @@ void Server_Room::broadcastGameListUpdate(const ServerInfo_Game &gameInfo, bool
void
Server_Room
::
addGame
(
Server_Game
*
game
)
void
Server_Room
::
addGame
(
Server_Game
*
game
)
{
{
// Lock gamesMutex before calling this
gamesMutex
.
lock
();
connect
(
game
,
SIGNAL
(
gameInfoChanged
(
ServerInfo_Game
)),
this
,
SLOT
(
broadcastGameListUpdate
(
ServerInfo_Game
)));
connect
(
game
,
SIGNAL
(
gameInfoChanged
(
ServerInfo_Game
)),
this
,
SLOT
(
broadcastGameListUpdate
(
ServerInfo_Game
)));
game
->
gameMutex
.
lock
();
game
->
gameMutex
.
lock
();
...
@@ -238,6 +241,7 @@ void Server_Room::addGame(Server_Game *game)
...
@@ -238,6 +241,7 @@ void Server_Room::addGame(Server_Game *game)
ServerInfo_Game
gameInfo
;
ServerInfo_Game
gameInfo
;
game
->
getInfo
(
gameInfo
);
game
->
getInfo
(
gameInfo
);
game
->
gameMutex
.
unlock
();
game
->
gameMutex
.
unlock
();
gamesMutex
.
unlock
();
emit
gameListChanged
(
gameInfo
);
emit
gameListChanged
(
gameInfo
);
ServerInfo_Room
roomInfo
;
ServerInfo_Room
roomInfo
;
...
...
common/server_room.h
View file @
00029eee
...
@@ -37,7 +37,7 @@ private:
...
@@ -37,7 +37,7 @@ private:
QStringList
gameTypes
;
QStringList
gameTypes
;
QMap
<
int
,
Server_Game
*>
games
;
QMap
<
int
,
Server_Game
*>
games
;
QMap
<
int
,
ServerInfo_Game
>
externalGames
;
QMap
<
int
,
ServerInfo_Game
>
externalGames
;
Q
List
<
Server_ProtocolHandler
*>
user
List
;
Q
Map
<
QString
,
Server_ProtocolHandler
*>
user
s
;
QMap
<
QString
,
ServerInfo_User_Container
>
externalUsers
;
QMap
<
QString
,
ServerInfo_User_Container
>
externalUsers
;
private
slots
:
private
slots
:
void
broadcastGameListUpdate
(
const
ServerInfo_Game
&
gameInfo
,
bool
sendToIsl
=
true
);
void
broadcastGameListUpdate
(
const
ServerInfo_Game
&
gameInfo
,
bool
sendToIsl
=
true
);
...
...
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