Keep lobby open in the background during internet games. Show the lobby after the game finished. Re-open the game. Start and stop irc thread together with the client thread.
This commit is contained in:
@@ -49,10 +49,6 @@ void gameLobbyDialogImpl::exec()
|
|||||||
{
|
{
|
||||||
hideShowGameDescription(FALSE);
|
hideShowGameDescription(FALSE);
|
||||||
|
|
||||||
assert(mySession);
|
|
||||||
mySession->terminateIrcClient();
|
|
||||||
mySession->startIrcClient();
|
|
||||||
|
|
||||||
if(myConfig->readConfigInt("UseIRCLobbyChat")) {
|
if(myConfig->readConfigInt("UseIRCLobbyChat")) {
|
||||||
groupBox_lobbyChat->show();
|
groupBox_lobbyChat->show();
|
||||||
}
|
}
|
||||||
@@ -61,7 +57,6 @@ void gameLobbyDialogImpl::exec()
|
|||||||
}
|
}
|
||||||
|
|
||||||
QDialog::exec();
|
QDialog::exec();
|
||||||
mySession->terminateIrcClient();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -140,7 +140,7 @@ void GuiWrapper::SignalNetClientGameListPlayerLeft(unsigned gameId, unsigned pla
|
|||||||
|
|
||||||
void GuiWrapper::SignalNetClientGameStart(boost::shared_ptr<Game> game) { myW->signalNetClientGameStart(game); }
|
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::SignalNetClientChatMsg(const string &playerName, const string &msg) { myChat->signalChatMessage(QString::fromUtf8(playerName.c_str()), QString::fromUtf8(msg.c_str())); }
|
||||||
void GuiWrapper::SignalNetClientWaitDialog() { myW->signalShowNetworkStartDialog(); }
|
void GuiWrapper::SignalNetClientWaitDialog() { myW->signalShowClientDialog(); }
|
||||||
|
|
||||||
void GuiWrapper::SignalNetServerSuccess(int actionID) { }
|
void GuiWrapper::SignalNetServerSuccess(int actionID) { }
|
||||||
void GuiWrapper::SignalNetServerError(int errorID, int osErrorID) { myW->signalNetServerError(errorID, osErrorID); }
|
void GuiWrapper::SignalNetServerError(int errorID, int osErrorID) { myW->signalNetServerError(errorID, osErrorID); }
|
||||||
|
|||||||
@@ -605,7 +605,7 @@ mainWindowImpl::mainWindowImpl(ConfigFile *c, QMainWindow *parent)
|
|||||||
//Nachrichten Thread-Save
|
//Nachrichten Thread-Save
|
||||||
connect(this, SIGNAL(signalInitGui(int)), this, SLOT(initGui(int)));
|
connect(this, SIGNAL(signalInitGui(int)), this, SLOT(initGui(int)));
|
||||||
|
|
||||||
connect(this, SIGNAL(signalShowNetworkStartDialog()), this, SLOT(showNetworkStartDialog()));
|
connect(this, SIGNAL(signalShowClientDialog()), this, SLOT(showClientDialog()));
|
||||||
|
|
||||||
connect(this, SIGNAL(signalRefreshSet()), this, SLOT(refreshSet()));
|
connect(this, SIGNAL(signalRefreshSet()), this, SLOT(refreshSet()));
|
||||||
connect(this, SIGNAL(signalRefreshCash()), this, SLOT(refreshCash()));
|
connect(this, SIGNAL(signalRefreshCash()), this, SLOT(refreshCash()));
|
||||||
@@ -984,17 +984,7 @@ void mainWindowImpl::joinGameLobby() {
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
myGameLobbyDialog->exec();
|
showLobbyDialog();
|
||||||
|
|
||||||
if (myGameLobbyDialog->result() == QDialog::Accepted)
|
|
||||||
{
|
|
||||||
//some gui modifications
|
|
||||||
networkGameModification();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
mySession->terminateNetworkClient();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1149,6 +1139,14 @@ void mainWindowImpl::initGui(int speed)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void mainWindowImpl::showClientDialog()
|
||||||
|
{
|
||||||
|
if (mySession->GetGameType() == Session::GAME_TYPE_NETWORK)
|
||||||
|
showNetworkStartDialog();
|
||||||
|
else if (mySession->GetGameType() == Session::GAME_TYPE_INTERNET)
|
||||||
|
showLobbyDialog();
|
||||||
|
}
|
||||||
|
|
||||||
void mainWindowImpl::showNetworkStartDialog()
|
void mainWindowImpl::showNetworkStartDialog()
|
||||||
{
|
{
|
||||||
myStartNetworkGameDialog->exec();
|
myStartNetworkGameDialog->exec();
|
||||||
@@ -1165,6 +1163,21 @@ void mainWindowImpl::showNetworkStartDialog()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void mainWindowImpl::showLobbyDialog()
|
||||||
|
{
|
||||||
|
myGameLobbyDialog->exec();
|
||||||
|
|
||||||
|
if (myGameLobbyDialog->result() == QDialog::Accepted)
|
||||||
|
{
|
||||||
|
//some gui modifications
|
||||||
|
networkGameModification();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
mySession->terminateNetworkClient();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Session &mainWindowImpl::getSession() { assert(mySession.get()); return *mySession; }
|
Session &mainWindowImpl::getSession() { assert(mySession.get()); return *mySession; }
|
||||||
void mainWindowImpl::setSession(boost::shared_ptr<Session> session) { mySession = session; }
|
void mainWindowImpl::setSession(boost::shared_ptr<Session> session) { mySession = session; }
|
||||||
|
|
||||||
|
|||||||
@@ -76,7 +76,7 @@ public:
|
|||||||
signals:
|
signals:
|
||||||
void signalInitGui(int speed);
|
void signalInitGui(int speed);
|
||||||
|
|
||||||
void signalShowNetworkStartDialog();
|
void signalShowClientDialog();
|
||||||
|
|
||||||
void signalRefreshSet();
|
void signalRefreshSet();
|
||||||
void signalRefreshCash();
|
void signalRefreshCash();
|
||||||
@@ -154,7 +154,9 @@ public slots:
|
|||||||
|
|
||||||
void initGui(int speed);
|
void initGui(int speed);
|
||||||
|
|
||||||
|
void showClientDialog();
|
||||||
void showNetworkStartDialog();
|
void showNetworkStartDialog();
|
||||||
|
void showLobbyDialog();
|
||||||
|
|
||||||
//refresh-Funktionen
|
//refresh-Funktionen
|
||||||
void refreshSet();
|
void refreshSet();
|
||||||
|
|||||||
@@ -1126,6 +1126,7 @@ ServerGameStateNextGameDelay::Process(ServerGameThread &server)
|
|||||||
|
|
||||||
// Wait for the start of a new game.
|
// Wait for the start of a new game.
|
||||||
server.SetState(ServerGameStateInit::Instance());
|
server.SetState(ServerGameStateInit::Instance());
|
||||||
|
server.GetLobbyThread().NotifyReopeningGame(server.GetId());
|
||||||
}
|
}
|
||||||
|
|
||||||
return retVal;
|
return retVal;
|
||||||
|
|||||||
@@ -162,6 +162,14 @@ ServerLobbyThread::NotifyStartingGame(unsigned gameId)
|
|||||||
m_gameSessionManager.SendToAllSessions(GetSender(), packet, SessionData::Game);
|
m_gameSessionManager.SendToAllSessions(GetSender(), packet, SessionData::Game);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
ServerLobbyThread::NotifyReopeningGame(unsigned gameId)
|
||||||
|
{
|
||||||
|
boost::shared_ptr<NetPacket> packet = CreateNetPacketGameListUpdate(gameId, GAME_MODE_CREATED);
|
||||||
|
m_sessionManager.SendToAllSessions(GetSender(), packet, SessionData::Established);
|
||||||
|
m_gameSessionManager.SendToAllSessions(GetSender(), packet, SessionData::Game);
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ServerLobbyThread::HandleGameRetrievePlayerInfo(SessionWrapper session, const NetPacketRetrievePlayerInfo &tmpPacket)
|
ServerLobbyThread::HandleGameRetrievePlayerInfo(SessionWrapper session, const NetPacketRetrievePlayerInfo &tmpPacket)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -59,6 +59,7 @@ public:
|
|||||||
void NotifyPlayerJoinedGame(unsigned gameId, unsigned playerId);
|
void NotifyPlayerJoinedGame(unsigned gameId, unsigned playerId);
|
||||||
void NotifyPlayerLeftGame(unsigned gameId, unsigned playerId);
|
void NotifyPlayerLeftGame(unsigned gameId, unsigned playerId);
|
||||||
void NotifyStartingGame(unsigned gameId);
|
void NotifyStartingGame(unsigned gameId);
|
||||||
|
void NotifyReopeningGame(unsigned gameId);
|
||||||
|
|
||||||
void HandleGameRetrievePlayerInfo(SessionWrapper session, const NetPacketRetrievePlayerInfo &tmpPacket);
|
void HandleGameRetrievePlayerInfo(SessionWrapper session, const NetPacketRetrievePlayerInfo &tmpPacket);
|
||||||
void HandleGameRetrieveAvatar(SessionWrapper session, const NetPacketRetrieveAvatar &tmpPacket);
|
void HandleGameRetrieveAvatar(SessionWrapper session, const NetPacketRetrieveAvatar &tmpPacket);
|
||||||
|
|||||||
+33
-38
@@ -39,7 +39,8 @@
|
|||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
Session::Session(GuiInterface *g, ConfigFile *c)
|
Session::Session(GuiInterface *g, ConfigFile *c)
|
||||||
: currentGameID(0), myNetClient(NULL), myNetServer(NULL), myIrcThread(NULL), myGui(g), myConfig(c)
|
: currentGameID(0), myNetClient(NULL), myNetServer(NULL), myIrcThread(NULL),
|
||||||
|
myGui(g), myConfig(c), myGameType(GAME_TYPE_NONE)
|
||||||
{
|
{
|
||||||
myAvatarManager.reset(new AvatarManager);
|
myAvatarManager.reset(new AvatarManager);
|
||||||
}
|
}
|
||||||
@@ -49,7 +50,6 @@ Session::~Session()
|
|||||||
{
|
{
|
||||||
terminateNetworkClient();
|
terminateNetworkClient();
|
||||||
terminateNetworkServer();
|
terminateNetworkServer();
|
||||||
terminateIrcClient();
|
|
||||||
delete myConfig;
|
delete myConfig;
|
||||||
myConfig = 0;
|
myConfig = 0;
|
||||||
}
|
}
|
||||||
@@ -61,6 +61,8 @@ bool Session::init()
|
|||||||
|
|
||||||
void Session::startLocalGame(const GameData &gameData, const StartData &startData) {
|
void Session::startLocalGame(const GameData &gameData, const StartData &startData) {
|
||||||
|
|
||||||
|
myGameType = GAME_TYPE_LOCAL;
|
||||||
|
|
||||||
currentGame.reset();
|
currentGame.reset();
|
||||||
currentGameID++;
|
currentGameID++;
|
||||||
|
|
||||||
@@ -96,7 +98,6 @@ void Session::startLocalGame(const GameData &gameData, const StartData &startDat
|
|||||||
currentGame->initHand();
|
currentGame->initHand();
|
||||||
currentGame->startHand();
|
currentGame->startHand();
|
||||||
// SPIEL-SCHLEIFE
|
// SPIEL-SCHLEIFE
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Session::startClientGame(boost::shared_ptr<Game> game)
|
void Session::startClientGame(boost::shared_ptr<Game> game)
|
||||||
@@ -116,13 +117,29 @@ GuiInterface *Session::getGui()
|
|||||||
return myGui;
|
return myGui;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Session::GameType Session::GetGameType()
|
||||||
|
{
|
||||||
|
return myGameType;
|
||||||
|
}
|
||||||
|
|
||||||
void Session::startInternetClient()
|
void Session::startInternetClient()
|
||||||
{
|
{
|
||||||
if (myNetClient || !myGui)
|
if (myNetClient || myIrcThread || !myGui)
|
||||||
{
|
{
|
||||||
assert(false);
|
assert(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
myGameType = GAME_TYPE_INTERNET;
|
||||||
|
|
||||||
|
myIrcThread = new IrcThread(*myGui);
|
||||||
|
myIrcThread->Init(
|
||||||
|
myConfig->readConfigString("IRCServerAddress"),
|
||||||
|
myConfig->readConfigInt("IRCServerPort"),
|
||||||
|
myConfig->readConfigInt("IRCServerUseIpv6") == 1,
|
||||||
|
myConfig->readConfigString("MyName"),
|
||||||
|
myConfig->readConfigString("IRCChannel"));
|
||||||
|
myIrcThread->Run();
|
||||||
|
|
||||||
myNetClient = new ClientThread(*myGui, *myAvatarManager);
|
myNetClient = new ClientThread(*myGui, *myAvatarManager);
|
||||||
myNetClient->Init(
|
myNetClient->Init(
|
||||||
myConfig->readConfigString("InternetServerAddress"),
|
myConfig->readConfigString("InternetServerAddress"),
|
||||||
@@ -142,6 +159,8 @@ void Session::startNetworkClient(const string &serverAddress, unsigned serverPor
|
|||||||
assert(false);
|
assert(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
myGameType = GAME_TYPE_NETWORK;
|
||||||
|
|
||||||
myNetClient = new ClientThread(*myGui, *myAvatarManager);
|
myNetClient = new ClientThread(*myGui, *myAvatarManager);
|
||||||
myNetClient->Init(
|
myNetClient->Init(
|
||||||
serverAddress,
|
serverAddress,
|
||||||
@@ -162,6 +181,8 @@ void Session::startNetworkClientForLocalServer(const GameData &gameData)
|
|||||||
assert(false);
|
assert(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
myGameType = GAME_TYPE_NETWORK;
|
||||||
|
|
||||||
myNetClient = new ClientThread(*myGui, *myAvatarManager);
|
myNetClient = new ClientThread(*myGui, *myAvatarManager);
|
||||||
bool useIpv6 = myConfig->readConfigInt("ServerUseIpv6") == 1;
|
bool useIpv6 = myConfig->readConfigInt("ServerUseIpv6") == 1;
|
||||||
const char *loopbackAddr = useIpv6 ? "::1" : "127.0.0.1";
|
const char *loopbackAddr = useIpv6 ? "::1" : "127.0.0.1";
|
||||||
@@ -182,13 +203,18 @@ void Session::terminateNetworkClient()
|
|||||||
if (!myNetClient)
|
if (!myNetClient)
|
||||||
return; // already terminated
|
return; // already terminated
|
||||||
myNetClient->SignalTermination();
|
myNetClient->SignalTermination();
|
||||||
// Give the thread some time to terminate.
|
if (myIrcThread)
|
||||||
|
myIrcThread->SignalTermination();
|
||||||
|
// Give the threads some time to terminate.
|
||||||
if (myNetClient->Join(NET_CLIENT_TERMINATE_TIMEOUT_MSEC))
|
if (myNetClient->Join(NET_CLIENT_TERMINATE_TIMEOUT_MSEC))
|
||||||
{
|
|
||||||
delete myNetClient;
|
delete myNetClient;
|
||||||
}
|
if (myIrcThread && myIrcThread->Join(NET_IRC_TERMINATE_TIMEOUT_MSEC))
|
||||||
|
delete myIrcThread;
|
||||||
|
|
||||||
// If termination fails, leave a memory leak to prevent a crash.
|
// If termination fails, leave a memory leak to prevent a crash.
|
||||||
myNetClient = 0;
|
myNetClient = 0;
|
||||||
|
myIrcThread = 0;
|
||||||
|
myGameType = GAME_TYPE_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Session::clientCreateGame(const GameData &gameData, const string &name, const string &password)
|
void Session::clientCreateGame(const GameData &gameData, const string &name, const string &password)
|
||||||
@@ -252,23 +278,6 @@ bool Session::waitForNetworkServer(unsigned timeoutMsec)
|
|||||||
return retVal;
|
return retVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Session::startIrcClient()
|
|
||||||
{
|
|
||||||
if (myIrcThread || !myGui)
|
|
||||||
{
|
|
||||||
assert(false);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
myIrcThread = new IrcThread(*myGui);
|
|
||||||
myIrcThread->Init(
|
|
||||||
myConfig->readConfigString("IRCServerAddress"),
|
|
||||||
myConfig->readConfigInt("IRCServerPort"),
|
|
||||||
myConfig->readConfigInt("IRCServerUseIpv6") == 1,
|
|
||||||
myConfig->readConfigString("MyName"),
|
|
||||||
myConfig->readConfigString("IRCChannel"));
|
|
||||||
myIrcThread->Run();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Session::sendIrcChatMessage(const std::string &message)
|
void Session::sendIrcChatMessage(const std::string &message)
|
||||||
{
|
{
|
||||||
if (!myIrcThread)
|
if (!myIrcThread)
|
||||||
@@ -276,20 +285,6 @@ void Session::sendIrcChatMessage(const std::string &message)
|
|||||||
myIrcThread->SendChatMessage(message);
|
myIrcThread->SendChatMessage(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Session::terminateIrcClient()
|
|
||||||
{
|
|
||||||
if (!myIrcThread)
|
|
||||||
return; // already terminated
|
|
||||||
myIrcThread->SignalTermination();
|
|
||||||
// Give the thread some time to terminate.
|
|
||||||
if (myIrcThread->Join(NET_IRC_TERMINATE_TIMEOUT_MSEC))
|
|
||||||
delete myIrcThread;
|
|
||||||
else
|
|
||||||
assert(false);
|
|
||||||
// If termination fails, leave a memory leak to prevent a crash.
|
|
||||||
myIrcThread = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Session::sendLeaveCurrentGame()
|
void Session::sendLeaveCurrentGame()
|
||||||
{
|
{
|
||||||
if (!myNetClient)
|
if (!myNetClient)
|
||||||
|
|||||||
+5
-2
@@ -40,6 +40,8 @@ public:
|
|||||||
|
|
||||||
~Session();
|
~Session();
|
||||||
|
|
||||||
|
enum GameType { GAME_TYPE_NONE, GAME_TYPE_LOCAL, GAME_TYPE_NETWORK, GAME_TYPE_INTERNET };
|
||||||
|
|
||||||
bool init();
|
bool init();
|
||||||
|
|
||||||
void startLocalGame(const GameData &gameData, const StartData &startData);
|
void startLocalGame(const GameData &gameData, const StartData &startData);
|
||||||
@@ -49,6 +51,8 @@ public:
|
|||||||
|
|
||||||
GuiInterface *getGui();
|
GuiInterface *getGui();
|
||||||
|
|
||||||
|
GameType GetGameType();
|
||||||
|
|
||||||
void startInternetClient();
|
void startInternetClient();
|
||||||
void startNetworkClient(const std::string &serverAddress, unsigned serverPort, bool ipv6, bool sctp, const std::string &pwd);
|
void startNetworkClient(const std::string &serverAddress, unsigned serverPort, bool ipv6, bool sctp, const std::string &pwd);
|
||||||
void startNetworkClientForLocalServer(const GameData &gameData);
|
void startNetworkClientForLocalServer(const GameData &gameData);
|
||||||
@@ -62,9 +66,7 @@ public:
|
|||||||
void terminateNetworkServer();
|
void terminateNetworkServer();
|
||||||
bool waitForNetworkServer(unsigned timeoutMsec);
|
bool waitForNetworkServer(unsigned timeoutMsec);
|
||||||
|
|
||||||
void startIrcClient();
|
|
||||||
void sendIrcChatMessage(const std::string &message);
|
void sendIrcChatMessage(const std::string &message);
|
||||||
void terminateIrcClient();
|
|
||||||
|
|
||||||
void sendClientPlayerAction();
|
void sendClientPlayerAction();
|
||||||
|
|
||||||
@@ -92,6 +94,7 @@ private:
|
|||||||
boost::shared_ptr<Game> currentGame;
|
boost::shared_ptr<Game> currentGame;
|
||||||
GuiInterface *myGui;
|
GuiInterface *myGui;
|
||||||
ConfigFile *myConfig;
|
ConfigFile *myConfig;
|
||||||
|
GameType myGameType;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user