automatic assign of game server TCP port
authordisplacer
Fri, 08 Dec 2006 21:14:52 +0000
changeset 291 afa378f1e961
parent 290 09738170c557
child 292 0ca921ca7557
automatic assign of game server TCP port
QTfrontend/game.cpp
QTfrontend/hwmap.cpp
QTfrontend/tcpBase.cpp
QTfrontend/tcpBase.h
--- a/QTfrontend/game.cpp	Thu Dec 07 21:24:58 2006 +0000
+++ b/QTfrontend/game.cpp	Fri Dec 08 21:14:52 2006 +0000
@@ -189,7 +189,7 @@
 	arguments << resolutions[0][config->vid_Resolution()];
 	arguments << resolutions[1][config->vid_Resolution()];
 	arguments << "16";
-	arguments << "46631";
+	arguments << QString("%1").arg(ipc_port);
 	arguments << (config->vid_Fullscreen() ? "1" : "0");
 	arguments << (config->isSoundEnabled() ? "1" : "0");
 	arguments << tr("en.txt");
--- a/QTfrontend/hwmap.cpp	Thu Dec 07 21:24:58 2006 +0000
+++ b/QTfrontend/hwmap.cpp	Fri Dec 08 21:14:52 2006 +0000
@@ -35,7 +35,7 @@
 QStringList HWMap::setArguments()
 {
   QStringList arguments;
-  arguments << "46631";
+  arguments << QString("%1").arg(ipc_port);
   arguments << "landpreview";
   return arguments;
 }
--- a/QTfrontend/tcpBase.cpp	Thu Dec 07 21:24:58 2006 +0000
+++ b/QTfrontend/tcpBase.cpp	Fri Dec 08 21:14:52 2006 +0000
@@ -35,12 +35,14 @@
   if(!IPCServer) {
     IPCServer = new QTcpServer(this);
     IPCServer->setMaxPendingConnections(1);
-    if (!IPCServer->listen(QHostAddress::LocalHost, IPC_PORT)) {
+    if (!IPCServer->listen(QHostAddress::LocalHost)) {
       QMessageBox::critical(0, tr("Error"),
 			    tr("Unable to start the server: %1.")
 			    .arg(IPCServer->errorString()));
+      exit(0); // FIXME - should be graceful exit here
     }
   }
+  ipc_port=IPCServer->serverPort();
 }
 
 void TCPBase::NewConnection()
--- a/QTfrontend/tcpBase.h	Thu Dec 07 21:24:58 2006 +0000
+++ b/QTfrontend/tcpBase.h	Fri Dec 08 21:14:52 2006 +0000
@@ -29,7 +29,6 @@
 
 #include <QImage>
 
-#define IPC_PORT 46631
 #define MAXMSGCHARS 255
 
 class TCPBase : public QObject
@@ -43,6 +42,8 @@
   void isReadyNow();
 
  protected:
+  quint16 ipc_port;
+
   void Start();
 
   QByteArray readbuffer;