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
c00027f9
Commit
c00027f9
authored
Jun 11, 2009
by
Max-Wilhelm Bruker
Browse files
removed the need to refresh the game list
parent
197bf0dc
Changes
21
Hide whitespace changes
Inline
Side-by-side
cockatrice/src/cardinfowidget.cpp
View file @
c00027f9
...
...
@@ -9,20 +9,32 @@ CardInfoWidget::CardInfoWidget(CardDatabase *_db, QWidget *parent)
cardPicture
=
new
QLabel
();
cardPicture
->
setAlignment
(
Qt
::
AlignCenter
);
QFont
f
;
f
.
setPointSize
(
9
);
nameLabel1
=
new
QLabel
(
tr
(
"Name:"
));
nameLabel1
->
setFont
(
f
);
nameLabel2
=
new
QLabel
();
nameLabel2
->
setWordWrap
(
true
);
nameLabel2
->
setFont
(
f
);
manacostLabel1
=
new
QLabel
(
tr
(
"Mana cost:"
));
manacostLabel1
->
setFont
(
f
);
manacostLabel2
=
new
QLabel
();
manacostLabel2
->
setFont
(
f
);
manacostLabel2
->
setWordWrap
(
true
);
cardtypeLabel1
=
new
QLabel
(
tr
(
"Card type:"
));
cardtypeLabel1
->
setFont
(
f
);
cardtypeLabel2
=
new
QLabel
();
cardtypeLabel2
->
setFont
(
f
);
cardtypeLabel2
->
setWordWrap
(
true
);
powtoughLabel1
=
new
QLabel
(
tr
(
"P / T:"
));
powtoughLabel1
->
setFont
(
f
);
powtoughLabel2
=
new
QLabel
();
powtoughLabel2
->
setFont
(
f
);
textLabel
=
new
QTextEdit
();
textLabel
->
setReadOnly
(
true
);
textLabel
->
setFont
(
f
);
QGridLayout
*
grid
=
new
QGridLayout
(
this
);
grid
->
addWidget
(
cardPicture
,
0
,
0
,
1
,
2
);
...
...
@@ -36,8 +48,11 @@ CardInfoWidget::CardInfoWidget(CardDatabase *_db, QWidget *parent)
grid
->
addWidget
(
powtoughLabel2
,
4
,
1
);
grid
->
addWidget
(
textLabel
,
5
,
0
,
-
1
,
2
);
grid
->
setRowStretch
(
5
,
1
);
grid
->
setColumnStretch
(
1
,
1
);
setFrameStyle
(
QFrame
::
Panel
|
QFrame
::
Raised
);
setCard
(
db
->
getCard
());
setFixedSize
(
sizeHint
());
}
void
CardInfoWidget
::
setCard
(
CardInfo
*
card
)
...
...
cockatrice/src/client.cpp
View file @
c00027f9
...
...
@@ -61,7 +61,7 @@ void Client::readLine()
QStringList
values
=
line
.
split
(
"|"
);
QString
prefix
=
values
.
takeFirst
();
// prefix is one of {welcome, private, public, resp, list_games, list_players, list_counters, list_zones, dump_zone}
if
(
!
(
prefix
.
compare
(
"private"
)
&&
prefix
.
compare
(
"public"
))
)
{
if
((
prefix
==
"private"
)
||
(
prefix
==
"public"
))
{
ServerEventData
event
(
line
);
if
(
event
.
getEventType
()
==
eventPlayerId
)
{
QStringList
data
=
event
.
getEventData
();
...
...
@@ -76,7 +76,7 @@ void Client::readLine()
emit
playerIdReceived
(
id
,
data
[
1
]);
}
else
emit
gameEvent
(
event
);
}
else
if
(
!
prefix
.
compare
(
"resp"
)
)
{
}
else
if
(
prefix
==
"resp"
)
{
bool
ok
;
int
msgid
=
values
.
takeFirst
().
toInt
(
&
ok
);
if
(
!
ok
)
{
...
...
@@ -110,16 +110,12 @@ void Client::readLine()
qDebug
(
QString
(
"msgid unknown: %1"
).
arg
(
msgid
).
toLatin1
());
emit
responseReceived
(
new
ServerResponse
(
msgid
,
ok
,
message
));
}
else
if
(
!
(
prefix
.
compare
(
"list_games"
)
&&
prefix
.
compare
(
"list_players"
)
&&
prefix
.
compare
(
"list_counters"
)
&&
prefix
.
compare
(
"list_zones"
)
&&
prefix
.
compare
(
"dump_zone"
)
&&
prefix
.
compare
(
"welcome"
)))
{
}
else
if
(
prefix
==
"list_games"
)
{
emit
gameListEvent
(
new
ServerGame
(
values
[
0
].
toInt
(),
values
[
5
],
values
[
1
],
values
[
2
].
toInt
(),
values
[
3
].
toInt
(),
values
[
4
].
toInt
()));
}
else
if
((
prefix
==
"list_players"
)
||
(
prefix
==
"list_counters"
)
||
(
prefix
==
"list_zones"
)
||
(
prefix
==
"dump_zone"
)
||
(
prefix
==
"welcome"
))
{
int
cmdid
=
values
.
takeFirst
().
toInt
();
if
(
!
values
[
0
]
.
compare
(
"."
)
)
{
if
(
values
[
0
]
==
"."
)
{
QListIterator
<
QStringList
>
i
(
msgbuf
);
QList
<
ServerGame
*>
gamelist
;
QList
<
ServerPlayer
*>
playerlist
;
QList
<
ServerZone
*>
zonelist
;
QList
<
ServerZoneCard
*>
zonedump
;
...
...
@@ -128,9 +124,7 @@ void Client::readLine()
QStringList
val
=
i
.
next
();
// XXX Parametergültigkeit überprüfen
if
(
!
prefix
.
compare
(
"list_games"
))
gamelist
<<
new
ServerGame
(
val
[
0
].
toInt
(),
val
[
5
],
val
[
1
],
val
[
2
].
toInt
(),
val
[
3
].
toInt
(),
val
[
4
].
toInt
());
else
if
(
!
prefix
.
compare
(
"list_players"
))
if
(
!
prefix
.
compare
(
"list_players"
))
playerlist
<<
new
ServerPlayer
(
val
[
0
].
toInt
(),
val
[
1
]);
else
if
(
!
prefix
.
compare
(
"list_counters"
))
{
}
...
...
@@ -141,9 +135,7 @@ void Client::readLine()
else
if
(
!
prefix
.
compare
(
"welcome"
))
welcomemsg
<<
val
[
0
];
}
if
(
!
prefix
.
compare
(
"list_games"
))
emit
gameListReceived
(
gamelist
);
else
if
(
!
prefix
.
compare
(
"list_players"
))
if
(
!
prefix
.
compare
(
"list_players"
))
emit
playerListReceived
(
playerlist
);
else
if
(
!
prefix
.
compare
(
"list_counters"
))
{
}
...
...
cockatrice/src/client.h
View file @
c00027f9
...
...
@@ -26,7 +26,7 @@ class Client : public QObject {
signals:
void
statusChanged
(
ProtocolStatus
_status
);
void
welcomeMsgReceived
(
QStringList
welcomeMsg
);
void
gameList
Received
(
QList
<
ServerGame
*
>
game
s
);
void
gameList
Event
(
ServerGame
*
game
);
void
playerListReceived
(
QList
<
ServerPlayer
*>
players
);
void
zoneListReceived
(
int
commandId
,
QList
<
ServerZone
*>
zones
);
void
zoneDumpReceived
(
int
commandId
,
QList
<
ServerZoneCard
*>
cards
);
...
...
cockatrice/src/dlg_games.cpp
View file @
c00027f9
...
...
@@ -5,34 +5,29 @@
DlgGames
::
DlgGames
(
Client
*
_client
,
QWidget
*
parent
)
:
QDialog
(
parent
),
client
(
_client
),
msgid
(
0
)
{
table
View
=
new
QTreeView
;
table
Model
=
new
GamesModel
(
this
);
table
View
->
setModel
(
table
Model
);
gameList
View
=
new
QTreeView
;
gameList
Model
=
new
GamesModel
(
this
);
gameList
View
->
setModel
(
gameList
Model
);
createButton
=
new
QPushButton
(
tr
(
"&Create"
));
refreshButton
=
new
QPushButton
(
tr
(
"&Refresh"
));
joinButton
=
new
QPushButton
(
tr
(
"&Join"
));
QHBoxLayout
*
buttonLayout
=
new
QHBoxLayout
;
buttonLayout
->
addWidget
(
createButton
);
buttonLayout
->
addStretch
();
buttonLayout
->
addWidget
(
refreshButton
);
buttonLayout
->
addStretch
();
buttonLayout
->
addWidget
(
createButton
);
buttonLayout
->
addWidget
(
joinButton
);
QVBoxLayout
*
mainLayout
=
new
QVBoxLayout
;
mainLayout
->
addWidget
(
table
View
);
mainLayout
->
addWidget
(
gameList
View
);
mainLayout
->
addLayout
(
buttonLayout
);
setLayout
(
mainLayout
);
setWindowTitle
(
tr
(
"Games"
));
setMinimumWidth
(
table
View
->
columnWidth
(
0
)
*
table
Model
->
columnCount
());
setMinimumWidth
(
gameList
View
->
columnWidth
(
0
)
*
gameList
Model
->
columnCount
());
connect
(
createButton
,
SIGNAL
(
clicked
()),
this
,
SLOT
(
actCreate
()));
connect
(
refreshButton
,
SIGNAL
(
clicked
()),
this
,
SLOT
(
actRefresh
()));
connect
(
joinButton
,
SIGNAL
(
clicked
()),
this
,
SLOT
(
actJoin
()));
connect
(
client
,
SIGNAL
(
gameList
Received
(
QList
<
ServerGame
*
>
)),
this
,
SLOT
(
gameListReceived
(
Q
List
<
ServerGame
*
>
)));
connect
(
client
,
SIGNAL
(
gameList
Event
(
ServerGame
*
)),
gameListModel
,
SLOT
(
updateGame
List
(
ServerGame
*
)));
client
->
listGames
();
}
...
...
@@ -66,7 +61,7 @@ void DlgGames::actJoin()
if
(
msgid
)
return
;
ServerGame
*
game
=
table
Model
->
getGame
(
table
View
->
currentIndex
().
row
());
ServerGame
*
game
=
gameList
Model
->
getGame
(
gameList
View
->
currentIndex
().
row
());
QString
password
;
if
(
game
->
getHasPassword
())
{
bool
ok
;
...
...
@@ -78,8 +73,3 @@ void DlgGames::actJoin()
connect
(
client
,
SIGNAL
(
responseReceived
(
ServerResponse
*
)),
this
,
SLOT
(
checkResponse
(
ServerResponse
*
)));
msgid
=
client
->
joinGame
(
game
->
getGameId
(),
password
);
}
void
DlgGames
::
gameListReceived
(
QList
<
ServerGame
*>
_gameList
)
{
tableModel
->
setGameList
(
_gameList
);
}
cockatrice/src/dlg_games.h
View file @
c00027f9
...
...
@@ -17,14 +17,13 @@ private slots:
void
actCreate
();
void
actRefresh
();
void
actJoin
();
void
gameListReceived
(
QList
<
ServerGame
*>
_gameList
);
void
checkResponse
(
ServerResponse
*
response
);
private:
Client
*
client
;
int
msgid
;
QTreeView
*
table
View
;
GamesModel
*
table
Model
;
QTreeView
*
gameList
View
;
GamesModel
*
gameList
Model
;
QPushButton
*
refreshButton
,
*
createButton
,
*
joinButton
;
};
...
...
cockatrice/src/game.cpp
View file @
c00027f9
...
...
@@ -43,7 +43,7 @@ Game::Game(CardDatabase *_db, Client *_client, QGraphicsScene *_scene, QMenu *_a
connect
(
aDraw
,
SIGNAL
(
triggered
()),
this
,
SLOT
(
actDrawCard
()));
aDrawCards
=
new
QAction
(
tr
(
"D&raw cards..."
),
this
);
connect
(
aDrawCards
,
SIGNAL
(
triggered
()),
this
,
SLOT
(
actDrawCards
()));
aDrawCards
->
setShortcut
(
tr
(
"Ctrl+
C
"
));
aDrawCards
->
setShortcut
(
tr
(
"Ctrl+
E
"
));
aRollDice
=
new
QAction
(
tr
(
"R&oll dice..."
),
this
);
aRollDice
->
setShortcut
(
tr
(
"Ctrl+I"
));
connect
(
aRollDice
,
SIGNAL
(
triggered
()),
this
,
SLOT
(
actRollDice
()));
...
...
cockatrice/src/gamesmodel.cpp
View file @
c00027f9
...
...
@@ -6,32 +6,19 @@ GamesModel::~GamesModel()
cleanList
();
}
int
GamesModel
::
rowCount
(
const
QModelIndex
&
/*parent*/
)
const
{
return
gameList
.
size
();
}
int
GamesModel
::
columnCount
(
const
QModelIndex
&
/*parent*/
)
const
{
return
5
;
}
QVariant
GamesModel
::
data
(
const
QModelIndex
&
index
,
int
role
)
const
{
if
(
!
index
.
isValid
())
if
(
(
role
!=
Qt
::
DisplayRole
)
||
!
index
.
isValid
())
return
QVariant
();
if
((
index
.
row
()
>=
gameList
.
size
())
||
(
index
.
column
()
>=
columnCount
()))
return
QVariant
();
if
(
role
!=
Qt
::
DisplayRole
)
return
QVariant
();
ServerGame
*
g
=
gameList
.
at
(
index
.
row
());
switch
(
index
.
column
())
{
case
0
:
return
g
->
getGameId
();
case
1
:
return
g
->
getCreator
();
case
2
:
return
g
->
getDescription
();
case
3
:
return
QString
(
g
->
getHasPassword
()
?
"yes"
:
"no"
);
case
3
:
return
QString
(
g
->
getHasPassword
()
?
tr
(
"yes"
)
:
tr
(
"no"
)
)
;
case
4
:
return
QString
(
"%1/%2"
).
arg
(
g
->
getPlayerCount
()).
arg
(
g
->
getMaxPlayers
());
default:
return
QVariant
();
}
...
...
@@ -39,16 +26,14 @@ QVariant GamesModel::data(const QModelIndex &index, int role) const
QVariant
GamesModel
::
headerData
(
int
section
,
Qt
::
Orientation
orientation
,
int
role
)
const
{
if
(
role
!=
Qt
::
DisplayRole
)
return
QVariant
();
if
(
orientation
!=
Qt
::
Horizontal
)
if
((
role
!=
Qt
::
DisplayRole
)
||
(
orientation
!=
Qt
::
Horizontal
))
return
QVariant
();
switch
(
section
)
{
case
0
:
return
QString
(
"Game ID"
);
case
1
:
return
QString
(
"Creator"
);
case
2
:
return
QString
(
"Description"
);
case
3
:
return
QString
(
"Password"
);
case
4
:
return
QString
(
"Players"
);
case
0
:
return
tr
(
"Game ID"
);
case
1
:
return
tr
(
"Creator"
);
case
2
:
return
tr
(
"Description"
);
case
3
:
return
tr
(
"Password"
);
case
4
:
return
tr
(
"Players"
);
default:
return
QVariant
();
}
}
...
...
@@ -60,11 +45,26 @@ ServerGame *GamesModel::getGame(int row)
return
gameList
[
row
];
}
void
GamesModel
::
set
GameList
(
const
QList
<
ServerGame
*>
&
_gameList
)
void
GamesModel
::
update
GameList
(
ServerGame
*
game
)
{
cleanList
();
gameList
=
_gameList
;
reset
();
for
(
int
i
=
0
;
i
<
gameList
.
size
();
i
++
)
if
(
gameList
[
i
]
->
getGameId
()
==
game
->
getGameId
())
{
if
((
game
->
getPlayerCount
()
==
0
)
||
(
game
->
getPlayerCount
()
==
game
->
getMaxPlayers
()))
{
beginRemoveRows
(
QModelIndex
(),
i
,
i
);
delete
gameList
.
takeAt
(
i
);
endRemoveRows
();
}
else
{
delete
gameList
[
i
];
gameList
[
i
]
=
game
;
emit
dataChanged
(
index
(
i
,
0
),
index
(
i
,
4
));
}
return
;
}
if
((
game
->
getPlayerCount
()
==
0
)
||
(
game
->
getPlayerCount
()
==
game
->
getMaxPlayers
()))
return
;
beginInsertRows
(
QModelIndex
(),
gameList
.
size
(),
gameList
.
size
());
gameList
<<
game
;
endInsertRows
();
}
void
GamesModel
::
cleanList
()
...
...
cockatrice/src/gamesmodel.h
View file @
c00027f9
...
...
@@ -5,19 +5,19 @@
#include
<QList>
#include
"servergame.h"
class
GamesModel
:
public
QAbstract
List
Model
{
class
GamesModel
:
public
QAbstract
Table
Model
{
Q_OBJECT
public:
GamesModel
(
QObject
*
parent
=
0
)
:
QAbstractListModel
(
parent
)
{
}
GamesModel
(
QObject
*
parent
=
0
)
:
QAbstractTableModel
(
parent
)
{
}
~
GamesModel
();
int
rowCount
(
const
QModelIndex
&
parent
=
QModelIndex
())
const
;
int
columnCount
(
const
QModelIndex
&
parent
=
QModelIndex
())
const
;
int
rowCount
(
const
QModelIndex
&
parent
=
QModelIndex
())
const
{
return
parent
.
isValid
()
?
0
:
gameList
.
size
();
}
int
columnCount
(
const
QModelIndex
&
/*
parent
*/
=
QModelIndex
())
const
{
return
5
;
}
QVariant
data
(
const
QModelIndex
&
index
,
int
role
)
const
;
QVariant
headerData
(
int
section
,
Qt
::
Orientation
orientation
,
int
role
=
Qt
::
DisplayRole
)
const
;
void
setGameList
(
const
QList
<
ServerGame
*>
&
_gameList
);
ServerGame
*
getGame
(
int
row
);
public
slots
:
void
updateGameList
(
ServerGame
*
game
);
private:
QList
<
ServerGame
*>
gameList
;
void
cleanList
();
...
...
cockatrice/src/messagelogwidget.cpp
View file @
c00027f9
...
...
@@ -2,34 +2,28 @@
#include
"game.h"
#include
<QScrollBar>
void
MessageLogWidget
::
appendAndScroll
(
const
QString
&
s
)
{
append
(
s
);
verticalScrollBar
()
->
setValue
(
verticalScrollBar
()
->
maximum
());
}
void
MessageLogWidget
::
logConnecting
(
QString
hostname
)
{
append
AndScroll
(
tr
(
"Connecting to %1..."
).
arg
(
hostname
));
append
(
tr
(
"Connecting to %1..."
).
arg
(
hostname
));
}
void
MessageLogWidget
::
logConnected
(
const
QStringList
WelcomeMsg
)
{
append
AndScroll
(
tr
(
"Connected."
));
append
(
tr
(
"Connected."
));
QStringListIterator
i
(
WelcomeMsg
);
while
(
i
.
hasNext
())
append
AndScroll
(
i
.
next
());
append
(
i
.
next
());
}
void
MessageLogWidget
::
logDisconnected
()
{
append
AndScroll
(
tr
(
"Disconnected from server."
));
append
(
tr
(
"Disconnected from server."
));
}
void
MessageLogWidget
::
logSocketError
(
const
QString
&
errorString
)
{
append
AndScroll
(
errorString
);
append
(
errorString
);
}
void
MessageLogWidget
::
logPlayerListReceived
(
QStringList
players
)
...
...
@@ -38,96 +32,96 @@ void MessageLogWidget::logPlayerListReceived(QStringList players)
append
(
tr
(
"You have joined the game. Player list:"
));
for
(
int
i
=
0
;
i
<
players
.
size
();
i
++
)
append
(
players
.
at
(
i
));
append
AndScroll
(
"---"
);
append
(
"---"
);
}
void
MessageLogWidget
::
logJoin
(
QString
playerName
)
{
append
AndScroll
(
tr
(
"%1 has joined the game"
).
arg
(
playerName
));
append
(
tr
(
"%1 has joined the game"
).
arg
(
playerName
));
}
void
MessageLogWidget
::
logLeave
(
QString
playerName
)
{
append
AndScroll
(
tr
(
"%1 has left the game"
).
arg
(
playerName
));
append
(
tr
(
"%1 has left the game"
).
arg
(
playerName
));
}
void
MessageLogWidget
::
logReadyStart
(
QString
playerName
)
{
append
AndScroll
(
tr
(
"%1 is ready to start a new game."
).
arg
(
playerName
));
append
(
tr
(
"%1 is ready to start a new game."
).
arg
(
playerName
));
}
void
MessageLogWidget
::
logGameStart
()
{
append
AndScroll
(
tr
(
"Game has started."
));
append
(
tr
(
"Game has started."
));
}
void
MessageLogWidget
::
logSay
(
QString
playerName
,
QString
message
)
{
append
AndScroll
(
QString
(
"<font color=
\"
red
\"
>%1:</font> %2"
).
arg
(
playerName
).
arg
(
message
));
append
(
QString
(
"<font color=
\"
red
\"
>%1:</font> %2"
).
arg
(
playerName
).
arg
(
message
));
}
void
MessageLogWidget
::
logShuffle
(
QString
playerName
)
{
append
AndScroll
(
tr
(
"%1 shuffles his/her library"
).
arg
(
playerName
));
append
(
tr
(
"%1 shuffles his/her library"
).
arg
(
playerName
));
}
void
MessageLogWidget
::
logRollDice
(
QString
playerName
,
int
sides
,
int
roll
)
{
append
AndScroll
(
tr
(
"%1 rolled a %2 with a %3-sided dice"
).
arg
(
playerName
).
arg
(
roll
).
arg
(
sides
));
append
(
tr
(
"%1 rolled a %2 with a %3-sided dice"
).
arg
(
playerName
).
arg
(
roll
).
arg
(
sides
));
}
void
MessageLogWidget
::
logDraw
(
QString
playerName
,
int
number
)
{
if
(
number
==
1
)
append
AndScroll
(
tr
(
"%1 draws a card"
).
arg
(
playerName
));
append
(
tr
(
"%1 draws a card"
).
arg
(
playerName
));
else
append
AndScroll
(
tr
(
"%1 draws %2 cards"
).
arg
(
playerName
).
arg
(
number
));
append
(
tr
(
"%1 draws %2 cards"
).
arg
(
playerName
).
arg
(
number
));
}
void
MessageLogWidget
::
logMoveCard
(
QString
playerName
,
QString
cardName
,
QString
startZone
,
QString
targetZone
)
{
append
AndScroll
(
tr
(
"%1 moves %2 from %3 to %4"
).
arg
(
playerName
).
arg
(
cardName
).
arg
(
startZone
).
arg
(
targetZone
));
append
(
tr
(
"%1 moves %2 from %3 to %4"
).
arg
(
playerName
).
arg
(
cardName
).
arg
(
startZone
).
arg
(
targetZone
));
}
void
MessageLogWidget
::
logCreateToken
(
QString
playerName
,
QString
cardName
)
{
append
AndScroll
(
tr
(
"%1 creates token: %2"
).
arg
(
playerName
).
arg
(
cardName
));
append
(
tr
(
"%1 creates token: %2"
).
arg
(
playerName
).
arg
(
cardName
));
}
void
MessageLogWidget
::
logSetCardCounters
(
QString
playerName
,
QString
cardName
,
int
value
,
int
oldValue
)
{
if
(
value
>
oldValue
)
append
AndScroll
(
tr
(
"%1 places %2 counters on %3 (now %4)"
).
arg
(
playerName
).
arg
(
value
-
oldValue
).
arg
(
cardName
).
arg
(
value
));
append
(
tr
(
"%1 places %2 counters on %3 (now %4)"
).
arg
(
playerName
).
arg
(
value
-
oldValue
).
arg
(
cardName
).
arg
(
value
));
else
append
AndScroll
(
tr
(
"%1 removes %2 counters from %3 (now %4)"
).
arg
(
playerName
).
arg
(
oldValue
-
value
).
arg
(
cardName
).
arg
(
value
));
append
(
tr
(
"%1 removes %2 counters from %3 (now %4)"
).
arg
(
playerName
).
arg
(
oldValue
-
value
).
arg
(
cardName
).
arg
(
value
));
}
void
MessageLogWidget
::
logSetTapped
(
QString
playerName
,
QString
cardName
,
bool
tapped
)
{
if
(
cardName
==
"-1"
)
cardName
=
tr
(
"his permanents"
);
append
AndScroll
(
tr
(
"%1 %2 %3"
).
arg
(
playerName
).
arg
(
tapped
?
"taps"
:
"untaps"
).
arg
(
cardName
));
append
(
tr
(
"%1 %2 %3"
).
arg
(
playerName
).
arg
(
tapped
?
"taps"
:
"untaps"
).
arg
(
cardName
));
}
void
MessageLogWidget
::
logSetCounter
(
QString
playerName
,
QString
counterName
,
int
value
,
int
oldValue
)
{
append
AndScroll
(
tr
(
"%1 sets counter
\"
%2
\"
to %3 (%4%5)"
).
arg
(
playerName
).
arg
(
counterName
).
arg
(
value
).
arg
(
value
>
oldValue
?
"+"
:
""
).
arg
(
value
-
oldValue
));
append
(
tr
(
"%1 sets counter
\"
%2
\"
to %3 (%4%5)"
).
arg
(
playerName
).
arg
(
counterName
).
arg
(
value
).
arg
(
value
>
oldValue
?
"+"
:
""
).
arg
(
value
-
oldValue
));
}
void
MessageLogWidget
::
logSetDoesntUntap
(
QString
playerName
,
QString
cardName
,
bool
doesntUntap
)
{
if
(
doesntUntap
)
append
AndScroll
(
tr
(
"%1 sets %2 to not untap normally."
).
arg
(
playerName
).
arg
(
cardName
));
append
(
tr
(
"%1 sets %2 to not untap normally."
).
arg
(
playerName
).
arg
(
cardName
));
else
append
AndScroll
(
tr
(
"%1 sets %2 to untap normally."
).
arg
(
playerName
).
arg
(
cardName
));
append
(
tr
(
"%1 sets %2 to untap normally."
).
arg
(
playerName
).
arg
(
cardName
));
}
void
MessageLogWidget
::
logDumpZone
(
QString
playerName
,
QString
zoneName
,
QString
zoneOwner
,
int
numberCards
)
{
if
(
numberCards
)
append
AndScroll
(
tr
(
"%1 is looking at the top %2 cards of %3's %4"
).
arg
(
playerName
).
arg
(
numberCards
).
arg
(
zoneOwner
).
arg
(
zoneName
));
append
(
tr
(
"%1 is looking at the top %2 cards of %3's %4"
).
arg
(
playerName
).
arg
(
numberCards
).
arg
(
zoneOwner
).
arg
(
zoneName
));
else
append
AndScroll
(
tr
(
"%1 is looking at %2's %3"
).
arg
(
playerName
).
arg
(
zoneOwner
).
arg
(
zoneName
));
append
(
tr
(
"%1 is looking at %2's %3"
).
arg
(
playerName
).
arg
(
zoneOwner
).
arg
(
zoneName
));
}
...
...
@@ -155,4 +149,7 @@ MessageLogWidget::MessageLogWidget(QWidget *parent)
:
QTextEdit
(
parent
)
{
setReadOnly
(
true
);
QFont
f
;
f
.
setPointSize
(
9
);
setFont
(
f
);
}
cockatrice/src/messagelogwidget.h
View file @
c00027f9
...
...
@@ -30,8 +30,6 @@ private slots:
void
logSetCounter
(
QString
playerName
,
QString
counterName
,
int
value
,
int
oldValue
);
void
logSetDoesntUntap
(
QString
playerName
,
QString
cardName
,
bool
doesntUntap
);
void
logDumpZone
(
QString
playerName
,
QString
zoneName
,
QString
zoneOwner
,
int
numberCards
);
private:
void
appendAndScroll
(
const
QString
&
s
);
public:
void
connectToGame
(
Game
*
game
);
MessageLogWidget
(
QWidget
*
parent
=
0
);
...
...
servatrice/src/card.cpp
View file @
c00027f9
...
...
@@ -42,24 +42,24 @@ void Card::resetState()
bool
Card
::
setAttribute
(
const
QString
&
aname
,
const
QString
&
avalue
,
bool
allCards
)
{
if
(
!
aname
.
compare
(
"counters"
)
)
{
if
(
aname
==
"counters"
)
{
bool
ok
;
int
tmp_int
=
avalue
.
toInt
(
&
ok
);
if
(
!
ok
)
return
false
;
setCounters
(
tmp_int
);
}
else
if
(
!
aname
.
compare
(
"tapped"
)
)
{
bool
value
=
!
avalue
.
compare
(
"1"
)
;
}
else
if
(
aname
==
"tapped"
)
{
bool
value
=
avalue
==
"1"
;
if
(
!
(
!
value
&&
allCards
&&
doesntUntap
))
setTapped
(
value
);
}
else
if
(
!
aname
.
compare
(
"attacking"
)
)
{
setAttacking
(
!
avalue
.
compare
(
"1"
)
)
;
}
else
if
(
!
aname
.
compare
(
"facedown"
)
)
{
setFaceDown
(
!
avalue
.
compare
(
"1"
)
)
;
}
else
if
(
!
aname
.
compare
(
"annotation"
)
)
{
}
else
if
(
aname
==
"attacking"
)
{
setAttacking
(
avalue
==
"1"
);
}
else
if
(
aname
==
"facedown"
)
{
setFaceDown
(
avalue
==
"1"
);
}
else
if
(
aname
==
"annotation"
)
{
setAnnotation
(
avalue
);
}
else
if
(
!
aname
.
compare
(
"doesnt_untap"
)
)
{
setDoesntUntap
(
!
avalue
.
compare
(
"1"
)
)
;
}
else
if
(
aname
==
"doesnt_untap"
)
{
setDoesntUntap
(
avalue
==
"1"
);
}
else
return
false
;
...
...
servatrice/src/card.h
View file @
c00027f9
...
...
@@ -37,16 +37,16 @@ public:
Card
(
QString
_name
,
int
_id
,
int
_coord_x
,
int
_coord_y
);
~
Card
();
int
getId
()
{
return
id
;
}
int
getX
()
{
return
coord_x
;
}
int
getY
()
{
return
coord_y
;
}
QString
getName
()
{
return
name
;
}
int
getCounters
()
{
return
counters
;
}
bool
getTapped
()
{
return
tapped
;
}
bool
getAttacking
()
{
return
attacking
;
}
bool
getFaceDown
()
{
return
facedown
;
}
QString
getAnnotation
()
{
return
annotation
;
}
bool
getDoesntUntap
()
{
return
doesntUntap
;
}
int
getId
()
const
{
return
id
;
}
int
getX
()
const
{
return
coord_x
;
}
int
getY
()
const
{
return
coord_y
;
}
QString
getName
()
const
{
return
name
;
}
int
getCounters
()
const
{
return
counters
;
}
bool
getTapped
()
const
{
return
tapped
;
}
bool
getAttacking
()
const
{
return
attacking
;
}
bool
getFaceDown
()
const
{
return
facedown
;
}
QString
getAnnotation
()
const
{
return
annotation
;
}
bool
getDoesntUntap
()
const
{
return
doesntUntap
;
}
void
setId
(
int
_id
)
{
id
=
_id
;
}
void
setCoords
(
int
x
,
int
y
)
{
coord_x
=
x
;
coord_y
=
y
;
}
...
...
servatrice/src/counter.h
View file @
c00027f9
...
...
@@ -30,7 +30,7 @@ protected:
public:
Counter
(
QString
_name
,
int
_color
,
int
_count
=
0
)
:
name
(
_name
),
color
(
_color
),
count
(
_count
)
{
}
~
Counter
()
{
}
int
getCount
()
{
return
count
;
}
int
getCount
()
const
{
return
count
;
}
void
setCount
(
int
_count
)
{
count
=
_count
;
}
QString
getName
()
const
{
return
name
;
}
};
...
...
servatrice/src/returnmessage.cpp
View file @
c00027f9
#include
"returnmessage.h"
#include
"serversocket.h"
void
ReturnMessage
::
setMsgId
(
unsigned
int
_msg_id
)
{
msg_id
=
_msg_id
;
}
bool
ReturnMessage
::
send
(
ReturnCode
code
)
{
ServerSocket
*
s
=
qobject_cast
<
ServerSocket
*>
(
parent
());
...
...
servatrice/src/returnmessage.h
View file @
c00027f9
...
...
@@ -12,7 +12,7 @@ public:
enum
ReturnCode
{
ReturnNothing
,
ReturnOk
,
ReturnLoginNeeded
,
ReturnSyntaxError
,
ReturnContextError
,
ReturnPasswordWrong
,
ReturnNameNotFound
};
ReturnMessage
(
QObject
*
parent
=
0
)
:
QObject
(
parent
),
msg_id
(
0
)
{
}
unsigned
int
getMsgId
()
const
{
return
msg_id
;
}
void
setMsgId
(
unsigned
int
_msg_id
)
;
void
setMsgId
(
unsigned
int
_msg_id
)
{
msg_id
=
_msg_id
;
}
void
setCmd
(
const
QString
&
_cmd
)
{
cmd
=
_cmd
;
}
bool
send
(
ReturnCode
code
);
bool
sendList
(
const
QStringList
&
args
);
...
...
servatrice/src/server.cpp
View file @
c00027f9
...
...
@@ -71,10 +71,12 @@ bool Server::openDatabase()
void
Server
::
addGame
(
const
QString
description
,
const
QString
password
,
const
int
maxPlayers
,
ServerSocket
*
creator
)
{
ServerGame
*
newGame
=
new
ServerGame
(
creator
,
nextGameId
++
,
description
,
password
,
maxPlayers
);
ServerGame
*
newGame
=
new
ServerGame
(
creator
,
nextGameId
++
,
description
,
password
,
maxPlayers
,
this
);
games
<<
newGame
;
connect
(
newGame
,
SIGNAL
(
gameClosing
()),
this
,
SLOT
(
gameClosing
()));
newGame
->
addPlayer
(
creator
);
broadcastGameListUpdate
(
newGame
);
}
void
Server
::
incomingConnection
(
int
socketId
)
...
...
@@ -83,7 +85,9 @@ void Server::incomingConnection(int socketId)
socket
->
setSocketDescriptor
(
socketId
);
connect
(
socket
,
SIGNAL
(
createGame
(
const
QString
,
const
QString
,
const
int
,
ServerSocket
*
)),
this
,
SLOT
(
addGame
(
const
QString
,
const
QString
,
const
int
,
ServerSocket
*
)));
connect
(
socket
,
SIGNAL
(
joinGame
(
int
,
ServerSocket
*
)),
this
,
SLOT
(
addClientToGame
(
int
,
ServerSocket
*
)));
connect
(
socket
,
SIGNAL
(
destroyed
(
QObject
*
)),
this
,
SLOT
(
socketDestroyed
(
QObject
*
)));
socket
->
initConnection
();
players
<<
socket
;
}
AuthenticationResult
Server
::
checkUserPassword
(
const
QString
&
user
,
const
QString
&
password
)
...
...
@@ -118,7 +122,7 @@ ServerGame *Server::getGame(int gameId)
QListIterator
<
ServerGame
*>
i
(
games
);
while
(
i
.
hasNext
())
{
ServerGame
*
tmp
=
i
.
next
();
if
((
tmp
->
gameId
==
gameId
)
&&
!
tmp
->
getGameStarted
())
if
((
tmp
->
g
etG
ameId
()
==
gameId
)
&&
!
tmp
->
getGameStarted
())
return
tmp
;
}
return
NULL
;
...
...
@@ -131,7 +135,7 @@ QList<ServerGame *> Server::listOpenGames()
while
(
i
.
hasNext
())
{
ServerGame
*
tmp
=
i
.
next
();
if
((
!
tmp
->
getGameStarted
())
&&
(
tmp
->
getPlayerCount
()
<
tmp
->
m
axPlayers
))
&&
(
tmp
->
getPlayerCount
()
<
tmp
->
getM
axPlayers
()
))
result
.
append
(
tmp
);
}
return
result
;
...
...
@@ -141,23 +145,35 @@ bool Server::checkGamePassword(int gameId, const QString &password)
{
ServerGame
*
tmp
;
if
((
tmp
=
getGame
(
gameId
)))
{
if
((
!
tmp
->
getGameStarted
())
&&
(
!
tmp
->
password
.
compare
(
password
,
Qt
::
CaseSensitive
))
&&
(
tmp
->
getPlayerCount
()
<
tmp
->
maxPlayers
))
if
((
!
tmp
->
getGameStarted
())
&&
(
tmp
->
getPassword
()
==
password
)
&&
(
tmp
->
getPlayerCount
()
<
tmp
->
getMaxPlayers
()))
return
true
;
}
return
false
;
}
void
Server
::
broadcastGameListUpdate
(
ServerGame
*
game
)
{
QString
line
=
game
->
getGameListLine
();
for
(
int
i
=
0
;
i
<
players
.
size
();
i
++
)
if
(
players
[
i
]
->
getAcceptsGameListChanges
())
players
[
i
]
->
msg
(
line
);
}
void
Server
::
addClientToGame
(
int
gameId
,
ServerSocket
*
client
)
{
ServerGame
*
tmp
=
getGame
(
gameId
);
tmp
->
addPlayer
(
client
);
ServerGame
*
game
=
getGame
(
gameId
);
game
->
addPlayer
(
client
);
broadcastGameListUpdate
(
game
);
}
void
Server
::
gameClosing
()
{
qDebug
(
"Server::gameClosing"
);
ServerGame
*
g
=
qobject_cast
<
ServerGame
*>
(
sender
());
games
.
removeAt
(
games
.
indexOf
(
g
));
games
.
removeAt
(
games
.
indexOf
(
static_cast
<
ServerGame
*>
(
sender
())));
}
void
Server
::
socketDestroyed
(
QObject
*
obj
)
{
players
.
removeAt
(
players
.
indexOf
(
static_cast
<
ServerSocket
*>
(
obj
)));
qDebug
(
QString
(
"Server::socketDestroyed: %1 players left"
).
arg
(
players
.
size
()).
toLatin1
());
}
servatrice/src/server.h
View file @
c00027f9
...
...
@@ -37,6 +37,7 @@ private slots:
void
addGame
(
const
QString
description
,
const
QString
password
,
const
int
maxPlayers
,
ServerSocket
*
creator
);
void
addClientToGame
(
int
gameId
,
ServerSocket
*
client
);
void
gameClosing
();
void
socketDestroyed
(
QObject
*
obj
);
public:
Server
(
QObject
*
parent
=
0
);
~
Server
();
...
...
@@ -47,9 +48,11 @@ public:
QList
<
ServerGame
*>
listOpenGames
();
ServerGame
*
getGame
(
int
gameId
);
AbstractRNG
*
getRNG
()
const
{
return
rng
;
}
void
broadcastGameListUpdate
(
ServerGame
*
game
);
private:
void
incomingConnection
(
int
SocketId
);
QList
<
ServerGame
*>
games
;
QList
<
ServerSocket
*>
players
;
int
nextGameId
;
AbstractRNG
*
rng
;
};
...
...
servatrice/src/servergame.cpp
View file @
c00027f9
...
...
@@ -17,12 +17,13 @@
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include
"server.h"
#include
"servergame.h"
#include
"serversocket.h"
#include
<QSqlQuery>
ServerGame
::
ServerGame
(
ServerSocket
*
_creator
,
int
_gameId
,
QString
_description
,
QString
_password
,
int
_maxPlayers
,
QObject
*
parent
)
:
QObject
(
parent
),
gameStarted
(
false
),
creator
(
_creator
),
gameId
(
_gameId
),
description
(
_description
),
password
(
_password
),
maxPlayers
(
_maxPlayers
)
ServerGame
::
ServerGame
(
ServerSocket
*
_creator
,
int
_gameId
,
const
QString
&
_description
,
const
QString
&
_password
,
int
_maxPlayers
,
QObject
*
parent
)
:
QObject
(
parent
),
creator
(
_creator
),
gameStarted
(
false
),
gameId
(
_gameId
),
description
(
_description
),
password
(
_password
),
maxPlayers
(
_maxPlayers
)
{
}
...
...
@@ -32,23 +33,23 @@ ServerGame::~ServerGame()
qDebug
(
"ServerGame destructor"
);
}
bool
ServerGame
::
getGame
Started
()
QString
ServerGame
::
getGame
ListLine
()
const
{
return
gameStarted
;
return
QString
(
"list_games|%1|%2|%3|%4|%5|%6"
).
arg
(
gameId
)
.
arg
(
description
)
.
arg
(
password
.
isEmpty
()
?
0
:
1
)
.
arg
(
players
.
size
())
.
arg
(
maxPlayers
)
.
arg
(
creator
->
getPlayerName
());
}
int
ServerGame
::
getPlayerCount
()
{
return
players
.
size
();
}
QStringList
ServerGame
::
getPlayerNames
()
QStringList
ServerGame
::
getPlayerNames
()
const
{
QStringList
result
;
QListIterator
<
ServerSocket
*>
i
(
players
);
while
(
i
.
hasNext
())
{
ServerSocket
*
tmp
=
i
.
next
();
result
<<
QString
(
"%1|%2"
).
arg
(
tmp
->
getPlayerId
()).
arg
(
tmp
->
PlayerName
);
result
<<
QString
(
"%1|%2"
).
arg
(
tmp
->
getPlayerId
()).
arg
(
tmp
->
get
PlayerName
()
);
}
return
result
;
}
...
...
@@ -74,7 +75,7 @@ void ServerGame::msg(const QString &s)
void
ServerGame
::
broadcastEvent
(
const
QString
&
cmd
,
ServerSocket
*
player
)
{
if
(
player
)
msg
(
QString
(
"public|%1|%2|%3"
).
arg
(
player
->
getPlayerId
()).
arg
(
player
->
PlayerName
).
arg
(
cmd
));
msg
(
QString
(
"public|%1|%2|%3"
).
arg
(
player
->
getPlayerId
()).
arg
(
player
->
get
PlayerName
()
).
arg
(
cmd
));
else
msg
(
QString
(
"public|||%1"
).
arg
(
cmd
));
}
...
...
@@ -97,7 +98,7 @@ void ServerGame::startGameIfReady()
for
(
int
i
=
0
;
i
<
players
.
size
();
i
++
)
{
query
.
prepare
(
"insert into games_players (id_game, player) values(:id, :player)"
);
query
.
bindValue
(
":id"
,
gameId
);
query
.
bindValue
(
":player"
,
players
.
at
(
i
)
->
PlayerName
);
query
.
bindValue
(
":player"
,
players
.
at
(
i
)
->
get
PlayerName
()
);
query
.
exec
();
}
...
...
@@ -122,7 +123,7 @@ void ServerGame::addPlayer(ServerSocket *player)
player
->
setPlayerId
(
max
+
1
);
player
->
setGame
(
this
);
player
->
msg
(
QString
(
"private|||player_id|%1|%2"
).
arg
(
max
+
1
).
arg
(
player
->
PlayerName
));
player
->
msg
(
QString
(
"private|||player_id|%1|%2"
).
arg
(
max
+
1
).
arg
(
player
->
get
PlayerName
()
));
broadcastEvent
(
"join"
,
player
);
players
<<
player
;
...
...
@@ -136,6 +137,8 @@ void ServerGame::removePlayer(ServerSocket *player)
broadcastEvent
(
"leave"
,
player
);
if
(
!
players
.
size
())
deleteLater
();
if
(
!
gameStarted
)
qobject_cast
<
Server
*>
(
parent
())
->
broadcastGameListUpdate
(
this
);
}
void
ServerGame
::
setActivePlayer
(
int
_activePlayer
)
...
...
servatrice/src/servergame.h
View file @
c00027f9
...
...
@@ -27,32 +27,37 @@ class ServerSocket;
class
ServerGame
:
public
QObject
{
Q_OBJECT
private:
ServerSocket
*
creator
;
QList
<
ServerSocket
*>
players
;
bool
gameStarted
;
int
activePlayer
;
int
activePhase
;
int
gameId
;
QString
description
;
QString
password
;
int
maxPlayers
;
int
activePlayer
,
activePhase
;
signals:
void
gameClosing
();
public
slots
:
void
broadcastEvent
(
const
QString
&
event
,
ServerSocket
*
player
);
public:
ServerSocket
*
creator
;
int
gameId
;
QString
description
;
QString
password
;
int
maxPlayers
;
ServerGame
(
ServerSocket
*
_creator
,
int
_gameId
,
QString
_description
,
QString
_password
,
int
_maxPlayers
,
QObject
*
parent
=
0
);
ServerGame
(
ServerSocket
*
_creator
,
int
_gameId
,
const
QString
&
_description
,
const
QString
&
_password
,
int
_maxPlayers
,
QObject
*
parent
=
0
);
~
ServerGame
();
bool
getGameStarted
();
int
getPlayerCount
();
QStringList
getPlayerNames
();
ServerSocket
*
getCreator
()
const
{
return
creator
;
}
bool
getGameStarted
()
const
{
return
gameStarted
;
}
int
getPlayerCount
()
const
{
return
players
.
size
();
}
int
getGameId
()
const
{
return
gameId
;
}
QString
getDescription
()
const
{
return
description
;
}
QString
getPassword
()
const
{
return
password
;
}
int
getMaxPlayers
()
const
{
return
maxPlayers
;
}
QString
getGameListLine
()
const
;
QStringList
getPlayerNames
()
const
;
ServerSocket
*
getPlayer
(
int
player_id
);
void
addPlayer
(
ServerSocket
*
player
);
void
removePlayer
(
ServerSocket
*
player
);
void
startGameIfReady
();
void
msg
(
const
QString
&
s
);
int
getActivePlayer
()
{
return
activePlayer
;
}
int
getActivePhase
()
{
return
activePhase
;
}
int
getActivePlayer
()
const
{
return
activePlayer
;
}
int
getActivePhase
()
const
{
return
activePhase
;
}
void
setActivePlayer
(
int
_activePlayer
);
void
setActivePhase
(
int
_activePhase
);
};
...
...
servatrice/src/serversocket.cpp
View file @
c00027f9
...
...
@@ -30,14 +30,13 @@
#include
"abstractrng.h"
ServerSocket
::
ServerSocket
(
Server
*
_server
,
QObject
*
parent
)
:
QTcpSocket
(
parent
),
server
(
_server
),
game
(
0
),
authState
(
PasswordWrong
)
:
QTcpSocket
(
parent
),
server
(
_server
),
game
(
0
),
PlayerStatus
(
StatusNormal
),
authState
(
PasswordWrong
),
acceptsGameListChanges
(
false
)
{
remsg
=
new
ReturnMessage
(
this
);
connect
(
this
,
SIGNAL
(
readyRead
()),
this
,
SLOT
(
readClient
()));
connect
(
this
,
SIGNAL
(
disconnected
()),
this
,
SLOT
(
deleteLater
()));
connect
(
this
,
SIGNAL
(
error
(
QAbstractSocket
::
SocketError
)),
this
,
SLOT
(
catchSocketError
(
QAbstractSocket
::
SocketError
)));
setTextModeEnabled
(
true
);
PlayerStatus
=
StatusNormal
;
}
ServerSocket
::~
ServerSocket
()
...
...
@@ -52,29 +51,23 @@ int ServerSocket::newCardId()
return
nextCardId
++
;
}
void
ServerSocket
::
setName
(
const
QString
&
name
)
{
emit
broadcastEvent
(
QString
(
"name|%1|%2"
).
arg
(
PlayerName
).
arg
(
name
),
this
);
PlayerName
=
name
;
}
PlayerZone
*
ServerSocket
::
getZone
(
const
QString
&
name
)
PlayerZone
*
ServerSocket
::
getZone
(
const
QString
&
name
)
const
{
QListIterator
<
PlayerZone
*>
ZoneIterator
(
zones
);
while
(
ZoneIterator
.
hasNext
())
{
PlayerZone
*
temp
=
ZoneIterator
.
next
();
if
(
!
temp
->
getName
()
.
compare
(
name
)
)
if
(
temp
->
getName
()
==
name
)
return
temp
;
}
return
NULL
;
}
Counter
*
ServerSocket
::
getCounter
(
const
QString
&
name
)
Counter
*
ServerSocket
::
getCounter
(
const
QString
&
name
)
const
{
QListIterator
<
Counter
*>
CounterIterator
(
counters
);
while
(
CounterIterator
.
hasNext
())
{
Counter
*
temp
=
CounterIterator
.
next
();
if
(
!
temp
->
getName
()
.
compare
(
name
)
)
if
(
temp
->
getName
()
==
name
)
return
temp
;
}
return
NULL
;
...
...
@@ -137,7 +130,6 @@ void ServerSocket::leaveGame()
game
=
0
;
PlayerStatus
=
StatusNormal
;
clearZones
();
moveToThread
(
server
->
thread
());
}
void
ServerSocket
::
readClient
()
...
...
@@ -156,7 +148,7 @@ void ServerSocket::readClient()
break
;
case
StatusSubmitDeck
:
QString
card
=
line
;
if
(
!
card
.
compare
(
"."
)
)
{
if
(
card
==
"."
)
{
PlayerStatus
=
StatusNormal
;
remsg
->
send
(
ReturnMessage
::
ReturnOk
);
}
else
if
(
card
.
startsWith
(
"SB:"
))
...
...
@@ -229,27 +221,19 @@ ReturnMessage::ReturnCode ServerSocket::cmdLogin(const QList<QVariant> ¶ms)
authState
=
server
->
checkUserPassword
(
params
[
0
].
toString
(),
params
[
1
].
toString
());
if
(
authState
==
PasswordWrong
)
return
ReturnMessage
::
ReturnPasswordWrong
;
P
layerName
=
params
[
0
].
toString
();
p
layerName
=
params
[
0
].
toString
();
return
ReturnMessage
::
ReturnOk
;
}
ReturnMessage
::
ReturnCode
ServerSocket
::
cmdListGames
(
const
QList
<
QVariant
>
&
params
)
ReturnMessage
::
ReturnCode
ServerSocket
::
cmdListGames
(
const
QList
<
QVariant
>
&
/*
params
*/
)
{
Q_UNUSED
(
params
);
QList
<
ServerGame
*>
gameList
=
server
->
listOpenGames
();
QListIterator
<
ServerGame
*>
gameListIterator
(
gameList
);
QStringList
result
;
while
(
gameListIterator
.
hasNext
())
{
ServerGame
*
tmp
=
gameListIterator
.
next
();
result
<<
QString
(
"%1|%2|%3|%4|%5|%6"
).
arg
(
tmp
->
gameId
)
.
arg
(
tmp
->
description
)
.
arg
(
tmp
->
password
==
""
?
0
:
1
)
.
arg
(
tmp
->
getPlayerCount
())
.
arg
(
tmp
->
maxPlayers
)
.
arg
(
tmp
->
creator
->
PlayerName
);
}
remsg
->
sendList
(
result
);
while
(
gameListIterator
.
hasNext
())
msg
(
gameListIterator
.
next
()
->
getGameListLine
());
acceptsGameListChanges
=
true
;
return
ReturnMessage
::
ReturnOk
;
}
...
...
@@ -260,6 +244,7 @@ ReturnMessage::ReturnCode ServerSocket::cmdCreateGame(const QList<QVariant> &par
int
maxPlayers
=
params
[
2
].
toInt
();
leaveGame
();
emit
createGame
(
description
,
password
,
maxPlayers
,
this
);
acceptsGameListChanges
=
false
;
return
ReturnMessage
::
ReturnOk
;
}
...
...
@@ -271,19 +256,18 @@ ReturnMessage::ReturnCode ServerSocket::cmdJoinGame(const QList<QVariant> ¶m
return
ReturnMessage
::
ReturnPasswordWrong
;
leaveGame
();
emit
joinGame
(
gameId
,
this
);
acceptsGameListChanges
=
false
;
return
ReturnMessage
::
ReturnOk
;
}
ReturnMessage
::
ReturnCode
ServerSocket
::
cmdLeaveGame
(
const
QList
<
QVariant
>
&
params
)
ReturnMessage
::
ReturnCode
ServerSocket
::
cmdLeaveGame
(
const
QList
<
QVariant
>
&
/*
params
*/
)
{
Q_UNUSED
(
params
);
leaveGame
();
return
ReturnMessage
::
ReturnOk
;
}
ReturnMessage
::
ReturnCode
ServerSocket
::
cmdListPlayers
(
const
QList
<
QVariant
>
&
params
)
ReturnMessage
::
ReturnCode
ServerSocket
::
cmdListPlayers
(
const
QList
<
QVariant
>
&
/*
params
*/
)
{
Q_UNUSED
(
params
);
remsg
->
sendList
(
game
->
getPlayerNames
());
return
ReturnMessage
::
ReturnOk
;
}
...
...
@@ -294,27 +278,24 @@ ReturnMessage::ReturnCode ServerSocket::cmdSay(const QList<QVariant> ¶ms)
return
ReturnMessage
::
ReturnOk
;
}
ReturnMessage
::
ReturnCode
ServerSocket
::
cmdSubmitDeck
(
const
QList
<
QVariant
>
&
params
)
ReturnMessage
::
ReturnCode
ServerSocket
::
cmdSubmitDeck
(
const
QList
<
QVariant
>
&
/*
params
*/
)
{
Q_UNUSED
(
params
);
PlayerStatus
=
StatusSubmitDeck
;
DeckList
.
clear
();
SideboardList
.
clear
();
return
ReturnMessage
::
ReturnNothing
;
}
ReturnMessage
::
ReturnCode
ServerSocket
::
cmdReadyStart
(
const
QList
<
QVariant
>
&
params
)
ReturnMessage
::
ReturnCode
ServerSocket
::
cmdReadyStart
(
const
QList
<
QVariant
>
&
/*
params
*/
)
{
Q_UNUSED
(
params
);
PlayerStatus
=
StatusReadyStart
;
emit
broadcastEvent
(
QString
(
"ready_start"
),
this
);
game
->
startGameIfReady
();
return
ReturnMessage
::
ReturnOk
;
}
ReturnMessage
::
ReturnCode
ServerSocket
::
cmdShuffle
(
const
QList
<
QVariant
>
&
params
)
ReturnMessage
::
ReturnCode
ServerSocket
::
cmdShuffle
(
const
QList
<
QVariant
>
&
/*
params
*/
)
{
Q_UNUSED
(
params
);
getZone
(
"deck"
)
->
shuffle
(
server
->
getRNG
());
emit
broadcastEvent
(
"shuffle"
,
this
);
return
ReturnMessage
::
ReturnOk
;
...
...
@@ -545,7 +526,7 @@ ReturnMessage::ReturnCode ServerSocket::cmdDumpZone(const QList<QVariant> ¶m
PlayerZone
*
zone
=
player
->
getZone
(
params
[
1
].
toString
());
if
(
!
zone
)
return
ReturnMessage
::
ReturnContextError
;
if
(
!
(
zone
->
isPublic
()
||
(
player_id
==
P
layerId
)))
if
(
!
(
zone
->
isPublic
()
||
(
player_id
==
p
layerId
)))
return
ReturnMessage
::
ReturnContextError
;
QListIterator
<
Card
*>
card_iterator
(
zone
->
cards
);
...
...
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