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
0d4717f4
Commit
0d4717f4
authored
Nov 25, 2009
by
Max-Wilhelm Bruker
Browse files
new code
parent
6c93b1e9
Changes
28
Hide whitespace changes
Inline
Side-by-side
cockatrice/cockatrice.pro
View file @
0d4717f4
...
...
@@ -99,7 +99,8 @@ SOURCES += src/counter.cpp \
src
/
deckview
.
cpp
\
..
/
common
/
decklist
.
cpp
\
..
/
common
/
protocol
.
cpp
\
..
/
common
/
protocol_items
.
cpp
..
/
common
/
protocol_items
.
cpp
\
..
/
common
/
protocol_datastructures
.
cpp
TRANSLATIONS
+=
translations
/
cockatrice_de
.
ts
translations
/
cockatrice_en
.
ts
CONFIG
+=
qt
debug
cockatrice/src/client.cpp
View file @
0d4717f4
...
...
@@ -99,170 +99,6 @@ void Client::readData()
}
}
}
/*
while (socket->canReadLine()) {
QString line = QString(socket->readLine()).trimmed();
if (line.isNull())
break;
qDebug(QString("<< %1").arg(line).toLatin1());
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 == "private") || (prefix == "public")) {
ServerEventData event(line);
emit gameEvent(event);
} else if (prefix == "chat") {
emit chatEvent(ChatEventData(line));
} else if (prefix == "resp") {
if (values.size() != 2) {
qDebug("Client::parseCommand: Invalid response");
continue;
}
bool ok;
int msgid = values.takeFirst().toInt(&ok);
PendingCommand *pc = pendingCommands.value(msgid, 0);
if (!ok || !pc) {
qDebug("Client::parseCommand: Invalid msgid");
continue;
}
ServerResponse resp;
if (values[0] == "ok")
resp = RespOk;
else if (values[0] == "name_not_found")
resp = RespNameNotFound;
else if (values[0] == "login_needed")
resp = RespLoginNeeded;
else if (values[0] == "syntax")
resp = RespSyntaxError;
else if (values[0] == "context")
resp = RespContextError;
else if (values[0] == "password")
resp = RespPasswordWrong;
else if (values[0] == "spectators_not_allowed")
resp = RespSpectatorsNotAllowed;
else
resp = RespInvalid;
pc->responseReceived(resp);
} else if (prefix == "list_games") {
if (values.size() != 8) {
emit protocolError();
continue;
}
emit gameListEvent(ServerGame(values[0].toInt(), values[5], values[1], values[2].toInt(), values[3].toInt(), values[4].toInt(), values[6].toInt(), values[7].toInt()));
} else if (prefix == "welcome") {
if (values.size() != 2) {
emit protocolError();
disconnectFromServer();
} else if (values[0].toInt() != protocolVersion) {
emit protocolVersionMismatch();
disconnectFromServer();
} else {
emit welcomeMsgReceived(values[1]);
setStatus(StatusLoggingIn);
login(playerName, password);
}
} else if (prefix == "list_players") {
if (values.size() != 4) {
emit protocolError();
continue;
}
int cmdid = values.takeFirst().toInt();
PendingCommand *pc = pendingCommands.value(cmdid, 0);
ServerPlayer sp(values[0].toInt(), values[1], values[2].toInt());
PendingCommand_ListPlayers *pcLP = qobject_cast<PendingCommand_ListPlayers *>(pc);
if (pcLP)
pcLP->addPlayer(sp);
else {
PendingCommand_DumpAll *pcDA = qobject_cast<PendingCommand_DumpAll *>(pc);
if (pcDA)
pcDA->addPlayer(sp);
else
emit protocolError();
}
} else if (prefix == "dump_zone") {
if (values.size() != 11) {
emit protocolError();
continue;
}
int cmdid = values.takeFirst().toInt();
PendingCommand *pc = pendingCommands.value(cmdid, 0);
ServerZoneCard szc(values[0].toInt(), values[1], values[2].toInt(), values[3], values[4].toInt(), values[5].toInt(), values[6].toInt(), values[7] == "1", values[8] == "1", values[9]);
PendingCommand_DumpZone *pcDZ = qobject_cast<PendingCommand_DumpZone *>(pc);
if (pcDZ)
pcDZ->addCard(szc);
else {
PendingCommand_DumpAll *pcDA = qobject_cast<PendingCommand_DumpAll *>(pc);
if (pcDA)
pcDA->addCard(szc);
else
emit protocolError();
}
} else if (prefix == "list_zones") {
if (values.size() != 6) {
emit protocolError();
continue;
}
int cmdid = values.takeFirst().toInt();
PendingCommand *pc = pendingCommands.value(cmdid, 0);
ServerZone::ZoneType type;
if (values[2] == "private")
type = ServerZone::PrivateZone;
else if (values[2] == "hidden")
type = ServerZone::HiddenZone;
else
type = ServerZone::PublicZone;
ServerZone sz(values[0].toInt(), values[1], type, values[3] == "1", values[4].toInt());
PendingCommand_ListZones *pcLZ = qobject_cast<PendingCommand_ListZones *>(pc);
if (pcLZ)
pcLZ->addZone(sz);
else {
PendingCommand_DumpAll *pcDA = qobject_cast<PendingCommand_DumpAll *>(pc);
if (pcDA)
pcDA->addZone(sz);
else
emit protocolError();
}
} else if (prefix == "list_counters") {
if (values.size() != 7) {
emit protocolError();
continue;
}
int cmdid = values.takeFirst().toInt();
PendingCommand *pc = pendingCommands.value(cmdid, 0);
ServerCounter sc(values[0].toInt(), values[1].toInt(), values[2], numberToColor(values[3].toInt()), values[4].toInt(), values[5].toInt());
PendingCommand_ListCounters *pcLC = qobject_cast<PendingCommand_ListCounters *>(pc);
if (pcLC)
pcLC->addCounter(sc);
else {
PendingCommand_DumpAll *pcDA = qobject_cast<PendingCommand_DumpAll *>(pc);
if (pcDA)
pcDA->addCounter(sc);
else
emit protocolError();
}
} else if (prefix == "list_arrows") {
if (values.size() != 10) {
emit protocolError();
continue;
}
int cmdid = values.takeFirst().toInt();
PendingCommand *pc = pendingCommands.value(cmdid, 0);
ServerArrow sa(values[0].toInt(), values[1].toInt(), values[2].toInt(), values[3], values[4].toInt(), values[5].toInt(), values[6], values[7].toInt(), numberToColor(values[8].toInt()));
PendingCommand_DumpAll *pcDA = qobject_cast<PendingCommand_DumpAll *>(pc);
if (pcDA)
pcDA->addArrow(sa);
else
emit protocolError();
} else
emit protocolError();
}
*/
}
void
Client
::
processProtocolItem
(
ProtocolItem
*
item
)
...
...
@@ -365,14 +201,3 @@ void Client::ping()
}
else
sendCommand
(
new
Command_Ping
);
}
/*
QColor Client::numberToColor(int colorValue) const
{
return QColor(colorValue / 65536, (colorValue % 65536) / 256, colorValue % 256);
}
int Client::colorToNumber(const QColor &color) const
{
return color.red() * 65536 + color.green() * 256 + color.blue();
}
*/
\ No newline at end of file
cockatrice/src/game.cpp
View file @
0d4717f4
...
...
@@ -128,25 +128,6 @@ void Game::retranslateUi()
i
.
next
().
value
()
->
retranslateUi
();
}
Player
*
Game
::
addPlayer
(
int
playerId
,
const
QString
&
playerName
,
bool
local
)
{
Player
*
newPlayer
=
new
Player
(
playerName
,
playerId
,
local
,
client
,
this
);
scene
->
addPlayer
(
newPlayer
);
connect
(
newPlayer
,
SIGNAL
(
sigShowCardMenu
(
QPoint
)),
this
,
SLOT
(
showCardMenu
(
QPoint
)));
connect
(
newPlayer
,
SIGNAL
(
logMoveCard
(
Player
*
,
QString
,
CardZone
*
,
int
,
CardZone
*
,
int
)),
this
,
SIGNAL
(
logMoveCard
(
Player
*
,
QString
,
CardZone
*
,
int
,
CardZone
*
,
int
)));
connect
(
newPlayer
,
SIGNAL
(
logCreateToken
(
Player
*
,
QString
)),
this
,
SIGNAL
(
logCreateToken
(
Player
*
,
QString
)));
connect
(
newPlayer
,
SIGNAL
(
logSetCardCounters
(
Player
*
,
QString
,
int
,
int
)),
this
,
SIGNAL
(
logSetCardCounters
(
Player
*
,
QString
,
int
,
int
)));
connect
(
newPlayer
,
SIGNAL
(
logSetTapped
(
Player
*
,
QString
,
bool
)),
this
,
SIGNAL
(
logSetTapped
(
Player
*
,
QString
,
bool
)));
connect
(
newPlayer
,
SIGNAL
(
logSetCounter
(
Player
*
,
QString
,
int
,
int
)),
this
,
SIGNAL
(
logSetCounter
(
Player
*
,
QString
,
int
,
int
)));
connect
(
newPlayer
,
SIGNAL
(
logCreateArrow
(
Player
*
,
Player
*
,
QString
,
Player
*
,
QString
)),
this
,
SIGNAL
(
logCreateArrow
(
Player
*
,
Player
*
,
QString
,
Player
*
,
QString
)));
connect
(
newPlayer
,
SIGNAL
(
logSetDoesntUntap
(
Player
*
,
QString
,
bool
)),
this
,
SIGNAL
(
logSetDoesntUntap
(
Player
*
,
QString
,
bool
)));
players
.
insert
(
playerId
,
newPlayer
);
emit
playerAdded
(
newPlayer
);
return
newPlayer
;
}
/*
void Game::cardListReceived(QList<ServerZoneCard> list)
{
...
...
@@ -570,4 +551,4 @@ Player *Game::getActiveLocalPlayer() const
return
p
;
}
return
0
;
}
\ No newline at end of file
}
cockatrice/src/game.h
View file @
0d4717f4
...
...
@@ -103,7 +103,6 @@ public:
void
retranslateUi
();
void
restartGameDialog
();
void
hoverCardEvent
(
CardItem
*
card
);
Player
*
addPlayer
(
int
playerId
,
const
QString
&
playerName
,
bool
local
);
Player
*
getActiveLocalPlayer
()
const
;
const
QMap
<
int
,
Player
*>
&
getPlayers
()
const
{
return
players
;
}
void
queryGameState
();
...
...
cockatrice/src/messagelogwidget.cpp
View file @
0d4717f4
...
...
@@ -275,9 +275,9 @@ void MessageLogWidget::logSetActivePhase(int phase)
append
(
"<font color=
\"
green
\"
>"
+
tr
(
"It is now the %1."
).
arg
(
phaseName
)
+
"</font>"
);
}
void
MessageLogWidget
::
connectTo
Game
(
Game
*
game
)
void
MessageLogWidget
::
connectTo
Player
(
Player
*
player
)
{
connect
(
game
,
SIGNAL
(
logPlayerListReceived
(
QStringList
)),
this
,
SLOT
(
logPlayerListReceived
(
QStringList
)));
/*
connect(game, SIGNAL(logPlayerListReceived(QStringList)), this, SLOT(logPlayerListReceived(QStringList)));
connect(game, SIGNAL(logJoin(Player *)), this, SLOT(logJoin(Player *)));
connect(game, SIGNAL(logLeave(Player *)), this, SLOT(logLeave(Player *)));
connect(game, SIGNAL(logGameClosed()), this, SLOT(logGameClosed()));
...
...
@@ -310,7 +310,7 @@ void MessageLogWidget::connectToGame(Game *game)
connect(game, SIGNAL(logDraw(Player *, int)), this, SLOT(msgAlert()));
connect(game, SIGNAL(logMoveCard(Player *, QString, CardZone *, int, CardZone *, int)), this, SLOT(msgAlert()));
connect(game, SIGNAL(logGameStart()), this, SLOT(msgAlert()));
}
*/
}
void
MessageLogWidget
::
msgAlert
()
{
...
...
cockatrice/src/messagelogwidget.h
View file @
0d4717f4
...
...
@@ -6,7 +6,6 @@
#include
"translation.h"
#include
"protocol_datastructures.h"
class
Game
;
class
Player
;
class
CardZone
;
...
...
@@ -49,7 +48,7 @@ private slots:
void
logSetActivePhase
(
int
phase
);
void
msgAlert
();
public:
void
connectTo
Game
(
Game
*
game
);
void
connectTo
Player
(
Player
*
player
);
MessageLogWidget
(
QWidget
*
parent
=
0
);
};
...
...
cockatrice/src/player.cpp
View file @
0d4717f4
...
...
@@ -5,16 +5,16 @@
#include
"arrowitem.h"
#include
"zoneviewzone.h"
#include
"zoneviewwidget.h"
#include
"game.h"
#include
"pilezone.h"
#include
"tablezone.h"
#include
"handzone.h"
#include
"cardlist.h"
#include
"tab_game.h"
#include
<QSettings>
#include
<QPainter>
#include
<QMenu>
Player
::
Player
(
const
QString
&
_name
,
int
_id
,
bool
_local
,
Client
*
_client
,
Game
*
_parent
)
Player
::
Player
(
const
QString
&
_name
,
int
_id
,
bool
_local
,
Client
*
_client
,
Tab
Game
*
_parent
)
:
QObject
(
_parent
),
defaultNumberTopCards
(
3
),
name
(
_name
),
id
(
_id
),
active
(
false
),
local
(
_local
),
client
(
_client
)
{
QSettings
settings
;
...
...
@@ -697,6 +697,10 @@ void Player::paint(QPainter *painter, const QStyleOptionGraphicsItem */*option*/
painter
->
drawText
(
QRectF
(
0
,
0
,
totalWidth
,
40
),
Qt
::
AlignCenter
,
nameStr
);
}
void
Player
::
processPlayerInfo
(
ServerInfo_Player
*
info
)
{
}
void
Player
::
addCounter
(
int
counterId
,
const
QString
&
name
,
QColor
color
,
int
radius
,
int
value
)
{
Counter
*
c
=
new
Counter
(
this
,
counterId
,
name
,
color
,
radius
,
value
,
this
);
...
...
cockatrice/src/player.h
View file @
0d4717f4
...
...
@@ -12,12 +12,13 @@ class CardDatabase;
class
QMenu
;
class
QAction
;
class
ZoneViewZone
;
class
Game
;
class
Tab
Game
;
class
Counter
;
class
ArrowItem
;
class
CardZone
;
class
TableZone
;
class
HandZone
;
class
ServerInfo_Player
;
class
Player
:
public
QObject
,
public
QGraphicsItem
{
Q_OBJECT
...
...
@@ -103,7 +104,7 @@ public:
Client
*
client
;
void
addZone
(
CardZone
*
z
);
Player
(
const
QString
&
_name
,
int
_id
,
bool
_local
,
Client
*
_client
,
Game
*
_parent
);
Player
(
const
QString
&
_name
,
int
_id
,
bool
_local
,
Client
*
_client
,
Tab
Game
*
_parent
);
~
Player
();
void
retranslateUi
();
QMenu
*
getPlayerMenu
()
const
{
return
playerMenu
;
}
...
...
@@ -117,6 +118,8 @@ public:
void
showCardMenu
(
const
QPoint
&
p
);
bool
getActive
()
const
{
return
active
;
}
void
setActive
(
bool
_active
);
void
processPlayerInfo
(
ServerInfo_Player
*
info
);
};
#endif
cockatrice/src/tab_chatchannel.cpp
View file @
0d4717f4
...
...
@@ -51,7 +51,7 @@ void TabChatChannel::processChatEvent(ChatEvent *event)
void
TabChatChannel
::
processListPlayersEvent
(
Event_ChatListPlayers
*
event
)
{
const
QList
<
Server
Play
erInfo
>
&
players
=
event
->
getPlayerList
();
const
QList
<
Server
ChatUs
erInfo
>
&
players
=
event
->
getPlayerList
();
for
(
int
i
=
0
;
i
<
players
.
size
();
++
i
)
playerList
->
addItem
(
players
[
i
].
getName
());
}
...
...
cockatrice/src/tab_game.cpp
View file @
0d4717f4
...
...
@@ -18,7 +18,7 @@
#include
"main.h"
TabGame
::
TabGame
(
Client
*
_client
,
int
_gameId
)
:
client
(
_client
),
gameId
(
_gameId
)
:
client
(
_client
),
gameId
(
_gameId
)
,
localPlayerId
(
-
1
)
{
zoneLayout
=
new
ZoneViewLayout
;
scene
=
new
GameScene
(
zoneLayout
,
this
);
...
...
@@ -38,6 +38,8 @@ TabGame::TabGame(Client *_client, int _gameId)
QVBoxLayout
*
deckViewLayout
=
new
QVBoxLayout
;
deckViewLayout
->
addLayout
(
buttonHBox
);
deckViewLayout
->
addWidget
(
deckView
);
deckViewContainer
=
new
QWidget
;
deckViewContainer
->
setLayout
(
deckViewLayout
);
cardInfo
=
new
CardInfoWidget
(
db
);
messageLog
=
new
MessageLogWidget
;
...
...
@@ -60,7 +62,7 @@ TabGame::TabGame(Client *_client, int _gameId)
QHBoxLayout
*
mainLayout
=
new
QHBoxLayout
;
mainLayout
->
addWidget
(
phasesToolbar
);
mainLayout
->
addWidget
(
gameView
,
10
);
mainLayout
->
add
Layou
t
(
deckView
Layout
,
10
);
mainLayout
->
add
Widge
t
(
deckView
Container
,
10
);
mainLayout
->
addLayout
(
verticalLayout
);
aCloseMostRecentZoneView
=
new
QAction
(
this
);
...
...
@@ -105,9 +107,44 @@ void TabGame::retranslateUi()
aCloseMostRecentZoneView
->
setShortcut
(
tr
(
"Esc"
));
}
Player
*
TabGame
::
addPlayer
(
int
playerId
,
const
QString
&
playerName
)
{
Player
*
newPlayer
=
new
Player
(
playerName
,
playerId
,
playerId
==
localPlayerId
,
client
,
this
);
scene
->
addPlayer
(
newPlayer
);
messageLog
->
connectToPlayer
(
newPlayer
);
players
.
insert
(
playerId
,
newPlayer
);
emit
playerAdded
(
newPlayer
);
return
newPlayer
;
}
void
TabGame
::
processGameEvent
(
GameEvent
*
event
)
{
// game->processGameEvent(event);
switch
(
event
->
getItemId
())
{
case
ItemId_Event_GameStart
:
eventGameStart
(
qobject_cast
<
Event_GameStart
*>
(
event
));
break
;
default:
qDebug
()
<<
"unhandled game event"
;
}
}
void
TabGame
::
processGameJoinedEvent
(
Event_GameJoined
*
event
)
{
localPlayerId
=
event
->
getPlayerId
();
spectator
=
event
->
getSpectator
();
const
QList
<
ServerInfo_Player
*>
&
plList
=
event
->
getPlayerList
();
for
(
int
i
=
0
;
i
<
plList
.
size
();
++
i
)
{
ServerInfo_Player
*
pl
=
plList
[
i
];
Player
*
newPlayer
=
addPlayer
(
pl
->
getPlayerId
(),
pl
->
getName
());
newPlayer
->
processPlayerInfo
(
pl
);
}
}
void
TabGame
::
eventGameStart
(
Event_GameStart
*
event
)
{
deckViewContainer
->
hide
();
gameView
->
show
();
}
void
TabGame
::
loadLocalDeck
()
...
...
cockatrice/src/tab_game.h
View file @
0d4717f4
...
...
@@ -2,14 +2,13 @@
#define TAB_GAME_H
#include
<QWidget>
#include
<QMap>
class
Client
;
class
CardDatabase
;
class
GameEvent
;
class
GameView
;
class
DeckView
;
class
GameScene
;
class
Game
;
class
CardInfoWidget
;
class
MessageLogWidget
;
class
QLabel
;
...
...
@@ -19,12 +18,23 @@ class ZoneViewLayout;
class
ZoneViewWidget
;
class
PhasesToolbar
;
class
ProtocolResponse
;
class
GameEvent
;
class
Event_GameJoined
;
class
Event_GameStart
;
class
Player
;
class
CardZone
;
class
TabGame
:
public
QWidget
{
Q_OBJECT
private:
Client
*
client
;
int
gameId
;
int
localPlayerId
;
bool
spectator
;
QStringList
spectatorList
;
QMap
<
int
,
Player
*>
players
;
bool
started
;
int
currentPhase
;
QPushButton
*
loadLocalButton
,
*
loadRemoteButton
,
*
readyStartButton
;
CardInfoWidget
*
cardInfo
;
...
...
@@ -35,9 +45,41 @@ private:
GameScene
*
scene
;
GameView
*
gameView
;
DeckView
*
deckView
;
Game
*
game
;
QWidget
*
deckViewContainer
;
ZoneViewLayout
*
zoneLayout
;
QAction
*
aCloseMostRecentZoneView
;
Player
*
addPlayer
(
int
playerId
,
const
QString
&
playerName
);
void
eventGameStart
(
Event_GameStart
*
event
);
signals:
void
playerAdded
(
Player
*
player
);
void
playerRemoved
(
Player
*
player
);
// Log events
void
logPlayerListReceived
(
QStringList
players
);
void
logJoin
(
Player
*
player
);
void
logLeave
(
Player
*
player
);
void
logGameClosed
();
void
logJoinSpectator
(
QString
playerName
);
void
logLeaveSpectator
(
QString
playerName
);
void
logReadyStart
(
Player
*
player
);
void
logGameStart
();
void
logSay
(
Player
*
player
,
QString
text
);
void
logShuffle
(
Player
*
player
);
void
logRollDie
(
Player
*
player
,
int
sides
,
int
roll
);
void
logDraw
(
Player
*
player
,
int
number
);
void
logMoveCard
(
Player
*
player
,
QString
cardName
,
CardZone
*
startZone
,
int
oldX
,
CardZone
*
targetZone
,
int
newX
);
void
logCreateToken
(
Player
*
player
,
QString
cardName
);
void
logCreateArrow
(
Player
*
player
,
Player
*
startPlayer
,
QString
startCard
,
Player
*
targetPlayer
,
QString
targetCard
);
void
logSetCardCounters
(
Player
*
player
,
QString
cardName
,
int
value
,
int
oldValue
);
void
logSetTapped
(
Player
*
player
,
QString
cardName
,
bool
tapped
);
void
logSetCounter
(
Player
*
player
,
QString
counterName
,
int
value
,
int
oldValue
);
void
logSetDoesntUntap
(
Player
*
player
,
QString
cardName
,
bool
doesntUntap
);
void
logDumpZone
(
Player
*
player
,
CardZone
*
zone
,
int
numberCards
);
void
logStopDumpZone
(
Player
*
player
,
CardZone
*
zone
);
void
logSetActivePlayer
(
Player
*
player
);
void
setActivePhase
(
int
phase
);
private
slots
:
void
loadLocalDeck
();
void
loadRemoteDeck
();
...
...
@@ -46,7 +88,9 @@ private slots:
public:
TabGame
(
Client
*
_client
,
int
_gameId
);
void
retranslateUi
();
void
processGameEvent
(
GameEvent
*
event
);
void
processGameJoinedEvent
(
Event_GameJoined
*
event
);
};
#endif
cockatrice/src/tab_supervisor.cpp
View file @
0d4717f4
...
...
@@ -104,6 +104,8 @@ void TabSupervisor::gameJoined(Event_GameJoined *event)
TabGame
*
tab
=
new
TabGame
(
client
,
event
->
getGameId
());
addTab
(
tab
,
tr
(
"Game %1"
).
arg
(
event
->
getGameId
()));
gameTabs
.
insert
(
event
->
getGameId
(),
tab
);
tab
->
processGameJoinedEvent
(
event
);
setCurrentWidget
(
tab
);
}
void
TabSupervisor
::
addChatChannelTab
(
const
QString
&
channelName
)
...
...
@@ -111,6 +113,7 @@ void TabSupervisor::addChatChannelTab(const QString &channelName)
TabChatChannel
*
tab
=
new
TabChatChannel
(
client
,
channelName
);
addTab
(
tab
,
channelName
);
chatChannelTabs
.
insert
(
channelName
,
tab
);
setCurrentWidget
(
tab
);
}
void
TabSupervisor
::
processChatEvent
(
ChatEvent
*
event
)
...
...
cockatrice/src/zoneviewzone.cpp
View file @
0d4717f4
...
...
@@ -41,7 +41,7 @@ void ZoneViewZone::initializeCards()
}
}
void
ZoneViewZone
::
zoneDumpReceived
(
QList
<
Server
Zone
Card
>
cards
)
void
ZoneViewZone
::
zoneDumpReceived
(
QList
<
Server
Info_
Card
>
cards
)
{
for
(
int
i
=
0
;
i
<
cards
.
size
();
i
++
)
{
CardItem
*
card
=
new
CardItem
(
cards
[
i
].
getName
(),
i
,
this
);
...
...
cockatrice/src/zoneviewzone.h
View file @
0d4717f4
...
...
@@ -29,7 +29,7 @@ public:
public
slots
:
void
setSortingEnabled
(
int
_sortingEnabled
);
private
slots
:
void
zoneDumpReceived
(
QList
<
Server
Zone
Card
>
cards
);
void
zoneDumpReceived
(
QList
<
Server
Info_
Card
>
cards
);
protected:
void
addCardImpl
(
CardItem
*
card
,
int
x
,
int
y
);
QSizeF
sizeHint
(
Qt
::
SizeHint
which
,
const
QSizeF
&
constraint
=
QSizeF
())
const
;
...
...
common/protocol.cpp
View file @
0d4717f4
...
...
@@ -76,6 +76,7 @@ void ProtocolItem::initializeHash()
itemNameHash
.
insert
(
"generic_eventlist_games"
,
Event_ListGames
::
newItem
);
itemNameHash
.
insert
(
"generic_eventlist_chat_channels"
,
Event_ListChatChannels
::
newItem
);
itemNameHash
.
insert
(
"generic_eventgame_joined"
,
Event_GameJoined
::
newItem
);
itemNameHash
.
insert
(
"chat_eventchat_list_players"
,
Event_ChatListPlayers
::
newItem
);
}
...
...
@@ -210,57 +211,6 @@ void ProtocolResponse::initializeHash()
responseHash
.
insert
(
"spectators_not_allowed"
,
RespSpectatorsNotAllowed
);
}
bool
DeckList_File
::
readElement
(
QXmlStreamReader
*
xml
)
{
if
(
xml
->
isEndElement
())
return
true
;
else
return
false
;
}
void
DeckList_File
::
writeElement
(
QXmlStreamWriter
*
xml
)
{
xml
->
writeStartElement
(
"file"
);
xml
->
writeAttribute
(
"name"
,
name
);
xml
->
writeAttribute
(
"id"
,
QString
::
number
(
id
));
xml
->
writeAttribute
(
"upload_time"
,
QString
::
number
(
uploadTime
.
toTime_t
()));
xml
->
writeEndElement
();
}
DeckList_Directory
::~
DeckList_Directory
()
{
for
(
int
i
=
0
;
i
<
size
();
++
i
)
delete
at
(
i
);
}
bool
DeckList_Directory
::
readElement
(
QXmlStreamReader
*
xml
)
{
if
(
currentItem
)
{
if
(
currentItem
->
readElement
(
xml
))
currentItem
=
0
;
return
false
;
}
if
(
xml
->
isStartElement
()
&&
(
xml
->
name
()
==
"directory"
))
{
currentItem
=
new
DeckList_Directory
(
xml
->
attributes
().
value
(
"name"
).
toString
());
append
(
currentItem
);
}
else
if
(
xml
->
isStartElement
()
&&
(
xml
->
name
()
==
"file"
))
{
currentItem
=
new
DeckList_File
(
xml
->
attributes
().
value
(
"name"
).
toString
(),
xml
->
attributes
().
value
(
"id"
).
toString
().
toInt
(),
QDateTime
::
fromTime_t
(
xml
->
attributes
().
value
(
"upload_time"
).
toString
().
toUInt
()));
append
(
currentItem
);
}
else
if
(
xml
->
isEndElement
()
&&
(
xml
->
name
()
==
"directory"
))
return
true
;
return
false
;
}
void
DeckList_Directory
::
writeElement
(
QXmlStreamWriter
*
xml
)
{
xml
->
writeStartElement
(
"directory"
);
xml
->
writeAttribute
(
"name"
,
name
);
for
(
int
i
=
0
;
i
<
size
();
++
i
)
at
(
i
)
->
writeElement
(
xml
);
xml
->
writeEndElement
();
}
Response_DeckList
::
Response_DeckList
(
int
_cmdId
,
ResponseCode
_responseCode
,
DeckList_Directory
*
_root
)
:
ProtocolResponse
(
_cmdId
,
_responseCode
,
"deck_list"
),
root
(
_root
),
readFinished
(
false
)
{
...
...
@@ -420,7 +370,7 @@ void Event_ListChatChannels::writeElement(QXmlStreamWriter *xml)
bool
Event_ChatListPlayers
::
readElement
(
QXmlStreamReader
*
xml
)
{
if
(
xml
->
isStartElement
()
&&
((
xml
->
name
()
==
"player"
)))
{
playerList
.
append
(
Server
Play
erInfo
(
playerList
.
append
(
Server
ChatUs
erInfo
(
xml
->
attributes
().
value
(
"name"
).
toString
()
));
return
true
;
...
...
@@ -470,3 +420,50 @@ void Event_ListGames::writeElement(QXmlStreamWriter *xml)
xml
->
writeEndElement
();
}
}
Event_GameJoined
::
Event_GameJoined
(
int
_gameId
,
int
_playerId
,
bool
_spectator
,
const
QList
<
ServerInfo_Player
*>
&
_playerList
)
:
GenericEvent
(
"game_joined"
),
currentItem
(
0
),
readFinished
(
false
),
gameId
(
_gameId
),
playerId
(
_playerId
),
spectator
(
_spectator
),
playerList
(
_playerList
)
{
setParameter
(
"game_id"
,
gameId
);
setParameter
(
"player_id"
,
playerId
);
setParameter
(
"spectator"
,
spectator
);
}
Event_GameJoined
::~
Event_GameJoined
()
{
for
(
int
i
=
0
;
i
<
playerList
.
size
();
++
i
)
delete
playerList
[
i
];
}
void
Event_GameJoined
::
extractParameters
()
{
GenericEvent
::
extractParameters
();
gameId
=
parameters
[
"game_id"
].
toInt
();
playerId
=
parameters
[
"player_id"
].
toInt
();
spectator
=
(
parameters
[
"spectator"
]
==
"1"
);
}
bool
Event_GameJoined
::
readElement
(
QXmlStreamReader
*
xml
)
{
if
(
currentItem
)
{
if
(
currentItem
->
readElement
(
xml
))
currentItem
=
0
;
return
true
;
}
if
(
xml
->
isStartElement
()
&&
(
xml
->
name
()
==
"player"
))
{
ServerInfo_Player
*
player
=
new
ServerInfo_Player
;
playerList
.
append
(
player
);
currentItem
=
player
;
}
else
return
false
;
if
(
currentItem
)
if
(
currentItem
->
readElement
(
xml
))
currentItem
=
0
;
return
true
;
}
void
Event_GameJoined
::
writeElement
(
QXmlStreamWriter
*
xml
)
{
for
(
int
i
=
0
;
i
<
playerList
.
size
();
++
i
)
playerList
[
i
]
->
writeElement
(
xml
);
}
common/protocol.h
View file @
0d4717f4
...
...
@@ -22,6 +22,7 @@ enum ItemId {
ItemId_Event_ListChatChannels
=
ItemId_Other
+
200
,
ItemId_Event_ChatListPlayers
=
ItemId_Other
+
201
,
ItemId_Event_ListGames
=
ItemId_Other
+
202
,
ItemId_Event_GameJoined
=
ItemId_Other
+
203
,
ItemId_Response_DeckList
=
ItemId_Other
+
300
,
ItemId_Response_DeckDownload
=
ItemId_Other
+
301
,
ItemId_Response_DeckUpload
=
ItemId_Other
+
302
...
...
@@ -297,16 +298,16 @@ public:
class
Event_ChatListPlayers
:
public
ChatEvent
{
Q_OBJECT
private:
QList
<
Server
Play
erInfo
>
playerList
;
QList
<
Server
ChatUs
erInfo
>
playerList
;
public:
Event_ChatListPlayers
(
const
QString
&
_channel
=
QString
())
:
ChatEvent
(
"chat_list_players"
,
_channel
)
{
}
int
getItemId
()
const
{
return
ItemId_Event_ChatListPlayers
;
}
static
ProtocolItem
*
newItem
()
{
return
new
Event_ChatListPlayers
;
}
void
addPlayer
(
const
QString
&
_name
)
{
playerList
.
append
(
Server
Play
erInfo
(
_name
));
playerList
.
append
(
Server
ChatUs
erInfo
(
_name
));
}
const
QList
<
Server
Play
erInfo
>
&
getPlayerList
()
const
{
return
playerList
;
}
const
QList
<
Server
ChatUs
erInfo
>
&
getPlayerList
()
const
{
return
playerList
;
}
bool
readElement
(
QXmlStreamReader
*
xml
);
void
writeElement
(
QXmlStreamWriter
*
xml
);
...
...
@@ -330,4 +331,29 @@ public:
void
writeElement
(
QXmlStreamWriter
*
xml
);
};
class
Event_GameJoined
:
public
GenericEvent
{
Q_OBJECT
private:
SerializableItem
*
currentItem
;
bool
readFinished
;
int
gameId
;
int
playerId
;
bool
spectator
;
QList
<
ServerInfo_Player
*>
playerList
;
protected:
void
extractParameters
();
public:
Event_GameJoined
(
int
_gameId
=
-
1
,
int
_playerId
=
-
1
,
bool
_spectator
=
false
,
const
QList
<
ServerInfo_Player
*>
&
_playerList
=
QList
<
ServerInfo_Player
*>
());
~
Event_GameJoined
();
int
getGameId
()
const
{
return
gameId
;
}
int
getPlayerId
()
const
{
return
playerId
;
}
bool
getSpectator
()
const
{
return
spectator
;
}
const
QList
<
ServerInfo_Player
*>
&
getPlayerList
()
const
{
return
playerList
;
}
static
ProtocolItem
*
newItem
()
{
return
new
Event_GameJoined
;
}
int
getItemId
()
const
{
return
ItemId_Event_GameJoined
;
}
bool
readElement
(
QXmlStreamReader
*
xml
);
void
writeElement
(
QXmlStreamWriter
*
xml
);
};
#endif
common/protocol_datastructures.cpp
0 → 100644
View file @
0d4717f4
#include
"protocol_datastructures.h"
#include
<QXmlStreamReader>
#include
<QXmlStreamWriter>
class
ColorConverter
{
public:
static
int
colorToInt
(
const
QColor
&
color
)
{
return
color
.
red
()
*
65536
+
color
.
green
()
*
256
+
color
.
blue
();
}
static
QColor
colorFromInt
(
int
colorValue
)
{
return
QColor
(
colorValue
/
65536
,
(
colorValue
%
65536
)
/
256
,
colorValue
%
256
);
}
};
ServerInfo_Player
::~
ServerInfo_Player
()
{
for
(
int
i
=
0
;
i
<
zoneList
.
size
();
++
i
)
delete
zoneList
[
i
];
for
(
int
i
=
0
;
i
<
arrowList
.
size
();
++
i
)
delete
arrowList
[
i
];
for
(
int
i
=
0
;
i
<
counterList
.
size
();
++
i
)
delete
counterList
[
i
];
}
ServerInfo_Zone
::~
ServerInfo_Zone
()
{
for
(
int
i
=
0
;
i
<
cardList
.
size
();
++
i
)
delete
cardList
[
i
];
}
bool
ServerInfo_Arrow
::
readElement
(
QXmlStreamReader
*
xml
)
{
if
(
xml
->
isStartElement
()
&&
(
xml
->
name
()
==
"arrow"
))
{
id
=
xml
->
attributes
().
value
(
"id"
).
toString
().
toInt
();
startPlayerId
=
xml
->
attributes
().
value
(
"start_player_id"
).
toString
().
toInt
();
startZone
=
xml
->
attributes
().
value
(
"start_zone"
).
toString
();
startCardId
=
xml
->
attributes
().
value
(
"start_card_id"
).
toString
().
toInt
();
targetPlayerId
=
xml
->
attributes
().
value
(
"target_player_id"
).
toString
().
toInt
();
targetZone
=
xml
->
attributes
().
value
(
"target_zone"
).
toString
();
targetCardId
=
xml
->
attributes
().
value
(
"target_card_id"
).
toString
().
toInt
();
color
=
ColorConverter
::
colorFromInt
(
xml
->
attributes
().
value
(
"color"
).
toString
().
toInt
());
}
else
if
(
xml
->
isEndElement
()
&&
(
xml
->
name
()
==
"arrow"
))
return
true
;
return
false
;
}
void
ServerInfo_Arrow
::
writeElement
(
QXmlStreamWriter
*
xml
)
{
xml
->
writeStartElement
(
"arrow"
);
xml
->
writeAttribute
(
"id"
,
QString
::
number
(
id
));
xml
->
writeAttribute
(
"start_player_id"
,
QString
::
number
(
startPlayerId
));
xml
->
writeAttribute
(
"start_zone"
,
startZone
);
xml
->
writeAttribute
(
"start_card_id"
,
QString
::
number
(
startCardId
));
xml
->
writeAttribute
(
"target_player_id"
,
QString
::
number
(
targetPlayerId
));
xml
->
writeAttribute
(
"target_zone"
,
targetZone
);
xml
->
writeAttribute
(
"target_card_id"
,
QString
::
number
(
targetCardId
));
xml
->
writeAttribute
(
"color"
,
QString
::
number
(
ColorConverter
::
colorToInt
(
color
)));
xml
->
writeEndElement
();
}
bool
ServerInfo_Counter
::
readElement
(
QXmlStreamReader
*
xml
)
{
if
(
xml
->
isStartElement
()
&&
(
xml
->
name
()
==
"counter"
))
{
id
=
xml
->
attributes
().
value
(
"id"
).
toString
().
toInt
();
name
=
xml
->
attributes
().
value
(
"name"
).
toString
();
color
=
ColorConverter
::
colorFromInt
(
xml
->
attributes
().
value
(
"color"
).
toString
().
toInt
());
radius
=
xml
->
attributes
().
value
(
"radius"
).
toString
().
toInt
();
count
=
xml
->
attributes
().
value
(
"count"
).
toString
().
toInt
();
}
else
if
(
xml
->
isEndElement
()
&&
(
xml
->
name
()
==
"counter"
))
return
true
;
return
false
;
}
void
ServerInfo_Counter
::
writeElement
(
QXmlStreamWriter
*
xml
)
{
xml
->
writeStartElement
(
"counter"
);
xml
->
writeAttribute
(
"id"
,
QString
::
number
(
id
));
xml
->
writeAttribute
(
"name"
,
name
);
xml
->
writeAttribute
(
"color"
,
QString
::
number
(
ColorConverter
::
colorToInt
(
color
)));
xml
->
writeAttribute
(
"radius"
,
QString
::
number
(
radius
));
xml
->
writeAttribute
(
"count"
,
QString
::
number
(
count
));
xml
->
writeEndElement
();
}
bool
ServerInfo_Card
::
readElement
(
QXmlStreamReader
*
xml
)
{
if
(
xml
->
isStartElement
()
&&
(
xml
->
name
()
==
"card"
))
{
id
=
xml
->
attributes
().
value
(
"id"
).
toString
().
toInt
();
name
=
xml
->
attributes
().
value
(
"name"
).
toString
();
x
=
xml
->
attributes
().
value
(
"x"
).
toString
().
toInt
();
y
=
xml
->
attributes
().
value
(
"y"
).
toString
().
toInt
();
counters
=
xml
->
attributes
().
value
(
"counters"
).
toString
().
toInt
();
tapped
=
xml
->
attributes
().
value
(
"tapped"
).
toString
().
toInt
();
attacking
=
xml
->
attributes
().
value
(
"attacking"
).
toString
().
toInt
();
annotation
=
xml
->
attributes
().
value
(
"annotation"
).
toString
();
}
else
if
(
xml
->
isEndElement
()
&&
(
xml
->
name
()
==
"card"
))
return
true
;
return
false
;
}
void
ServerInfo_Card
::
writeElement
(
QXmlStreamWriter
*
xml
)
{
xml
->
writeStartElement
(
"card"
);
xml
->
writeAttribute
(
"id"
,
QString
::
number
(
id
));
xml
->
writeAttribute
(
"name"
,
name
);
xml
->
writeAttribute
(
"x"
,
QString
::
number
(
x
));
xml
->
writeAttribute
(
"y"
,
QString
::
number
(
y
));
xml
->
writeAttribute
(
"counters"
,
QString
::
number
(
counters
));
xml
->
writeAttribute
(
"tapped"
,
tapped
?
"1"
:
"0"
);
xml
->
writeAttribute
(
"attacking"
,
attacking
?
"1"
:
"0"
);
xml
->
writeAttribute
(
"annotation"
,
annotation
);
xml
->
writeEndElement
();
}
bool
ServerInfo_Zone
::
readElement
(
QXmlStreamReader
*
xml
)
{
if
(
currentItem
)
{
if
(
currentItem
->
readElement
(
xml
))
currentItem
=
0
;
return
false
;
}
if
(
xml
->
isStartElement
()
&&
(
xml
->
name
()
==
"zone"
))
{
name
=
xml
->
attributes
().
value
(
"name"
).
toString
();
type
=
(
ZoneType
)
xml
->
attributes
().
value
(
"type"
).
toString
().
toInt
();
hasCoords
=
xml
->
attributes
().
value
(
"has_coords"
).
toString
().
toInt
();
cardCount
=
xml
->
attributes
().
value
(
"card_count"
).
toString
().
toInt
();
}
else
if
(
xml
->
isStartElement
()
&&
(
xml
->
name
()
==
"card"
))
{
ServerInfo_Card
*
card
=
new
ServerInfo_Card
;
cardList
.
append
(
card
);
currentItem
=
card
;
}
else
if
(
xml
->
isEndElement
()
&&
(
xml
->
name
()
==
"zone"
))
return
true
;
if
(
currentItem
)
if
(
currentItem
->
readElement
(
xml
))
currentItem
=
0
;
return
false
;
}
void
ServerInfo_Zone
::
writeElement
(
QXmlStreamWriter
*
xml
)
{
xml
->
writeStartElement
(
"zone"
);
xml
->
writeAttribute
(
"name"
,
name
);
QString
typeStr
;
switch
(
type
)
{
case
PrivateZone
:
typeStr
=
"private"
;
break
;
case
HiddenZone
:
typeStr
=
"hidden"
;
break
;
case
PublicZone
:
typeStr
=
"public"
;
break
;
}
xml
->
writeAttribute
(
"type"
,
typeStr
);
xml
->
writeAttribute
(
"has_coords"
,
hasCoords
?
"1"
:
"0"
);
xml
->
writeAttribute
(
"card_count"
,
QString
::
number
(
cardCount
));
for
(
int
i
=
0
;
i
<
cardList
.
size
();
++
i
)
cardList
[
i
]
->
writeElement
(
xml
);
xml
->
writeEndElement
();
}
bool
ServerInfo_Player
::
readElement
(
QXmlStreamReader
*
xml
)
{
if
(
currentItem
)
{
if
(
currentItem
->
readElement
(
xml
))
currentItem
=
0
;
return
false
;
}
if
(
xml
->
isStartElement
()
&&
(
xml
->
name
()
==
"player"
))
{
playerId
=
xml
->
attributes
().
value
(
"player_id"
).
toString
().
toInt
();
name
=
xml
->
attributes
().
value
(
"name"
).
toString
();
}
else
if
(
xml
->
isStartElement
()
&&
(
xml
->
name
()
==
"zone"
))
{
ServerInfo_Zone
*
zone
=
new
ServerInfo_Zone
;
zoneList
.
append
(
zone
);
currentItem
=
zone
;
}
else
if
(
xml
->
isStartElement
()
&&
(
xml
->
name
()
==
"counter"
))
{
ServerInfo_Counter
*
counter
=
new
ServerInfo_Counter
;
counterList
.
append
(
counter
);
currentItem
=
counter
;
}
else
if
(
xml
->
isStartElement
()
&&
(
xml
->
name
()
==
"arrow"
))
{
ServerInfo_Arrow
*
arrow
=
new
ServerInfo_Arrow
;
arrowList
.
append
(
arrow
);
currentItem
=
arrow
;
}
else
if
(
xml
->
isEndElement
()
&&
(
xml
->
name
()
==
"player"
))
return
true
;
if
(
currentItem
)
if
(
currentItem
->
readElement
(
xml
))
currentItem
=
0
;
return
false
;
}
void
ServerInfo_Player
::
writeElement
(
QXmlStreamWriter
*
xml
)
{
xml
->
writeStartElement
(
"player"
);
xml
->
writeAttribute
(
"player_id"
,
QString
::
number
(
playerId
));
xml
->
writeAttribute
(
"name"
,
name
);
for
(
int
i
=
0
;
i
<
zoneList
.
size
();
++
i
)
zoneList
[
i
]
->
writeElement
(
xml
);
for
(
int
i
=
0
;
i
<
counterList
.
size
();
++
i
)
counterList
[
i
]
->
writeElement
(
xml
);
for
(
int
i
=
0
;
i
<
arrowList
.
size
();
++
i
)
arrowList
[
i
]
->
writeElement
(
xml
);
xml
->
writeEndElement
();
}
bool
DeckList_File
::
readElement
(
QXmlStreamReader
*
xml
)
{
if
(
xml
->
isEndElement
())
return
true
;
else
return
false
;
}
void
DeckList_File
::
writeElement
(
QXmlStreamWriter
*
xml
)
{
xml
->
writeStartElement
(
"file"
);
xml
->
writeAttribute
(
"name"
,
name
);
xml
->
writeAttribute
(
"id"
,
QString
::
number
(
id
));
xml
->
writeAttribute
(
"upload_time"
,
QString
::
number
(
uploadTime
.
toTime_t
()));
xml
->
writeEndElement
();
}
DeckList_Directory
::~
DeckList_Directory
()
{
for
(
int
i
=
0
;
i
<
size
();
++
i
)
delete
at
(
i
);
}
bool
DeckList_Directory
::
readElement
(
QXmlStreamReader
*
xml
)
{
if
(
currentItem
)
{
if
(
currentItem
->
readElement
(
xml
))
currentItem
=
0
;
return
false
;
}
if
(
xml
->
isStartElement
()
&&
(
xml
->
name
()
==
"directory"
))
{
DeckList_Directory
*
newItem
=
new
DeckList_Directory
(
xml
->
attributes
().
value
(
"name"
).
toString
());
append
(
newItem
);
currentItem
=
newItem
;
}
else
if
(
xml
->
isStartElement
()
&&
(
xml
->
name
()
==
"file"
))
{
DeckList_File
*
newItem
=
new
DeckList_File
(
xml
->
attributes
().
value
(
"name"
).
toString
(),
xml
->
attributes
().
value
(
"id"
).
toString
().
toInt
(),
QDateTime
::
fromTime_t
(
xml
->
attributes
().
value
(
"upload_time"
).
toString
().
toUInt
()));
append
(
newItem
);
currentItem
=
newItem
;
}
else
if
(
xml
->
isEndElement
()
&&
(
xml
->
name
()
==
"directory"
))
return
true
;
return
false
;
}
void
DeckList_Directory
::
writeElement
(
QXmlStreamWriter
*
xml
)
{
xml
->
writeStartElement
(
"directory"
);
xml
->
writeAttribute
(
"name"
,
name
);
for
(
int
i
=
0
;
i
<
size
();
++
i
)
at
(
i
)
->
writeElement
(
xml
);
xml
->
writeEndElement
();
}
common/protocol_datastructures.h
View file @
0d4717f4
...
...
@@ -10,6 +10,25 @@ class QXmlStreamWriter;
enum
ResponseCode
{
RespNothing
,
RespOk
,
RespInvalidCommand
,
RespInvalidData
,
RespNameNotFound
,
RespLoginNeeded
,
RespContextError
,
RespWrongPassword
,
RespSpectatorsNotAllowed
};
// PrivateZone: Contents of the zone are always visible to the owner,
// but not to anyone else.
// PublicZone: Contents of the zone are always visible to anyone.
// HiddenZone: Contents of the zone are never visible to anyone.
// However, the owner of the zone can issue a dump_zone command,
// setting beingLookedAt to true.
// Cards in a zone with the type HiddenZone are referenced by their
// list index, whereas cards in any other zone are referenced by their ids.
enum
ZoneType
{
PrivateZone
,
PublicZone
,
HiddenZone
};
class
SerializableItem
{
protected:
SerializableItem
*
currentItem
;
public:
SerializableItem
()
:
currentItem
(
0
)
{
}
virtual
bool
readElement
(
QXmlStreamReader
*
xml
)
=
0
;
virtual
void
writeElement
(
QXmlStreamWriter
*
xml
)
=
0
;
};
class
ServerChatChannelInfo
{
private:
QString
name
;
...
...
@@ -25,11 +44,11 @@ public:
bool
getAutoJoin
()
const
{
return
autoJoin
;
}
};
class
Server
Play
erInfo
{
class
Server
ChatUs
erInfo
{
private:
QString
name
;
public:
Server
Play
erInfo
(
const
QString
&
_name
)
Server
ChatUs
erInfo
(
const
QString
&
_name
)
:
name
(
_name
)
{
}
QString
getName
()
const
{
return
name
;
}
};
...
...
@@ -57,23 +76,8 @@ public:
int
getSpectatorCount
()
const
{
return
spectatorCount
;
}
};
class
ServerPlayer
{
private:
int
PlayerId
;
QString
name
;
bool
local
;
public:
ServerPlayer
(
int
_PlayerId
,
const
QString
&
_name
,
bool
_local
)
:
PlayerId
(
_PlayerId
),
name
(
_name
),
local
(
_local
)
{
}
int
getPlayerId
()
const
{
return
PlayerId
;
}
QString
getName
()
const
{
return
name
;
}
bool
getLocal
()
const
{
return
local
;
}
};
class
ServerZoneCard
{
class
ServerInfo_Card
:
public
SerializableItem
{
private:
int
playerId
;
QString
zoneName
;
int
id
;
QString
name
;
int
x
,
y
;
...
...
@@ -82,10 +86,8 @@ private:
bool
attacking
;
QString
annotation
;
public:
ServerZoneCard
(
int
_playerId
,
const
QString
&
_zoneName
,
int
_id
,
const
QString
&
_name
,
int
_x
,
int
_y
,
int
_counters
,
bool
_tapped
,
bool
_attacking
,
const
QString
&
_annotation
)
:
playerId
(
_playerId
),
zoneName
(
_zoneName
),
id
(
_id
),
name
(
_name
),
x
(
_x
),
y
(
_y
),
counters
(
_counters
),
tapped
(
_tapped
),
attacking
(
_attacking
),
annotation
(
_annotation
)
{
}
int
getPlayerId
()
const
{
return
playerId
;
}
QString
getZoneName
()
const
{
return
zoneName
;
}
ServerInfo_Card
(
int
_id
=
-
1
,
const
QString
&
_name
=
QString
(),
int
_x
=
-
1
,
int
_y
=
-
1
,
int
_counters
=
-
1
,
bool
_tapped
=
false
,
bool
_attacking
=
false
,
const
QString
&
_annotation
=
QString
())
:
id
(
_id
),
name
(
_name
),
x
(
_x
),
y
(
_y
),
counters
(
_counters
),
tapped
(
_tapped
),
attacking
(
_attacking
),
annotation
(
_annotation
)
{
}
int
getId
()
const
{
return
id
;
}
QString
getName
()
const
{
return
name
;
}
int
getX
()
const
{
return
x
;
}
...
...
@@ -94,50 +96,53 @@ public:
bool
getTapped
()
const
{
return
tapped
;
}
bool
getAttacking
()
const
{
return
attacking
;
}
QString
getAnnotation
()
const
{
return
annotation
;
}
bool
readElement
(
QXmlStreamReader
*
xml
);
void
writeElement
(
QXmlStreamWriter
*
xml
);
};
class
ServerZone
{
public:
enum
ZoneType
{
PrivateZone
,
PublicZone
,
HiddenZone
};
class
ServerInfo_Zone
:
public
SerializableItem
{
private:
int
playerId
;
QString
name
;
ZoneType
type
;
bool
hasCoords
;
int
cardCount
;
QList
<
ServerInfo_Card
*>
cardList
;
public:
ServerZone
(
int
_playerId
,
const
QString
&
_name
,
ZoneType
_type
,
bool
_hasCoords
,
int
_cardCount
)
:
playerId
(
_playerId
),
name
(
_name
),
type
(
_type
),
hasCoords
(
_hasCoords
),
cardCount
(
_cardCount
)
{
}
int
getPlayerId
()
const
{
return
playerId
;
}
Server
Info_
Zone
(
const
QString
&
_name
=
QString
()
,
ZoneType
_type
=
PrivateZone
,
bool
_hasCoords
=
false
,
int
_cardCount
=
-
1
,
const
QList
<
ServerInfo_Card
*>
&
_cardList
=
QList
<
ServerInfo_Card
*>
()
)
:
name
(
_name
),
type
(
_type
),
hasCoords
(
_hasCoords
),
cardCount
(
_cardCount
)
,
cardList
(
_cardList
)
{
}
~
ServerInfo_Zone
();
QString
getName
()
const
{
return
name
;
}
ZoneType
getType
()
const
{
return
type
;
}
bool
getHasCoords
()
const
{
return
hasCoords
;
}
int
getCardCount
()
const
{
return
cardCount
;
}
const
QList
<
ServerInfo_Card
*>
&
getCardList
()
const
{
return
cardList
;
}
void
addCard
(
ServerInfo_Card
*
card
)
{
cardList
.
append
(
card
);
++
cardCount
;
}
bool
readElement
(
QXmlStreamReader
*
xml
);
void
writeElement
(
QXmlStreamWriter
*
xml
);
};
class
ServerCounter
{
class
Server
Info_
Counter
:
public
SerializableItem
{
private:
int
playerId
;
int
id
;
QString
name
;
QColor
color
;
int
radius
;
int
count
;
public:
ServerCounter
(
int
_playerId
,
int
_id
,
const
QString
&
_name
,
QColor
_color
,
int
_radius
,
int
_count
)
:
playerId
(
_playerId
),
id
(
_id
),
name
(
_name
),
color
(
_color
),
radius
(
_radius
),
count
(
_count
)
{
}
int
getPlayerId
()
const
{
return
playerId
;
}
ServerInfo_Counter
(
int
_id
=
-
1
,
const
QString
&
_name
=
QString
(),
const
QColor
&
_color
=
QColor
(),
int
_radius
=
-
1
,
int
_count
=
-
1
)
:
id
(
_id
),
name
(
_name
),
color
(
_color
),
radius
(
_radius
),
count
(
_count
)
{
}
int
getId
()
const
{
return
id
;
}
QString
getName
()
const
{
return
name
;
}
QColor
getColor
()
const
{
return
color
;
}
int
getRadius
()
const
{
return
radius
;
}
int
getCount
()
const
{
return
count
;
}
bool
readElement
(
QXmlStreamReader
*
xml
);
void
writeElement
(
QXmlStreamWriter
*
xml
);
};
class
Server
Arrow
{
class
Server
Info_Arrow
:
public
SerializableItem
{
private:
int
id
;
int
playerId
;
int
startPlayerId
;
QString
startZone
;
int
startCardId
;
...
...
@@ -146,10 +151,9 @@ private:
int
targetCardId
;
QColor
color
;
public:
ServerArrow
(
int
_
playerId
,
int
_id
,
int
_startPlayerId
,
const
QString
&
_startZone
,
int
_startCardId
,
int
_targetPlayerId
,
const
QString
&
_targetZone
,
int
_targetCardId
,
const
QColor
&
_color
)
:
id
(
_id
),
playerId
(
_playerId
),
startPlayerId
(
_startPlayerId
),
startZone
(
_startZone
),
startCardId
(
_startCardId
),
targetPlayerId
(
_targetPlayerId
),
targetZone
(
_targetZone
),
targetCardId
(
_targetCardId
),
color
(
_color
)
{
}
Server
Info_
Arrow
(
int
_
id
=
-
1
,
int
_startPlayerId
=
-
1
,
const
QString
&
_startZone
=
QString
()
,
int
_startCardId
=
-
1
,
int
_targetPlayerId
=
-
1
,
const
QString
&
_targetZone
=
QString
()
,
int
_targetCardId
=
-
1
,
const
QColor
&
_color
=
QColor
()
)
:
id
(
_id
),
startPlayerId
(
_startPlayerId
),
startZone
(
_startZone
),
startCardId
(
_startCardId
),
targetPlayerId
(
_targetPlayerId
),
targetZone
(
_targetZone
),
targetCardId
(
_targetCardId
),
color
(
_color
)
{
}
int
getId
()
const
{
return
id
;
}
int
getPlayerId
()
const
{
return
playerId
;
}
int
getStartPlayerId
()
const
{
return
startPlayerId
;
}
QString
getStartZone
()
const
{
return
startZone
;
}
int
getStartCardId
()
const
{
return
startCardId
;
}
...
...
@@ -157,9 +161,34 @@ public:
QString
getTargetZone
()
const
{
return
targetZone
;
}
int
getTargetCardId
()
const
{
return
targetCardId
;
}
QColor
getColor
()
const
{
return
color
;
}
bool
readElement
(
QXmlStreamReader
*
xml
);
void
writeElement
(
QXmlStreamWriter
*
xml
);
};
class
DeckList_TreeItem
{
class
ServerInfo_Player
:
public
SerializableItem
{
private:
int
playerId
;
QString
name
;
QList
<
ServerInfo_Zone
*>
zoneList
;
QList
<
ServerInfo_Counter
*>
counterList
;
QList
<
ServerInfo_Arrow
*>
arrowList
;
public:
ServerInfo_Player
(
int
_playerId
=
-
1
,
const
QString
&
_name
=
QString
(),
const
QList
<
ServerInfo_Zone
*>
&
_zoneList
=
QList
<
ServerInfo_Zone
*>
(),
const
QList
<
ServerInfo_Counter
*>
&
_counterList
=
QList
<
ServerInfo_Counter
*>
(),
const
QList
<
ServerInfo_Arrow
*>
&
_arrowList
=
QList
<
ServerInfo_Arrow
*>
())
:
playerId
(
_playerId
),
name
(
_name
),
zoneList
(
_zoneList
),
counterList
(
_counterList
),
arrowList
(
_arrowList
)
{
}
~
ServerInfo_Player
();
int
getPlayerId
()
const
{
return
playerId
;
}
QString
getName
()
const
{
return
name
;
}
const
QList
<
ServerInfo_Zone
*>
&
getZoneList
()
const
{
return
zoneList
;
}
const
QList
<
ServerInfo_Counter
*>
&
getCounterList
()
const
{
return
counterList
;
}
const
QList
<
ServerInfo_Arrow
*>
&
getArrowList
()
const
{
return
arrowList
;
}
void
addZone
(
ServerInfo_Zone
*
zone
)
{
zoneList
.
append
(
zone
);
}
void
addCounter
(
ServerInfo_Counter
*
counter
)
{
counterList
.
append
(
counter
);
}
void
addArrow
(
ServerInfo_Arrow
*
arrow
)
{
arrowList
.
append
(
arrow
);
}
bool
readElement
(
QXmlStreamReader
*
xml
);
void
writeElement
(
QXmlStreamWriter
*
xml
);
};
class
DeckList_TreeItem
:
public
SerializableItem
{
protected:
QString
name
;
int
id
;
...
...
@@ -167,8 +196,6 @@ public:
DeckList_TreeItem
(
const
QString
&
_name
,
int
_id
)
:
name
(
_name
),
id
(
_id
)
{
}
QString
getName
()
const
{
return
name
;
}
int
getId
()
const
{
return
id
;
}
virtual
bool
readElement
(
QXmlStreamReader
*
xml
)
=
0
;
virtual
void
writeElement
(
QXmlStreamWriter
*
xml
)
=
0
;
};
class
DeckList_File
:
public
DeckList_TreeItem
{
private:
...
...
@@ -180,10 +207,8 @@ public:
QDateTime
getUploadTime
()
const
{
return
uploadTime
;
}
};
class
DeckList_Directory
:
public
DeckList_TreeItem
,
public
QList
<
DeckList_TreeItem
*>
{
private:
DeckList_TreeItem
*
currentItem
;
public:
DeckList_Directory
(
const
QString
&
_name
=
QString
(),
int
_id
=
0
)
:
DeckList_TreeItem
(
_name
,
_id
)
,
currentItem
(
0
)
{
}
DeckList_Directory
(
const
QString
&
_name
=
QString
(),
int
_id
=
0
)
:
DeckList_TreeItem
(
_name
,
_id
)
{
}
~
DeckList_Directory
();
bool
readElement
(
QXmlStreamReader
*
xml
);
void
writeElement
(
QXmlStreamWriter
*
xml
);
...
...
common/protocol_item_ids.h
View file @
0d4717f4
...
...
@@ -56,9 +56,8 @@ ItemId_Event_SetActivePhase = 1054,
ItemId_Event_DumpZone
=
1055
,
ItemId_Event_StopDumpZone
=
1056
,
ItemId_Event_ServerMessage
=
1057
,
ItemId_Event_GameJoined
=
1058
,
ItemId_Event_ChatJoinChannel
=
1059
,
ItemId_Event_ChatLeaveChannel
=
1060
,
ItemId_Event_ChatSay
=
1061
,
ItemId_Other
=
1062
ItemId_Event_ChatJoinChannel
=
1058
,
ItemId_Event_ChatLeaveChannel
=
1059
,
ItemId_Event_ChatSay
=
1060
,
ItemId_Other
=
1061
};
common/protocol_items.cpp
View file @
0d4717f4
...
...
@@ -613,18 +613,6 @@ void Event_ServerMessage::extractParameters()
GenericEvent
::
extractParameters
();
message
=
parameters
[
"message"
];
}
Event_GameJoined
::
Event_GameJoined
(
int
_gameId
,
bool
_spectator
)
:
GenericEvent
(
"game_joined"
),
gameId
(
_gameId
),
spectator
(
_spectator
)
{
setParameter
(
"game_id"
,
gameId
);
setParameter
(
"spectator"
,
spectator
);
}
void
Event_GameJoined
::
extractParameters
()
{
GenericEvent
::
extractParameters
();
gameId
=
parameters
[
"game_id"
].
toInt
();
spectator
=
(
parameters
[
"spectator"
]
==
"1"
);
}
Event_ChatJoinChannel
::
Event_ChatJoinChannel
(
const
QString
&
_channel
,
const
QString
&
_playerName
)
:
ChatEvent
(
"chat_join_channel"
,
_channel
),
playerName
(
_playerName
)
{
...
...
@@ -716,7 +704,6 @@ void ProtocolItem::initializeHashAuto()
itemNameHash
.
insert
(
"game_eventdump_zone"
,
Event_DumpZone
::
newItem
);
itemNameHash
.
insert
(
"game_eventstop_dump_zone"
,
Event_StopDumpZone
::
newItem
);
itemNameHash
.
insert
(
"generic_eventserver_message"
,
Event_ServerMessage
::
newItem
);
itemNameHash
.
insert
(
"generic_eventgame_joined"
,
Event_GameJoined
::
newItem
);
itemNameHash
.
insert
(
"chat_eventchat_join_channel"
,
Event_ChatJoinChannel
::
newItem
);
itemNameHash
.
insert
(
"chat_eventchat_leave_channel"
,
Event_ChatLeaveChannel
::
newItem
);
itemNameHash
.
insert
(
"chat_eventchat_say"
,
Event_ChatSay
::
newItem
);
...
...
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