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
abd54257
Commit
abd54257
authored
Jul 02, 2011
by
Max-Wilhelm Bruker
Browse files
finished getGamesOfUser function
parent
d5de76ec
Changes
24
Hide whitespace changes
Inline
Side-by-side
common/protocol_datastructures.h
View file @
abd54257
...
...
@@ -8,7 +8,7 @@
class
DeckList
;
enum
ResponseCode
{
RespNothing
,
RespOk
,
RespInternalError
,
RespInvalidCommand
,
RespInvalidData
,
RespNameNotFound
,
RespLoginNeeded
,
RespFunctionNotAllowed
,
RespGameNotStarted
,
RespGameFull
,
RespContextError
,
RespWrongPassword
,
RespSpectatorsNotAllowed
,
RespOnlyBuddies
,
RespUserLevelTooLow
,
RespInIgnoreList
,
RespWouldOverwriteOldSession
,
RespChatFlood
};
enum
ResponseCode
{
RespNothing
,
RespOk
,
RespNotInRoom
,
RespInternalError
,
RespInvalidCommand
,
RespInvalidData
,
RespNameNotFound
,
RespLoginNeeded
,
RespFunctionNotAllowed
,
RespGameNotStarted
,
RespGameFull
,
RespContextError
,
RespWrongPassword
,
RespSpectatorsNotAllowed
,
RespOnlyBuddies
,
RespUserLevelTooLow
,
RespInIgnoreList
,
RespWouldOverwriteOldSession
,
RespChatFlood
};
// PrivateZone: Contents of the zone are always visible to the owner,
// but not to anyone else.
...
...
@@ -71,6 +71,7 @@ class ServerInfo_Game : public SerializableItem_Map {
public:
ServerInfo_Game
(
int
_roomId
=
-
1
,
int
_gameId
=
-
1
,
const
QString
&
_description
=
QString
(),
bool
_hasPassword
=
false
,
int
_playerCount
=
-
1
,
int
_maxPlayers
=
-
1
,
const
QList
<
GameTypeId
*>
&
_gameTypes
=
QList
<
GameTypeId
*>
(),
ServerInfo_User
*
creatorInfo
=
0
,
bool
_onlyBuddies
=
false
,
bool
_onlyRegistered
=
false
,
bool
_spectatorsAllowed
=
false
,
bool
_spectatorsNeedPassword
=
false
,
int
_spectatorCount
=
-
1
);
static
SerializableItem
*
newItem
()
{
return
new
ServerInfo_Game
;
}
int
getRoomId
()
const
{
return
static_cast
<
SerializableItem_Int
*>
(
itemMap
.
value
(
"room_id"
))
->
getData
();
}
int
getGameId
()
const
{
return
static_cast
<
SerializableItem_Int
*>
(
itemMap
.
value
(
"game_id"
))
->
getData
();
}
QString
getDescription
()
const
{
return
static_cast
<
SerializableItem_String
*>
(
itemMap
.
value
(
"description"
))
->
getData
();
}
bool
getHasPassword
()
const
{
return
static_cast
<
SerializableItem_Bool
*>
(
itemMap
.
value
(
"has_password"
))
->
getData
();
}
...
...
common/server_protocolhandler.cpp
View file @
abd54257
...
...
@@ -80,7 +80,7 @@ ResponseCode Server_ProtocolHandler::processCommandHelper(Command *command, Comm
Server_Room
*
room
=
rooms
.
value
(
roomCommand
->
getRoomId
(),
0
);
if
(
!
room
)
return
RespN
ameNotFound
;
return
RespN
otInRoom
;
QMutexLocker
locker
(
&
room
->
roomMutex
);
...
...
@@ -101,7 +101,7 @@ ResponseCode Server_ProtocolHandler::processCommandHelper(Command *command, Comm
gameListMutex
.
lock
();
if
(
!
games
.
contains
(
gameCommand
->
getGameId
()))
{
qDebug
()
<<
"invalid game"
;
return
RespN
ameNotFound
;
return
RespN
otInRoom
;
}
QPair
<
Server_Game
*
,
Server_Player
*>
gamePair
=
games
.
value
(
gameCommand
->
getGameId
());
Server_Game
*
game
=
gamePair
.
first
;
...
...
@@ -340,13 +340,19 @@ ResponseCode Server_ProtocolHandler::cmdGetGamesOfUser(Command_GetGamesOfUser *c
if
(
!
server
->
getUsers
().
contains
(
cmd
->
getUserName
()))
return
RespNameNotFound
;
QList
<
ServerInfo_Room
*>
roomList
;
QList
<
ServerInfo_Game
*>
gameList
;
QMapIterator
<
int
,
Server_Room
*>
roomIterator
(
server
->
getRooms
());
while
(
roomIterator
.
hasNext
())
gameList
.
append
(
roomIterator
.
next
().
value
()
->
getGamesOfUser
(
cmd
->
getUserName
()));
while
(
roomIterator
.
hasNext
())
{
Server_Room
*
room
=
roomIterator
.
next
().
value
();
room
->
roomMutex
.
lock
();
roomList
.
append
(
room
->
getInfo
(
false
,
true
));
gameList
.
append
(
room
->
getGamesOfUser
(
cmd
->
getUserName
()));
room
->
roomMutex
.
unlock
();
}
server
->
serverMutex
.
unlock
();
ProtocolResponse
*
resp
=
new
Response_GetGamesOfUser
(
cont
->
getCmdId
(),
RespOk
,
gameList
);
ProtocolResponse
*
resp
=
new
Response_GetGamesOfUser
(
cont
->
getCmdId
(),
RespOk
,
roomList
,
gameList
);
if
(
getCompressionSupport
())
resp
->
setCompressed
(
true
);
cont
->
setResponse
(
resp
);
...
...
common/server_room.cpp
View file @
abd54257
...
...
@@ -26,7 +26,7 @@ Server *Server_Room::getServer() const
return
static_cast
<
Server
*>
(
parent
());
}
ServerInfo_Room
*
Server_Room
::
getInfo
(
bool
complete
)
const
ServerInfo_Room
*
Server_Room
::
getInfo
(
bool
complete
,
bool
showGameTypes
)
const
{
QMutexLocker
locker
(
&
roomMutex
);
...
...
@@ -40,10 +40,10 @@ ServerInfo_Room *Server_Room::getInfo(bool complete) const
for
(
int
i
=
0
;
i
<
size
();
++
i
)
userList
.
append
(
new
ServerInfo_User
(
at
(
i
)
->
getUserInfo
(),
false
));
}
if
(
complete
||
showGameTypes
)
for
(
int
i
=
0
;
i
<
gameTypes
.
size
();
++
i
)
gameTypeList
.
append
(
new
ServerInfo_GameType
(
i
,
gameTypes
[
i
]));
}
return
new
ServerInfo_Room
(
id
,
name
,
description
,
games
.
size
(),
size
(),
autoJoin
,
gameList
,
userList
,
gameTypeList
);
}
...
...
@@ -133,8 +133,6 @@ int Server_Room::getGamesCreatedByUser(const QString &userName) const
QList
<
ServerInfo_Game
*>
Server_Room
::
getGamesOfUser
(
const
QString
&
userName
)
const
{
QMutexLocker
locker
(
&
roomMutex
);
QList
<
ServerInfo_Game
*>
result
;
QMapIterator
<
int
,
Server_Game
*>
gamesIterator
(
games
);
while
(
gamesIterator
.
hasNext
())
{
...
...
common/server_room.h
View file @
abd54257
...
...
@@ -38,7 +38,7 @@ public:
QString
getJoinMessage
()
const
{
return
joinMessage
;
}
const
QMap
<
int
,
Server_Game
*>
&
getGames
()
const
{
return
games
;
}
Server
*
getServer
()
const
;
ServerInfo_Room
*
getInfo
(
bool
complete
)
const
;
ServerInfo_Room
*
getInfo
(
bool
complete
,
bool
showGameTypes
=
false
)
const
;
int
getGamesCreatedByUser
(
const
QString
&
name
)
const
;
QList
<
ServerInfo_Game
*>
getGamesOfUser
(
const
QString
&
name
)
const
;
...
...
Prev
1
2
Next
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