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
80277ff5
Commit
80277ff5
authored
Jan 02, 2011
by
Max-Wilhelm Bruker
Browse files
rooms work mostly
parent
b73001e9
Changes
25
Hide whitespace changes
Inline
Side-by-side
common/server_protocolhandler.cpp
View file @
80277ff5
...
...
@@ -279,10 +279,8 @@ ResponseCode Server_ProtocolHandler::cmdListRooms(Command_ListRooms * /*cmd*/, C
QList
<
ServerInfo_Room
*>
eventRoomList
;
QMapIterator
<
int
,
Server_Room
*>
roomIterator
(
server
->
getRooms
());
while
(
roomIterator
.
hasNext
())
{
Server_Room
*
r
=
roomIterator
.
next
().
value
();
eventRoomList
.
append
(
new
ServerInfo_Room
(
r
->
getId
(),
r
->
getName
(),
r
->
getDescription
(),
r
->
getGames
().
size
(),
r
->
size
(),
r
->
getAutoJoin
()));
}
while
(
roomIterator
.
hasNext
())
eventRoomList
.
append
(
roomIterator
.
next
().
value
()
->
getInfo
(
false
));
cont
->
enqueueItem
(
new
Event_ListRooms
(
eventRoomList
));
acceptsRoomListChanges
=
true
;
...
...
@@ -303,7 +301,9 @@ ResponseCode Server_ProtocolHandler::cmdJoinRoom(Command_JoinRoom *cmd, CommandC
r
->
addClient
(
this
);
rooms
.
insert
(
r
->
getId
(),
r
);
return
RespOk
;
cont
->
setResponse
(
new
Response_JoinRoom
(
cont
->
getCmdId
(),
RespOk
,
r
->
getInfo
(
true
)));
return
RespNothing
;
}
ResponseCode
Server_ProtocolHandler
::
cmdLeaveRoom
(
Command_LeaveRoom
*
/*cmd*/
,
CommandContainer
*
cont
,
Server_Room
*
room
)
...
...
common/server_room.cpp
View file @
80277ff5
#include
"server_room.h"
#include
"server_protocolhandler.h"
#include
"server_game.h"
#include
<QDebug>
Server_Room
::
Server_Room
(
int
_id
,
const
QString
&
_name
,
const
QString
&
_description
,
bool
_autoJoin
,
const
QString
&
_joinMessage
,
Server
*
parent
)
:
QObject
(
parent
),
id
(
_id
),
name
(
_name
),
description
(
_description
),
autoJoin
(
_autoJoin
),
joinMessage
(
_joinMessage
)
...
...
@@ -12,7 +13,24 @@ Server *Server_Room::getServer() const
return
static_cast
<
Server
*>
(
parent
());
}
QList
<
ServerInfo_User
*>
Server_Room
::
addClient
(
Server_ProtocolHandler
*
client
)
ServerInfo_Room
*
Server_Room
::
getInfo
(
bool
complete
)
const
{
QList
<
ServerInfo_Game
*>
gameList
;
QList
<
ServerInfo_User
*>
userList
;
qDebug
()
<<
"getInfo: complete="
<<
complete
;
if
(
complete
)
{
QMapIterator
<
int
,
Server_Game
*>
gameIterator
(
games
);
while
(
gameIterator
.
hasNext
())
gameList
.
append
(
gameIterator
.
next
().
value
()
->
getInfo
());
for
(
int
i
=
0
;
i
<
size
();
++
i
)
userList
.
append
(
new
ServerInfo_User
(
at
(
i
)
->
getUserInfo
(),
false
));
}
return
new
ServerInfo_Room
(
id
,
name
,
description
,
games
.
size
(),
size
(),
autoJoin
,
gameList
,
userList
);
}
void
Server_Room
::
addClient
(
Server_ProtocolHandler
*
client
)
{
sendRoomEvent
(
new
Event_JoinRoom
(
id
,
new
ServerInfo_User
(
client
->
getUserInfo
())));
append
(
client
);
...
...
@@ -22,7 +40,6 @@ QList<ServerInfo_User *> Server_Room::addClient(Server_ProtocolHandler *client)
eventUserList
.
append
(
new
ServerInfo_User
(
at
(
i
)
->
getUserInfo
()));
emit
roomInfoChanged
();
return
eventUserList
;
}
void
Server_Room
::
removeClient
(
Server_ProtocolHandler
*
client
)
...
...
common/server_room.h
View file @
80277ff5
...
...
@@ -9,6 +9,7 @@
class
Server_ProtocolHandler
;
class
RoomEvent
;
class
ServerInfo_User
;
class
ServerInfo_Room
;
class
Server_Game
;
class
Server
;
...
...
@@ -35,8 +36,9 @@ public:
bool
getAutoJoin
()
const
{
return
autoJoin
;
}
const
QMap
<
int
,
Server_Game
*>
&
getGames
()
const
{
return
games
;
}
Server
*
getServer
()
const
;
ServerInfo_Room
*
getInfo
(
bool
complete
)
const
;
QList
<
ServerInfo_User
*>
addClient
(
Server_ProtocolHandler
*
client
);
void
addClient
(
Server_ProtocolHandler
*
client
);
void
removeClient
(
Server_ProtocolHandler
*
client
);
void
say
(
Server_ProtocolHandler
*
client
,
const
QString
&
s
);
void
broadcastGameListUpdate
(
Server_Game
*
game
);
...
...
servatrice/src/servatrice.cpp
View file @
80277ff5
...
...
@@ -64,7 +64,7 @@ Servatrice::Servatrice(QObject *parent)
}
settings
->
endArray
();
l
oginMessage
=
settings
->
value
(
"messages/login"
).
toString
();
updateL
oginMessage
();
maxGameInactivityTime
=
settings
->
value
(
"game/max_game_inactivity_time"
).
toInt
();
maxPlayerInactivityTime
=
settings
->
value
(
"game/max_player_inactivity_time"
).
toInt
();
...
...
@@ -185,6 +185,16 @@ ServerInfo_User *Servatrice::getUserData(const QString &name)
return
new
ServerInfo_User
(
name
,
ServerInfo_User
::
IsUser
);
}
void
Servatrice
::
updateLoginMessage
()
{
checkSql
();
QSqlQuery
query
;
query
.
prepare
(
"select message from "
+
dbPrefix
+
"_servermessages order by timest desc limit 1"
);
if
(
execSqlQuery
(
query
))
if
(
query
.
next
())
loginMessage
=
query
.
value
(
0
).
toString
();
}
void
Servatrice
::
statusUpdate
()
{
uptime
+=
statusUpdateClock
->
interval
()
/
1000
;
...
...
servatrice/src/servatrice.h
View file @
80277ff5
...
...
@@ -46,6 +46,7 @@ public:
int
getMaxGameInactivityTime
()
const
{
return
maxGameInactivityTime
;
}
int
getMaxPlayerInactivityTime
()
const
{
return
maxPlayerInactivityTime
;
}
QString
getDbPrefix
()
const
{
return
dbPrefix
;
}
void
updateLoginMessage
();
protected:
AuthenticationResult
checkUserPassword
(
const
QString
&
user
,
const
QString
&
password
);
ServerInfo_User
*
getUserData
(
const
QString
&
name
);
...
...
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