Merge pull request #1347 from woogerboy21/fix_clientid_localgame
Fix local game not starting properly.
This commit is contained in:
commit
644ea0482f
3 changed files with 29 additions and 28 deletions
|
@ -3,13 +3,14 @@
|
||||||
|
|
||||||
#include "pb/session_commands.pb.h"
|
#include "pb/session_commands.pb.h"
|
||||||
|
|
||||||
LocalClient::LocalClient(LocalServerInterface *_lsi, const QString &_playerName, QObject *parent)
|
LocalClient::LocalClient(LocalServerInterface *_lsi, const QString &_playerName, const QString &_clientId, QObject *parent)
|
||||||
: AbstractClient(parent), lsi(_lsi)
|
: AbstractClient(parent), lsi(_lsi)
|
||||||
{
|
{
|
||||||
connect(lsi, SIGNAL(itemToClient(const ServerMessage &)), this, SLOT(itemFromServer(const ServerMessage &)));
|
connect(lsi, SIGNAL(itemToClient(const ServerMessage &)), this, SLOT(itemFromServer(const ServerMessage &)));
|
||||||
|
|
||||||
Command_Login loginCmd;
|
Command_Login loginCmd;
|
||||||
loginCmd.set_user_name(_playerName.toStdString());
|
loginCmd.set_user_name(_playerName.toStdString());
|
||||||
|
loginCmd.set_clientid(_clientId.toStdString());
|
||||||
sendCommand(prepareSessionCommand(loginCmd));
|
sendCommand(prepareSessionCommand(loginCmd));
|
||||||
|
|
||||||
Command_JoinRoom joinCmd;
|
Command_JoinRoom joinCmd;
|
||||||
|
|
|
@ -10,7 +10,7 @@ class LocalClient : public AbstractClient {
|
||||||
private:
|
private:
|
||||||
LocalServerInterface *lsi;
|
LocalServerInterface *lsi;
|
||||||
public:
|
public:
|
||||||
LocalClient(LocalServerInterface *_lsi, const QString &_playerName, QObject *parent = 0);
|
LocalClient(LocalServerInterface *_lsi, const QString &_playerName, const QString &_clientId, QObject *parent = 0);
|
||||||
~LocalClient();
|
~LocalClient();
|
||||||
|
|
||||||
void sendCommandContainer(const CommandContainer &cont);
|
void sendCommandContainer(const CommandContainer &cont);
|
||||||
|
|
|
@ -31,7 +31,7 @@
|
||||||
#include <QSystemTrayIcon>
|
#include <QSystemTrayIcon>
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#if QT_VERSION < 0x050000
|
#if QT_VERSION < 0x050000
|
||||||
// for Qt::escape()
|
// for Qt::escape()
|
||||||
#include <QtGui/qtextdocument.h>
|
#include <QtGui/qtextdocument.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -182,24 +182,24 @@ void MainWindow::actSinglePlayer()
|
||||||
int numberPlayers = QInputDialog::getInt(this, tr("Number of players"), tr("Please enter the number of players."), 1, 1, 8, 1, &ok);
|
int numberPlayers = QInputDialog::getInt(this, tr("Number of players"), tr("Please enter the number of players."), 1, 1, 8, 1, &ok);
|
||||||
if (!ok)
|
if (!ok)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
aConnect->setEnabled(false);
|
aConnect->setEnabled(false);
|
||||||
aRegister->setEnabled(false);
|
aRegister->setEnabled(false);
|
||||||
aSinglePlayer->setEnabled(false);
|
aSinglePlayer->setEnabled(false);
|
||||||
|
|
||||||
localServer = new LocalServer(this);
|
localServer = new LocalServer(this);
|
||||||
LocalServerInterface *mainLsi = localServer->newConnection();
|
LocalServerInterface *mainLsi = localServer->newConnection();
|
||||||
LocalClient *mainClient = new LocalClient(mainLsi, tr("Player %1").arg(1), this);
|
LocalClient *mainClient = new LocalClient(mainLsi, tr("Player %1").arg(1), settingsCache->getClientID(), this);
|
||||||
QList<AbstractClient *> localClients;
|
QList<AbstractClient *> localClients;
|
||||||
localClients.append(mainClient);
|
localClients.append(mainClient);
|
||||||
|
|
||||||
for (int i = 0; i < numberPlayers - 1; ++i) {
|
for (int i = 0; i < numberPlayers - 1; ++i) {
|
||||||
LocalServerInterface *slaveLsi = localServer->newConnection();
|
LocalServerInterface *slaveLsi = localServer->newConnection();
|
||||||
LocalClient *slaveClient = new LocalClient(slaveLsi, tr("Player %1").arg(i + 2), this);
|
LocalClient *slaveClient = new LocalClient(slaveLsi, tr("Player %1").arg(i + 2), settingsCache->getClientID(), this);
|
||||||
localClients.append(slaveClient);
|
localClients.append(slaveClient);
|
||||||
}
|
}
|
||||||
tabSupervisor->startLocal(localClients);
|
tabSupervisor->startLocal(localClients);
|
||||||
|
|
||||||
Command_CreateGame createCommand;
|
Command_CreateGame createCommand;
|
||||||
createCommand.set_max_players(numberPlayers);
|
createCommand.set_max_players(numberPlayers);
|
||||||
mainClient->sendCommand(mainClient->prepareRoomCommand(createCommand, 0));
|
mainClient->sendCommand(mainClient->prepareRoomCommand(createCommand, 0));
|
||||||
|
@ -212,17 +212,17 @@ void MainWindow::actWatchReplay()
|
||||||
dlg.setNameFilters(QStringList() << QObject::tr("Cockatrice replays (*.cor)"));
|
dlg.setNameFilters(QStringList() << QObject::tr("Cockatrice replays (*.cor)"));
|
||||||
if (!dlg.exec())
|
if (!dlg.exec())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
QString fileName = dlg.selectedFiles().at(0);
|
QString fileName = dlg.selectedFiles().at(0);
|
||||||
QFile file(fileName);
|
QFile file(fileName);
|
||||||
if (!file.open(QIODevice::ReadOnly))
|
if (!file.open(QIODevice::ReadOnly))
|
||||||
return;
|
return;
|
||||||
QByteArray buf = file.readAll();
|
QByteArray buf = file.readAll();
|
||||||
file.close();
|
file.close();
|
||||||
|
|
||||||
GameReplay *replay = new GameReplay;
|
GameReplay *replay = new GameReplay;
|
||||||
replay->ParseFromArray(buf.data(), buf.size());
|
replay->ParseFromArray(buf.data(), buf.size());
|
||||||
|
|
||||||
tabSupervisor->openReplay(replay);
|
tabSupervisor->openReplay(replay);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -230,7 +230,7 @@ void MainWindow::localGameEnded()
|
||||||
{
|
{
|
||||||
delete localServer;
|
delete localServer;
|
||||||
localServer = 0;
|
localServer = 0;
|
||||||
|
|
||||||
aConnect->setEnabled(true);
|
aConnect->setEnabled(true);
|
||||||
aRegister->setEnabled(true);
|
aRegister->setEnabled(true);
|
||||||
aSinglePlayer->setEnabled(true);
|
aSinglePlayer->setEnabled(true);
|
||||||
|
@ -303,7 +303,7 @@ void MainWindow::loginError(Response::ResponseCode r, QString reasonStr, quint32
|
||||||
bannedStr = tr("You are banned indefinitely.");
|
bannedStr = tr("You are banned indefinitely.");
|
||||||
if (!reasonStr.isEmpty())
|
if (!reasonStr.isEmpty())
|
||||||
bannedStr.append("\n\n" + reasonStr);
|
bannedStr.append("\n\n" + reasonStr);
|
||||||
|
|
||||||
QMessageBox::critical(this, tr("Error"), bannedStr);
|
QMessageBox::critical(this, tr("Error"), bannedStr);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -351,7 +351,7 @@ QString MainWindow::extractInvalidUsernameMessage(QString & in)
|
||||||
out += "<li>" + tr("can %1 contain numeric characters").arg((rules.at(4).toInt() > 0) ? "" : tr("NOT")) + "</li>";
|
out += "<li>" + tr("can %1 contain numeric characters").arg((rules.at(4).toInt() > 0) ? "" : tr("NOT")) + "</li>";
|
||||||
|
|
||||||
if (rules.at(6).size() > 0)
|
if (rules.at(6).size() > 0)
|
||||||
{
|
{
|
||||||
out += "<li>" + tr("can contain the following punctuation: %1").arg(
|
out += "<li>" + tr("can contain the following punctuation: %1").arg(
|
||||||
#if QT_VERSION < 0x050000
|
#if QT_VERSION < 0x050000
|
||||||
Qt::escape(rules.at(6))
|
Qt::escape(rules.at(6))
|
||||||
|
@ -360,7 +360,7 @@ QString MainWindow::extractInvalidUsernameMessage(QString & in)
|
||||||
#endif
|
#endif
|
||||||
) + "</li>";
|
) + "</li>";
|
||||||
}
|
}
|
||||||
|
|
||||||
out += "<li>" + tr("first character can %1 be a punctuation mark").arg((rules.at(5).toInt() > 0) ? "" : tr("NOT")) + "</li>";
|
out += "<li>" + tr("first character can %1 be a punctuation mark").arg((rules.at(5).toInt() > 0) ? "" : tr("NOT")) + "</li>";
|
||||||
out += "</ul>";
|
out += "</ul>";
|
||||||
}
|
}
|
||||||
|
@ -398,7 +398,7 @@ void MainWindow::registerError(Response::ResponseCode r, QString reasonStr, quin
|
||||||
bannedStr = tr("You are banned indefinitely.");
|
bannedStr = tr("You are banned indefinitely.");
|
||||||
if (!reasonStr.isEmpty())
|
if (!reasonStr.isEmpty())
|
||||||
bannedStr.append("\n\n" + reasonStr);
|
bannedStr.append("\n\n" + reasonStr);
|
||||||
|
|
||||||
QMessageBox::critical(this, tr("Error"), bannedStr);
|
QMessageBox::critical(this, tr("Error"), bannedStr);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -451,7 +451,7 @@ void MainWindow::setClientStatusTitle()
|
||||||
void MainWindow::retranslateUi()
|
void MainWindow::retranslateUi()
|
||||||
{
|
{
|
||||||
setClientStatusTitle();
|
setClientStatusTitle();
|
||||||
|
|
||||||
aConnect->setText(tr("&Connect..."));
|
aConnect->setText(tr("&Connect..."));
|
||||||
aDisconnect->setText(tr("&Disconnect"));
|
aDisconnect->setText(tr("&Disconnect"));
|
||||||
aSinglePlayer->setText(tr("Start &local game..."));
|
aSinglePlayer->setText(tr("Start &local game..."));
|
||||||
|
@ -462,7 +462,7 @@ void MainWindow::retranslateUi()
|
||||||
aRegister->setText(tr("&Register to server..."));
|
aRegister->setText(tr("&Register to server..."));
|
||||||
aSettings->setText(tr("&Settings..."));
|
aSettings->setText(tr("&Settings..."));
|
||||||
aExit->setText(tr("&Exit"));
|
aExit->setText(tr("&Exit"));
|
||||||
|
|
||||||
#if defined(__APPLE__) /* For OSX */
|
#if defined(__APPLE__) /* For OSX */
|
||||||
cockatriceMenu->setTitle(tr("A&ctions"));
|
cockatriceMenu->setTitle(tr("A&ctions"));
|
||||||
#else
|
#else
|
||||||
|
@ -471,7 +471,7 @@ void MainWindow::retranslateUi()
|
||||||
aAbout->setText(tr("&About Cockatrice"));
|
aAbout->setText(tr("&About Cockatrice"));
|
||||||
helpMenu->setTitle(tr("&Help"));
|
helpMenu->setTitle(tr("&Help"));
|
||||||
aCheckCardUpdates->setText(tr("Check for card updates..."));
|
aCheckCardUpdates->setText(tr("Check for card updates..."));
|
||||||
|
|
||||||
tabSupervisor->retranslateUi();
|
tabSupervisor->retranslateUi();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -497,7 +497,7 @@ void MainWindow::createActions()
|
||||||
connect(aSettings, SIGNAL(triggered()), this, SLOT(actSettings()));
|
connect(aSettings, SIGNAL(triggered()), this, SLOT(actSettings()));
|
||||||
aExit = new QAction(this);
|
aExit = new QAction(this);
|
||||||
connect(aExit, SIGNAL(triggered()), this, SLOT(actExit()));
|
connect(aExit, SIGNAL(triggered()), this, SLOT(actExit()));
|
||||||
|
|
||||||
aAbout = new QAction(this);
|
aAbout = new QAction(this);
|
||||||
connect(aAbout, SIGNAL(triggered()), this, SLOT(actAbout()));
|
connect(aAbout, SIGNAL(triggered()), this, SLOT(actAbout()));
|
||||||
|
|
||||||
|
@ -538,7 +538,7 @@ void MainWindow::createMenus()
|
||||||
cockatriceMenu->addAction(aCheckCardUpdates);
|
cockatriceMenu->addAction(aCheckCardUpdates);
|
||||||
cockatriceMenu->addSeparator();
|
cockatriceMenu->addSeparator();
|
||||||
cockatriceMenu->addAction(aExit);
|
cockatriceMenu->addAction(aExit);
|
||||||
|
|
||||||
helpMenu = menuBar()->addMenu(QString());
|
helpMenu = menuBar()->addMenu(QString());
|
||||||
helpMenu->addAction(aAbout);
|
helpMenu->addAction(aAbout);
|
||||||
}
|
}
|
||||||
|
@ -571,17 +571,17 @@ MainWindow::MainWindow(QWidget *parent)
|
||||||
|
|
||||||
createActions();
|
createActions();
|
||||||
createMenus();
|
createMenus();
|
||||||
|
|
||||||
tabSupervisor = new TabSupervisor(client);
|
tabSupervisor = new TabSupervisor(client);
|
||||||
connect(tabSupervisor, SIGNAL(setMenu(QList<QMenu *>)), this, SLOT(updateTabMenu(QList<QMenu *>)));
|
connect(tabSupervisor, SIGNAL(setMenu(QList<QMenu *>)), this, SLOT(updateTabMenu(QList<QMenu *>)));
|
||||||
connect(tabSupervisor, SIGNAL(localGameEnded()), this, SLOT(localGameEnded()));
|
connect(tabSupervisor, SIGNAL(localGameEnded()), this, SLOT(localGameEnded()));
|
||||||
connect(tabSupervisor, SIGNAL(maximize()), this, SLOT(maximize()));
|
connect(tabSupervisor, SIGNAL(maximize()), this, SLOT(maximize()));
|
||||||
tabSupervisor->addDeckEditorTab(0);
|
tabSupervisor->addDeckEditorTab(0);
|
||||||
|
|
||||||
setCentralWidget(tabSupervisor);
|
setCentralWidget(tabSupervisor);
|
||||||
|
|
||||||
retranslateUi();
|
retranslateUi();
|
||||||
|
|
||||||
resize(900, 700);
|
resize(900, 700);
|
||||||
restoreGeometry(settingsCache->getMainWindowGeometry());
|
restoreGeometry(settingsCache->getMainWindowGeometry());
|
||||||
aFullScreen->setChecked(windowState() & Qt::WindowFullScreen);
|
aFullScreen->setChecked(windowState() & Qt::WindowFullScreen);
|
||||||
|
@ -603,7 +603,7 @@ MainWindow::~MainWindow()
|
||||||
void MainWindow::createTrayIcon() {
|
void MainWindow::createTrayIcon() {
|
||||||
QMenu *trayIconMenu = new QMenu(this);
|
QMenu *trayIconMenu = new QMenu(this);
|
||||||
trayIconMenu->addAction(closeAction);
|
trayIconMenu->addAction(closeAction);
|
||||||
|
|
||||||
trayIcon = new QSystemTrayIcon(this);
|
trayIcon = new QSystemTrayIcon(this);
|
||||||
trayIcon->setContextMenu(trayIconMenu);
|
trayIcon->setContextMenu(trayIconMenu);
|
||||||
trayIcon->setIcon(QIcon(":/resources/appicon.svg"));
|
trayIcon->setIcon(QIcon(":/resources/appicon.svg"));
|
||||||
|
@ -713,7 +713,7 @@ void MainWindow::actCheckCardUpdates()
|
||||||
binaryName = getCardUpdaterBinaryName() + ".exe";
|
binaryName = getCardUpdaterBinaryName() + ".exe";
|
||||||
#else
|
#else
|
||||||
binaryName = getCardUpdaterBinaryName();
|
binaryName = getCardUpdaterBinaryName();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if(dir.exists(binaryName))
|
if(dir.exists(binaryName))
|
||||||
updaterCmd = dir.absoluteFilePath(binaryName);
|
updaterCmd = dir.absoluteFilePath(binaryName);
|
||||||
|
|
Loading…
Reference in a new issue