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
99ff7fd1
Commit
99ff7fd1
authored
Apr 14, 2009
by
Max-Wilhelm Bruker
Browse files
minor improvements
parent
3388804e
Changes
23
Hide whitespace changes
Inline
Side-by-side
cockatrice/src/client.cpp
View file @
99ff7fd1
...
@@ -130,7 +130,7 @@ void Client::readLine()
...
@@ -130,7 +130,7 @@ void Client::readLine()
// XXX Parametergültigkeit überprüfen
// XXX Parametergültigkeit überprüfen
if
(
!
prefix
.
compare
(
"list_games"
))
if
(
!
prefix
.
compare
(
"list_games"
))
gamelist
<<
new
ServerGame
(
val
[
0
],
val
[
1
],
val
[
2
].
toInt
(),
val
[
3
].
toInt
(),
val
[
4
].
toInt
());
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"
))
else
if
(
!
prefix
.
compare
(
"list_players"
))
playerlist
<<
new
ServerPlayer
(
val
[
0
].
toInt
(),
val
[
1
]);
playerlist
<<
new
ServerPlayer
(
val
[
0
].
toInt
(),
val
[
1
]);
else
if
(
!
prefix
.
compare
(
"list_counters"
))
else
if
(
!
prefix
.
compare
(
"list_counters"
))
...
@@ -215,14 +215,14 @@ int Client::listPlayers()
...
@@ -215,14 +215,14 @@ int Client::listPlayers()
return
cmd
(
"list_players"
);
return
cmd
(
"list_players"
);
}
}
int
Client
::
createGame
(
const
QString
&
name
,
const
QString
&
description
,
const
QString
&
password
,
unsigned
int
maxPlayers
)
int
Client
::
createGame
(
const
QString
&
description
,
const
QString
&
password
,
unsigned
int
maxPlayers
)
{
{
return
cmd
(
QString
(
"create_game|%1|%2|%3
|%4"
).
arg
(
name
).
arg
(
description
).
arg
(
password
).
arg
(
maxPlayers
));
return
cmd
(
QString
(
"create_game|%1|%2|%3
"
).
arg
(
description
).
arg
(
password
).
arg
(
maxPlayers
));
}
}
int
Client
::
joinGame
(
const
QString
&
n
ame
,
const
QString
&
password
)
int
Client
::
joinGame
(
int
g
ame
Id
,
const
QString
&
password
)
{
{
return
cmd
(
QString
(
"join_game|%1|%2"
).
arg
(
n
ame
).
arg
(
password
));
return
cmd
(
QString
(
"join_game|%1|%2"
).
arg
(
g
ame
Id
).
arg
(
password
));
}
}
int
Client
::
leaveGame
()
int
Client
::
leaveGame
()
...
...
cockatrice/src/client.h
View file @
99ff7fd1
...
@@ -64,8 +64,8 @@ public:
...
@@ -64,8 +64,8 @@ public:
void
disconnectFromServer
();
void
disconnectFromServer
();
int
listGames
();
int
listGames
();
int
listPlayers
();
int
listPlayers
();
int
createGame
(
const
QString
&
name
,
const
QString
&
description
,
const
QString
&
password
,
unsigned
int
maxPlayers
);
int
createGame
(
const
QString
&
description
,
const
QString
&
password
,
unsigned
int
maxPlayers
);
int
joinGame
(
const
QString
&
n
ame
,
const
QString
&
password
);
int
joinGame
(
int
g
ame
Id
,
const
QString
&
password
);
int
leaveGame
();
int
leaveGame
();
int
login
(
const
QString
&
name
,
const
QString
&
pass
);
int
login
(
const
QString
&
name
,
const
QString
&
pass
);
int
say
(
const
QString
&
s
);
int
say
(
const
QString
&
s
);
...
...
cockatrice/src/dlg_creategame.cpp
View file @
99ff7fd1
...
@@ -2,14 +2,8 @@
...
@@ -2,14 +2,8 @@
#include
"dlg_creategame.h"
#include
"dlg_creategame.h"
DlgCreateGame
::
DlgCreateGame
(
Client
*
_client
,
QWidget
*
parent
)
DlgCreateGame
::
DlgCreateGame
(
Client
*
_client
,
QWidget
*
parent
)
:
QDialog
(
parent
),
client
(
_client
)
:
QDialog
(
parent
),
client
(
_client
)
,
msgid
(
0
)
{
{
msgid
=
0
;
nameLabel
=
new
QLabel
(
tr
(
"&Name:"
));
nameEdit
=
new
QLineEdit
;
nameLabel
->
setBuddy
(
nameEdit
);
descriptionLabel
=
new
QLabel
(
tr
(
"&Description:"
));
descriptionLabel
=
new
QLabel
(
tr
(
"&Description:"
));
descriptionEdit
=
new
QLineEdit
;
descriptionEdit
=
new
QLineEdit
;
descriptionLabel
->
setBuddy
(
descriptionEdit
);
descriptionLabel
->
setBuddy
(
descriptionEdit
);
...
@@ -18,19 +12,17 @@ DlgCreateGame::DlgCreateGame(Client *_client, QWidget *parent)
...
@@ -18,19 +12,17 @@ DlgCreateGame::DlgCreateGame(Client *_client, QWidget *parent)
passwordEdit
=
new
QLineEdit
;
passwordEdit
=
new
QLineEdit
;
passwordLabel
->
setBuddy
(
passwordEdit
);
passwordLabel
->
setBuddy
(
passwordEdit
);
maxPlayersLabel
=
new
QLabel
(
tr
(
"
&Max
Players:"
));
maxPlayersLabel
=
new
QLabel
(
tr
(
"P
&
layers:"
));
maxPlayersEdit
=
new
QLineEdit
(
"2"
);
maxPlayersEdit
=
new
QLineEdit
(
"2"
);
maxPlayersLabel
->
setBuddy
(
maxPlayersEdit
);
maxPlayersLabel
->
setBuddy
(
maxPlayersEdit
);
QGridLayout
*
grid
=
new
QGridLayout
;
QGridLayout
*
grid
=
new
QGridLayout
;
grid
->
addWidget
(
nameLabel
,
0
,
0
);
grid
->
addWidget
(
descriptionLabel
,
0
,
0
);
grid
->
addWidget
(
nameEdit
,
0
,
1
);
grid
->
addWidget
(
descriptionEdit
,
0
,
1
);
grid
->
addWidget
(
descriptionLabel
,
1
,
0
);
grid
->
addWidget
(
passwordLabel
,
1
,
0
);
grid
->
addWidget
(
descriptionEdit
,
1
,
1
);
grid
->
addWidget
(
passwordEdit
,
1
,
1
);
grid
->
addWidget
(
passwordLabel
,
2
,
0
);
grid
->
addWidget
(
maxPlayersLabel
,
2
,
0
);
grid
->
addWidget
(
passwordEdit
,
2
,
1
);
grid
->
addWidget
(
maxPlayersEdit
,
2
,
1
);
grid
->
addWidget
(
maxPlayersLabel
,
3
,
0
);
grid
->
addWidget
(
maxPlayersEdit
,
3
,
1
);
okButton
=
new
QPushButton
(
tr
(
"&OK"
));
okButton
=
new
QPushButton
(
tr
(
"&OK"
));
okButton
->
setDefault
(
true
);
okButton
->
setDefault
(
true
);
...
@@ -65,8 +57,7 @@ void DlgCreateGame::actOK()
...
@@ -65,8 +57,7 @@ void DlgCreateGame::actOK()
QMessageBox
::
critical
(
this
,
tr
(
"Error"
),
tr
(
"Invalid number of players."
));
QMessageBox
::
critical
(
this
,
tr
(
"Error"
),
tr
(
"Invalid number of players."
));
return
;
return
;
}
}
msgid
=
client
->
createGame
(
nameEdit
->
text
(),
msgid
=
client
->
createGame
(
descriptionEdit
->
text
(),
descriptionEdit
->
text
(),
passwordEdit
->
text
(),
passwordEdit
->
text
(),
maxPlayers
);
maxPlayers
);
}
}
...
...
cockatrice/src/dlg_creategame.h
View file @
99ff7fd1
...
@@ -19,8 +19,8 @@ private:
...
@@ -19,8 +19,8 @@ private:
Client
*
client
;
Client
*
client
;
int
msgid
;
int
msgid
;
QLabel
*
nameLabel
,
*
descriptionLabel
,
*
passwordLabel
,
*
maxPlayersLabel
;
QLabel
*
descriptionLabel
,
*
passwordLabel
,
*
maxPlayersLabel
;
QLineEdit
*
nameEdit
,
*
descriptionEdit
,
*
passwordEdit
,
*
maxPlayersEdit
;
QLineEdit
*
descriptionEdit
,
*
passwordEdit
,
*
maxPlayersEdit
;
QPushButton
*
okButton
,
*
cancelButton
;
QPushButton
*
okButton
,
*
cancelButton
;
};
};
...
...
cockatrice/src/dlg_games.cpp
View file @
99ff7fd1
...
@@ -3,10 +3,8 @@
...
@@ -3,10 +3,8 @@
#include
"dlg_creategame.h"
#include
"dlg_creategame.h"
DlgGames
::
DlgGames
(
Client
*
_client
,
QWidget
*
parent
)
DlgGames
::
DlgGames
(
Client
*
_client
,
QWidget
*
parent
)
:
QDialog
(
parent
),
client
(
_client
)
:
QDialog
(
parent
),
client
(
_client
)
,
msgid
(
0
)
{
{
msgid
=
0
;
tableView
=
new
QTreeView
;
tableView
=
new
QTreeView
;
tableModel
=
new
GamesModel
(
this
);
tableModel
=
new
GamesModel
(
this
);
tableView
->
setModel
(
tableModel
);
tableView
->
setModel
(
tableModel
);
...
@@ -28,8 +26,8 @@ DlgGames::DlgGames(Client *_client, QWidget *parent)
...
@@ -28,8 +26,8 @@ DlgGames::DlgGames(Client *_client, QWidget *parent)
setLayout
(
mainLayout
);
setLayout
(
mainLayout
);
setWindowTitle
(
tr
(
"Games"
));
setWindowTitle
(
tr
(
"Games"
));
setMinimumWidth
(
sizeHint
().
width
());
setMinimumWidth
(
tableView
->
columnWidth
(
0
)
*
tableModel
->
columnCount
());
connect
(
createButton
,
SIGNAL
(
clicked
()),
this
,
SLOT
(
actCreate
()));
connect
(
createButton
,
SIGNAL
(
clicked
()),
this
,
SLOT
(
actCreate
()));
connect
(
refreshButton
,
SIGNAL
(
clicked
()),
this
,
SLOT
(
actRefresh
()));
connect
(
refreshButton
,
SIGNAL
(
clicked
()),
this
,
SLOT
(
actRefresh
()));
connect
(
joinButton
,
SIGNAL
(
clicked
()),
this
,
SLOT
(
actJoin
()));
connect
(
joinButton
,
SIGNAL
(
clicked
()),
this
,
SLOT
(
actJoin
()));
...
@@ -78,7 +76,7 @@ void DlgGames::actJoin()
...
@@ -78,7 +76,7 @@ void DlgGames::actJoin()
}
}
connect
(
client
,
SIGNAL
(
responseReceived
(
ServerResponse
*
)),
this
,
SLOT
(
checkResponse
(
ServerResponse
*
)));
connect
(
client
,
SIGNAL
(
responseReceived
(
ServerResponse
*
)),
this
,
SLOT
(
checkResponse
(
ServerResponse
*
)));
msgid
=
client
->
joinGame
(
game
->
get
N
ame
(),
password
);
msgid
=
client
->
joinGame
(
game
->
get
G
ame
Id
(),
password
);
}
}
void
DlgGames
::
gameListReceived
(
QList
<
ServerGame
*>
_gameList
)
void
DlgGames
::
gameListReceived
(
QList
<
ServerGame
*>
_gameList
)
...
...
cockatrice/src/game.h
View file @
99ff7fd1
...
@@ -73,12 +73,11 @@ signals:
...
@@ -73,12 +73,11 @@ signals:
void
logSetCounter
(
QString
playerName
,
QString
counterName
,
int
value
,
int
oldValue
);
void
logSetCounter
(
QString
playerName
,
QString
counterName
,
int
value
,
int
oldValue
);
void
logSetDoesntUntap
(
QString
playerName
,
QString
cardName
,
bool
doesntUntap
);
void
logSetDoesntUntap
(
QString
playerName
,
QString
cardName
,
bool
doesntUntap
);
void
logDumpZone
(
QString
playerName
,
QString
zoneName
,
QString
zoneOwner
,
int
numberCards
);
void
logDumpZone
(
QString
playerName
,
QString
zoneName
,
QString
zoneOwner
,
int
numberCards
);
public
slots
:
void
restartGameDialog
();
public:
public:
Game
(
CardDatabase
*
_db
,
Client
*
_client
,
QGraphicsScene
*
_scene
,
QMenu
*
_actionsMenu
,
QMenu
*
_cardMenu
,
int
playerId
,
const
QString
&
playerName
);
Game
(
CardDatabase
*
_db
,
Client
*
_client
,
QGraphicsScene
*
_scene
,
QMenu
*
_actionsMenu
,
QMenu
*
_cardMenu
,
int
playerId
,
const
QString
&
playerName
);
~
Game
();
~
Game
();
Player
*
getLocalPlayer
()
const
{
return
localPlayer
;
}
Player
*
getLocalPlayer
()
const
{
return
localPlayer
;
}
void
restartGameDialog
();
};
};
#endif
#endif
cockatrice/src/gamesmodel.cpp
View file @
99ff7fd1
...
@@ -13,14 +13,14 @@ int GamesModel::rowCount(const QModelIndex &parent) const
...
@@ -13,14 +13,14 @@ int GamesModel::rowCount(const QModelIndex &parent) const
int
GamesModel
::
columnCount
(
const
QModelIndex
&
parent
)
const
int
GamesModel
::
columnCount
(
const
QModelIndex
&
parent
)
const
{
{
return
4
;
return
5
;
}
}
QVariant
GamesModel
::
data
(
const
QModelIndex
&
index
,
int
role
)
const
QVariant
GamesModel
::
data
(
const
QModelIndex
&
index
,
int
role
)
const
{
{
if
(
!
index
.
isValid
())
if
(
!
index
.
isValid
())
return
QVariant
();
return
QVariant
();
if
((
index
.
row
()
>=
gameList
.
size
())
||
(
index
.
column
()
>=
4
))
if
((
index
.
row
()
>=
gameList
.
size
())
||
(
index
.
column
()
>=
columnCount
()
))
return
QVariant
();
return
QVariant
();
if
(
role
!=
Qt
::
DisplayRole
)
if
(
role
!=
Qt
::
DisplayRole
)
...
@@ -28,10 +28,11 @@ QVariant GamesModel::data(const QModelIndex &index, int role) const
...
@@ -28,10 +28,11 @@ QVariant GamesModel::data(const QModelIndex &index, int role) const
ServerGame
*
g
=
gameList
.
at
(
index
.
row
());
ServerGame
*
g
=
gameList
.
at
(
index
.
row
());
switch
(
index
.
column
())
{
switch
(
index
.
column
())
{
case
0
:
return
g
->
getName
();
case
0
:
return
g
->
getGameId
();
case
1
:
return
g
->
getDescription
();
case
1
:
return
g
->
getCreator
();
case
2
:
return
QString
(
g
->
getHasPassword
()
?
"yes"
:
"no"
);
case
2
:
return
g
->
getDescription
();
case
3
:
return
QString
(
"%1/%2"
).
arg
(
g
->
getPlayerCount
()).
arg
(
g
->
getMaxPlayers
());
case
3
:
return
QString
(
g
->
getHasPassword
()
?
"yes"
:
"no"
);
case
4
:
return
QString
(
"%1/%2"
).
arg
(
g
->
getPlayerCount
()).
arg
(
g
->
getMaxPlayers
());
default:
return
QVariant
();
default:
return
QVariant
();
}
}
}
}
...
@@ -43,10 +44,11 @@ QVariant GamesModel::headerData(int section, Qt::Orientation orientation, int ro
...
@@ -43,10 +44,11 @@ QVariant GamesModel::headerData(int section, Qt::Orientation orientation, int ro
if
(
orientation
!=
Qt
::
Horizontal
)
if
(
orientation
!=
Qt
::
Horizontal
)
return
QVariant
();
return
QVariant
();
switch
(
section
)
{
switch
(
section
)
{
case
0
:
return
QString
(
"Name"
);
case
0
:
return
QString
(
"Game ID"
);
case
1
:
return
QString
(
"Description"
);
case
1
:
return
QString
(
"Creator"
);
case
2
:
return
QString
(
"Password"
);
case
2
:
return
QString
(
"Description"
);
case
3
:
return
QString
(
"Players"
);
case
3
:
return
QString
(
"Password"
);
case
4
:
return
QString
(
"Players"
);
default:
return
QVariant
();
default:
return
QVariant
();
}
}
}
}
...
...
cockatrice/src/player.cpp
View file @
99ff7fd1
...
@@ -276,7 +276,6 @@ void Player::gameEvent(ServerEventData *event)
...
@@ -276,7 +276,6 @@ void Player::gameEvent(ServerEventData *event)
int
colorValue
=
data
[
1
].
toInt
();
int
colorValue
=
data
[
1
].
toInt
();
int
value
=
data
[
2
].
toInt
();
int
value
=
data
[
2
].
toInt
();
QColor
color
(
colorValue
/
65536
,
(
colorValue
%
65536
)
/
256
,
colorValue
%
256
);
QColor
color
(
colorValue
/
65536
,
(
colorValue
%
65536
)
/
256
,
colorValue
%
256
);
qDebug
(
QString
(
"%1 / %2 / %3"
).
arg
(
color
.
red
()).
arg
(
color
.
green
()).
arg
(
color
.
blue
()).
toLatin1
());
area
->
addCounter
(
counterName
,
color
,
value
);
area
->
addCounter
(
counterName
,
color
,
value
);
break
;
break
;
}
}
...
...
cockatrice/src/servergame.h
View file @
99ff7fd1
...
@@ -3,15 +3,17 @@
...
@@ -3,15 +3,17 @@
class
ServerGame
{
class
ServerGame
{
private:
private:
QString
name
;
int
gameId
;
QString
creator
;
QString
description
;
QString
description
;
bool
hasPassword
;
bool
hasPassword
;
unsigned
char
playerCount
;
unsigned
char
playerCount
;
unsigned
char
maxPlayers
;
unsigned
char
maxPlayers
;
public:
public:
ServerGame
(
const
QString
&
_name
,
const
QString
&
_description
,
bool
_hasPassword
,
unsigned
char
_playerCount
,
unsigned
char
_maxPlayers
)
ServerGame
(
int
_gameId
,
const
QString
&
_creator
,
const
QString
&
_description
,
bool
_hasPassword
,
unsigned
char
_playerCount
,
unsigned
char
_maxPlayers
)
:
name
(
_name
),
description
(
_description
),
hasPassword
(
_hasPassword
),
playerCount
(
_playerCount
),
maxPlayers
(
_maxPlayers
)
{
}
:
gameId
(
_gameId
),
creator
(
_creator
),
description
(
_description
),
hasPassword
(
_hasPassword
),
playerCount
(
_playerCount
),
maxPlayers
(
_maxPlayers
)
{
}
QString
getName
()
{
return
name
;
}
int
getGameId
()
{
return
gameId
;
}
QString
getCreator
()
{
return
creator
;
}
QString
getDescription
()
{
return
description
;
}
QString
getDescription
()
{
return
description
;
}
bool
getHasPassword
()
{
return
hasPassword
;
}
bool
getHasPassword
()
{
return
hasPassword
;
}
unsigned
char
getPlayerCount
()
{
return
playerCount
;
}
unsigned
char
getPlayerCount
()
{
return
playerCount
;
}
...
...
cockatrice/src/window_main.cpp
View file @
99ff7fd1
...
@@ -96,8 +96,15 @@ void MainWindow::actGames()
...
@@ -96,8 +96,15 @@ void MainWindow::actGames()
dlg
.
exec
();
dlg
.
exec
();
}
}
void
MainWindow
::
actRestartGame
()
{
zoneLayout
->
clear
();
game
->
restartGameDialog
();
}
void
MainWindow
::
actLeaveGame
()
void
MainWindow
::
actLeaveGame
()
{
{
zoneLayout
->
clear
();
client
->
leaveGame
();
client
->
leaveGame
();
delete
game
;
delete
game
;
game
=
0
;
game
=
0
;
...
@@ -145,7 +152,6 @@ void MainWindow::playerIdReceived(int id, QString name)
...
@@ -145,7 +152,6 @@ void MainWindow::playerIdReceived(int id, QString name)
connect
(
game
,
SIGNAL
(
hoverCard
(
QString
)),
this
,
SLOT
(
hoverCard
(
QString
)));
connect
(
game
,
SIGNAL
(
hoverCard
(
QString
)),
this
,
SLOT
(
hoverCard
(
QString
)));
connect
(
game
,
SIGNAL
(
playerAdded
(
Player
*
)),
this
,
SLOT
(
playerAdded
(
Player
*
)));
connect
(
game
,
SIGNAL
(
playerAdded
(
Player
*
)),
this
,
SLOT
(
playerAdded
(
Player
*
)));
connect
(
game
,
SIGNAL
(
playerRemoved
(
Player
*
)),
this
,
SLOT
(
playerRemoved
(
Player
*
)));
connect
(
game
,
SIGNAL
(
playerRemoved
(
Player
*
)),
this
,
SLOT
(
playerRemoved
(
Player
*
)));
connect
(
aRestartGame
,
SIGNAL
(
triggered
()),
game
,
SLOT
(
restartGameDialog
()));
playerAdded
(
game
->
getLocalPlayer
());
playerAdded
(
game
->
getLocalPlayer
());
messageLog
->
connectToGame
(
game
);
messageLog
->
connectToGame
(
game
);
...
@@ -174,6 +180,7 @@ void MainWindow::createActions()
...
@@ -174,6 +180,7 @@ void MainWindow::createActions()
aRestartGame
=
new
QAction
(
tr
(
"&Restart game..."
),
this
);
aRestartGame
=
new
QAction
(
tr
(
"&Restart game..."
),
this
);
aRestartGame
->
setShortcut
(
tr
(
"F2"
));
aRestartGame
->
setShortcut
(
tr
(
"F2"
));
aRestartGame
->
setEnabled
(
false
);
aRestartGame
->
setEnabled
(
false
);
connect
(
aRestartGame
,
SIGNAL
(
triggered
()),
this
,
SLOT
(
actRestartGame
()));
aLeaveGame
=
new
QAction
(
tr
(
"&Leave game"
),
this
);
aLeaveGame
=
new
QAction
(
tr
(
"&Leave game"
),
this
);
aLeaveGame
->
setEnabled
(
false
);
aLeaveGame
->
setEnabled
(
false
);
connect
(
aLeaveGame
,
SIGNAL
(
triggered
()),
this
,
SLOT
(
actLeaveGame
()));
connect
(
aLeaveGame
,
SIGNAL
(
triggered
()),
this
,
SLOT
(
actLeaveGame
()));
...
...
cockatrice/src/window_main.h
View file @
99ff7fd1
...
@@ -53,6 +53,7 @@ private slots:
...
@@ -53,6 +53,7 @@ private slots:
void
actConnect
();
void
actConnect
();
void
actDisconnect
();
void
actDisconnect
();
void
actGames
();
void
actGames
();
void
actRestartGame
();
void
actLeaveGame
();
void
actLeaveGame
();
void
actDeckEditor
();
void
actDeckEditor
();
void
actExit
();
void
actExit
();
...
...
cockatrice/src/zoneviewlayout.cpp
View file @
99ff7fd1
...
@@ -52,3 +52,9 @@ void ZoneViewLayout::closeMostRecentZoneView()
...
@@ -52,3 +52,9 @@ void ZoneViewLayout::closeMostRecentZoneView()
return
;
return
;
views
.
at
(
views
.
size
()
-
1
)
->
close
();
views
.
at
(
views
.
size
()
-
1
)
->
close
();
}
}
void
ZoneViewLayout
::
clear
()
{
for
(
int
i
=
views
.
size
()
-
1
;
i
>=
0
;
i
--
)
views
.
at
(
i
)
->
close
();
}
cockatrice/src/zoneviewlayout.h
View file @
99ff7fd1
...
@@ -21,6 +21,7 @@ public slots:
...
@@ -21,6 +21,7 @@ public slots:
void
addItem
(
Player
*
player
,
const
QString
&
zoneName
,
int
numberCards
=
0
);
void
addItem
(
Player
*
player
,
const
QString
&
zoneName
,
int
numberCards
=
0
);
void
removeItem
(
ZoneViewWidget
*
item
);
void
removeItem
(
ZoneViewWidget
*
item
);
void
closeMostRecentZoneView
();
void
closeMostRecentZoneView
();
void
clear
();
};
};
#endif
#endif
servatrice/servatrice.ini.example
0 → 100644
View file @
99ff7fd1
[database]
hostname=localhost
database=servatrice
user=servatrice
password=foobar
servatrice/src/main.cpp
View file @
99ff7fd1
...
@@ -25,6 +25,8 @@
...
@@ -25,6 +25,8 @@
int
main
(
int
argc
,
char
*
argv
[])
int
main
(
int
argc
,
char
*
argv
[])
{
{
QCoreApplication
app
(
argc
,
argv
);
QCoreApplication
app
(
argc
,
argv
);
app
.
setOrganizationName
(
"Cockatrice"
);
app
.
setApplicationName
(
"Servatrice"
);
Server
server
;
Server
server
;
if
(
!
server
.
openDatabase
())
{
if
(
!
server
.
openDatabase
())
{
...
...
servatrice/src/server.cpp
View file @
99ff7fd1
...
@@ -23,10 +23,12 @@
...
@@ -23,10 +23,12 @@
#include
"serversocket.h"
#include
"serversocket.h"
#include
"counter.h"
#include
"counter.h"
#include
<QtSql>
#include
<QtSql>
#include
<QSettings>
Server
::
Server
(
QObject
*
parent
)
Server
::
Server
(
QObject
*
parent
)
:
QTcpServer
(
parent
)
:
QTcpServer
(
parent
)
,
nextGameId
(
1
)
{
{
settings
=
new
QSettings
(
"servatrice.ini"
,
QSettings
::
IniFormat
,
this
);
}
}
Server
::~
Server
()
Server
::~
Server
()
...
@@ -35,11 +37,14 @@ Server::~Server()
...
@@ -35,11 +37,14 @@ Server::~Server()
bool
Server
::
openDatabase
()
bool
Server
::
openDatabase
()
{
{
settings
->
beginGroup
(
"database"
);
QSqlDatabase
sqldb
=
QSqlDatabase
::
addDatabase
(
"QMYSQL"
);
QSqlDatabase
sqldb
=
QSqlDatabase
::
addDatabase
(
"QMYSQL"
);
sqldb
.
setHostName
(
"localhost"
);
sqldb
.
setHostName
(
settings
->
value
(
"hostname"
).
toString
());
sqldb
.
setDatabaseName
(
"cockatrice"
);
sqldb
.
setDatabaseName
(
settings
->
value
(
"database"
).
toString
());
sqldb
.
setUserName
(
"cockatrice"
);
sqldb
.
setUserName
(
settings
->
value
(
"user"
).
toString
());
sqldb
.
setPassword
(
"45CdX6rmd"
);
sqldb
.
setPassword
(
settings
->
value
(
"password"
).
toString
());
settings
->
endGroup
();
return
sqldb
.
open
();
return
sqldb
.
open
();
}
}
...
@@ -50,9 +55,9 @@ void Server::gameCreated(ServerGame *_game, ServerSocket *_creator)
...
@@ -50,9 +55,9 @@ void Server::gameCreated(ServerGame *_game, ServerSocket *_creator)
_game
->
addPlayer
(
_creator
);
_game
->
addPlayer
(
_creator
);
}
}
void
Server
::
addGame
(
const
QString
name
,
const
QString
description
,
const
QString
password
,
const
int
maxPlayers
,
ServerSocket
*
creator
)
void
Server
::
addGame
(
const
QString
description
,
const
QString
password
,
const
int
maxPlayers
,
ServerSocket
*
creator
)
{
{
ServerGameThread
*
newThread
=
new
ServerGameThread
(
n
ame
,
description
,
password
,
maxPlayers
,
creator
);
ServerGameThread
*
newThread
=
new
ServerGameThread
(
n
extGameId
++
,
description
,
password
,
maxPlayers
,
creator
);
connect
(
newThread
,
SIGNAL
(
gameCreated
(
ServerGame
*
,
ServerSocket
*
)),
this
,
SLOT
(
gameCreated
(
ServerGame
*
,
ServerSocket
*
)));
connect
(
newThread
,
SIGNAL
(
gameCreated
(
ServerGame
*
,
ServerSocket
*
)),
this
,
SLOT
(
gameCreated
(
ServerGame
*
,
ServerSocket
*
)));
connect
(
newThread
,
SIGNAL
(
finished
()),
this
,
SLOT
(
gameClosed
()));
connect
(
newThread
,
SIGNAL
(
finished
()),
this
,
SLOT
(
gameClosed
()));
newThread
->
start
();
newThread
->
start
();
...
@@ -62,8 +67,8 @@ void Server::incomingConnection(int socketId)
...
@@ -62,8 +67,8 @@ void Server::incomingConnection(int socketId)
{
{
ServerSocket
*
socket
=
new
ServerSocket
(
this
);
ServerSocket
*
socket
=
new
ServerSocket
(
this
);
socket
->
setSocketDescriptor
(
socketId
);
socket
->
setSocketDescriptor
(
socketId
);
connect
(
socket
,
SIGNAL
(
createGame
(
const
QString
,
const
QString
,
const
QString
,
const
int
,
ServerSocket
*
)),
this
,
SLOT
(
addGame
(
const
QString
,
const
QString
,
const
QString
,
const
int
,
ServerSocket
*
)));
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
(
const
QStr
in
g
,
ServerSocket
*
)),
this
,
SLOT
(
addClientToGame
(
const
QStr
in
g
,
ServerSocket
*
)));
connect
(
socket
,
SIGNAL
(
joinGame
(
in
t
,
ServerSocket
*
)),
this
,
SLOT
(
addClientToGame
(
in
t
,
ServerSocket
*
)));
socket
->
initConnection
();
socket
->
initConnection
();
}
}
...
@@ -85,12 +90,12 @@ AuthenticationResult Server::checkUserPassword(const QString &user, const QStrin
...
@@ -85,12 +90,12 @@ AuthenticationResult Server::checkUserPassword(const QString &user, const QStrin
return
UnknownUser
;
return
UnknownUser
;
}
}
ServerGame
*
Server
::
getGame
(
const
QString
&
n
ame
)
ServerGame
*
Server
::
getGame
(
int
g
ame
Id
)
{
{
QListIterator
<
ServerGame
*>
i
(
games
);
QListIterator
<
ServerGame
*>
i
(
games
);
while
(
i
.
hasNext
())
{
while
(
i
.
hasNext
())
{
ServerGame
*
tmp
=
i
.
next
();
ServerGame
*
tmp
=
i
.
next
();
if
((
!
tmp
->
n
ame
.
compare
(
name
,
Qt
::
CaseSensitive
)
)
&&
!
tmp
->
getGameStarted
())
if
((
tmp
->
g
ame
Id
==
gameId
)
&&
!
tmp
->
getGameStarted
())
return
tmp
;
return
tmp
;
}
}
return
NULL
;
return
NULL
;
...
@@ -111,10 +116,10 @@ QList<ServerGame *> Server::listOpenGames()
...
@@ -111,10 +116,10 @@ QList<ServerGame *> Server::listOpenGames()
return
result
;
return
result
;
}
}
bool
Server
::
checkGamePassword
(
const
QString
&
n
ame
,
const
QString
&
password
)
bool
Server
::
checkGamePassword
(
int
g
ame
Id
,
const
QString
&
password
)
{
{
ServerGame
*
tmp
;
ServerGame
*
tmp
;
if
((
tmp
=
getGame
(
n
ame
)))
{
if
((
tmp
=
getGame
(
g
ame
Id
)))
{
QMutexLocker
locker
(
tmp
->
mutex
);
QMutexLocker
locker
(
tmp
->
mutex
);
if
((
!
tmp
->
getGameStarted
())
if
((
!
tmp
->
getGameStarted
())
&&
(
!
tmp
->
password
.
compare
(
password
,
Qt
::
CaseSensitive
))
&&
(
!
tmp
->
password
.
compare
(
password
,
Qt
::
CaseSensitive
))
...
@@ -124,9 +129,9 @@ bool Server::checkGamePassword(const QString &name, const QString &password)
...
@@ -124,9 +129,9 @@ bool Server::checkGamePassword(const QString &name, const QString &password)
return
false
;
return
false
;
}
}
void
Server
::
addClientToGame
(
const
QString
n
ame
,
ServerSocket
*
client
)
void
Server
::
addClientToGame
(
int
g
ame
Id
,
ServerSocket
*
client
)
{
{
ServerGame
*
tmp
=
getGame
(
n
ame
);
ServerGame
*
tmp
=
getGame
(
g
ame
Id
);
client
->
moveToThread
(
tmp
->
thread
());
client
->
moveToThread
(
tmp
->
thread
());
tmp
->
addPlayer
(
client
);
tmp
->
addPlayer
(
client
);
}
}
...
...
servatrice/src/server.h
View file @
99ff7fd1
...
@@ -25,6 +25,7 @@
...
@@ -25,6 +25,7 @@
class
ServerGame
;
class
ServerGame
;
class
ServerSocket
;
class
ServerSocket
;
class
QSqlDatabase
;
class
QSqlDatabase
;
class
QSettings
;
enum
AuthenticationResult
{
PasswordWrong
=
0
,
PasswordRight
=
1
,
UnknownUser
=
2
};
enum
AuthenticationResult
{
PasswordWrong
=
0
,
PasswordRight
=
1
,
UnknownUser
=
2
};
...
@@ -32,21 +33,23 @@ class Server : public QTcpServer
...
@@ -32,21 +33,23 @@ class Server : public QTcpServer
{
{
Q_OBJECT
Q_OBJECT
private
slots
:
private
slots
:
void
addGame
(
const
QString
name
,
const
QString
description
,
const
QString
password
,
const
int
maxPlayers
,
ServerSocket
*
creator
);
void
addGame
(
const
QString
description
,
const
QString
password
,
const
int
maxPlayers
,
ServerSocket
*
creator
);
void
addClientToGame
(
const
QString
n
ame
,
ServerSocket
*
client
);
void
addClientToGame
(
int
g
ame
Id
,
ServerSocket
*
client
);
void
gameCreated
(
ServerGame
*
_game
,
ServerSocket
*
_creator
);
void
gameCreated
(
ServerGame
*
_game
,
ServerSocket
*
_creator
);
void
gameClosed
();
void
gameClosed
();
public:
public:
Server
(
QObject
*
parent
=
0
);
Server
(
QObject
*
parent
=
0
);
~
Server
();
~
Server
();
QSettings
*
settings
;
bool
openDatabase
();
bool
openDatabase
();
bool
checkGamePassword
(
const
QString
&
n
ame
,
const
QString
&
password
);
bool
checkGamePassword
(
int
g
ame
Id
,
const
QString
&
password
);
AuthenticationResult
checkUserPassword
(
const
QString
&
user
,
const
QString
&
password
);
AuthenticationResult
checkUserPassword
(
const
QString
&
user
,
const
QString
&
password
);
QList
<
ServerGame
*>
listOpenGames
();
QList
<
ServerGame
*>
listOpenGames
();
ServerGame
*
getGame
(
const
QString
&
n
ame
);
ServerGame
*
getGame
(
int
g
ame
Id
);
private:
private:
void
incomingConnection
(
int
SocketId
);
void
incomingConnection
(
int
SocketId
);
QList
<
ServerGame
*>
games
;
QList
<
ServerGame
*>
games
;
int
nextGameId
;
};
};
#endif
#endif
servatrice/src/servergame.cpp
View file @
99ff7fd1
...
@@ -21,8 +21,8 @@
...
@@ -21,8 +21,8 @@
#include
"random.h"
#include
"random.h"
#include
"serversocket.h"
#include
"serversocket.h"
ServerGame
::
ServerGame
(
QStr
in
g
_
n
ame
,
QString
_description
,
QString
_password
,
int
_maxPlayers
,
QObject
*
parent
)
ServerGame
::
ServerGame
(
ServerSocket
*
_creator
,
in
t
_
g
ame
Id
,
QString
_description
,
QString
_password
,
int
_maxPlayers
,
QObject
*
parent
)
:
QObject
(
parent
),
gameStarted
(
false
),
rnd
(
0
),
n
ame
(
_
n
ame
),
description
(
_description
),
password
(
_password
),
maxPlayers
(
_maxPlayers
)
:
QObject
(
parent
),
gameStarted
(
false
),
rnd
(
0
),
creator
(
_creator
),
g
ame
Id
(
_
g
ame
Id
),
description
(
_description
),
password
(
_password
),
maxPlayers
(
_maxPlayers
)
{
{
mutex
=
new
QMutex
(
QMutex
::
Recursive
);
mutex
=
new
QMutex
(
QMutex
::
Recursive
);
}
}
...
...
servatrice/src/servergame.h
View file @
99ff7fd1
...
@@ -39,11 +39,12 @@ public slots:
...
@@ -39,11 +39,12 @@ public slots:
public:
public:
QMutex
*
mutex
;
QMutex
*
mutex
;
Random
*
rnd
;
Random
*
rnd
;
QString
name
;
ServerSocket
*
creator
;
int
gameId
;
QString
description
;
QString
description
;
QString
password
;
QString
password
;
int
maxPlayers
;
int
maxPlayers
;
ServerGame
(
QStr
in
g
_
n
ame
,
QString
_description
,
QString
_password
,
int
_maxPlayers
,
QObject
*
parent
=
0
);
ServerGame
(
ServerSocket
*
_creator
,
in
t
_
g
ame
Id
,
QString
_description
,
QString
_password
,
int
_maxPlayers
,
QObject
*
parent
=
0
);
~
ServerGame
();
~
ServerGame
();
bool
getGameStarted
();
bool
getGameStarted
();
int
getPlayerCount
();
int
getPlayerCount
();
...
...
servatrice/src/servergamethread.cpp
View file @
99ff7fd1
#include
"servergamethread.h"
#include
"servergamethread.h"
#include
"servergame.h"
#include
"servergame.h"
ServerGameThread
::
ServerGameThread
(
const
QStr
in
g
_
n
ame
,
const
QString
_description
,
const
QString
_password
,
const
int
_maxPlayers
,
ServerSocket
*
_creator
,
QObject
*
parent
)
ServerGameThread
::
ServerGameThread
(
in
t
_
g
ame
Id
,
const
QString
_description
,
const
QString
_password
,
const
int
_maxPlayers
,
ServerSocket
*
_creator
,
QObject
*
parent
)
:
QThread
(
parent
),
n
ame
(
_
n
ame
),
description
(
_description
),
password
(
_password
),
maxPlayers
(
_maxPlayers
),
creator
(
_creator
),
game
(
0
)
:
QThread
(
parent
),
g
ame
Id
(
_
g
ame
Id
),
description
(
_description
),
password
(
_password
),
maxPlayers
(
_maxPlayers
),
creator
(
_creator
),
game
(
0
)
{
{
}
}
...
@@ -15,7 +15,7 @@ ServerGameThread::~ServerGameThread()
...
@@ -15,7 +15,7 @@ ServerGameThread::~ServerGameThread()
void
ServerGameThread
::
run
()
void
ServerGameThread
::
run
()
{
{
game
=
new
ServerGame
(
n
ame
,
description
,
password
,
maxPlayers
);
game
=
new
ServerGame
(
creator
,
g
ame
Id
,
description
,
password
,
maxPlayers
);
emit
gameCreated
(
game
,
creator
);
emit
gameCreated
(
game
,
creator
);
exec
();
exec
();
}
}
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