added menu item: game->game information, issue #1 fixed

This commit is contained in:
Max-Wilhelm Bruker 2012-03-24 22:09:06 +01:00
parent 5ff1fd8ec6
commit 542fd2c5c8
12 changed files with 182 additions and 88 deletions

View file

@ -8,14 +8,15 @@
#include <QSpinBox> #include <QSpinBox>
#include <QGroupBox> #include <QGroupBox>
#include <QMessageBox> #include <QMessageBox>
#include <QSet>
#include "dlg_creategame.h" #include "dlg_creategame.h"
#include "tab_room.h" #include "tab_room.h"
#include "pending_command.h" #include "pending_command.h"
#include "pb/room_commands.pb.h" #include "pb/room_commands.pb.h"
#include "pb/serverinfo_game.pb.h"
DlgCreateGame::DlgCreateGame(TabRoom *_room, const QMap<int, QString> &_gameTypes, QWidget *parent) void DlgCreateGame::sharedCtor()
: QDialog(parent), room(_room), gameTypes(_gameTypes)
{ {
descriptionLabel = new QLabel(tr("&Description:")); descriptionLabel = new QLabel(tr("&Description:"));
descriptionEdit = new QLineEdit; descriptionEdit = new QLineEdit;
@ -98,13 +99,63 @@ DlgCreateGame::DlgCreateGame(TabRoom *_room, const QMap<int, QString> &_gameType
setLayout(mainLayout); setLayout(mainLayout);
setWindowTitle(tr("Create game"));
setFixedHeight(sizeHint().height()); setFixedHeight(sizeHint().height());
}
DlgCreateGame::DlgCreateGame(TabRoom *_room, const QMap<int, QString> &_gameTypes, QWidget *parent)
: QDialog(parent), room(_room), gameTypes(_gameTypes)
{
sharedCtor();
setWindowTitle(tr("Create game"));
connect(okButton, SIGNAL(clicked()), this, SLOT(actOK())); connect(okButton, SIGNAL(clicked()), this, SLOT(actOK()));
connect(cancelButton, SIGNAL(clicked()), this, SLOT(reject())); connect(cancelButton, SIGNAL(clicked()), this, SLOT(reject()));
} }
DlgCreateGame::DlgCreateGame(const ServerInfo_Game &gameInfo, const QMap<int, QString> &_gameTypes, QWidget *parent)
: QDialog(parent), room(0), gameTypes(_gameTypes)
{
sharedCtor();
descriptionEdit->setEnabled(false);
maxPlayersEdit->setEnabled(false);
passwordEdit->setEnabled(false);
onlyBuddiesCheckBox->setEnabled(false);
onlyRegisteredCheckBox->setEnabled(false);
spectatorsAllowedCheckBox->setEnabled(false);
spectatorsNeedPasswordCheckBox->setEnabled(false);
spectatorsCanTalkCheckBox->setEnabled(false);
spectatorsSeeEverythingCheckBox->setEnabled(false);
descriptionEdit->setText(QString::fromStdString(gameInfo.description()));
maxPlayersEdit->setValue(gameInfo.max_players());
onlyBuddiesCheckBox->setChecked(gameInfo.only_buddies());
onlyRegisteredCheckBox->setChecked(gameInfo.only_registered());
spectatorsAllowedCheckBox->setChecked(gameInfo.spectators_allowed());
spectatorsNeedPasswordCheckBox->setChecked(gameInfo.spectators_need_password());
spectatorsCanTalkCheckBox->setChecked(gameInfo.spectators_can_chat());
spectatorsSeeEverythingCheckBox->setChecked(gameInfo.spectators_omniscient());
QSet<int> types;
for (int i = 0; i < gameInfo.game_types_size(); ++i)
types.insert(gameInfo.game_types(i));
QMapIterator<int, QString> gameTypeIterator(gameTypes);
while (gameTypeIterator.hasNext()) {
gameTypeIterator.next();
QCheckBox *gameTypeCheckBox = gameTypeCheckBoxes.value(gameTypeIterator.key());
gameTypeCheckBox->setEnabled(false);
gameTypeCheckBox->setChecked(types.contains(gameTypeIterator.key()));
}
setWindowTitle(tr("Game information"));
okButton->setAutoDefault(true);
cancelButton->hide();
connect(okButton, SIGNAL(clicked()), this, SLOT(accept()));
}
void DlgCreateGame::actOK() void DlgCreateGame::actOK()
{ {
Command_CreateGame cmd; Command_CreateGame cmd;

View file

@ -13,10 +13,13 @@ class QGroupBox;
class QSpinBox; class QSpinBox;
class TabRoom; class TabRoom;
class ServerInfo_Game;
class DlgCreateGame : public QDialog { class DlgCreateGame : public QDialog {
Q_OBJECT Q_OBJECT
public: public:
DlgCreateGame(TabRoom *_room, const QMap<int, QString> &_gameTypes, QWidget *parent = 0); DlgCreateGame(TabRoom *_room, const QMap<int, QString> &_gameTypes, QWidget *parent = 0);
DlgCreateGame(const ServerInfo_Game &game, const QMap<int, QString> &_gameTypes, QWidget *parent = 0);
private slots: private slots:
void actOK(); void actOK();
void checkResponse(Response::ResponseCode response); void checkResponse(Response::ResponseCode response);
@ -33,6 +36,8 @@ private:
QCheckBox *onlyBuddiesCheckBox, *onlyRegisteredCheckBox; QCheckBox *onlyBuddiesCheckBox, *onlyRegisteredCheckBox;
QCheckBox *spectatorsAllowedCheckBox, *spectatorsNeedPasswordCheckBox, *spectatorsCanTalkCheckBox, *spectatorsSeeEverythingCheckBox; QCheckBox *spectatorsAllowedCheckBox, *spectatorsNeedPasswordCheckBox, *spectatorsCanTalkCheckBox, *spectatorsSeeEverythingCheckBox;
QPushButton *okButton, *cancelButton; QPushButton *okButton, *cancelButton;
void sharedCtor();
}; };
#endif #endif

View file

@ -8,6 +8,7 @@
#include <QTimer> #include <QTimer>
#include <QToolButton> #include <QToolButton>
#include "dlg_creategame.h"
#include "tab_game.h" #include "tab_game.h"
#include "tab_supervisor.h" #include "tab_supervisor.h"
#include "cardinfowidget.h" #include "cardinfowidget.h"
@ -204,10 +205,7 @@ TabGame::TabGame(GameReplay *_replay)
hostId(-1), hostId(-1),
localPlayerId(-1), localPlayerId(-1),
spectator(true), spectator(true),
spectatorsCanTalk(false),
spectatorsSeeEverything(true),
gameStateKnown(false), gameStateKnown(false),
started(false),
resuming(false), resuming(false),
currentPhase(-1), currentPhase(-1),
activeCard(0), activeCard(0),
@ -216,8 +214,8 @@ TabGame::TabGame(GameReplay *_replay)
{ {
setAttribute(Qt::WA_DeleteOnClose); setAttribute(Qt::WA_DeleteOnClose);
gameId = replay->game_info().game_id(); gameInfo.CopyFrom(replay->game_info());
gameDescription = QString::fromStdString(replay->game_info().description()); gameInfo.set_spectators_omniscient(true);
// Create list: event number -> time [ms] // Create list: event number -> time [ms]
// Distribute simultaneous events evenly across 1 second. // Distribute simultaneous events evenly across 1 second.
@ -325,6 +323,7 @@ TabGame::TabGame(GameReplay *_replay)
aNextPhase = 0; aNextPhase = 0;
aNextTurn = 0; aNextTurn = 0;
aRemoveLocalArrows = 0; aRemoveLocalArrows = 0;
aGameInfo = 0;
aConcede = 0; aConcede = 0;
aLeaveGame = 0; aLeaveGame = 0;
aCloseReplay = new QAction(this); aCloseReplay = new QAction(this);
@ -339,26 +338,25 @@ TabGame::TabGame(GameReplay *_replay)
splitter->restoreState(settingsCache->getTabGameSplitterSizes()); splitter->restoreState(settingsCache->getTabGameSplitterSizes());
messageLog->logReplayStarted(gameId); messageLog->logReplayStarted(gameInfo.game_id());
} }
TabGame::TabGame(TabSupervisor *_tabSupervisor, QList<AbstractClient *> &_clients, const Event_GameJoined &event) TabGame::TabGame(TabSupervisor *_tabSupervisor, QList<AbstractClient *> &_clients, const Event_GameJoined &event, const QMap<int, QString> &_roomGameTypes)
: Tab(_tabSupervisor), : Tab(_tabSupervisor),
clients(_clients), clients(_clients),
gameId(event.game_id()), gameInfo(event.game_info()),
gameDescription(QString::fromStdString(event.game_description())), roomGameTypes(_roomGameTypes),
hostId(event.host_id()), hostId(event.host_id()),
localPlayerId(event.player_id()), localPlayerId(event.player_id()),
spectator(event.spectator()), spectator(event.spectator()),
spectatorsCanTalk(event.spectators_can_talk()),
spectatorsSeeEverything(event.spectators_see_everything()),
gameStateKnown(true), gameStateKnown(true),
started(false),
resuming(event.resuming()), resuming(event.resuming()),
currentPhase(-1), currentPhase(-1),
activeCard(0), activeCard(0),
replay(0) replay(0)
{ {
gameInfo.set_started(false);
gameTimer = new QTimer(this); gameTimer = new QTimer(this);
gameTimer->setInterval(1000); gameTimer->setInterval(1000);
connect(gameTimer, SIGNAL(timeout()), this, SLOT(incrementGameTime())); connect(gameTimer, SIGNAL(timeout()), this, SLOT(incrementGameTime()));
@ -411,7 +409,7 @@ TabGame::TabGame(TabSupervisor *_tabSupervisor, QList<AbstractClient *> &_client
mainLayout->addLayout(deckViewContainerLayout, 10); mainLayout->addLayout(deckViewContainerLayout, 10);
mainLayout->addWidget(splitter); mainLayout->addWidget(splitter);
if (spectator && !spectatorsCanTalk && tabSupervisor->getAdminLocked()) { if (spectator && !gameInfo.spectators_can_chat() && tabSupervisor->getAdminLocked()) {
sayLabel->hide(); sayLabel->hide();
sayEdit->hide(); sayEdit->hide();
} }
@ -425,6 +423,8 @@ TabGame::TabGame(TabSupervisor *_tabSupervisor, QList<AbstractClient *> &_client
connect(aNextTurn, SIGNAL(triggered()), this, SLOT(actNextTurn())); connect(aNextTurn, SIGNAL(triggered()), this, SLOT(actNextTurn()));
aRemoveLocalArrows = new QAction(this); aRemoveLocalArrows = new QAction(this);
connect(aRemoveLocalArrows, SIGNAL(triggered()), this, SLOT(actRemoveLocalArrows())); connect(aRemoveLocalArrows, SIGNAL(triggered()), this, SLOT(actRemoveLocalArrows()));
aGameInfo = new QAction(this);
connect(aGameInfo, SIGNAL(triggered()), this, SLOT(actGameInfo()));
aConcede = new QAction(this); aConcede = new QAction(this);
connect(aConcede, SIGNAL(triggered()), this, SLOT(actConcede())); connect(aConcede, SIGNAL(triggered()), this, SLOT(actConcede()));
aLeaveGame = new QAction(this); aLeaveGame = new QAction(this);
@ -457,6 +457,7 @@ TabGame::TabGame(TabSupervisor *_tabSupervisor, QList<AbstractClient *> &_client
tabMenu->addSeparator(); tabMenu->addSeparator();
tabMenu->addAction(aRemoveLocalArrows); tabMenu->addAction(aRemoveLocalArrows);
tabMenu->addSeparator(); tabMenu->addSeparator();
tabMenu->addAction(aGameInfo);
tabMenu->addAction(aConcede); tabMenu->addAction(aConcede);
tabMenu->addAction(aLeaveGame); tabMenu->addAction(aLeaveGame);
@ -465,7 +466,7 @@ TabGame::TabGame(TabSupervisor *_tabSupervisor, QList<AbstractClient *> &_client
splitter->restoreState(settingsCache->getTabGameSplitterSizes()); splitter->restoreState(settingsCache->getTabGameSplitterSizes());
messageLog->logGameJoined(gameId); messageLog->logGameJoined(gameInfo.game_id());
} }
TabGame::~TabGame() TabGame::~TabGame()
@ -504,6 +505,8 @@ void TabGame::retranslateUi()
aRemoveLocalArrows->setText(tr("&Remove all local arrows")); aRemoveLocalArrows->setText(tr("&Remove all local arrows"));
aRemoveLocalArrows->setShortcut(tr("Ctrl+R")); aRemoveLocalArrows->setShortcut(tr("Ctrl+R"));
} }
if (aGameInfo)
aGameInfo->setText(tr("Game &information"));
if (aConcede) { if (aConcede) {
aConcede->setText(tr("&Concede")); aConcede->setText(tr("&Concede"));
aConcede->setShortcut(tr("F2")); aConcede->setShortcut(tr("F2"));
@ -607,11 +610,17 @@ void TabGame::incrementGameTime()
void TabGame::adminLockChanged(bool lock) void TabGame::adminLockChanged(bool lock)
{ {
bool v = !(spectator && !spectatorsCanTalk && lock); bool v = !(spectator && !gameInfo.spectators_can_chat() && lock);
sayLabel->setVisible(v); sayLabel->setVisible(v);
sayEdit->setVisible(v); sayEdit->setVisible(v);
} }
void TabGame::actGameInfo()
{
DlgCreateGame dlg(gameInfo, roomGameTypes);
dlg.exec();
}
void TabGame::actConcede() void TabGame::actConcede()
{ {
if (QMessageBox::question(this, tr("Concede"), tr("Are you sure you want to concede this game?"), QMessageBox::Yes | QMessageBox::No, QMessageBox::No) != QMessageBox::Yes) if (QMessageBox::question(this, tr("Concede"), tr("Are you sure you want to concede this game?"), QMessageBox::Yes | QMessageBox::No, QMessageBox::No) != QMessageBox::Yes)
@ -782,7 +791,7 @@ void TabGame::sendGameCommand(const google::protobuf::Message &command, int play
PendingCommand *TabGame::prepareGameCommand(const ::google::protobuf::Message &cmd) PendingCommand *TabGame::prepareGameCommand(const ::google::protobuf::Message &cmd)
{ {
CommandContainer cont; CommandContainer cont;
cont.set_game_id(gameId); cont.set_game_id(gameInfo.game_id());
GameCommand *c = cont.add_game_command(); GameCommand *c = cont.add_game_command();
c->GetReflection()->MutableMessage(c, cmd.GetDescriptor()->FindExtensionByName("ext"))->CopyFrom(cmd); c->GetReflection()->MutableMessage(c, cmd.GetDescriptor()->FindExtensionByName("ext"))->CopyFrom(cmd);
return new PendingCommand(cont); return new PendingCommand(cont);
@ -791,7 +800,7 @@ PendingCommand *TabGame::prepareGameCommand(const ::google::protobuf::Message &c
PendingCommand *TabGame::prepareGameCommand(const QList< const ::google::protobuf::Message * > &cmdList) PendingCommand *TabGame::prepareGameCommand(const QList< const ::google::protobuf::Message * > &cmdList)
{ {
CommandContainer cont; CommandContainer cont;
cont.set_game_id(gameId); cont.set_game_id(gameInfo.game_id());
for (int i = 0; i < cmdList.size(); ++i) { for (int i = 0; i < cmdList.size(); ++i) {
GameCommand *c = cont.add_game_command(); GameCommand *c = cont.add_game_command();
c->GetReflection()->MutableMessage(c, cmdList[i]->GetDescriptor()->FindExtensionByName("ext"))->CopyFrom(*cmdList[i]); c->GetReflection()->MutableMessage(c, cmdList[i]->GetDescriptor()->FindExtensionByName("ext"))->CopyFrom(*cmdList[i]);
@ -819,7 +828,7 @@ void TabGame::startGame(bool resuming)
} }
playerListWidget->setGameStarted(true, resuming); playerListWidget->setGameStarted(true, resuming);
started = true; gameInfo.set_started(true);
static_cast<GameScene *>(gameView->scene())->rearrange(); static_cast<GameScene *>(gameView->scene())->rearrange();
gameView->show(); gameView->show();
phasesToolbar->show(); phasesToolbar->show();
@ -839,7 +848,7 @@ void TabGame::stopGame()
playerListWidget->setActivePlayer(-1); playerListWidget->setActivePlayer(-1);
playerListWidget->setGameStarted(false, false); playerListWidget->setGameStarted(false, false);
started = false; gameInfo.set_started(false);
gameView->hide(); gameView->hide();
phasesToolbar->hide(); phasesToolbar->hide();
} }
@ -897,13 +906,13 @@ void TabGame::eventGameStateChanged(const Event_GameStateChanged &event, int /*e
secondsElapsed = event.seconds_elapsed(); secondsElapsed = event.seconds_elapsed();
if (event.game_started() && !started) { if (event.game_started() && !gameInfo.started()) {
startGame(!gameStateKnown); startGame(!gameStateKnown);
if (gameStateKnown) if (gameStateKnown)
messageLog->logGameStart(); messageLog->logGameStart();
setActivePlayer(event.active_player_id()); setActivePlayer(event.active_player_id());
setActivePhase(event.active_phase()); setActivePhase(event.active_phase());
} else if (!event.game_started() && started) { } else if (!event.game_started() && gameInfo.started()) {
stopGame(); stopGame();
scene->clearViews(); scene->clearViews();
} }
@ -1004,7 +1013,7 @@ void TabGame::eventGameHostChanged(const Event_GameHostChanged & /*event*/, int
void TabGame::eventGameClosed(const Event_GameClosed & /*event*/, int /*eventPlayerId*/, const GameEventContext & /*context*/) void TabGame::eventGameClosed(const Event_GameClosed & /*event*/, int /*eventPlayerId*/, const GameEventContext & /*context*/)
{ {
started = false; gameInfo.set_started(false);
messageLog->logGameClosed(); messageLog->logGameClosed();
emit userEvent(); emit userEvent();
} }
@ -1084,9 +1093,9 @@ CardItem *TabGame::getCard(int playerId, const QString &zoneName, int cardId) co
QString TabGame::getTabText() const QString TabGame::getTabText() const
{ {
if (replay) if (replay)
return tr("Replay %1: %2").arg(gameId).arg(gameDescription); return tr("Replay %1: %2").arg(gameInfo.game_id()).arg(QString::fromStdString(gameInfo.description()));
else else
return tr("Game %1: %2").arg(gameId).arg(gameDescription); return tr("Game %1: %2").arg(gameInfo.game_id()).arg(QString::fromStdString(gameInfo.description()));
} }
Player *TabGame::getActiveLocalPlayer() const Player *TabGame::getActiveLocalPlayer() const

View file

@ -4,8 +4,8 @@
#include <QMap> #include <QMap>
#include <QPushButton> #include <QPushButton>
#include "tab.h" #include "tab.h"
#include "pb/serverinfo_game.pb.h"
namespace google { namespace protobuf { class Message; } }
class AbstractClient; class AbstractClient;
class CardDatabase; class CardDatabase;
class GameView; class GameView;
@ -96,16 +96,14 @@ private:
QTimer *gameTimer; QTimer *gameTimer;
int secondsElapsed; int secondsElapsed;
QList<AbstractClient *> clients; QList<AbstractClient *> clients;
int gameId; ServerInfo_Game gameInfo;
QString gameDescription; QMap<int, QString> roomGameTypes;
int hostId; int hostId;
int localPlayerId; int localPlayerId;
bool spectator; bool spectator;
bool spectatorsCanTalk, spectatorsSeeEverything;
QMap<int, Player *> players; QMap<int, Player *> players;
QMap<int, QString> spectators; QMap<int, QString> spectators;
bool gameStateKnown; bool gameStateKnown;
bool started;
bool resuming; bool resuming;
QStringList phasesList; QStringList phasesList;
int currentPhase; int currentPhase;
@ -135,7 +133,7 @@ private:
ZoneViewLayout *zoneLayout; ZoneViewLayout *zoneLayout;
QAction *playersSeparator; QAction *playersSeparator;
QMenu *phasesMenu; QMenu *phasesMenu;
QAction *aConcede, *aLeaveGame, *aCloseReplay, *aNextPhase, *aNextTurn, *aRemoveLocalArrows; QAction *aGameInfo, *aConcede, *aLeaveGame, *aCloseReplay, *aNextPhase, *aNextTurn, *aRemoveLocalArrows;
QList<QAction *> phaseActions; QList<QAction *> phaseActions;
Player *addPlayer(int playerId, const ServerInfo_User &info); Player *addPlayer(int playerId, const ServerInfo_User &info);
@ -180,6 +178,7 @@ private slots:
void newCardAdded(AbstractCardItem *card); void newCardAdded(AbstractCardItem *card);
void updateCardMenu(AbstractCardItem *card); void updateCardMenu(AbstractCardItem *card);
void actGameInfo();
void actConcede(); void actConcede();
void actLeaveGame(); void actLeaveGame();
void actRemoveLocalArrows(); void actRemoveLocalArrows();
@ -188,7 +187,7 @@ private slots:
void actNextPhase(); void actNextPhase();
void actNextTurn(); void actNextTurn();
public: public:
TabGame(TabSupervisor *_tabSupervisor, QList<AbstractClient *> &_clients, const Event_GameJoined &event); TabGame(TabSupervisor *_tabSupervisor, QList<AbstractClient *> &_clients, const Event_GameJoined &event, const QMap<int, QString> &_roomGameTypes);
TabGame(GameReplay *replay); TabGame(GameReplay *replay);
~TabGame(); ~TabGame();
void retranslateUi(); void retranslateUi();
@ -196,11 +195,10 @@ public:
const QMap<int, Player *> &getPlayers() const { return players; } const QMap<int, Player *> &getPlayers() const { return players; }
CardItem *getCard(int playerId, const QString &zoneName, int cardId) const; CardItem *getCard(int playerId, const QString &zoneName, int cardId) const;
bool isHost() const { return hostId == localPlayerId; } bool isHost() const { return hostId == localPlayerId; }
int getGameId() const { return gameId; } int getGameId() const { return gameInfo.game_id(); }
QString getTabText() const; QString getTabText() const;
bool getSpectator() const { return spectator; } bool getSpectator() const { return spectator; }
bool getSpectatorsCanTalk() const { return spectatorsCanTalk; } bool getSpectatorsSeeEverything() const { return gameInfo.spectators_omniscient(); }
bool getSpectatorsSeeEverything() const { return spectatorsSeeEverything; }
Player *getActiveLocalPlayer() const; Player *getActiveLocalPlayer() const;
AbstractClient *getClientForPlayer(int playerId) const; AbstractClient *getClientForPlayer(int playerId) const;

View file

@ -250,27 +250,35 @@ void TabSupervisor::addCloseButtonToTab(Tab *tab, int tabIndex)
void TabSupervisor::gameJoined(const Event_GameJoined &event) void TabSupervisor::gameJoined(const Event_GameJoined &event)
{ {
TabGame *tab = new TabGame(this, QList<AbstractClient *>() << client, event); QMap<int, QString> roomGameTypes;
TabRoom *room = roomTabs.value(event.game_info().room_id());
if (room)
roomGameTypes = room->getGameTypes();
else
for (int i = 0; i < event.game_types_size(); ++i)
roomGameTypes.insert(event.game_types(i).game_type_id(), QString::fromStdString(event.game_types(i).description()));
TabGame *tab = new TabGame(this, QList<AbstractClient *>() << client, event, roomGameTypes);
connect(tab, SIGNAL(gameClosing(TabGame *)), this, SLOT(gameLeft(TabGame *))); connect(tab, SIGNAL(gameClosing(TabGame *)), this, SLOT(gameLeft(TabGame *)));
connect(tab, SIGNAL(openMessageDialog(const QString &, bool)), this, SLOT(addMessageTab(const QString &, bool))); connect(tab, SIGNAL(openMessageDialog(const QString &, bool)), this, SLOT(addMessageTab(const QString &, bool)));
int tabIndex = myAddTab(tab); int tabIndex = myAddTab(tab);
addCloseButtonToTab(tab, tabIndex); addCloseButtonToTab(tab, tabIndex);
gameTabs.insert(event.game_id(), tab); gameTabs.insert(event.game_info().game_id(), tab);
setCurrentWidget(tab); setCurrentWidget(tab);
} }
void TabSupervisor::localGameJoined(const Event_GameJoined &event) void TabSupervisor::localGameJoined(const Event_GameJoined &event)
{ {
TabGame *tab = new TabGame(this, localClients, event); TabGame *tab = new TabGame(this, localClients, event, QMap<int, QString>());
connect(tab, SIGNAL(gameClosing(TabGame *)), this, SLOT(gameLeft(TabGame *))); connect(tab, SIGNAL(gameClosing(TabGame *)), this, SLOT(gameLeft(TabGame *)));
int tabIndex = myAddTab(tab); int tabIndex = myAddTab(tab);
addCloseButtonToTab(tab, tabIndex); addCloseButtonToTab(tab, tabIndex);
gameTabs.insert(event.game_id(), tab); gameTabs.insert(event.game_info().game_id(), tab);
setCurrentWidget(tab); setCurrentWidget(tab);
for (int i = 1; i < localClients.size(); ++i) { for (int i = 1; i < localClients.size(); ++i) {
Command_JoinGame cmd; Command_JoinGame cmd;
cmd.set_game_id(event.game_id()); cmd.set_game_id(event.game_info().game_id());
localClients[i]->sendCommand(localClients[i]->prepareRoomCommand(cmd, 0)); localClients[i]->sendCommand(localClients[i]->prepareRoomCommand(cmd, 0));
} }
} }

View file

@ -1,16 +1,15 @@
import "session_event.proto"; import "session_event.proto";
import "serverinfo_game.proto";
import "serverinfo_gametype.proto";
message Event_GameJoined { message Event_GameJoined {
extend SessionEvent { extend SessionEvent {
optional Event_GameJoined ext = 1009; optional Event_GameJoined ext = 1009;
} }
optional sint32 room_id = 1; optional ServerInfo_Game game_info = 1;
optional sint32 game_id = 2; repeated ServerInfo_GameType game_types = 2;
optional string game_description = 3; optional sint32 host_id = 3;
optional sint32 host_id = 4; optional sint32 player_id = 4;
optional sint32 player_id = 5; optional bool spectator = 5;
optional bool spectator = 6; optional bool resuming = 6;
optional bool spectators_can_talk = 7;
optional bool spectators_see_everything = 8;
optional bool resuming = 9;
} }

View file

@ -1,20 +1,22 @@
import "serverinfo_user.proto"; import "serverinfo_user.proto";
message ServerInfo_Game { message ServerInfo_Game {
optional sint32 room_id = 1; optional sint32 server_id = 1 [default = -1];
optional sint32 game_id = 2; optional sint32 room_id = 2 [default = -1];
optional string description = 3; optional sint32 game_id = 3 [default = -1];
optional bool with_password = 4; optional string description = 4;
optional uint32 player_count = 5; optional bool with_password = 5;
optional uint32 max_players = 6; optional uint32 max_players = 6;
optional bool started = 7; repeated sint32 game_types = 7;
repeated sint32 game_types = 8; optional ServerInfo_User creator_info = 8;
optional ServerInfo_User creator_info = 9; optional bool only_buddies = 9;
optional bool only_buddies = 10; optional bool only_registered = 10;
optional bool only_registered = 11; optional bool spectators_allowed = 11;
optional bool spectators_allowed = 12; optional bool spectators_need_password = 12;
optional bool spectators_need_password = 13; optional bool spectators_can_chat = 13;
optional uint32 spectators_count = 14; optional bool spectators_omniscient = 14;
optional uint32 start_time = 15; optional uint32 player_count = 30;
optional sint32 server_id = 16 [default = -1]; optional uint32 spectators_count = 31;
optional bool started = 50;
optional uint32 start_time = 51;
} }

View file

@ -108,7 +108,7 @@ protected:
QMap<QString, Server_AbstractUserInterface *> externalUsers; QMap<QString, Server_AbstractUserInterface *> externalUsers;
QMap<int, Server_Room *> rooms; QMap<int, Server_Room *> rooms;
virtual qint64 startSession(const QString &userName, const QString &address) { return -1; } virtual qint64 startSession(const QString &userName, const QString &address) { return 0; }
virtual void endSession(qint64 sessionId) { } virtual void endSession(qint64 sessionId) { }
virtual bool userExists(const QString &user) { return false; } virtual bool userExists(const QString &user) { return false; }
virtual AuthenticationResult checkUserPassword(Server_ProtocolHandler *handler, const QString &user, const QString &password, QString &reason) { return UnknownUser; } virtual AuthenticationResult checkUserPassword(Server_ProtocolHandler *handler, const QString &user, const QString &password, QString &reason) { return UnknownUser; }

View file

@ -77,7 +77,7 @@ Server_Game::Server_Game(const ServerInfo_User &_creatorInfo, int _gameId, const
connect(this, SIGNAL(sigStartGameIfReady()), this, SLOT(doStartGameIfReady()), Qt::QueuedConnection); connect(this, SIGNAL(sigStartGameIfReady()), this, SLOT(doStartGameIfReady()), Qt::QueuedConnection);
currentReplay->mutable_game_info()->CopyFrom(getInfo()); getInfo(*currentReplay->mutable_game_info());
if (room->getServer()->getGameShouldPing()) { if (room->getServer()->getGameShouldPing()) {
pingClock = new QTimer(this); pingClock = new QTimer(this);
@ -271,7 +271,7 @@ void Server_Game::doStartGameIfReady()
replayList.append(currentReplay); replayList.append(currentReplay);
currentReplay = new GameReplay; currentReplay = new GameReplay;
currentReplay->set_replay_id(room->getServer()->getNextReplayId()); currentReplay->set_replay_id(room->getServer()->getNextReplayId());
currentReplay->mutable_game_info()->CopyFrom(getInfo()); getInfo(*currentReplay->mutable_game_info());
Event_GameStateChanged omniscientEvent; Event_GameStateChanged omniscientEvent;
QListIterator<ServerInfo_Player> omniscientGameStateIterator(getGameState(0, true, true)); QListIterator<ServerInfo_Player> omniscientGameStateIterator(getGameState(0, true, true));
@ -294,7 +294,10 @@ void Server_Game::doStartGameIfReady()
nextTurn(); nextTurn();
locker.unlock(); locker.unlock();
emit gameInfoChanged(getInfo());
ServerInfo_Game gameInfo;
getInfo(gameInfo);
emit gameInfoChanged(gameInfo);
} }
void Server_Game::startGameIfReady() void Server_Game::startGameIfReady()
@ -390,8 +393,11 @@ void Server_Game::addPlayer(Server_AbstractUserInterface *userInterface, Respons
sendGameEventContainer(prepareGameEvent(Event_GameHostChanged(), hostId)); sendGameEventContainer(prepareGameEvent(Event_GameHostChanged(), hostId));
} }
if (broadcastUpdate) if (broadcastUpdate) {
emit gameInfoChanged(getInfo()); ServerInfo_Game gameInfo;
getInfo(gameInfo);
emit gameInfoChanged(gameInfo);
}
if ((newPlayer->getUserInfo()->user_level() & ServerInfo_User::IsRegistered) && !spectator) if ((newPlayer->getUserInfo()->user_level() & ServerInfo_User::IsRegistered) && !spectator)
room->getServer()->addPersistentPlayer(playerName, room->getId(), gameId, newPlayer->getPlayerId()); room->getServer()->addPersistentPlayer(playerName, room->getId(), gameId, newPlayer->getPlayerId());
@ -439,7 +445,10 @@ void Server_Game::removePlayer(Server_Player *player)
if (gameStarted && playerActive) if (gameStarted && playerActive)
nextTurn(); nextTurn();
} }
emit gameInfoChanged(getInfo());
ServerInfo_Game gameInfo;
getInfo(gameInfo);
emit gameInfoChanged(gameInfo);
} }
void Server_Game::removeArrowsToPlayer(GameEventStorage &ges, Server_Player *player) void Server_Game::removeArrowsToPlayer(GameEventStorage &ges, Server_Player *player)
@ -672,15 +681,19 @@ QList<ServerInfo_Player> Server_Game::getGameState(Server_Player *playerWhosAski
void Server_Game::createGameJoinedEvent(Server_Player *player, ResponseContainer &rc, bool resuming) void Server_Game::createGameJoinedEvent(Server_Player *player, ResponseContainer &rc, bool resuming)
{ {
Event_GameJoined event1; Event_GameJoined event1;
event1.set_room_id(room->getId()); getInfo(*event1.mutable_game_info());
event1.set_game_id(gameId);
event1.set_game_description(description.toStdString());
event1.set_host_id(hostId); event1.set_host_id(hostId);
event1.set_player_id(player->getPlayerId()); event1.set_player_id(player->getPlayerId());
event1.set_spectator(player->getSpectator()); event1.set_spectator(player->getSpectator());
event1.set_spectators_can_talk(spectatorsCanTalk);
event1.set_spectators_see_everything(spectatorsSeeEverything);
event1.set_resuming(resuming); event1.set_resuming(resuming);
if (resuming) {
const QStringList &allGameTypes = room->getGameTypes();
for (int i = 0; i < allGameTypes.size(); ++i) {
ServerInfo_GameType *newGameType = event1.add_game_types();
newGameType->set_game_type_id(i);
newGameType->set_description(allGameTypes[i].toStdString());
}
}
rc.enqueuePostResponseItem(ServerMessage::SESSION_EVENT, Server_AbstractUserInterface::prepareSessionEvent(event1)); rc.enqueuePostResponseItem(ServerMessage::SESSION_EVENT, Server_AbstractUserInterface::prepareSessionEvent(event1));
Event_GameStateChanged event2; Event_GameStateChanged event2;
@ -728,11 +741,10 @@ GameEventContainer *Server_Game::prepareGameEvent(const ::google::protobuf::Mess
return cont; return cont;
} }
ServerInfo_Game Server_Game::getInfo() const void Server_Game::getInfo(ServerInfo_Game &result) const
{ {
QMutexLocker locker(&gameMutex); QMutexLocker locker(&gameMutex);
ServerInfo_Game result;
result.set_room_id(room->getId()); result.set_room_id(room->getId());
result.set_game_id(getGameId()); result.set_game_id(getGameId());
if (!players.isEmpty()) { if (!players.isEmpty()) {
@ -749,8 +761,9 @@ ServerInfo_Game Server_Game::getInfo() const
result.set_only_registered(onlyRegistered); result.set_only_registered(onlyRegistered);
result.set_spectators_allowed(getSpectatorsAllowed()); result.set_spectators_allowed(getSpectatorsAllowed());
result.set_spectators_need_password(getSpectatorsNeedPassword()); result.set_spectators_need_password(getSpectatorsNeedPassword());
result.set_spectators_can_chat(spectatorsCanTalk);
result.set_spectators_omniscient(spectatorsSeeEverything);
result.set_spectators_count(getSpectatorCount()); result.set_spectators_count(getSpectatorCount());
result.set_start_time(startTime.toTime_t()); result.set_start_time(startTime.toTime_t());
} }
return result;
} }

View file

@ -77,7 +77,7 @@ public:
Server_Game(const ServerInfo_User &_creatorInfo, int _gameId, const QString &_description, const QString &_password, int _maxPlayers, const QList<int> &_gameTypes, bool _onlyBuddies, bool _onlyRegistered, bool _spectatorsAllowed, bool _spectatorsNeedPassword, bool _spectatorsCanTalk, bool _spectatorsSeeEverything, Server_Room *parent); Server_Game(const ServerInfo_User &_creatorInfo, int _gameId, const QString &_description, const QString &_password, int _maxPlayers, const QList<int> &_gameTypes, bool _onlyBuddies, bool _onlyRegistered, bool _spectatorsAllowed, bool _spectatorsNeedPassword, bool _spectatorsCanTalk, bool _spectatorsSeeEverything, Server_Room *parent);
~Server_Game(); ~Server_Game();
Server_Room *getRoom() const { return room; } Server_Room *getRoom() const { return room; }
ServerInfo_Game getInfo() const; void getInfo(ServerInfo_Game &result) const;
int getHostId() const { return hostId; } int getHostId() const { return hostId; }
ServerInfo_User *getCreatorInfo() const { return creatorInfo; } ServerInfo_User *getCreatorInfo() const { return creatorInfo; }
bool getGameStarted() const { return gameStarted; } bool getGameStarted() const { return gameStarted; }

View file

@ -54,7 +54,7 @@ ServerInfo_Room Server_Room::getInfo(bool complete, bool showGameTypes, bool upd
if (complete) { if (complete) {
QMapIterator<int, Server_Game *> gameIterator(games); QMapIterator<int, Server_Game *> gameIterator(games);
while (gameIterator.hasNext()) while (gameIterator.hasNext())
result.add_game_list()->CopyFrom(gameIterator.next().value()->getInfo()); gameIterator.next().value()->getInfo(*result.add_game_list());
if (includeExternalData) { if (includeExternalData) {
QMapIterator<int, ServerInfo_Game> externalGameIterator(externalGames); QMapIterator<int, ServerInfo_Game> externalGameIterator(externalGames);
while (externalGameIterator.hasNext()) while (externalGameIterator.hasNext())
@ -231,9 +231,11 @@ void Server_Room::addGame(Server_Game *game)
game->gameMutex.lock(); game->gameMutex.lock();
games.insert(game->getGameId(), game); games.insert(game->getGameId(), game);
emit gameListChanged(game->getInfo()); ServerInfo_Game gameInfo;
game->getInfo(gameInfo);
game->gameMutex.unlock(); game->gameMutex.unlock();
emit gameListChanged(gameInfo);
emit roomInfoChanged(getInfo(false, false, true)); emit roomInfoChanged(getInfo(false, false, true));
} }
@ -243,7 +245,11 @@ void Server_Room::removeGame(Server_Game *game)
// called from ~Server_Game, which locks both mutexes anyway beforehand. // called from ~Server_Game, which locks both mutexes anyway beforehand.
disconnect(game, 0, this, 0); disconnect(game, 0, this, 0);
emit gameListChanged(game->getInfo());
ServerInfo_Game gameInfo;
game->getInfo(gameInfo);
emit gameListChanged(gameInfo);
games.remove(game->getGameId()); games.remove(game->getGameId());
emit roomInfoChanged(getInfo(false, false, true)); emit roomInfoChanged(getInfo(false, false, true));
@ -269,8 +275,11 @@ QList<ServerInfo_Game> Server_Room::getGamesOfUser(const QString &userName) cons
QMapIterator<int, Server_Game *> gamesIterator(games); QMapIterator<int, Server_Game *> gamesIterator(games);
while (gamesIterator.hasNext()) { while (gamesIterator.hasNext()) {
Server_Game *game = gamesIterator.next().value(); Server_Game *game = gamesIterator.next().value();
if (game->containsUser(userName)) if (game->containsUser(userName)) {
result.append(game->getInfo()); ServerInfo_Game gameInfo;
game->getInfo(gameInfo);
result.append(gameInfo);
}
} }
return result; return result;
} }

View file

@ -339,7 +339,7 @@ void IslInterface::processSessionEvent(const SessionEvent &event, qint64 session
break; break;
} }
const Event_GameJoined &gameJoined = event.GetExtension(Event_GameJoined::ext); const Event_GameJoined &gameJoined = event.GetExtension(Event_GameJoined::ext);
client->playerAddedToGame(gameJoined.game_id(), gameJoined.room_id(), gameJoined.player_id()); client->playerAddedToGame(gameJoined.game_info().game_id(), gameJoined.game_info().room_id(), gameJoined.player_id());
client->sendProtocolItem(event); client->sendProtocolItem(event);
break; break;
} }