The console server can now be fully used for a single game. The first player to join the game is admin, he can start the game and kick players.

However, if the admin player leaves, a new game can only be started if all players have left before (this is a bug, admin status should be passed to another player).
This commit is contained in:
lotodore
2007-08-02 20:52:13 +00:00
parent f11998c28c
commit 0da29b3874
25 changed files with 481 additions and 262 deletions
+2 -2
View File
@@ -105,7 +105,8 @@ void ServerGuiWrapper::logPlayerWinGame(std::string playerName, int gameID) {}
void ServerGuiWrapper::SignalNetClientConnect(int actionID) { if (myClientcb) myClientcb->SignalNetClientConnect(actionID); }
void ServerGuiWrapper::SignalNetClientGameInfo(int actionID) { if (myClientcb) myClientcb->SignalNetClientGameInfo(actionID); }
void ServerGuiWrapper::SignalNetClientError(int errorID, int osErrorID) { if (myClientcb) myClientcb->SignalNetClientError(errorID, osErrorID); }
void ServerGuiWrapper::SignalNetClientPlayerJoined(const string &playerName) { if (myClientcb) myClientcb->SignalNetClientPlayerJoined(playerName); }
void ServerGuiWrapper::SignalNetClientSelfJoined(const string &playerName, PlayerRights rights) { if (myClientcb) myClientcb->SignalNetClientSelfJoined(playerName, rights); }
void ServerGuiWrapper::SignalNetClientPlayerJoined(const string &playerName, PlayerRights rights) { if (myClientcb) myClientcb->SignalNetClientPlayerJoined(playerName, rights); }
void ServerGuiWrapper::SignalNetClientPlayerLeft(const string &playerName) { if (myClientcb) myClientcb->SignalNetClientPlayerLeft(playerName); }
void ServerGuiWrapper::SignalNetClientGameStart(boost::shared_ptr<Game> game) { if (myClientcb) myClientcb->SignalNetClientGameStart(game); }
void ServerGuiWrapper::SignalNetClientChatMsg(const string &playerName, const string &msg) { if (myClientcb) myClientcb->SignalNetClientChatMsg(playerName, msg); }
@@ -115,5 +116,4 @@ void ServerGuiWrapper::SignalNetServerSuccess(int actionID) { if (myServercb) my
void ServerGuiWrapper::SignalNetServerError(int errorID, int osErrorID) { if (myServercb) myServercb->SignalNetServerError(errorID, osErrorID); }
void ServerGuiWrapper::SignalNetServerPlayerJoined(const string &playerName) { if (myServercb) myServercb->SignalNetServerPlayerJoined(playerName); }
void ServerGuiWrapper::SignalNetServerPlayerLeft(const string &playerName) { if (myServercb) myServercb->SignalNetServerPlayerLeft(playerName); }
void ServerGuiWrapper::SignalNetServerStartDialog() { if (myServercb) myServercb->SignalNetServerStartDialog(); }
+2 -2
View File
@@ -89,7 +89,8 @@ public:
void SignalNetClientConnect(int actionID);
void SignalNetClientGameInfo(int actionID);
void SignalNetClientError(int errorID, int osErrorID);
void SignalNetClientPlayerJoined(const std::string &playerName);
void SignalNetClientSelfJoined(const std::string &playerName, PlayerRights rights);
void SignalNetClientPlayerJoined(const std::string &playerName, PlayerRights rights);
void SignalNetClientPlayerLeft(const std::string &playerName);
void SignalNetClientChatMsg(const std::string &playerName, const std::string &msg);
void SignalNetClientWaitDialog();
@@ -100,7 +101,6 @@ public:
void SignalNetServerError(int errorID, int osErrorID);
void SignalNetServerPlayerJoined(const std::string &playerName);
void SignalNetServerPlayerLeft(const std::string &playerName);
void SignalNetServerStartDialog();
private:
+5 -5
View File
@@ -107,7 +107,8 @@ void GuiWrapper::logPlayerWinGame(std::string playerName, int gameID) { myLog->s
void GuiWrapper::SignalNetClientConnect(int actionID) { myW->signalNetClientConnect(actionID); }
void GuiWrapper::SignalNetClientGameInfo(int actionID) { myW->signalNetClientGameInfo(actionID); }
void GuiWrapper::SignalNetClientError(int errorID, int osErrorID) { myW->signalNetClientError(errorID, osErrorID); }
void GuiWrapper::SignalNetClientPlayerJoined(const string &playerName) { myW->signalNetClientPlayerJoined(QString::fromUtf8(playerName.c_str())); }
void GuiWrapper::SignalNetClientSelfJoined(const string &playerName, PlayerRights rights) { myW->signalNetClientSelfJoined(QString::fromUtf8(playerName.c_str()), rights); }
void GuiWrapper::SignalNetClientPlayerJoined(const string &playerName, PlayerRights rights) { myW->signalNetClientPlayerJoined(QString::fromUtf8(playerName.c_str()), rights); }
void GuiWrapper::SignalNetClientPlayerLeft(const string &playerName)
{
QString tmpName(QString::fromUtf8(playerName.c_str()));
@@ -116,11 +117,10 @@ void GuiWrapper::SignalNetClientPlayerLeft(const string &playerName)
}
void GuiWrapper::SignalNetClientGameStart(boost::shared_ptr<Game> game) { myW->signalNetClientGameStart(game); }
void GuiWrapper::SignalNetClientChatMsg(const string &playerName, const string &msg) { myChat->signalChatMessage(QString::fromUtf8(playerName.c_str()), QString::fromUtf8(msg.c_str())); }
void GuiWrapper::SignalNetClientWaitDialog() { myW->signalShowClientWaitDialog(); }
void GuiWrapper::SignalNetClientWaitDialog() { myW->signalShowNetworkStartDialog(); }
void GuiWrapper::SignalNetServerSuccess(int actionID) { }
void GuiWrapper::SignalNetServerError(int errorID, int osErrorID) { myW->signalNetServerError(errorID, osErrorID); }
void GuiWrapper::SignalNetServerPlayerJoined(const string &playerName) { myW->signalNetServerPlayerJoined(QString::fromUtf8(playerName.c_str())); }
void GuiWrapper::SignalNetServerPlayerLeft(const string &playerName) { myW->signalNetServerPlayerLeft(QString::fromUtf8(playerName.c_str())); }
void GuiWrapper::SignalNetServerStartDialog() { myW->signalShowServerStartDialog(); }
void GuiWrapper::SignalNetServerPlayerJoined(const string &playerName) { }
void GuiWrapper::SignalNetServerPlayerLeft(const string &playerName) { }
+2 -5
View File
@@ -42,9 +42,6 @@ public:
Session &getSession();
void setSession(boost::shared_ptr<Session> session);
void showServerStartDialog();
void showClientWaitDialog();
void refreshSet() const;
void refreshCash() const;
void refreshAction(int =-1, int =-1) const;
@@ -99,7 +96,8 @@ public:
void SignalNetClientConnect(int actionID);
void SignalNetClientGameInfo(int actionID);
void SignalNetClientError(int errorID, int osErrorID);
void SignalNetClientPlayerJoined(const std::string &playerName);
void SignalNetClientSelfJoined(const std::string &playerName, PlayerRights rights);
void SignalNetClientPlayerJoined(const std::string &playerName, PlayerRights rights);
void SignalNetClientPlayerLeft(const std::string &playerName);
void SignalNetClientChatMsg(const std::string &playerName, const std::string &msg);
void SignalNetClientWaitDialog();
@@ -110,7 +108,6 @@ public:
void SignalNetServerError(int errorID, int osErrorID);
void SignalNetServerPlayerJoined(const std::string &playerName);
void SignalNetServerPlayerLeft(const std::string &playerName);
void SignalNetServerStartDialog();
private:
+14 -33
View File
@@ -587,8 +587,7 @@ mainWindowImpl::mainWindowImpl(ConfigFile *c, QMainWindow *parent)
//Nachrichten Thread-Save
connect(this, SIGNAL(signalInitGui(int)), this, SLOT(initGui(int)));
connect(this, SIGNAL(signalShowServerStartDialog()), this, SLOT(showServerStartDialog()));
connect(this, SIGNAL(signalShowClientWaitDialog()), this, SLOT(showClientWaitDialog()));
connect(this, SIGNAL(signalShowNetworkStartDialog()), this, SLOT(showNetworkStartDialog()));
connect(this, SIGNAL(signalRefreshSet()), this, SLOT(refreshSet()));
connect(this, SIGNAL(signalRefreshCash()), this, SLOT(refreshCash()));
@@ -631,18 +630,16 @@ mainWindowImpl::mainWindowImpl(ConfigFile *c, QMainWindow *parent)
connect(this, SIGNAL(signalNextRoundCleanGui()), this, SLOT(nextRoundCleanGui()));
connect(this, SIGNAL(signalNetClientConnect(int)), myConnectToServerDialog, SLOT(refresh(int)));
connect(this, SIGNAL(signalNetClientGameInfo(int)), myWaitingForServerGameDialog, SLOT(refresh(int)));
connect(this, SIGNAL(signalNetClientPlayerJoined(QString)), myWaitingForServerGameDialog, SLOT(addConnectedPlayer(QString)));
connect(this, SIGNAL(signalNetClientPlayerLeft(QString)), myWaitingForServerGameDialog, SLOT(removePlayer(QString)));
connect(this, SIGNAL(signalNetClientGameInfo(int)), myStartNetworkGameDialog, SLOT(refresh(int)));
connect(this, SIGNAL(signalNetClientSelfJoined(QString, int)), myStartNetworkGameDialog, SLOT(joinedNetworkGame(QString, int)));
connect(this, SIGNAL(signalNetClientPlayerJoined(QString, int)), myStartNetworkGameDialog, SLOT(addConnectedPlayer(QString, int)));
connect(this, SIGNAL(signalNetClientPlayerLeft(QString)), myStartNetworkGameDialog, SLOT(removePlayer(QString)));
// Errors are handled globally, not within one dialog.
connect(this, SIGNAL(signalNetClientError(int, int)), this, SLOT(networkError(int, int)));
connect(this, SIGNAL(signalNetServerError(int, int)), this, SLOT(networkError(int, int)));
connect(this, SIGNAL(signalNetClientGameStart(boost::shared_ptr<Game>)), this, SLOT(networkStart(boost::shared_ptr<Game>)));
connect(this, SIGNAL(signalNetServerPlayerJoined(QString)), myStartNetworkGameDialog, SLOT(addConnectedPlayer(QString)));
connect(this, SIGNAL(signalNetServerPlayerLeft(QString)), myStartNetworkGameDialog, SLOT(removePlayer(QString)));
//Sound
mySDLPlayer = new SDLPlayer(myConfig);
@@ -743,7 +740,7 @@ void mainWindowImpl::callCreateNetworkGameDialog() {
gameData.guiSpeed = 4;
gameData.playerActionTimeoutSec = myCreateNetworkGameDialog->spinBox_netTimeOutPlayerAction->value();
myStartNetworkGameDialog->setSession(&myServerGuiInterface->getSession());
myStartNetworkGameDialog->setSession(&getSession());
myStartNetworkGameDialog->treeWidget->clear();
myServerGuiInterface->getSession().startNetworkServer(gameData);
@@ -751,7 +748,7 @@ void mainWindowImpl::callCreateNetworkGameDialog() {
myStartNetworkGameDialog->setMaxPlayerNumber(gameData.maxNumberOfPlayers);
showServerStartDialog();
showNetworkStartDialog();
}
}
@@ -766,7 +763,8 @@ void mainWindowImpl::callJoinNetworkGameDialog() {
if (myServerGuiInterface.get())
myServerGuiInterface->getSession().terminateNetworkServer();
myWaitingForServerGameDialog->treeWidget->clear();
myStartNetworkGameDialog->setSession(&getSession());
myStartNetworkGameDialog->treeWidget->clear();
// Maybe use QUrl::toPunycode.
mySession->startNetworkClient(
myJoinNetworkGameDialog->lineEdit_ipAddress->text().toUtf8().constData(),
@@ -783,7 +781,7 @@ void mainWindowImpl::callJoinNetworkGameDialog() {
actionJoin_network_Game->trigger(); // re-trigger
}
else {
showClientWaitDialog();
showNetworkStartDialog();
}
}
}
@@ -891,7 +889,7 @@ void mainWindowImpl::initGui(int speed)
}
}
void mainWindowImpl::showServerStartDialog()
void mainWindowImpl::showNetworkStartDialog()
{
myStartNetworkGameDialog->exec();
@@ -899,28 +897,11 @@ void mainWindowImpl::showServerStartDialog()
//some gui modifications
networkGameModification();
myServerGuiInterface->getSession().initiateNetworkServerGame();
}
else {
mySession->terminateNetworkClient();
myServerGuiInterface->getSession().terminateNetworkServer();
}
}
void mainWindowImpl::showClientWaitDialog()
{
if (!myServerGuiInterface.get() || !myServerGuiInterface->getSession().isNetworkServerRunning())
{
myWaitingForServerGameDialog->exec();
if (myWaitingForServerGameDialog->result() == QDialog::Accepted) {
//some gui modifications
networkGameModification();
}
else {
mySession->terminateNetworkClient();
}
if (myServerGuiInterface)
myServerGuiInterface->getSession().terminateNetworkServer();
}
}
@@ -2547,7 +2528,7 @@ void mainWindowImpl::networkError(int errorID, int osErrorID) {
}
// close dialogs
myConnectToServerDialog->reject();
myWaitingForServerGameDialog->reject();
myStartNetworkGameDialog->reject();
}
void mainWindowImpl::networkStart(boost::shared_ptr<Game> game)
+4 -7
View File
@@ -76,8 +76,7 @@ public:
signals:
void signalInitGui(int speed);
void signalShowServerStartDialog();
void signalShowClientWaitDialog();
void signalShowNetworkStartDialog();
void signalRefreshSet();
void signalRefreshCash();
@@ -123,18 +122,16 @@ signals:
void signalNetClientGameInfo(int actionID);
void signalNetClientError(int errorID, int osErrorID);
void signalNetServerError(int errorID, int osErrorID);
void signalNetClientPlayerJoined(QString playerName);
void signalNetClientSelfJoined(QString playerName, int rights);
void signalNetClientPlayerJoined(QString playerName, int rights);
void signalNetClientPlayerLeft(QString playerName);
void signalNetClientGameStart(boost::shared_ptr<Game> game);
void signalNetServerPlayerJoined(QString playerName);
void signalNetServerPlayerLeft(QString playerName);
public slots:
void initGui(int speed);
void showServerStartDialog();
void showClientWaitDialog();
void showNetworkStartDialog();
//refresh-Funktionen
void refreshSet();
@@ -20,9 +20,10 @@
#include "startnetworkgamedialogimpl.h"
#include "session.h"
#include "configfile.h"
#include <net/socket_msg.h>
startNetworkGameDialogImpl::startNetworkGameDialogImpl(QWidget *parent, ConfigFile *config)
: QDialog(parent), myConfig(config)
: QDialog(parent), myConfig(config), isAdmin(false)
{
setupUi(this);
@@ -36,15 +37,29 @@ startNetworkGameDialogImpl::startNetworkGameDialogImpl(QWidget *parent, ConfigFi
}
void startNetworkGameDialogImpl::startGame() {
assert(mySession);
mySession->sendStartEvent();
}
void startNetworkGameDialogImpl::cancel() {
}
void startNetworkGameDialogImpl::refresh(int actionID) {
void startNetworkGameDialogImpl::addConnectedPlayer(QString playerName) {
if (actionID == MSG_NET_GAME_CLIENT_START)
{
QTimer::singleShot(500, this, SLOT(accept()));
}
}
void startNetworkGameDialogImpl::joinedNetworkGame(QString playerName, int rights) {
isAdmin = rights == PLAYER_RIGHTS_ADMIN;
addConnectedPlayer(playerName, rights);
}
void startNetworkGameDialogImpl::addConnectedPlayer(QString playerName, int rights) {
QTreeWidgetItem *item = new QTreeWidgetItem(treeWidget,0);
item->setData(0, 0, playerName);
@@ -64,7 +79,7 @@ void startNetworkGameDialogImpl::removePlayer(QString playerName) {
void startNetworkGameDialogImpl::playerSelected(QTreeWidgetItem*, int) {
pushButton_Kick->setEnabled(TRUE);
pushButton_Kick->setEnabled(isAdmin);
}
void startNetworkGameDialogImpl::kickPlayer() {
@@ -89,7 +104,7 @@ void startNetworkGameDialogImpl::kickPlayer() {
void startNetworkGameDialogImpl::checkPlayerQuantity() {
if (treeWidget->topLevelItemCount() >= 2)
if (treeWidget->topLevelItemCount() >= 2 && isAdmin)
pushButton_startGame->setEnabled(TRUE);
else
pushButton_startGame->setEnabled(FALSE);
@@ -37,7 +37,9 @@ public slots:
void startGame();
void cancel();
void addConnectedPlayer(QString playerName);
void refresh(int actionID);
void joinedNetworkGame(QString playerName, int rights);
void addConnectedPlayer(QString playerName, int rights);
void removePlayer(QString playerName);
void playerSelected(QTreeWidgetItem*, int);
void kickPlayer();
@@ -54,6 +56,7 @@ public slots:
private:
int maxPlayerNumber;
bool isAdmin;
ConfigFile *myConfig;
Session *mySession;
};