- Fix some stupid object casts
authorunc0rr
Fri, 14 Dec 2007 15:36:00 +0000
changeset 659 5eafb20566f1
parent 658 a7e625f5d9d0
child 660 7c155e849602
- Fix some stupid object casts - Fix deleting server entry in www list
QTfrontend/hwform.cpp
QTfrontend/netregister.h
QTfrontend/netserverslist.h
QTfrontend/netudpserver.cpp
QTfrontend/netudpserver.h
QTfrontend/netwwwserver.cpp
QTfrontend/netwwwserver.h
QTfrontend/pages.cpp
--- a/QTfrontend/hwform.cpp	Fri Dec 14 15:02:46 2007 +0000
+++ b/QTfrontend/hwform.cpp	Fri Dec 14 15:36:00 2007 +0000
@@ -432,9 +432,9 @@
   _NetConnect("localhost", pnetserver->getRunningPort(), ui.pageOptions->editNetNick->text());
 
   if (ui.pageNet->rbLocalGame->isChecked())
-    pRegisterServer = new HWNetUdpServer(0, "hedgewars server", ui.pageNetServer->sbPort->value());
+    pRegisterServer = new HWNetUdpServer(0, ui.pageNetServer->leServerDescr->text(), ui.pageNetServer->sbPort->value());
   else
-    pRegisterServer = new HWNetWwwServer(0, "hedgewars server", ui.pageNetServer->sbPort->value());
+    pRegisterServer = new HWNetWwwServer(0, ui.pageNetServer->leServerDescr->text(), ui.pageNetServer->sbPort->value());
 }
 
 void HWForm::NetDisconnect()
@@ -446,7 +446,8 @@
   }
   if(pnetserver) {
     pRegisterServer->unregister();
-    pRegisterServer->deleteLater();
+    pRegisterServer = 0;
+
     pnetserver->StopServer();
     delete pnetserver;
     pnetserver=0;
--- a/QTfrontend/netregister.h	Fri Dec 14 15:02:46 2007 +0000
+++ b/QTfrontend/netregister.h	Fri Dec 14 15:36:00 2007 +0000
@@ -29,7 +29,7 @@
 	HWNetRegisterServer(QObject *parent, const QString & descr, quint16 port);
 
 public slots:
-	void unregister();
+	virtual void unregister();
 };
 
 #endif // _NET_REGISTER_INCLUDED
--- a/QTfrontend/netserverslist.h	Fri Dec 14 15:02:46 2007 +0000
+++ b/QTfrontend/netserverslist.h	Fri Dec 14 15:36:00 2007 +0000
@@ -33,7 +33,7 @@
 	QListWidget* serversList;
 
 public slots:
-	void updateList();
+	virtual void updateList();
 
 private:
 	QVBoxLayout mainLayout;
--- a/QTfrontend/netudpserver.cpp	Fri Dec 14 15:02:46 2007 +0000
+++ b/QTfrontend/netudpserver.cpp	Fri Dec 14 15:36:00 2007 +0000
@@ -42,3 +42,8 @@
     }
   }
 }
+
+void HWNetUdpServer::unregister()
+{
+  deleteLater();
+}
--- a/QTfrontend/netudpserver.h	Fri Dec 14 15:02:46 2007 +0000
+++ b/QTfrontend/netudpserver.h	Fri Dec 14 15:36:00 2007 +0000
@@ -31,6 +31,9 @@
  public:
   HWNetUdpServer(QObject *parent, const QString & descr, quint16 port);
 
+ public slots:
+  void unregister();
+
  private slots:
   void onClientRead();
 
--- a/QTfrontend/netwwwserver.cpp	Fri Dec 14 15:02:46 2007 +0000
+++ b/QTfrontend/netwwwserver.cpp	Fri Dec 14 15:36:00 2007 +0000
@@ -26,6 +26,9 @@
 HWNetWwwServer::HWNetWwwServer(QObject *parent, const QString & descr, quint16 port) :
   HWNetRegisterServer(parent, descr, port), timer(0)
 {
+	destroyPosted = false;
+	destroyPostId = 0;
+
 	http = new QHttp(this);
 	http->setHost("www.hedgewars.org", 80);
 	connect(http, SIGNAL(requestFinished(int, bool)), this, SLOT(onClientRead(int, bool)));
@@ -40,6 +43,12 @@
 
 void HWNetWwwServer::onClientRead(int id, bool error)
 {
+	if (destroyPosted && (id == destroyPostId))
+	{
+		deleteLater();
+		return;
+	}
+
 	if (error)
 	{
 		QMessageBox::critical(0,
@@ -80,5 +89,6 @@
 	QString request = QString("id=%1&key=%2")
 			.arg(servid)
 			.arg(servkey);
-	http->post("/games/destroy_game", request.toUtf8());
+	destroyPostId = http->post("/games/destroy_game", request.toUtf8());
+	destroyPosted = true;
 }
--- a/QTfrontend/netwwwserver.h	Fri Dec 14 15:02:46 2007 +0000
+++ b/QTfrontend/netwwwserver.h	Fri Dec 14 15:36:00 2007 +0000
@@ -43,6 +43,8 @@
 	QHttp * http;
 	QTimer * timer;
 	QString servid, servkey;
+	bool destroyPosted;
+	int destroyPostId;
 };
 
 #endif // _NET_WWWSERVER_INCLUDED
--- a/QTfrontend/pages.cpp	Fri Dec 14 15:02:46 2007 +0000
+++ b/QTfrontend/pages.cpp	Fri Dec 14 15:36:00 2007 +0000
@@ -486,15 +486,11 @@
 	if (netServersWidget) delete netServersWidget;
 
 	if (rbLocalGame->isChecked())
-	{
 		netServersWidget = new HWNetUdpWidget(ConnGroupBox);
-		static_cast<HWNetUdpWidget *>(netServersWidget)->updateList();
-	}
 	else
-	{
 		netServersWidget = new HWNetWwwWidget(ConnGroupBox);
-		static_cast<HWNetWwwWidget *>(netServersWidget)->updateList();
-	}
+
+	netServersWidget->updateList();
 	GBClayout->addWidget(netServersWidget, 1, 0, 1, 3);
 
 	connect(BtnUpdateSList, SIGNAL(clicked()), netServersWidget, SLOT(updateList()));