implemented game types

This commit is contained in:
Max-Wilhelm Bruker 2011-01-27 19:13:22 +01:00
parent 7116382a96
commit 04742f6fb9
23 changed files with 249 additions and 127 deletions

View file

@ -11,8 +11,8 @@
#include "dlg_creategame.h" #include "dlg_creategame.h"
#include "protocol_items.h" #include "protocol_items.h"
DlgCreateGame::DlgCreateGame(AbstractClient *_client, int _roomId, QWidget *parent) DlgCreateGame::DlgCreateGame(AbstractClient *_client, int _roomId, const QMap<int, QString> &_gameTypes, QWidget *parent)
: QDialog(parent), client(_client), roomId(_roomId) : QDialog(parent), client(_client), roomId(_roomId), gameTypes(_gameTypes)
{ {
descriptionLabel = new QLabel(tr("&Description:")); descriptionLabel = new QLabel(tr("&Description:"));
descriptionEdit = new QLineEdit; descriptionEdit = new QLineEdit;
@ -29,6 +29,17 @@ DlgCreateGame::DlgCreateGame(AbstractClient *_client, int _roomId, QWidget *pare
maxPlayersEdit->setValue(2); maxPlayersEdit->setValue(2);
maxPlayersLabel->setBuddy(maxPlayersEdit); maxPlayersLabel->setBuddy(maxPlayersEdit);
QVBoxLayout *gameTypeLayout = new QVBoxLayout;
QMapIterator<int, QString> gameTypeIterator(gameTypes);
while (gameTypeIterator.hasNext()) {
gameTypeIterator.next();
QCheckBox *gameTypeCheckBox = new QCheckBox(gameTypeIterator.value());
gameTypeLayout->addWidget(gameTypeCheckBox);
gameTypeCheckBoxes.insert(gameTypeIterator.key(), gameTypeCheckBox);
}
QGroupBox *gameTypeGroupBox = new QGroupBox(tr("Game type"));
gameTypeGroupBox->setLayout(gameTypeLayout);
spectatorsAllowedCheckBox = new QCheckBox(tr("&Spectators allowed")); spectatorsAllowedCheckBox = new QCheckBox(tr("&Spectators allowed"));
spectatorsAllowedCheckBox->setChecked(true); spectatorsAllowedCheckBox->setChecked(true);
connect(spectatorsAllowedCheckBox, SIGNAL(stateChanged(int)), this, SLOT(spectatorsAllowedChanged(int))); connect(spectatorsAllowedCheckBox, SIGNAL(stateChanged(int)), this, SLOT(spectatorsAllowedChanged(int)));
@ -50,7 +61,8 @@ DlgCreateGame::DlgCreateGame(AbstractClient *_client, int _roomId, QWidget *pare
grid->addWidget(passwordEdit, 1, 1); grid->addWidget(passwordEdit, 1, 1);
grid->addWidget(maxPlayersLabel, 2, 0); grid->addWidget(maxPlayersLabel, 2, 0);
grid->addWidget(maxPlayersEdit, 2, 1); grid->addWidget(maxPlayersEdit, 2, 1);
grid->addWidget(spectatorsGroupBox, 3, 0, 1, 2); grid->addWidget(gameTypeGroupBox, 3, 0, 1, 2);
grid->addWidget(spectatorsGroupBox, 4, 0, 1, 2);
okButton = new QPushButton(tr("&OK")); okButton = new QPushButton(tr("&OK"));
okButton->setDefault(true); okButton->setDefault(true);
@ -76,11 +88,20 @@ DlgCreateGame::DlgCreateGame(AbstractClient *_client, int _roomId, QWidget *pare
void DlgCreateGame::actOK() void DlgCreateGame::actOK()
{ {
QList<GameTypeId *> gameTypeList;
QMapIterator<int, QCheckBox *> gameTypeCheckBoxIterator(gameTypeCheckBoxes);
while (gameTypeCheckBoxIterator.hasNext()) {
gameTypeCheckBoxIterator.next();
if (gameTypeCheckBoxIterator.value()->isChecked())
gameTypeList.append(new GameTypeId(gameTypeCheckBoxIterator.key()));
}
Command_CreateGame *createCommand = new Command_CreateGame( Command_CreateGame *createCommand = new Command_CreateGame(
roomId, roomId,
descriptionEdit->text(), descriptionEdit->text(),
passwordEdit->text(), passwordEdit->text(),
maxPlayersEdit->value(), maxPlayersEdit->value(),
gameTypeList,
spectatorsAllowedCheckBox->isChecked(), spectatorsAllowedCheckBox->isChecked(),
spectatorsNeedPasswordCheckBox->isChecked(), spectatorsNeedPasswordCheckBox->isChecked(),
spectatorsCanTalkCheckBox->isChecked(), spectatorsCanTalkCheckBox->isChecked(),

View file

@ -14,7 +14,7 @@ class QSpinBox;
class DlgCreateGame : public QDialog { class DlgCreateGame : public QDialog {
Q_OBJECT Q_OBJECT
public: public:
DlgCreateGame(AbstractClient *_client, int _roomId, QWidget *parent = 0); DlgCreateGame(AbstractClient *_client, int _roomId, const QMap<int, QString> &_gameTypes, QWidget *parent = 0);
private slots: private slots:
void actOK(); void actOK();
void checkResponse(ResponseCode response); void checkResponse(ResponseCode response);
@ -22,6 +22,8 @@ private slots:
private: private:
AbstractClient *client; AbstractClient *client;
int roomId; int roomId;
QMap<int, QString> gameTypes;
QMap<int, QCheckBox *> gameTypeCheckBoxes;
QGroupBox *spectatorsGroupBox; QGroupBox *spectatorsGroupBox;
QLabel *descriptionLabel, *passwordLabel, *maxPlayersLabel; QLabel *descriptionLabel, *passwordLabel, *maxPlayersLabel;

View file

@ -1,6 +1,11 @@
#include "gamesmodel.h" #include "gamesmodel.h"
#include "protocol_datastructures.h" #include "protocol_datastructures.h"
GamesModel::GamesModel(const QMap<int, QString> &_gameTypes, QObject *parent)
: QAbstractTableModel(parent), gameTypes(_gameTypes)
{
}
GamesModel::~GamesModel() GamesModel::~GamesModel()
{ {
if (!gameList.isEmpty()) { if (!gameList.isEmpty()) {
@ -27,9 +32,16 @@ QVariant GamesModel::data(const QModelIndex &index, int role) const
switch (index.column()) { switch (index.column()) {
case 0: return g->getDescription(); case 0: return g->getDescription();
case 1: return g->getCreatorInfo()->getName(); case 1: return g->getCreatorInfo()->getName();
case 2: return g->getHasPassword() ? (g->getSpectatorsNeedPassword() ? tr("yes") : tr("yes, free for spectators")) : tr("no"); case 2: {
case 3: return QString("%1/%2").arg(g->getPlayerCount()).arg(g->getMaxPlayers()); QStringList result;
case 4: return g->getSpectatorsAllowed() ? QVariant(g->getSpectatorCount()) : QVariant(tr("not allowed")); QList<GameTypeId *> gameTypeList = g->getGameTypes();
for (int i = 0; i < gameTypeList.size(); ++i)
result.append(gameTypes.value(gameTypeList[i]->getData()));
return result.join(", ");
}
case 3: return g->getHasPassword() ? (g->getSpectatorsNeedPassword() ? tr("yes") : tr("yes, free for spectators")) : tr("no");
case 4: return QString("%1/%2").arg(g->getPlayerCount()).arg(g->getMaxPlayers());
case 5: return g->getSpectatorsAllowed() ? QVariant(g->getSpectatorCount()) : QVariant(tr("not allowed"));
default: return QVariant(); default: return QVariant();
} }
} }
@ -41,9 +53,10 @@ QVariant GamesModel::headerData(int section, Qt::Orientation orientation, int ro
switch (section) { switch (section) {
case 0: return tr("Description"); case 0: return tr("Description");
case 1: return tr("Creator"); case 1: return tr("Creator");
case 2: return tr("Password"); case 2: return tr("Game type");
case 3: return tr("Players"); case 3: return tr("Password");
case 4: return tr("Spectators"); case 4: return tr("Players");
case 5: return tr("Spectators");
default: return QVariant(); default: return QVariant();
} }
} }
@ -56,7 +69,11 @@ ServerInfo_Game *GamesModel::getGame(int row)
void GamesModel::updateGameList(ServerInfo_Game *_game) void GamesModel::updateGameList(ServerInfo_Game *_game)
{ {
ServerInfo_Game *game = new ServerInfo_Game(_game->getGameId(), _game->getDescription(), _game->getHasPassword(), _game->getPlayerCount(), _game->getMaxPlayers(), new ServerInfo_User(_game->getCreatorInfo()), _game->getSpectatorsAllowed(), _game->getSpectatorsNeedPassword(), _game->getSpectatorCount()); QList<GameTypeId *> gameTypeList, oldGameTypeList = _game->getGameTypes();
for (int i = 0; i < oldGameTypeList.size(); ++i)
gameTypeList.append(new GameTypeId(oldGameTypeList[i]->getData()));
ServerInfo_Game *game = new ServerInfo_Game(_game->getGameId(), _game->getDescription(), _game->getHasPassword(), _game->getPlayerCount(), _game->getMaxPlayers(), gameTypeList, new ServerInfo_User(_game->getCreatorInfo()), _game->getSpectatorsAllowed(), _game->getSpectatorsNeedPassword(), _game->getSpectatorCount());
for (int i = 0; i < gameList.size(); i++) for (int i = 0; i < gameList.size(); i++)
if (gameList[i]->getGameId() == game->getGameId()) { if (gameList[i]->getGameId() == game->getGameId()) {
if (game->getPlayerCount() == 0) { if (game->getPlayerCount() == 0) {

View file

@ -9,8 +9,11 @@ class ServerInfo_Game;
class GamesModel : public QAbstractTableModel { class GamesModel : public QAbstractTableModel {
Q_OBJECT Q_OBJECT
private:
QList<ServerInfo_Game *> gameList;
QMap<int, QString> gameTypes;
public: public:
GamesModel(QObject *parent = 0) : QAbstractTableModel(parent) { } GamesModel(const QMap<int, QString> &_gameTypes, QObject *parent = 0);
~GamesModel(); ~GamesModel();
int rowCount(const QModelIndex &parent = QModelIndex()) const { return parent.isValid() ? 0 : gameList.size(); } int rowCount(const QModelIndex &parent = QModelIndex()) const { return parent.isValid() ? 0 : gameList.size(); }
int columnCount(const QModelIndex &/*parent*/ = QModelIndex()) const { return 5; } int columnCount(const QModelIndex &/*parent*/ = QModelIndex()) const { return 5; }
@ -19,8 +22,6 @@ public:
ServerInfo_Game *getGame(int row); ServerInfo_Game *getGame(int row);
void updateGameList(ServerInfo_Game *game); void updateGameList(ServerInfo_Game *game);
private:
QList<ServerInfo_Game *> gameList;
}; };
class GamesProxyModel : public QSortFilterProxyModel { class GamesProxyModel : public QSortFilterProxyModel {

View file

@ -5,7 +5,7 @@
LocalServer::LocalServer(QObject *parent) LocalServer::LocalServer(QObject *parent)
: Server(parent) : Server(parent)
{ {
addRoom(new Server_Room(0, QString(), QString(), false, QString(), this)); addRoom(new Server_Room(0, QString(), QString(), false, QString(), QStringList(), this));
} }
LocalServer::~LocalServer() LocalServer::~LocalServer()

View file

@ -17,15 +17,16 @@
#include "gamesmodel.h" #include "gamesmodel.h"
#include "chatview.h" #include "chatview.h"
GameSelector::GameSelector(AbstractClient *_client, int _roomId, QWidget *parent) GameSelector::GameSelector(AbstractClient *_client, TabRoom *_room, QWidget *parent)
: QGroupBox(parent), client(_client), roomId(_roomId) : QGroupBox(parent), client(_client), room(_room)
{ {
gameListView = new QTreeView; gameListView = new QTreeView;
gameListModel = new GamesModel(this); gameListModel = new GamesModel(room->getGameTypes(), this);
gameListProxyModel = new GamesProxyModel(this); gameListProxyModel = new GamesProxyModel(this);
gameListProxyModel->setSourceModel(gameListModel); gameListProxyModel->setSourceModel(gameListModel);
gameListView->setModel(gameListProxyModel); gameListView->setModel(gameListProxyModel);
gameListView->header()->setResizeMode(0, QHeaderView::ResizeToContents); gameListView->header()->setResizeMode(0, QHeaderView::ResizeToContents);
gameListView->setSortingEnabled(true);
showFullGamesCheckBox = new QCheckBox; showFullGamesCheckBox = new QCheckBox;
createButton = new QPushButton; createButton = new QPushButton;
@ -61,7 +62,7 @@ void GameSelector::showFullGamesChanged(int state)
void GameSelector::actCreate() void GameSelector::actCreate()
{ {
DlgCreateGame dlg(client, roomId, this); DlgCreateGame dlg(client, room->getRoomId(), room->getGameTypes(), this);
dlg.exec(); dlg.exec();
} }
@ -96,7 +97,7 @@ void GameSelector::actJoin()
return; return;
} }
Command_JoinGame *commandJoinGame = new Command_JoinGame(roomId, game->getGameId(), password, spectator); Command_JoinGame *commandJoinGame = new Command_JoinGame(room->getRoomId(), game->getGameId(), password, spectator);
connect(commandJoinGame, SIGNAL(finished(ResponseCode)), this, SLOT(checkResponse(ResponseCode))); connect(commandJoinGame, SIGNAL(finished(ResponseCode)), this, SLOT(checkResponse(ResponseCode)));
client->sendCommand(commandJoinGame); client->sendCommand(commandJoinGame);
@ -122,7 +123,11 @@ void GameSelector::processGameInfo(ServerInfo_Game *info)
TabRoom::TabRoom(AbstractClient *_client, const QString &_ownName, ServerInfo_Room *info) TabRoom::TabRoom(AbstractClient *_client, const QString &_ownName, ServerInfo_Room *info)
: Tab(), client(_client), roomId(info->getRoomId()), roomName(info->getName()), ownName(_ownName) : Tab(), client(_client), roomId(info->getRoomId()), roomName(info->getName()), ownName(_ownName)
{ {
gameSelector = new GameSelector(client, roomId); const QList<ServerInfo_GameType *> gameTypeList = info->getGameTypeList();
for (int i = 0; i < gameTypeList.size(); ++i)
gameTypes.insert(gameTypeList[i]->getGameTypeId(), gameTypeList[i]->getDescription());
gameSelector = new GameSelector(client, this);
userList = new UserList(client, false); userList = new UserList(client, false);
connect(userList, SIGNAL(openMessageDialog(const QString &, bool)), this, SIGNAL(openMessageDialog(const QString &, bool))); connect(userList, SIGNAL(openMessageDialog(const QString &, bool)), this, SIGNAL(openMessageDialog(const QString &, bool)));

View file

@ -23,6 +23,7 @@ class Event_ListGames;
class Event_JoinRoom; class Event_JoinRoom;
class Event_LeaveRoom; class Event_LeaveRoom;
class Event_RoomSay; class Event_RoomSay;
class TabRoom;
class GameSelector : public QGroupBox { class GameSelector : public QGroupBox {
Q_OBJECT Q_OBJECT
@ -35,7 +36,7 @@ signals:
void gameJoined(int gameId); void gameJoined(int gameId);
private: private:
AbstractClient *client; AbstractClient *client;
int roomId; TabRoom *room;
QTreeView *gameListView; QTreeView *gameListView;
GamesModel *gameListModel; GamesModel *gameListModel;
@ -43,7 +44,7 @@ private:
QPushButton *createButton, *joinButton, *spectateButton; QPushButton *createButton, *joinButton, *spectateButton;
QCheckBox *showFullGamesCheckBox; QCheckBox *showFullGamesCheckBox;
public: public:
GameSelector(AbstractClient *_client, int _roomId, QWidget *parent = 0); GameSelector(AbstractClient *_client, TabRoom *_room, QWidget *parent = 0);
void retranslateUi(); void retranslateUi();
void processGameInfo(ServerInfo_Game *info); void processGameInfo(ServerInfo_Game *info);
}; };
@ -55,6 +56,7 @@ private:
int roomId; int roomId;
QString roomName; QString roomName;
QString ownName; QString ownName;
QMap<int, QString> gameTypes;
GameSelector *gameSelector; GameSelector *gameSelector;
UserList *userList; UserList *userList;
@ -82,6 +84,7 @@ public:
void retranslateUi(); void retranslateUi();
void processRoomEvent(RoomEvent *event); void processRoomEvent(RoomEvent *event);
int getRoomId() const { return roomId; } int getRoomId() const { return roomId; }
const QMap<int, QString> &getGameTypes() const { return gameTypes; }
QString getChannelName() const { return roomName; } QString getChannelName() const { return roomName; }
QString getTabText() const { return roomName; } QString getTabText() const { return roomName; }
}; };

View file

@ -113,7 +113,7 @@ void MainWindow::actSinglePlayer()
} }
tabSupervisor->startLocal(localClients); tabSupervisor->startLocal(localClients);
Command_CreateGame *createCommand = new Command_CreateGame(0, QString(), QString(), numberPlayers, false, false, false, false); Command_CreateGame *createCommand = new Command_CreateGame(0, QString(), QString(), numberPlayers, QList<GameTypeId *>(), false, false, false, false);
mainClient->sendCommand(createCommand); mainClient->sendCommand(createCommand);
} }

View file

@ -17,6 +17,7 @@ void ProtocolItem::initializeHash()
registerSerializableItem("room", ServerInfo_Room::newItem); registerSerializableItem("room", ServerInfo_Room::newItem);
registerSerializableItem("user", ServerInfo_User::newItem); registerSerializableItem("user", ServerInfo_User::newItem);
registerSerializableItem("game", ServerInfo_Game::newItem); registerSerializableItem("game", ServerInfo_Game::newItem);
registerSerializableItem("game_type", ServerInfo_GameType::newItem);
registerSerializableItem("card_counter", ServerInfo_CardCounter::newItem); registerSerializableItem("card_counter", ServerInfo_CardCounter::newItem);
registerSerializableItem("card", ServerInfo_Card::newItem); registerSerializableItem("card", ServerInfo_Card::newItem);
registerSerializableItem("zone", ServerInfo_Zone::newItem); registerSerializableItem("zone", ServerInfo_Zone::newItem);
@ -28,10 +29,12 @@ void ProtocolItem::initializeHash()
registerSerializableItem("file", DeckList_File::newItem); registerSerializableItem("file", DeckList_File::newItem);
registerSerializableItem("directory", DeckList_Directory::newItem); registerSerializableItem("directory", DeckList_Directory::newItem);
registerSerializableItem("card_id", CardId::newItem); registerSerializableItem("card_id", CardId::newItem);
registerSerializableItem("game_type_id", GameTypeId::newItem);
registerSerializableItem("containercmd", CommandContainer::newItem); registerSerializableItem("containercmd", CommandContainer::newItem);
registerSerializableItem("containergame_event", GameEventContainer::newItem); registerSerializableItem("containergame_event", GameEventContainer::newItem);
registerSerializableItem("cmdcreate_game", Command_CreateGame::newItem);
registerSerializableItem("cmddeck_upload", Command_DeckUpload::newItem); registerSerializableItem("cmddeck_upload", Command_DeckUpload::newItem);
registerSerializableItem("cmddeck_select", Command_DeckSelect::newItem); registerSerializableItem("cmddeck_select", Command_DeckSelect::newItem);
registerSerializableItem("cmdset_sideboard_plan", Command_SetSideboardPlan::newItem); registerSerializableItem("cmdset_sideboard_plan", Command_SetSideboardPlan::newItem);
@ -166,6 +169,21 @@ void CommandContainer::enqueueGameEventPrivate(GameEvent *event, int gameId, int
gameEventQueuePrivate->setContext(context); gameEventQueuePrivate->setContext(context);
} }
Command_CreateGame::Command_CreateGame(int _roomId, const QString &_description, const QString &_password, int _maxPlayers, const QList<GameTypeId *> &_gameTypes, bool _spectatorsAllowed, bool _spectatorsNeedPassword, bool _spectatorsCanTalk, bool _spectatorsSeeEverything)
: RoomCommand("create_game", _roomId)
{
insertItem(new SerializableItem_String("description", _description));
insertItem(new SerializableItem_String("password", _password));
insertItem(new SerializableItem_Int("max_players", _maxPlayers));
insertItem(new SerializableItem_Bool("spectators_allowed", _spectatorsAllowed));
insertItem(new SerializableItem_Bool("spectators_need_password", _spectatorsNeedPassword));
insertItem(new SerializableItem_Bool("spectators_can_talk", _spectatorsCanTalk));
insertItem(new SerializableItem_Bool("spectators_see_everything", _spectatorsSeeEverything));
for (int i = 0; i < _gameTypes.size(); ++i)
itemList.append(_gameTypes[i]);
}
Command_DeckUpload::Command_DeckUpload(DeckList *_deck, const QString &_path) Command_DeckUpload::Command_DeckUpload(DeckList *_deck, const QString &_path)
: Command("deck_upload") : Command("deck_upload")
{ {

View file

@ -23,6 +23,7 @@ class MoveCardToZone;
enum ItemId { enum ItemId {
ItemId_CommandContainer = ItemId_Other + 50, ItemId_CommandContainer = ItemId_Other + 50,
ItemId_GameEventContainer = ItemId_Other + 51, ItemId_GameEventContainer = ItemId_Other + 51,
ItemId_Command_CreateGame = ItemId_Other + 99,
ItemId_Command_DeckUpload = ItemId_Other + 100, ItemId_Command_DeckUpload = ItemId_Other + 100,
ItemId_Command_DeckSelect = ItemId_Other + 101, ItemId_Command_DeckSelect = ItemId_Other + 101,
ItemId_Command_SetSideboardPlan = ItemId_Other + 102, ItemId_Command_SetSideboardPlan = ItemId_Other + 102,
@ -173,6 +174,22 @@ public:
} }
}; };
class Command_CreateGame : public RoomCommand {
Q_OBJECT
public:
Command_CreateGame(int _roomId = -1, const QString &_description = QString(), const QString &_password = QString(), int _maxPlayers = -1, const QList<GameTypeId *> &_gameTypes = QList<GameTypeId *>(), bool _spectatorsAllowed = false, bool _spectatorsNeedPassword = false, bool _spectatorsCanTalk = false, bool _spectatorsSeeEverything = false);
QString getDescription() const { return static_cast<SerializableItem_String *>(itemMap.value("description"))->getData(); };
QString getPassword() const { return static_cast<SerializableItem_String *>(itemMap.value("password"))->getData(); };
int getMaxPlayers() const { return static_cast<SerializableItem_Int *>(itemMap.value("max_players"))->getData(); };
bool getSpectatorsAllowed() const { return static_cast<SerializableItem_Bool *>(itemMap.value("spectators_allowed"))->getData(); };
bool getSpectatorsNeedPassword() const { return static_cast<SerializableItem_Bool *>(itemMap.value("spectators_need_password"))->getData(); };
bool getSpectatorsCanTalk() const { return static_cast<SerializableItem_Bool *>(itemMap.value("spectators_can_talk"))->getData(); };
bool getSpectatorsSeeEverything() const { return static_cast<SerializableItem_Bool *>(itemMap.value("spectators_see_everything"))->getData(); };
QList<GameTypeId *> getGameTypes() const { return typecastItemList<GameTypeId *>(); }
static SerializableItem *newItem() { return new Command_CreateGame; }
int getItemId() const { return ItemId_Command_CreateGame; }
};
class Command_DeckUpload : public Command { class Command_DeckUpload : public Command {
Q_OBJECT Q_OBJECT
public: public:

View file

@ -23,7 +23,7 @@ ServerInfo_User::ServerInfo_User(const ServerInfo_User *other, bool complete)
insertItem(new SerializableItem_ByteArray("avatar_bmp", complete ? other->getAvatarBmp() : QByteArray())); insertItem(new SerializableItem_ByteArray("avatar_bmp", complete ? other->getAvatarBmp() : QByteArray()));
} }
ServerInfo_Game::ServerInfo_Game(int _gameId, const QString &_description, bool _hasPassword, int _playerCount, int _maxPlayers, ServerInfo_User *_creatorInfo, bool _spectatorsAllowed, bool _spectatorsNeedPassword, int _spectatorCount) ServerInfo_Game::ServerInfo_Game(int _gameId, const QString &_description, bool _hasPassword, int _playerCount, int _maxPlayers, const QList<GameTypeId *> &_gameTypes, ServerInfo_User *_creatorInfo, bool _spectatorsAllowed, bool _spectatorsNeedPassword, int _spectatorCount)
: SerializableItem_Map("game") : SerializableItem_Map("game")
{ {
insertItem(new SerializableItem_Int("game_id", _gameId)); insertItem(new SerializableItem_Int("game_id", _gameId));
@ -37,9 +37,19 @@ ServerInfo_Game::ServerInfo_Game(int _gameId, const QString &_description, bool
insertItem(new SerializableItem_Bool("spectators_allowed", _spectatorsAllowed)); insertItem(new SerializableItem_Bool("spectators_allowed", _spectatorsAllowed));
insertItem(new SerializableItem_Bool("spectators_need_password", _spectatorsNeedPassword)); insertItem(new SerializableItem_Bool("spectators_need_password", _spectatorsNeedPassword));
insertItem(new SerializableItem_Int("spectator_count", _spectatorCount)); insertItem(new SerializableItem_Int("spectator_count", _spectatorCount));
for (int i = 0; i < _gameTypes.size(); ++i)
itemList.append(_gameTypes[i]);
} }
ServerInfo_Room::ServerInfo_Room(int _roomId, const QString &_name, const QString &_description, int _gameCount, int _playerCount, bool _autoJoin, const QList<ServerInfo_Game *> &_gameList, const QList<ServerInfo_User *> &_userList) ServerInfo_GameType::ServerInfo_GameType(int _gameTypeId, const QString &_description)
: SerializableItem_Map("game_type")
{
insertItem(new SerializableItem_Int("game_type_id", _gameTypeId));
insertItem(new SerializableItem_String("description", _description));
}
ServerInfo_Room::ServerInfo_Room(int _roomId, const QString &_name, const QString &_description, int _gameCount, int _playerCount, bool _autoJoin, const QList<ServerInfo_Game *> &_gameList, const QList<ServerInfo_User *> &_userList, const QList<ServerInfo_GameType *> &_gameTypeList)
: SerializableItem_Map("room") : SerializableItem_Map("room")
{ {
insertItem(new SerializableItem_Int("room_id", _roomId)); insertItem(new SerializableItem_Int("room_id", _roomId));
@ -55,6 +65,9 @@ ServerInfo_Room::ServerInfo_Room(int _roomId, const QString &_name, const QStrin
userList = _userList; userList = _userList;
for (int i = 0; i < _userList.size(); ++i) for (int i = 0; i < _userList.size(); ++i)
itemList.append(_userList[i]); itemList.append(_userList[i]);
gameTypeList = _gameTypeList;
for (int i = 0; i < _gameTypeList.size(); ++i)
itemList.append(_gameTypeList[i]);
} }
void ServerInfo_Room::extractData() void ServerInfo_Room::extractData()
@ -70,6 +83,11 @@ void ServerInfo_Room::extractData()
gameList.append(game); gameList.append(game);
continue; continue;
} }
ServerInfo_GameType *gameType = dynamic_cast<ServerInfo_GameType *>(itemList[i]);
if (gameType) {
gameTypeList.append(gameType);
continue;
}
} }
} }

View file

@ -25,6 +25,11 @@ public:
CardId(int _cardId = -1) : SerializableItem_Int("card_id", _cardId) { } CardId(int _cardId = -1) : SerializableItem_Int("card_id", _cardId) { }
static SerializableItem *newItem() { return new CardId; } static SerializableItem *newItem() { return new CardId; }
}; };
class GameTypeId : public SerializableItem_Int {
public:
GameTypeId(int _gameTypeId = -1) : SerializableItem_Int("game_type_id", _gameTypeId) { }
static SerializableItem *newItem() { return new GameTypeId; }
};
class ServerInfo_User : public SerializableItem_Map { class ServerInfo_User : public SerializableItem_Map {
public: public:
@ -48,27 +53,37 @@ public:
class ServerInfo_Game : public SerializableItem_Map { class ServerInfo_Game : public SerializableItem_Map {
public: public:
ServerInfo_Game(int _gameId = -1, const QString &_description = QString(), bool _hasPassword = false, int _playerCount = -1, int _maxPlayers = -1, ServerInfo_User *creatorInfo = 0, bool _spectatorsAllowed = false, bool _spectatorsNeedPassword = false, int _spectatorCount = -1); ServerInfo_Game(int _gameId = -1, const QString &_description = QString(), bool _hasPassword = false, int _playerCount = -1, int _maxPlayers = -1, const QList<GameTypeId *> &_gameTypes = QList<GameTypeId *>(), ServerInfo_User *creatorInfo = 0, bool _spectatorsAllowed = false, bool _spectatorsNeedPassword = false, int _spectatorCount = -1);
static SerializableItem *newItem() { return new ServerInfo_Game; } static SerializableItem *newItem() { return new ServerInfo_Game; }
int getGameId() const { return static_cast<SerializableItem_Int *>(itemMap.value("game_id"))->getData(); } int getGameId() const { return static_cast<SerializableItem_Int *>(itemMap.value("game_id"))->getData(); }
QString getDescription() const { return static_cast<SerializableItem_String *>(itemMap.value("description"))->getData(); } QString getDescription() const { return static_cast<SerializableItem_String *>(itemMap.value("description"))->getData(); }
bool getHasPassword() const { return static_cast<SerializableItem_Bool *>(itemMap.value("has_password"))->getData(); } bool getHasPassword() const { return static_cast<SerializableItem_Bool *>(itemMap.value("has_password"))->getData(); }
int getPlayerCount() const { return static_cast<SerializableItem_Int *>(itemMap.value("player_count"))->getData(); } int getPlayerCount() const { return static_cast<SerializableItem_Int *>(itemMap.value("player_count"))->getData(); }
int getMaxPlayers() const { return static_cast<SerializableItem_Int *>(itemMap.value("max_players"))->getData(); } int getMaxPlayers() const { return static_cast<SerializableItem_Int *>(itemMap.value("max_players"))->getData(); }
QList<GameTypeId *> getGameTypes() const { return typecastItemList<GameTypeId *>(); }
ServerInfo_User *getCreatorInfo() const { return static_cast<ServerInfo_User *>(itemMap.value("user")); } ServerInfo_User *getCreatorInfo() const { return static_cast<ServerInfo_User *>(itemMap.value("user")); }
bool getSpectatorsAllowed() const { return static_cast<SerializableItem_Bool *>(itemMap.value("spectators_allowed"))->getData(); } bool getSpectatorsAllowed() const { return static_cast<SerializableItem_Bool *>(itemMap.value("spectators_allowed"))->getData(); }
bool getSpectatorsNeedPassword() const { return static_cast<SerializableItem_Bool *>(itemMap.value("spectators_need_password"))->getData(); } bool getSpectatorsNeedPassword() const { return static_cast<SerializableItem_Bool *>(itemMap.value("spectators_need_password"))->getData(); }
int getSpectatorCount() const { return static_cast<SerializableItem_Int *>(itemMap.value("spectator_count"))->getData(); } int getSpectatorCount() const { return static_cast<SerializableItem_Int *>(itemMap.value("spectator_count"))->getData(); }
}; };
class ServerInfo_GameType : public SerializableItem_Map {
public:
ServerInfo_GameType(int _gameTypeId = -1, const QString &_description = QString());
static SerializableItem *newItem() { return new ServerInfo_GameType; }
int getGameTypeId() const { return static_cast<SerializableItem_Int *>(itemMap.value("game_type_id"))->getData(); }
QString getDescription() const { return static_cast<SerializableItem_String *>(itemMap.value("description"))->getData(); }
};
class ServerInfo_Room : public SerializableItem_Map { class ServerInfo_Room : public SerializableItem_Map {
private: private:
QList<ServerInfo_Game *> gameList; QList<ServerInfo_Game *> gameList;
QList<ServerInfo_User *> userList; QList<ServerInfo_User *> userList;
QList<ServerInfo_GameType *> gameTypeList;
protected: protected:
void extractData(); void extractData();
public: public:
ServerInfo_Room(int _id = -1, const QString &_name = QString(), const QString &_description = QString(), int _gameCount = -1, int _playerCount = -1, bool _autoJoin = false, const QList<ServerInfo_Game *> &_gameList = QList<ServerInfo_Game *>(), const QList<ServerInfo_User *> &_userList = QList<ServerInfo_User *>()); ServerInfo_Room(int _id = -1, const QString &_name = QString(), const QString &_description = QString(), int _gameCount = -1, int _playerCount = -1, bool _autoJoin = false, const QList<ServerInfo_Game *> &_gameList = QList<ServerInfo_Game *>(), const QList<ServerInfo_User *> &_userList = QList<ServerInfo_User *>(), const QList<ServerInfo_GameType *> &_gameTypeList = QList<ServerInfo_GameType *>());
static SerializableItem *newItem() { return new ServerInfo_Room; } static SerializableItem *newItem() { return new ServerInfo_Room; }
int getRoomId() const { return static_cast<SerializableItem_Int *>(itemMap.value("room_id"))->getData(); } int getRoomId() const { return static_cast<SerializableItem_Int *>(itemMap.value("room_id"))->getData(); }
QString getName() const { return static_cast<SerializableItem_String *>(itemMap.value("name"))->getData(); } QString getName() const { return static_cast<SerializableItem_String *>(itemMap.value("name"))->getData(); }
@ -78,6 +93,7 @@ public:
bool getAutoJoin() const { return static_cast<SerializableItem_Bool *>(itemMap.value("auto_join"))->getData(); } bool getAutoJoin() const { return static_cast<SerializableItem_Bool *>(itemMap.value("auto_join"))->getData(); }
const QList<ServerInfo_Game *> &getGameList() const { return gameList; } const QList<ServerInfo_Game *> &getGameList() const { return gameList; }
const QList<ServerInfo_User *> &getUserList() const { return userList; } const QList<ServerInfo_User *> &getUserList() const { return userList; }
const QList<ServerInfo_GameType *> &getGameTypeList() const { return gameTypeList; }
}; };
class ServerInfo_CardCounter : public SerializableItem_Map { class ServerInfo_CardCounter : public SerializableItem_Map {

View file

@ -13,63 +13,62 @@ ItemId_Command_ListRooms = 1011,
ItemId_Command_JoinRoom = 1012, ItemId_Command_JoinRoom = 1012,
ItemId_Command_LeaveRoom = 1013, ItemId_Command_LeaveRoom = 1013,
ItemId_Command_RoomSay = 1014, ItemId_Command_RoomSay = 1014,
ItemId_Command_CreateGame = 1015, ItemId_Command_JoinGame = 1015,
ItemId_Command_JoinGame = 1016, ItemId_Command_LeaveGame = 1016,
ItemId_Command_LeaveGame = 1017, ItemId_Command_Say = 1017,
ItemId_Command_Say = 1018, ItemId_Command_Shuffle = 1018,
ItemId_Command_Shuffle = 1019, ItemId_Command_Mulligan = 1019,
ItemId_Command_Mulligan = 1020, ItemId_Command_RollDie = 1020,
ItemId_Command_RollDie = 1021, ItemId_Command_DrawCards = 1021,
ItemId_Command_DrawCards = 1022, ItemId_Command_UndoDraw = 1022,
ItemId_Command_UndoDraw = 1023, ItemId_Command_FlipCard = 1023,
ItemId_Command_FlipCard = 1024, ItemId_Command_AttachCard = 1024,
ItemId_Command_AttachCard = 1025, ItemId_Command_CreateToken = 1025,
ItemId_Command_CreateToken = 1026, ItemId_Command_CreateArrow = 1026,
ItemId_Command_CreateArrow = 1027, ItemId_Command_DeleteArrow = 1027,
ItemId_Command_DeleteArrow = 1028, ItemId_Command_SetCardAttr = 1028,
ItemId_Command_SetCardAttr = 1029, ItemId_Command_SetCardCounter = 1029,
ItemId_Command_SetCardCounter = 1030, ItemId_Command_IncCardCounter = 1030,
ItemId_Command_IncCardCounter = 1031, ItemId_Command_ReadyStart = 1031,
ItemId_Command_ReadyStart = 1032, ItemId_Command_Concede = 1032,
ItemId_Command_Concede = 1033, ItemId_Command_IncCounter = 1033,
ItemId_Command_IncCounter = 1034, ItemId_Command_CreateCounter = 1034,
ItemId_Command_CreateCounter = 1035, ItemId_Command_SetCounter = 1035,
ItemId_Command_SetCounter = 1036, ItemId_Command_DelCounter = 1036,
ItemId_Command_DelCounter = 1037, ItemId_Command_NextTurn = 1037,
ItemId_Command_NextTurn = 1038, ItemId_Command_SetActivePhase = 1038,
ItemId_Command_SetActivePhase = 1039, ItemId_Command_DumpZone = 1039,
ItemId_Command_DumpZone = 1040, ItemId_Command_StopDumpZone = 1040,
ItemId_Command_StopDumpZone = 1041, ItemId_Command_RevealCards = 1041,
ItemId_Command_RevealCards = 1042, ItemId_Event_Say = 1042,
ItemId_Event_Say = 1043, ItemId_Event_Leave = 1043,
ItemId_Event_Leave = 1044, ItemId_Event_GameClosed = 1044,
ItemId_Event_GameClosed = 1045, ItemId_Event_Shuffle = 1045,
ItemId_Event_Shuffle = 1046, ItemId_Event_RollDie = 1046,
ItemId_Event_RollDie = 1047, ItemId_Event_MoveCard = 1047,
ItemId_Event_MoveCard = 1048, ItemId_Event_FlipCard = 1048,
ItemId_Event_FlipCard = 1049, ItemId_Event_DestroyCard = 1049,
ItemId_Event_DestroyCard = 1050, ItemId_Event_AttachCard = 1050,
ItemId_Event_AttachCard = 1051, ItemId_Event_CreateToken = 1051,
ItemId_Event_CreateToken = 1052, ItemId_Event_DeleteArrow = 1052,
ItemId_Event_DeleteArrow = 1053, ItemId_Event_SetCardAttr = 1053,
ItemId_Event_SetCardAttr = 1054, ItemId_Event_SetCardCounter = 1054,
ItemId_Event_SetCardCounter = 1055, ItemId_Event_SetCounter = 1055,
ItemId_Event_SetCounter = 1056, ItemId_Event_DelCounter = 1056,
ItemId_Event_DelCounter = 1057, ItemId_Event_SetActivePlayer = 1057,
ItemId_Event_SetActivePlayer = 1058, ItemId_Event_SetActivePhase = 1058,
ItemId_Event_SetActivePhase = 1059, ItemId_Event_DumpZone = 1059,
ItemId_Event_DumpZone = 1060, ItemId_Event_StopDumpZone = 1060,
ItemId_Event_StopDumpZone = 1061, ItemId_Event_ServerMessage = 1061,
ItemId_Event_ServerMessage = 1062, ItemId_Event_Message = 1062,
ItemId_Event_Message = 1063, ItemId_Event_GameJoined = 1063,
ItemId_Event_GameJoined = 1064, ItemId_Event_UserLeft = 1064,
ItemId_Event_UserLeft = 1065, ItemId_Event_LeaveRoom = 1065,
ItemId_Event_LeaveRoom = 1066, ItemId_Event_RoomSay = 1066,
ItemId_Event_RoomSay = 1067, ItemId_Context_ReadyStart = 1067,
ItemId_Context_ReadyStart = 1068, ItemId_Context_Concede = 1068,
ItemId_Context_Concede = 1069, ItemId_Context_DeckSelect = 1069,
ItemId_Context_DeckSelect = 1070, ItemId_Context_UndoDraw = 1070,
ItemId_Context_UndoDraw = 1071, ItemId_Command_UpdateServerMessage = 1071,
ItemId_Command_UpdateServerMessage = 1072, ItemId_Other = 1072
ItemId_Other = 1073
}; };

View file

@ -69,17 +69,6 @@ Command_RoomSay::Command_RoomSay(int _roomId, const QString &_message)
{ {
insertItem(new SerializableItem_String("message", _message)); insertItem(new SerializableItem_String("message", _message));
} }
Command_CreateGame::Command_CreateGame(int _roomId, const QString &_description, const QString &_password, int _maxPlayers, bool _spectatorsAllowed, bool _spectatorsNeedPassword, bool _spectatorsCanTalk, bool _spectatorsSeeEverything)
: RoomCommand("create_game", _roomId)
{
insertItem(new SerializableItem_String("description", _description));
insertItem(new SerializableItem_String("password", _password));
insertItem(new SerializableItem_Int("max_players", _maxPlayers));
insertItem(new SerializableItem_Bool("spectators_allowed", _spectatorsAllowed));
insertItem(new SerializableItem_Bool("spectators_need_password", _spectatorsNeedPassword));
insertItem(new SerializableItem_Bool("spectators_can_talk", _spectatorsCanTalk));
insertItem(new SerializableItem_Bool("spectators_see_everything", _spectatorsSeeEverything));
}
Command_JoinGame::Command_JoinGame(int _roomId, int _gameId, const QString &_password, bool _spectator) Command_JoinGame::Command_JoinGame(int _roomId, int _gameId, const QString &_password, bool _spectator)
: RoomCommand("join_game", _roomId) : RoomCommand("join_game", _roomId)
{ {
@ -453,7 +442,6 @@ void ProtocolItem::initializeHashAuto()
itemNameHash.insert("cmdjoin_room", Command_JoinRoom::newItem); itemNameHash.insert("cmdjoin_room", Command_JoinRoom::newItem);
itemNameHash.insert("cmdleave_room", Command_LeaveRoom::newItem); itemNameHash.insert("cmdleave_room", Command_LeaveRoom::newItem);
itemNameHash.insert("cmdroom_say", Command_RoomSay::newItem); itemNameHash.insert("cmdroom_say", Command_RoomSay::newItem);
itemNameHash.insert("cmdcreate_game", Command_CreateGame::newItem);
itemNameHash.insert("cmdjoin_game", Command_JoinGame::newItem); itemNameHash.insert("cmdjoin_game", Command_JoinGame::newItem);
itemNameHash.insert("cmdleave_game", Command_LeaveGame::newItem); itemNameHash.insert("cmdleave_game", Command_LeaveGame::newItem);
itemNameHash.insert("cmdsay", Command_Say::newItem); itemNameHash.insert("cmdsay", Command_Say::newItem);

View file

@ -12,7 +12,6 @@
0:join_room:i,room_id 0:join_room:i,room_id
1:leave_room 1:leave_room
1:room_say:s,message 1:room_say:s,message
1:create_game:s,description:s,password:i,max_players:b,spectators_allowed:b,spectators_need_password:b,spectators_can_talk:b,spectators_see_everything
1:join_game:i,game_id:s,password:b,spectator 1:join_game:i,game_id:s,password:b,spectator
2:leave_game 2:leave_game
2:say:s,message 2:say:s,message

View file

@ -113,20 +113,6 @@ public:
static SerializableItem *newItem() { return new Command_RoomSay; } static SerializableItem *newItem() { return new Command_RoomSay; }
int getItemId() const { return ItemId_Command_RoomSay; } int getItemId() const { return ItemId_Command_RoomSay; }
}; };
class Command_CreateGame : public RoomCommand {
Q_OBJECT
public:
Command_CreateGame(int _roomId = -1, const QString &_description = QString(), const QString &_password = QString(), int _maxPlayers = -1, bool _spectatorsAllowed = false, bool _spectatorsNeedPassword = false, bool _spectatorsCanTalk = false, bool _spectatorsSeeEverything = false);
QString getDescription() const { return static_cast<SerializableItem_String *>(itemMap.value("description"))->getData(); };
QString getPassword() const { return static_cast<SerializableItem_String *>(itemMap.value("password"))->getData(); };
int getMaxPlayers() const { return static_cast<SerializableItem_Int *>(itemMap.value("max_players"))->getData(); };
bool getSpectatorsAllowed() const { return static_cast<SerializableItem_Bool *>(itemMap.value("spectators_allowed"))->getData(); };
bool getSpectatorsNeedPassword() const { return static_cast<SerializableItem_Bool *>(itemMap.value("spectators_need_password"))->getData(); };
bool getSpectatorsCanTalk() const { return static_cast<SerializableItem_Bool *>(itemMap.value("spectators_can_talk"))->getData(); };
bool getSpectatorsSeeEverything() const { return static_cast<SerializableItem_Bool *>(itemMap.value("spectators_see_everything"))->getData(); };
static SerializableItem *newItem() { return new Command_CreateGame; }
int getItemId() const { return ItemId_Command_CreateGame; }
};
class Command_JoinGame : public RoomCommand { class Command_JoinGame : public RoomCommand {
Q_OBJECT Q_OBJECT
public: public:

View file

@ -28,8 +28,8 @@
#include <QTimer> #include <QTimer>
#include <QDebug> #include <QDebug>
Server_Game::Server_Game(Server_ProtocolHandler *_creator, int _gameId, const QString &_description, const QString &_password, int _maxPlayers, bool _spectatorsAllowed, bool _spectatorsNeedPassword, bool _spectatorsCanTalk, bool _spectatorsSeeEverything, Server_Room *parent) Server_Game::Server_Game(Server_ProtocolHandler *_creator, int _gameId, const QString &_description, const QString &_password, int _maxPlayers, const QList<int> &_gameTypes, bool _spectatorsAllowed, bool _spectatorsNeedPassword, bool _spectatorsCanTalk, bool _spectatorsSeeEverything, Server_Room *parent)
: QObject(parent), creatorInfo(new ServerInfo_User(_creator->getUserInfo())), gameStarted(false), gameId(_gameId), description(_description), password(_password), maxPlayers(_maxPlayers), activePlayer(-1), activePhase(-1), spectatorsAllowed(_spectatorsAllowed), spectatorsNeedPassword(_spectatorsNeedPassword), spectatorsCanTalk(_spectatorsCanTalk), spectatorsSeeEverything(_spectatorsSeeEverything), inactivityCounter(0), secondsElapsed(0) : QObject(parent), creatorInfo(new ServerInfo_User(_creator->getUserInfo())), gameStarted(false), gameId(_gameId), description(_description), password(_password), maxPlayers(_maxPlayers), gameTypes(_gameTypes), activePlayer(-1), activePhase(-1), spectatorsAllowed(_spectatorsAllowed), spectatorsNeedPassword(_spectatorsNeedPassword), spectatorsCanTalk(_spectatorsCanTalk), spectatorsSeeEverything(_spectatorsSeeEverything), inactivityCounter(0), secondsElapsed(0)
{ {
addPlayer(_creator, false, false); addPlayer(_creator, false, false);
@ -399,18 +399,25 @@ ServerInfo_Game *Server_Game::getInfo() const
{ {
if (players.isEmpty()) if (players.isEmpty())
// Game is closing // Game is closing
return new ServerInfo_Game(getGameId(), QString(), false, 0, getMaxPlayers(), 0, false, 0); return new ServerInfo_Game(getGameId(), QString(), false, 0, getMaxPlayers(), QList<GameTypeId *>(), 0, false, 0);
else else {
// Game is open // Game is open
QList<GameTypeId *> gameTypeList;
for (int i = 0; i < gameTypes.size(); ++i)
gameTypeList.append(new GameTypeId(gameTypes[i]));
return new ServerInfo_Game( return new ServerInfo_Game(
getGameId(), getGameId(),
getDescription(), getDescription(),
!getPassword().isEmpty(), !getPassword().isEmpty(),
getPlayerCount(), getPlayerCount(),
getMaxPlayers(), getMaxPlayers(),
gameTypeList,
new ServerInfo_User(getCreatorInfo(), false), new ServerInfo_User(getCreatorInfo(), false),
getSpectatorsAllowed(), getSpectatorsAllowed(),
getSpectatorsNeedPassword(), getSpectatorsNeedPassword(),
getSpectatorCount() getSpectatorCount()
); );
}
} }

View file

@ -40,6 +40,7 @@ private:
QString description; QString description;
QString password; QString password;
int maxPlayers; int maxPlayers;
QList<int> gameTypes;
int activePlayer, activePhase; int activePlayer, activePhase;
bool spectatorsAllowed; bool spectatorsAllowed;
bool spectatorsNeedPassword; bool spectatorsNeedPassword;
@ -53,7 +54,7 @@ signals:
private slots: private slots:
void pingClockTimeout(); void pingClockTimeout();
public: public:
Server_Game(Server_ProtocolHandler *_creator, int _gameId, const QString &_description, const QString &_password, int _maxPlayers, bool _spectatorsAllowed, bool _spectatorsNeedPassword, bool _spectatorsCanTalk, bool _spectatorsSeeEverything, Server_Room *parent); Server_Game(Server_ProtocolHandler *_creator, int _gameId, const QString &_description, const QString &_password, int _maxPlayers, const QList<int> &_gameTypes, bool _spectatorsAllowed, bool _spectatorsNeedPassword, bool _spectatorsCanTalk, bool _spectatorsSeeEverything, Server_Room *parent);
~Server_Game(); ~Server_Game();
ServerInfo_Game *getInfo() const; ServerInfo_Game *getInfo() const;
ServerInfo_User *getCreatorInfo() const { return creatorInfo; } ServerInfo_User *getCreatorInfo() const { return creatorInfo; }

View file

@ -356,7 +356,12 @@ ResponseCode Server_ProtocolHandler::cmdCreateGame(Command_CreateGame *cmd, Comm
if (authState == PasswordWrong) if (authState == PasswordWrong)
return RespLoginNeeded; return RespLoginNeeded;
Server_Game *game = room->createGame(cmd->getDescription(), cmd->getPassword(), cmd->getMaxPlayers(), cmd->getSpectatorsAllowed(), cmd->getSpectatorsNeedPassword(), cmd->getSpectatorsCanTalk(), cmd->getSpectatorsSeeEverything(), this); QList<int> gameTypes;
QList<GameTypeId *> gameTypeList = cmd->getGameTypes();
for (int i = 0; i < gameTypeList.size(); ++i)
gameTypes.append(gameTypeList[i]->getData());
Server_Game *game = room->createGame(cmd->getDescription(), cmd->getPassword(), cmd->getMaxPlayers(), gameTypes, cmd->getSpectatorsAllowed(), cmd->getSpectatorsNeedPassword(), cmd->getSpectatorsCanTalk(), cmd->getSpectatorsSeeEverything(), this);
Server_Player *creator = game->getPlayers().values().first(); Server_Player *creator = game->getPlayers().values().first();
games.insert(game->getGameId(), QPair<Server_Game *, Server_Player *>(game, creator)); games.insert(game->getGameId(), QPair<Server_Game *, Server_Player *>(game, creator));

View file

@ -3,8 +3,8 @@
#include "server_game.h" #include "server_game.h"
#include <QDebug> #include <QDebug>
Server_Room::Server_Room(int _id, const QString &_name, const QString &_description, bool _autoJoin, const QString &_joinMessage, Server *parent) Server_Room::Server_Room(int _id, const QString &_name, const QString &_description, bool _autoJoin, const QString &_joinMessage, const QStringList &_gameTypes, Server *parent)
: QObject(parent), id(_id), name(_name), description(_description), autoJoin(_autoJoin), joinMessage(_joinMessage) : QObject(parent), id(_id), name(_name), description(_description), autoJoin(_autoJoin), joinMessage(_joinMessage), gameTypes(_gameTypes)
{ {
} }
@ -17,6 +17,7 @@ ServerInfo_Room *Server_Room::getInfo(bool complete) const
{ {
QList<ServerInfo_Game *> gameList; QList<ServerInfo_Game *> gameList;
QList<ServerInfo_User *> userList; QList<ServerInfo_User *> userList;
QList<ServerInfo_GameType *> gameTypeList;
if (complete) { if (complete) {
QMapIterator<int, Server_Game *> gameIterator(games); QMapIterator<int, Server_Game *> gameIterator(games);
while (gameIterator.hasNext()) while (gameIterator.hasNext())
@ -24,9 +25,12 @@ ServerInfo_Room *Server_Room::getInfo(bool complete) const
for (int i = 0; i < size(); ++i) for (int i = 0; i < size(); ++i)
userList.append(new ServerInfo_User(at(i)->getUserInfo(), false)); userList.append(new ServerInfo_User(at(i)->getUserInfo(), false));
for (int i = 0; i < gameTypes.size(); ++i)
gameTypeList.append(new ServerInfo_GameType(i, gameTypes[i]));
} }
return new ServerInfo_Room(id, name, description, games.size(), size(), autoJoin, gameList, userList); return new ServerInfo_Room(id, name, description, games.size(), size(), autoJoin, gameList, userList, gameTypeList);
} }
void Server_Room::addClient(Server_ProtocolHandler *client) void Server_Room::addClient(Server_ProtocolHandler *client)
@ -64,9 +68,9 @@ void Server_Room::broadcastGameListUpdate(Server_Game *game)
delete event; delete event;
} }
Server_Game *Server_Room::createGame(const QString &description, const QString &password, int maxPlayers, bool spectatorsAllowed, bool spectatorsNeedPassword, bool spectatorsCanTalk, bool spectatorsSeeEverything, Server_ProtocolHandler *creator) Server_Game *Server_Room::createGame(const QString &description, const QString &password, int maxPlayers, const QList<int> &gameTypes, bool spectatorsAllowed, bool spectatorsNeedPassword, bool spectatorsCanTalk, bool spectatorsSeeEverything, Server_ProtocolHandler *creator)
{ {
Server_Game *newGame = new Server_Game(creator, static_cast<Server *>(parent())->getNextGameId(), description, password, maxPlayers, spectatorsAllowed, spectatorsNeedPassword, spectatorsCanTalk, spectatorsSeeEverything, this); Server_Game *newGame = new Server_Game(creator, static_cast<Server *>(parent())->getNextGameId(), description, password, maxPlayers, gameTypes, spectatorsAllowed, spectatorsNeedPassword, spectatorsCanTalk, spectatorsSeeEverything, this);
games.insert(newGame->getGameId(), newGame); games.insert(newGame->getGameId(), newGame);
connect(newGame, SIGNAL(gameClosing()), this, SLOT(removeGame())); connect(newGame, SIGNAL(gameClosing()), this, SLOT(removeGame()));

View file

@ -25,11 +25,12 @@ private:
QString description; QString description;
bool autoJoin; bool autoJoin;
QString joinMessage; QString joinMessage;
QStringList gameTypes;
QMap<int, Server_Game *> games; QMap<int, Server_Game *> games;
private slots: private slots:
void removeGame(); void removeGame();
public: public:
Server_Room(int _id, const QString &_name, const QString &_description, bool _autoJoin, const QString &_joinMessage, Server *parent); Server_Room(int _id, const QString &_name, const QString &_description, bool _autoJoin, const QString &_joinMessage, const QStringList &_gameTypes, Server *parent);
int getId() const { return id; } int getId() const { return id; }
QString getName() const { return name; } QString getName() const { return name; }
QString getDescription() const { return description; } QString getDescription() const { return description; }
@ -43,7 +44,7 @@ public:
void removeClient(Server_ProtocolHandler *client); void removeClient(Server_ProtocolHandler *client);
void say(Server_ProtocolHandler *client, const QString &s); void say(Server_ProtocolHandler *client, const QString &s);
void broadcastGameListUpdate(Server_Game *game); void broadcastGameListUpdate(Server_Game *game);
Server_Game *createGame(const QString &description, const QString &password, int maxPlayers, bool spectatorsAllowed, bool spectatorsNeedPassword, bool spectatorsCanTalk, bool spectatorsSeeEverything, Server_ProtocolHandler *creator); Server_Game *createGame(const QString &description, const QString &password, int maxPlayers, const QList<int> &_gameTypes, bool spectatorsAllowed, bool spectatorsNeedPassword, bool spectatorsCanTalk, bool spectatorsSeeEverything, Server_ProtocolHandler *creator);
void sendRoomEvent(RoomEvent *event); void sendRoomEvent(RoomEvent *event);
}; };

View file

@ -19,6 +19,10 @@ size=1
1\description="Play anything here." 1\description="Play anything here."
1\autojoin=true 1\autojoin=true
1\joinmessage="This message is only here to show that rooms can have a join message." 1\joinmessage="This message is only here to show that rooms can have a join message."
1\game_types\size=3
1\game_types\1\name="GameType1"
1\game_types\2\name="GameType2"
1\game_types\3\name="GameType3"
[game] [game]
max_game_inactivity_time=120 max_game_inactivity_time=120

View file

@ -58,12 +58,22 @@ Servatrice::Servatrice(QObject *parent)
int size = settings->beginReadArray("rooms"); int size = settings->beginReadArray("rooms");
for (int i = 0; i < size; ++i) { for (int i = 0; i < size; ++i) {
settings->setArrayIndex(i); settings->setArrayIndex(i);
QStringList gameTypes;
int size2 = settings->beginReadArray("game_types");
for (int j = 0; j < size2; ++j) {
settings->setArrayIndex(j);
gameTypes.append(settings->value("name").toString());
}
settings->endArray();
Server_Room *newRoom = new Server_Room( Server_Room *newRoom = new Server_Room(
i, i,
settings->value("name").toString(), settings->value("name").toString(),
settings->value("description").toString(), settings->value("description").toString(),
settings->value("autojoin").toBool(), settings->value("autojoin").toBool(),
settings->value("joinmessage").toString(), settings->value("joinmessage").toString(),
gameTypes,
this this
); );
addRoom(newRoom); addRoom(newRoom);