Major redesign: The game can not be left without disconnecting from the server. This happens if a player is kicked, if he wishes to leave, or for other reasons. Error packets from the server will always cause a disconnect, however.
If joining a game fails, there is a proper failure packet now.
This commit is contained in:
@@ -108,6 +108,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::SignalNetClientNotification(int notificationId) { if (myClientcb) myClientcb->SignalNetClientNotification(notificationId); }
|
||||
void ServerGuiWrapper::SignalNetClientRemovedFromGame(int notificationId) { if (myClientcb) myClientcb->SignalNetClientRemovedFromGame(notificationId); }
|
||||
void ServerGuiWrapper::SignalNetClientSelfJoined(unsigned playerId, const std::string &playerName, PlayerRights rights) { if (myClientcb) myClientcb->SignalNetClientSelfJoined(playerId, playerName, rights); }
|
||||
void ServerGuiWrapper::SignalNetClientPlayerJoined(unsigned playerId, const std::string &playerName, PlayerRights rights) { if (myClientcb) myClientcb->SignalNetClientPlayerJoined(playerId, playerName, rights); }
|
||||
void ServerGuiWrapper::SignalNetClientPlayerChanged(unsigned playerId, const std::string &newPlayerName) { if (myClientcb) myClientcb->SignalNetClientPlayerChanged(playerId, newPlayerName); }
|
||||
|
||||
@@ -92,6 +92,8 @@ public:
|
||||
void SignalNetClientConnect(int actionID);
|
||||
void SignalNetClientGameInfo(int actionID);
|
||||
void SignalNetClientError(int errorID, int osErrorID);
|
||||
void SignalNetClientNotification(int notificationId);
|
||||
void SignalNetClientRemovedFromGame(int notificationId);
|
||||
void SignalNetClientSelfJoined(unsigned playerId, const std::string &playerName, PlayerRights rights);
|
||||
void SignalNetClientPlayerJoined(unsigned playerId, const std::string &playerName, PlayerRights rights);
|
||||
void SignalNetClientPlayerChanged(unsigned playerId, const std::string &newPlayerName);
|
||||
|
||||
@@ -25,6 +25,7 @@ gameLobbyDialogImpl::gameLobbyDialogImpl(QWidget *parent, ConfigFile *c)
|
||||
connect( treeWidget_GameList, SIGNAL( currentItemChanged ( QTreeWidgetItem*, QTreeWidgetItem*) ), this, SLOT( gameSelected(QTreeWidgetItem*, QTreeWidgetItem*) ) );
|
||||
connect( pushButton_StartGame, SIGNAL( clicked() ), this, SLOT( startGame() ) );
|
||||
connect( pushButton_Kick, SIGNAL( clicked() ), this, SLOT( kickPlayer() ) );
|
||||
connect( pushButton_Leave, SIGNAL( clicked() ), this, SLOT( leaveGame() ) );
|
||||
connect( treeWidget_connectedPlayers, SIGNAL( currentItemChanged ( QTreeWidgetItem*, QTreeWidgetItem*) ), this, SLOT( playerSelected(QTreeWidgetItem*, QTreeWidgetItem*) ) );
|
||||
|
||||
clearDialog();
|
||||
@@ -66,9 +67,6 @@ void gameLobbyDialogImpl::createGame()
|
||||
|
||||
currentGameName = QString::fromUtf8(myConfig->readConfigString("MyName").c_str()) + QString("'s game");
|
||||
|
||||
// Update dialog
|
||||
gameModeDialogUpdate();
|
||||
|
||||
label_SmallBlind->setText(QString::number(gameData.smallBlind));
|
||||
label_StartCash->setText(QString::number(gameData.startMoney));
|
||||
label_MaximumNumberOfPlayers->setText(QString::number(gameData.maxNumberOfPlayers));
|
||||
@@ -86,9 +84,6 @@ void gameLobbyDialogImpl::joinGame()
|
||||
{
|
||||
assert(mySession);
|
||||
mySession->clientJoinGame(item->data(0, Qt::UserRole).toUInt(), "");
|
||||
|
||||
// Update dialog
|
||||
gameModeDialogUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -100,6 +95,11 @@ void gameLobbyDialogImpl::refresh(int actionID) {
|
||||
}
|
||||
}
|
||||
|
||||
void gameLobbyDialogImpl::removedFromGame(int reason)
|
||||
{
|
||||
clearDialog();
|
||||
}
|
||||
|
||||
void gameLobbyDialogImpl::gameSelected(QTreeWidgetItem* item, QTreeWidgetItem*)
|
||||
{
|
||||
if (item)
|
||||
@@ -259,6 +259,9 @@ void gameLobbyDialogImpl::checkPlayerQuantity() {
|
||||
|
||||
void gameLobbyDialogImpl::joinedNetworkGame(unsigned playerId, QString playerName, int rights) {
|
||||
|
||||
// Update dialog
|
||||
gameModeDialogUpdate();
|
||||
|
||||
isAdmin = rights == PLAYER_RIGHTS_ADMIN;
|
||||
addConnectedPlayer(playerId, playerName, rights);
|
||||
}
|
||||
@@ -329,10 +332,17 @@ void gameLobbyDialogImpl::playerSelected(QTreeWidgetItem* item, QTreeWidgetItem*
|
||||
}
|
||||
|
||||
void gameLobbyDialogImpl::startGame() {
|
||||
|
||||
assert(mySession);
|
||||
mySession->sendStartEvent(checkBox_fillUpWithComputerOpponents->isChecked());
|
||||
}
|
||||
|
||||
void gameLobbyDialogImpl::leaveGame() {
|
||||
|
||||
assert(mySession);
|
||||
mySession->sendLeaveCurrentGame();
|
||||
}
|
||||
|
||||
void gameLobbyDialogImpl::kickPlayer() {
|
||||
|
||||
QTreeWidgetItem *item = treeWidget_connectedPlayers->currentItem();
|
||||
|
||||
@@ -65,7 +65,9 @@ public slots:
|
||||
|
||||
void playerSelected(QTreeWidgetItem*, QTreeWidgetItem*);
|
||||
void refresh(int actionID);
|
||||
void removedFromGame(int reason);
|
||||
void startGame();
|
||||
void leaveGame();
|
||||
void kickPlayer();
|
||||
|
||||
void gameModeDialogUpdate();
|
||||
|
||||
@@ -111,6 +111,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::SignalNetClientNotification(int notificationId) { myW->signalNetClientNotification(notificationId); }
|
||||
void GuiWrapper::SignalNetClientRemovedFromGame(int notificationId) { myW->signalNetClientRemovedFromGame(notificationId); }
|
||||
void GuiWrapper::SignalNetClientSelfJoined(unsigned playerId, const string &playerName, PlayerRights rights) { myW->signalNetClientSelfJoined(playerId, QString::fromUtf8(playerName.c_str()), rights); }
|
||||
void GuiWrapper::SignalNetClientPlayerJoined(unsigned playerId, const string &playerName, PlayerRights rights) { myW->signalNetClientPlayerJoined(playerId, QString::fromUtf8(playerName.c_str()), rights); }
|
||||
void GuiWrapper::SignalNetClientPlayerChanged(unsigned playerId, const string &newPlayerName)
|
||||
|
||||
@@ -99,6 +99,8 @@ public:
|
||||
void SignalNetClientConnect(int actionID);
|
||||
void SignalNetClientGameInfo(int actionID);
|
||||
void SignalNetClientError(int errorID, int osErrorID);
|
||||
void SignalNetClientNotification(int notificationId);
|
||||
void SignalNetClientRemovedFromGame(int notificationId);
|
||||
void SignalNetClientSelfJoined(unsigned playerId, const std::string &playerName, PlayerRights rights);
|
||||
void SignalNetClientPlayerJoined(unsigned playerId, const std::string &playerName, PlayerRights rights);
|
||||
void SignalNetClientPlayerChanged(unsigned playerId, const std::string &newPlayerName);
|
||||
|
||||
@@ -663,9 +663,12 @@ mainWindowImpl::mainWindowImpl(ConfigFile *c, QMainWindow *parent)
|
||||
connect(this, SIGNAL(signalNetClientGameListRemove(unsigned)), myGameLobbyDialog, SLOT(removeGame(unsigned)));
|
||||
connect(this, SIGNAL(signalNetClientGameListPlayerJoined(unsigned, unsigned)), myGameLobbyDialog, SLOT(gameAddPlayer(unsigned, unsigned)));
|
||||
connect(this, SIGNAL(signalNetClientGameListPlayerLeft(unsigned, unsigned)), myGameLobbyDialog, SLOT(gameRemovePlayer(unsigned, unsigned)));
|
||||
connect(this, SIGNAL(signalNetClientRemovedFromGame(int)), myGameLobbyDialog, SLOT(removedFromGame(int)));
|
||||
|
||||
// Errors are handled globally, not within one dialog.
|
||||
connect(this, SIGNAL(signalNetClientError(int, int)), this, SLOT(networkError(int, int)));
|
||||
connect(this, SIGNAL(signalNetClientNotification(int)), this, SLOT(networkNotification(int)));
|
||||
connect(this, SIGNAL(signalNetClientRemovedFromGame(int)), this, SLOT(networkNotification(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>)));
|
||||
|
||||
@@ -2587,11 +2590,6 @@ void mainWindowImpl::networkError(int errorID, int osErrorID) {
|
||||
tr("Sorry, this server is already full."),
|
||||
QMessageBox::Close); }
|
||||
break;
|
||||
case ERR_NET_GAME_ALREADY_RUNNING:
|
||||
{ QMessageBox::warning(this, tr("Network Error"),
|
||||
tr("Unable to join - the server has already started the game."),
|
||||
QMessageBox::Close); }
|
||||
break;
|
||||
case ERR_NET_INVALID_PASSWORD:
|
||||
{ QMessageBox::warning(this, tr("Network Error"),
|
||||
tr("Invalid password when joining the game.\nPlease reenter the password and try again."),
|
||||
@@ -2649,6 +2647,35 @@ void mainWindowImpl::networkError(int errorID, int osErrorID) {
|
||||
myStartNetworkGameDialog->reject();
|
||||
}
|
||||
|
||||
void mainWindowImpl::networkNotification(int notificationId)
|
||||
{
|
||||
switch (notificationId)
|
||||
{
|
||||
case NTF_NET_REMOVED_KICKED:
|
||||
{ QMessageBox::warning(this, tr("Network Notification"),
|
||||
tr("You were kicked from the game."),
|
||||
QMessageBox::Close); }
|
||||
break;
|
||||
case NTF_NET_REMOVED_GAME_FULL:
|
||||
case NTF_NET_JOIN_GAME_FULL:
|
||||
{ QMessageBox::warning(this, tr("Network Notification"),
|
||||
tr("Sorry, this game is already full."),
|
||||
QMessageBox::Close); }
|
||||
break;
|
||||
case NTF_NET_REMOVED_ALREADY_RUNNING:
|
||||
case NTF_NET_JOIN_ALREADY_RUNNING:
|
||||
{ QMessageBox::warning(this, tr("Network Notification"),
|
||||
tr("Unable to join - the server has already started the game."),
|
||||
QMessageBox::Close); }
|
||||
break;
|
||||
case NTF_NET_JOIN_INVALID_PASSWORD:
|
||||
{ QMessageBox::warning(this, tr("Network Notification"),
|
||||
tr("Invalid password when joining the game.\nPlease reenter the password and try again."),
|
||||
QMessageBox::Close); }
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void mainWindowImpl::networkStart(boost::shared_ptr<Game> game)
|
||||
{
|
||||
mySession->startClientGame(game);
|
||||
|
||||
@@ -126,6 +126,8 @@ signals:
|
||||
void signalNetClientConnect(int actionID);
|
||||
void signalNetClientGameInfo(int actionID);
|
||||
void signalNetClientError(int errorID, int osErrorID);
|
||||
void signalNetClientNotification(int notificationId);
|
||||
void signalNetClientRemovedFromGame(int notificationId);
|
||||
void signalNetServerError(int errorID, int osErrorID);
|
||||
void signalNetClientSelfJoined(unsigned playerId, QString playerName, int rights);
|
||||
void signalNetClientPlayerJoined(unsigned playerId, QString playerName, int rights);
|
||||
@@ -276,6 +278,7 @@ public slots:
|
||||
void tabSwitchAction();
|
||||
|
||||
void networkError(int, int);
|
||||
void networkNotification(int);
|
||||
void networkStart(boost::shared_ptr<Game> game);
|
||||
|
||||
void closeEvent(QCloseEvent*);
|
||||
|
||||
Reference in New Issue
Block a user