--- a/QTfrontend/frameTeam.cpp Sat Feb 03 21:40:50 2007 +0000
+++ b/QTfrontend/frameTeam.cpp Sun Feb 04 14:35:28 2007 +0000
@@ -67,8 +67,8 @@
TeamShowWidget* pTeamShowWidget = new TeamShowWidget(team, willPlay, this);
if(nonInteractive) pTeamShowWidget->setNonInteractive();
// int hght=teamToWidget.empty() ? 0 : teamToWidget.begin()->second->size().height();
+ mainLayout.addWidget(pTeamShowWidget);
teamToWidget.insert(team, pTeamShowWidget);
- mainLayout.addWidget(pTeamShowWidget);
QResizeEvent* pevent=new QResizeEvent(parentWidget()->size(), parentWidget()->size());
QCoreApplication::postEvent(parentWidget(), pevent);
}
@@ -76,11 +76,21 @@
void FrameTeams::removeTeam(HWTeam team)
{
tmapTeamToWidget::iterator it=teamToWidget.find(team);
+ if(it==teamToWidget.end()) return;
mainLayout.removeWidget(it.value());
delete it.value();
teamToWidget.erase(it);
}
+void FrameTeams::resetTeams()
+{
+ for(tmapTeamToWidget::iterator it=teamToWidget.begin(); it!=teamToWidget.end(); ) {
+ mainLayout.removeWidget(it.value());
+ delete it.value();
+ teamToWidget.erase(it++);
+ }
+}
+
void FrameTeams::setHHNum(const HWTeam& team)
{
TeamShowWidget* pTeamShowWidget = dynamic_cast<TeamShowWidget*>(getTeamWidget(team));
--- a/QTfrontend/frameTeam.h Sat Feb 03 21:40:50 2007 +0000
+++ b/QTfrontend/frameTeam.h Sun Feb 04 14:35:28 2007 +0000
@@ -38,6 +38,7 @@
QWidget* getTeamWidget(HWTeam team);
bool isFullTeams() const;
void resetColors();
+ void resetTeams();
void setHHNum(const HWTeam& team);
void setTeamColor(const HWTeam& team);
void setNonInteractive();
@@ -59,7 +60,7 @@
void emitTeamColorChanged(const HWTeam& team);
QVBoxLayout mainLayout;
- typedef QMultiMap<HWTeam, QWidget*> tmapTeamToWidget;
+ typedef QMap<HWTeam, QWidget*> tmapTeamToWidget;
tmapTeamToWidget teamToWidget;
bool nonInteractive;
};
--- a/QTfrontend/hwform.cpp Sat Feb 03 21:40:50 2007 +0000
+++ b/QTfrontend/hwform.cpp Sun Feb 04 14:35:28 2007 +0000
@@ -181,7 +181,7 @@
void HWForm::GoBack()
{
if (!PagesStack.isEmpty() && PagesStack.top() == ID_PAGE_NET) {
- NetDisconnect();
+ if(hwnet || pnetserver) NetDisconnect();
}
quint8 id = PagesStack.isEmpty() ? ID_PAGE_MAIN : PagesStack.pop();
OnPageShown(id);
@@ -261,6 +261,7 @@
connect(ui.pageNetGame->pGameCFG, SIGNAL(turnTimeChanged(quint32)), hwnet, SLOT(onTurnTimeChanged(quint32)));
connect(ui.pageNetGame->pGameCFG, SIGNAL(fortsModeChanged(bool)), hwnet, SLOT(onFortsModeChanged(bool)));
+ connect(hwnet, SIGNAL(Disconnected()), this, SLOT(ForcedDisconnect()));
connect(hwnet, SIGNAL(seedChanged(const QString &)), ui.pageNetGame->pGameCFG, SLOT(setSeed(const QString &)));
connect(hwnet, SIGNAL(mapChanged(const QString &)), ui.pageNetGame->pGameCFG, SLOT(setMap(const QString &)));
connect(hwnet, SIGNAL(themeChanged(const QString &)), ui.pageNetGame->pGameCFG, SLOT(setTheme(const QString &)));
@@ -290,9 +291,11 @@
void HWForm::NetDisconnect()
{
- hwnet->Disconnect();
- delete hwnet;
- hwnet=0;
+ if(hwnet) {
+ hwnet->Disconnect();
+ delete hwnet;
+ hwnet=0;
+ }
if(pnetserver) {
pnetserver->StopServer();
delete pnetserver;
@@ -300,6 +303,16 @@
}
}
+void HWForm::ForcedDisconnect()
+{
+ if(pnetserver) return; // we have server - let it care of all things
+ if (hwnet) {
+ hwnet->deleteLater();
+ hwnet=0;
+ }
+ GoBack();
+}
+
void HWForm::AddGame(const QString & chan)
{
ui.pageNetChat->ChannelsList->addItem(chan);
--- a/QTfrontend/hwform.h Sat Feb 03 21:40:50 2007 +0000
+++ b/QTfrontend/hwform.h Sun Feb 04 14:35:28 2007 +0000
@@ -70,6 +70,7 @@
void StartMPGame();
void GameStateChanged(GameState gameState);
void GameStats(char type, const QString & info);
+ void ForcedDisconnect();
private:
void _NetConnect(const QString & hostName, quint16 port, const QString & nick);
--- a/QTfrontend/netserver.cpp Sat Feb 03 21:40:50 2007 +0000
+++ b/QTfrontend/netserver.cpp Sun Feb 04 14:35:28 2007 +0000
@@ -44,6 +44,10 @@
void HWNetServer::StopServer()
{
+ QList<HWConnectedClient*>::iterator it;
+ for(it=connclients.begin(); it!=connclients.end(); ++it) {
+ ClientDisconnect(*it);
+ }
IPCServer->close();
}
@@ -59,8 +63,9 @@
void HWNetServer::ClientDisconnect(HWConnectedClient* client)
{
QList<HWConnectedClient*>::iterator it=std::find(connclients.begin(), connclients.end(), client);
+ if(it==connclients.end()) return;
for(QList<QStringList>::iterator tmIt=(*it)->m_teamsCfg.begin(); tmIt!=(*it)->m_teamsCfg.end(); ++tmIt) {
- sendOthers(*it, QString("REMOVETEAM:")+delimeter+*(tmIt->begin()));
+ sendOthers(*it, QString("REMOVETEAM:")+delimeter+*(tmIt->begin()) + delimeter + *(tmIt->begin()+1));
}
connclients.erase(it);
//teamChanged();
--- a/QTfrontend/newnetclient.cpp Sat Feb 03 21:40:50 2007 +0000
+++ b/QTfrontend/newnetclient.cpp Sun Feb 04 14:35:28 2007 +0000
@@ -32,7 +32,8 @@
config(config),
m_pGameCFGWidget(pGameCFGWidget),
m_pTeamSelWidget(pTeamSelWidget),
- isChief(false)
+ isChief(false),
+ m_game_connected(false)
{
connect(&NetSocket, SIGNAL(readyRead()), this, SLOT(ClientRead()));
connect(&NetSocket, SIGNAL(connected()), this, SLOT(OnConnect()));
@@ -50,7 +51,7 @@
void HWNewNet::Disconnect()
{
- NetSocket.disconnect();
+ NetSocket.disconnectFromHost();
}
void HWNewNet::JoinGame(const QString & game)
@@ -123,7 +124,8 @@
void HWNewNet::OnDisconnect()
{
//emit ChangeInTeams(QStringList());
- emit Disconnected();
+ if(m_game_connected) emit Disconnected();
+ m_game_connected=false;
}
void HWNewNet::displayError(QAbstractSocket::SocketError socketError)
@@ -158,6 +160,7 @@
}
if (lst[0] == "CONNECTED") {
+ m_game_connected=true;
emit Connected();
emit EnteredGame();
return;
--- a/QTfrontend/newnetclient.h Sat Feb 03 21:40:50 2007 +0000
+++ b/QTfrontend/newnetclient.h Sun Feb 04 14:35:28 2007 +0000
@@ -52,6 +52,7 @@
QString mynick;
QTcpSocket NetSocket;
QString seed;
+ bool m_game_connected;
QMap<unsigned int, QString> m_networkToLocalteams; // key is netID, value is local team name
--- a/QTfrontend/teamselect.cpp Sat Feb 03 21:40:50 2007 +0000
+++ b/QTfrontend/teamselect.cpp Sun Feb 04 14:35:28 2007 +0000
@@ -197,14 +197,16 @@
void TeamSelWidget::resetPlayingTeams(const QList<HWTeam>& teamslist)
{
QList<HWTeam>::iterator it;
- for(it=curPlayingTeams.begin(); it!=curPlayingTeams.end(); it++) {
- framePlaying->removeTeam(*it);
- }
+ //for(it=curPlayingTeams.begin(); it!=curPlayingTeams.end(); it++) {
+ //framePlaying->removeTeam(*it);
+ //}
+ framePlaying->resetTeams();
framePlaying->resetColors();
curPlayingTeams.clear();
- for(it=curDontPlayingTeams.begin(); it!=curDontPlayingTeams.end(); it++) {
- frameDontPlaying->removeTeam(*it);
- }
+ //for(it=curDontPlayingTeams.begin(); it!=curDontPlayingTeams.end(); it++) {
+ //frameDontPlaying->removeTeam(*it);
+ //}
+ frameDontPlaying->resetTeams();
curDontPlayingTeams.clear();
for (QList<HWTeam>::ConstIterator it = teamslist.begin(); it != teamslist.end(); ++it ) {