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:
lotodore
2007-10-08 20:14:44 +00:00
parent dc8f9e0c73
commit 310fadefdb
9 changed files with 77 additions and 59 deletions
@@ -49,10 +49,6 @@ void gameLobbyDialogImpl::exec()
{
hideShowGameDescription(FALSE);
assert(mySession);
mySession->terminateIrcClient();
mySession->startIrcClient();
if(myConfig->readConfigInt("UseIRCLobbyChat")) {
groupBox_lobbyChat->show();
}
@@ -61,7 +57,6 @@ void gameLobbyDialogImpl::exec()
}
QDialog::exec();
mySession->terminateIrcClient();
}
+1 -1
View File
@@ -140,7 +140,7 @@ void GuiWrapper::SignalNetClientGameListPlayerLeft(unsigned gameId, unsigned pla
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->signalShowNetworkStartDialog(); }
void GuiWrapper::SignalNetClientWaitDialog() { myW->signalShowClientDialog(); }
void GuiWrapper::SignalNetServerSuccess(int actionID) { }
void GuiWrapper::SignalNetServerError(int errorID, int osErrorID) { myW->signalNetServerError(errorID, osErrorID); }
+25 -12
View File
@@ -605,7 +605,7 @@ mainWindowImpl::mainWindowImpl(ConfigFile *c, QMainWindow *parent)
//Nachrichten Thread-Save
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(signalRefreshCash()), this, SLOT(refreshCash()));
@@ -984,17 +984,7 @@ void mainWindowImpl::joinGameLobby() {
}
else
{
myGameLobbyDialog->exec();
if (myGameLobbyDialog->result() == QDialog::Accepted)
{
//some gui modifications
networkGameModification();
}
else
{
mySession->terminateNetworkClient();
}
showLobbyDialog();
}
}
@@ -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()
{
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; }
void mainWindowImpl::setSession(boost::shared_ptr<Session> session) { mySession = session; }
+3 -1
View File
@@ -76,7 +76,7 @@ public:
signals:
void signalInitGui(int speed);
void signalShowNetworkStartDialog();
void signalShowClientDialog();
void signalRefreshSet();
void signalRefreshCash();
@@ -154,7 +154,9 @@ public slots:
void initGui(int speed);
void showClientDialog();
void showNetworkStartDialog();
void showLobbyDialog();
//refresh-Funktionen
void refreshSet();
+1
View File
@@ -1126,6 +1126,7 @@ ServerGameStateNextGameDelay::Process(ServerGameThread &server)
// Wait for the start of a new game.
server.SetState(ServerGameStateInit::Instance());
server.GetLobbyThread().NotifyReopeningGame(server.GetId());
}
return retVal;
+8
View File
@@ -162,6 +162,14 @@ ServerLobbyThread::NotifyStartingGame(unsigned gameId)
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
ServerLobbyThread::HandleGameRetrievePlayerInfo(SessionWrapper session, const NetPacketRetrievePlayerInfo &tmpPacket)
{
+1
View File
@@ -59,6 +59,7 @@ public:
void NotifyPlayerJoinedGame(unsigned gameId, unsigned playerId);
void NotifyPlayerLeftGame(unsigned gameId, unsigned playerId);
void NotifyStartingGame(unsigned gameId);
void NotifyReopeningGame(unsigned gameId);
void HandleGameRetrievePlayerInfo(SessionWrapper session, const NetPacketRetrievePlayerInfo &tmpPacket);
void HandleGameRetrieveAvatar(SessionWrapper session, const NetPacketRetrieveAvatar &tmpPacket);
+33 -38
View File
@@ -39,7 +39,8 @@
using namespace std;
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);
}
@@ -49,7 +50,6 @@ Session::~Session()
{
terminateNetworkClient();
terminateNetworkServer();
terminateIrcClient();
delete myConfig;
myConfig = 0;
}
@@ -61,6 +61,8 @@ bool Session::init()
void Session::startLocalGame(const GameData &gameData, const StartData &startData) {
myGameType = GAME_TYPE_LOCAL;
currentGame.reset();
currentGameID++;
@@ -96,7 +98,6 @@ void Session::startLocalGame(const GameData &gameData, const StartData &startDat
currentGame->initHand();
currentGame->startHand();
// SPIEL-SCHLEIFE
}
void Session::startClientGame(boost::shared_ptr<Game> game)
@@ -116,13 +117,29 @@ GuiInterface *Session::getGui()
return myGui;
}
Session::GameType Session::GetGameType()
{
return myGameType;
}
void Session::startInternetClient()
{
if (myNetClient || !myGui)
if (myNetClient || myIrcThread || !myGui)
{
assert(false);
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->Init(
myConfig->readConfigString("InternetServerAddress"),
@@ -142,6 +159,8 @@ void Session::startNetworkClient(const string &serverAddress, unsigned serverPor
assert(false);
return;
}
myGameType = GAME_TYPE_NETWORK;
myNetClient = new ClientThread(*myGui, *myAvatarManager);
myNetClient->Init(
serverAddress,
@@ -162,6 +181,8 @@ void Session::startNetworkClientForLocalServer(const GameData &gameData)
assert(false);
return;
}
myGameType = GAME_TYPE_NETWORK;
myNetClient = new ClientThread(*myGui, *myAvatarManager);
bool useIpv6 = myConfig->readConfigInt("ServerUseIpv6") == 1;
const char *loopbackAddr = useIpv6 ? "::1" : "127.0.0.1";
@@ -182,13 +203,18 @@ void Session::terminateNetworkClient()
if (!myNetClient)
return; // already terminated
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))
{
delete myNetClient;
}
if (myIrcThread && myIrcThread->Join(NET_IRC_TERMINATE_TIMEOUT_MSEC))
delete myIrcThread;
// If termination fails, leave a memory leak to prevent a crash.
myNetClient = 0;
myIrcThread = 0;
myGameType = GAME_TYPE_NONE;
}
void Session::clientCreateGame(const GameData &gameData, const string &name, const string &password)
@@ -252,23 +278,6 @@ bool Session::waitForNetworkServer(unsigned timeoutMsec)
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)
{
if (!myIrcThread)
@@ -276,20 +285,6 @@ void Session::sendIrcChatMessage(const std::string &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()
{
if (!myNetClient)
+5 -2
View File
@@ -40,6 +40,8 @@ public:
~Session();
enum GameType { GAME_TYPE_NONE, GAME_TYPE_LOCAL, GAME_TYPE_NETWORK, GAME_TYPE_INTERNET };
bool init();
void startLocalGame(const GameData &gameData, const StartData &startData);
@@ -49,6 +51,8 @@ public:
GuiInterface *getGui();
GameType GetGameType();
void startInternetClient();
void startNetworkClient(const std::string &serverAddress, unsigned serverPort, bool ipv6, bool sctp, const std::string &pwd);
void startNetworkClientForLocalServer(const GameData &gameData);
@@ -62,9 +66,7 @@ public:
void terminateNetworkServer();
bool waitForNetworkServer(unsigned timeoutMsec);
void startIrcClient();
void sendIrcChatMessage(const std::string &message);
void terminateIrcClient();
void sendClientPlayerAction();
@@ -92,6 +94,7 @@ private:
boost::shared_ptr<Game> currentGame;
GuiInterface *myGui;
ConfigFile *myConfig;
GameType myGameType;
};