- Fix a bug when server fails to start, and then connecting to another server on the same host (strange, the fix won't work on my machine)
authorunc0rr
Sat, 15 Dec 2007 23:24:43 +0000
changeset 672 08ed55ea1e2a
parent 671 a8970859f50e
child 673 bd82104a28af
- Fix a bug when server fails to start, and then connecting to another server on the same host (strange, the fix won't work on my machine) - Fix port in previous commit
QTfrontend/hwform.cpp
QTfrontend/netserver.cpp
QTfrontend/netserver.h
QTfrontend/pages.cpp
--- a/QTfrontend/hwform.cpp	Sat Dec 15 22:57:22 2007 +0000
+++ b/QTfrontend/hwform.cpp	Sat Dec 15 23:24:43 2007 +0000
@@ -416,15 +416,24 @@
 
 void HWForm::NetStartServer()
 {
-  config->SaveOptions();
-  pnetserver = new HWNetServer;
-  pnetserver->StartServer(ui.pageNetServer->sbPort->value());
-  _NetConnect("localhost", pnetserver->getRunningPort(), ui.pageOptions->editNetNick->text());
+	config->SaveOptions();
 
-  if (ui.pageNet->rbLocalGame->isChecked())
-    pRegisterServer = new HWNetUdpServer(0, ui.pageNetServer->leServerDescr->text(), ui.pageNetServer->sbPort->value());
-  else
-    pRegisterServer = new HWNetWwwServer(0, ui.pageNetServer->leServerDescr->text(), ui.pageNetServer->sbPort->value());
+	pnetserver = new HWNetServer;
+	if(!pnetserver->StartServer(ui.pageNetServer->sbPort->value()))
+	{
+		QMessageBox::critical(0, tr("Error"),
+					tr("Unable to start the server"));
+		delete pnetserver;
+		pnetserver = 0;
+		return;
+	}
+
+	_NetConnect("localhost", pnetserver->getRunningPort(), ui.pageOptions->editNetNick->text());
+
+	if (ui.pageNet->rbLocalGame->isChecked())
+		pRegisterServer = new HWNetUdpServer(0, ui.pageNetServer->leServerDescr->text(), ui.pageNetServer->sbPort->value());
+	else
+		pRegisterServer = new HWNetWwwServer(0, ui.pageNetServer->leServerDescr->text(), ui.pageNetServer->sbPort->value());
 }
 
 void HWForm::NetDisconnect()
--- a/QTfrontend/netserver.cpp	Sat Dec 15 22:57:22 2007 +0000
+++ b/QTfrontend/netserver.cpp	Sat Dec 15 23:24:43 2007 +0000
@@ -25,18 +25,15 @@
 
 extern char delimeter;
 
-void HWNetServer::StartServer(quint16 port)
+bool HWNetServer::StartServer(quint16 port)
 {
   ds_port = port;
   hhnum=0;
   IPCServer = new QTcpServer(this);
-  if (!IPCServer->listen(QHostAddress::Any, ds_port)) {
-    QMessageBox::critical(0, tr("Error"),
-			  tr("Unable to start the server: %1.")
-			  .arg(IPCServer->errorString()));
-  }
 
   connect(IPCServer, SIGNAL(newConnection()), this, SLOT(NewConnection()));
+
+  return IPCServer->listen(QHostAddress::Any, ds_port);
 }
 
 void HWNetServer::StopServer()
--- a/QTfrontend/netserver.h	Sat Dec 15 22:57:22 2007 +0000
+++ b/QTfrontend/netserver.h	Sat Dec 15 23:24:43 2007 +0000
@@ -35,7 +35,7 @@
   Q_OBJECT
 
  public:
-  void StartServer(quint16 port);
+  bool StartServer(quint16 port);
   void StopServer();
   bool isChiefClient(HWConnectedClient* cl) const;
   QMap<QString, QStringList> getGameCfg() const;
--- a/QTfrontend/pages.cpp	Sat Dec 15 22:57:22 2007 +0000
+++ b/QTfrontend/pages.cpp	Sat Dec 15 23:24:43 2007 +0000
@@ -510,7 +510,8 @@
 	}
 	QString host = model->index(mi.row(), 1).data().toString();
 	quint16 port = model->index(mi.row(), 2).data().toUInt();
-	emit connectClicked(host, 46631);
+
+	emit connectClicked(host, port);
 }
 
 PageNetServer::PageNetServer(QWidget* parent) : QWidget(parent)