- Fixed crash in IPC code
authorunc0rr
Mon, 09 Jan 2006 20:29:14 +0000
changeset 41 5d7a505875cd
parent 40 416d54ce0c34
child 42 72ffe21f027c
- Fixed crash in IPC code - Fix exec engine by frontend
QTfrontend/game.cpp
QTfrontend/game.h
QTfrontend/hwform.cpp
QTfrontend/hwform.ui
--- a/QTfrontend/game.cpp	Sat Jan 07 15:23:45 2006 +0000
+++ b/QTfrontend/game.cpp	Mon Jan 09 20:29:14 2006 +0000
@@ -45,15 +45,6 @@
 {
 	vid_Resolution = Resolution;
 	vid_Fullscreen = Fullscreen;
-	IPCServer.setMaxPendingConnections(1);
-	if (!IPCServer.listen(QHostAddress::LocalHost, IPC_PORT))
-	{
-		QMessageBox::critical(0, tr("Error"),
-				tr("Unable to start the server: %1.")
-				.arg(IPCServer.errorString()));
-	}
-	connect(&IPCServer, SIGNAL(newConnection()), this, SLOT(NewConnection()));
-	IPCSocket = 0;
 	TeamCount = 0;
 	seed = "";
 	cfgdir.setPath(cfgdir.homePath());
@@ -62,9 +53,10 @@
 
 void HWGame::NewConnection()
 {
-	QTcpSocket * client = IPCServer.nextPendingConnection();
+	QTcpSocket * client = IPCServer->nextPendingConnection();
 	if(!IPCSocket)
 	{
+		IPCServer->close();
 		IPCSocket = client;
 		connect(client, SIGNAL(disconnected()), this, SLOT(ClientDisconnect()));
 		connect(client, SIGNAL(readyRead()), this, SLOT(ClientRead()));
@@ -73,16 +65,17 @@
 			SENDIPC("?");
 	} else
 	{
+		qWarning("2nd IPC client?!");
 		client->disconnectFromHost();
-		delete client;
 	}
 }
 
 void HWGame::ClientDisconnect()
 {
+	SaveDemo("demo.hwd_1");
+    IPCSocket->deleteLater();
 	IPCSocket = 0;
-	SaveDemo("demo.hwd_1");
-	delete this;
+	deleteLater();
 }
 
 void HWGame::SendTeamConfig(int index)
@@ -218,6 +211,17 @@
 
 void HWGame::Start()
 {
+	IPCServer = new QTcpServer(this);
+	connect(IPCServer, SIGNAL(newConnection()), this, SLOT(NewConnection()));
+	IPCServer->setMaxPendingConnections(1);
+	IPCSocket = 0;
+	if (!IPCServer->listen(QHostAddress::LocalHost, IPC_PORT))
+	{
+		QMessageBox::critical(0, tr("Error"),
+				tr("Unable to start the server: %1.")
+				.arg(IPCServer->errorString()));
+	}
+
 	QProcess * process;
 	QStringList arguments;
 	process = new QProcess;
@@ -227,7 +231,7 @@
 	arguments << "46631";
 	arguments << seed;
 	arguments << (vid_Fullscreen ? "1" : "0");
-	process->start("hw", arguments);
+	process->start("./hw", arguments);
 }
 
 void HWGame::AddTeam(const QString & teamname)
@@ -265,7 +269,7 @@
 	quint32 k = 0;
 	for (int i = 0; i < seed.length(); i++)
 	{
-		k += seed[i].unicode();
+		k += seed[i].cell();
 	}
 	return themes[k % len];
 }
--- a/QTfrontend/game.h	Sat Jan 07 15:23:45 2006 +0000
+++ b/QTfrontend/game.h	Mon Jan 09 20:29:14 2006 +0000
@@ -70,7 +70,7 @@
         gtDemo  = 2,
         gtNet   = 3
     };
-    QTcpServer IPCServer;
+    QTcpServer * IPCServer;
 	QTcpSocket * IPCSocket;
 	char msgbuf[MAXMSGCHARS];
 	quint8 msgbufsize;
--- a/QTfrontend/hwform.cpp	Sat Jan 07 15:23:45 2006 +0000
+++ b/QTfrontend/hwform.cpp	Mon Jan 09 20:29:14 2006 +0000
@@ -70,11 +70,11 @@
 	for(quint8 i = 0; i < BINDS_NUMBER; i++)
 	{
 		LBind[i] = new QLabel(ui.BindsBox->widget(widind));
-		LBind[i]->setGeometry(QRect(10, top + 3, 60, 20));
+		LBind[i]->setGeometry(QRect(10, top + 3, 70, 20));
 		LBind[i]->setText(cbinds[i].name);
 		LBind[i]->setAlignment(Qt::AlignRight);
 		CBBind[i] = new QComboBox(ui.BindsBox->widget(widind));
-		CBBind[i]->setGeometry(QRect(80, top, 80, 20));
+		CBBind[i]->setGeometry(QRect(90, top, 80, 20));
 		CBBind[i]->addItems(binds);
 		if (cbinds[i].chwidget)
 		{
@@ -82,7 +82,7 @@
 			widind++;
 		} else
 		{
-			top += 30;
+			top += 28;
 		}
 	}
 
--- a/QTfrontend/hwform.ui	Sat Jan 07 15:23:45 2006 +0000
+++ b/QTfrontend/hwform.ui	Mon Jan 09 20:29:14 2006 +0000
@@ -50,7 +50,7 @@
      </size>
     </property>
     <property name="currentIndex" >
-     <number>8</number>
+     <number>1</number>
     </property>
     <widget class="QWidget" name="pageLG" >
      <widget class="QPushButton" name="BtnSimpleGame" >
@@ -141,119 +141,6 @@
        <string>Team</string>
       </property>
      </widget>
-     <widget class="QGroupBox" name="GBoxPlayer" >
-      <property name="geometry" >
-       <rect>
-        <x>20</x>
-        <y>340</y>
-        <width>161</width>
-        <height>51</height>
-       </rect>
-      </property>
-      <property name="title" >
-       <string>Player</string>
-      </property>
-      <widget class="QComboBox" name="comboBox" >
-       <property name="geometry" >
-        <rect>
-         <x>10</x>
-         <y>20</y>
-         <width>141</width>
-         <height>22</height>
-        </rect>
-       </property>
-       <item>
-        <property name="text" >
-         <string>Human</string>
-        </property>
-       </item>
-       <item>
-        <property name="text" >
-         <string>CPU level 1</string>
-        </property>
-       </item>
-       <item>
-        <property name="text" >
-         <string>CPU level 2</string>
-        </property>
-       </item>
-       <item>
-        <property name="text" >
-         <string>CPU level 3</string>
-        </property>
-       </item>
-       <item>
-        <property name="text" >
-         <string>CPU level 4</string>
-        </property>
-       </item>
-       <item>
-        <property name="text" >
-         <string>CPU level 5</string>
-        </property>
-       </item>
-      </widget>
-     </widget>
-     <widget class="QPushButton" name="BtnTeamDiscard" >
-      <property name="geometry" >
-       <rect>
-        <x>440</x>
-        <y>400</y>
-        <width>161</width>
-        <height>41</height>
-       </rect>
-      </property>
-      <property name="font" >
-       <font>
-        <family>MS Shell Dlg</family>
-        <pointsize>14</pointsize>
-        <weight>50</weight>
-        <italic>false</italic>
-        <bold>false</bold>
-        <underline>false</underline>
-        <strikeout>false</strikeout>
-       </font>
-      </property>
-      <property name="text" >
-       <string>Discard</string>
-      </property>
-      <property name="checkable" >
-       <bool>false</bool>
-      </property>
-      <property name="checked" >
-       <bool>false</bool>
-      </property>
-     </widget>
-     <widget class="QPushButton" name="BtnTeamSave" >
-      <property name="geometry" >
-       <rect>
-        <x>440</x>
-        <y>340</y>
-        <width>161</width>
-        <height>41</height>
-       </rect>
-      </property>
-      <property name="font" >
-       <font>
-        <family>MS Shell Dlg</family>
-        <pointsize>14</pointsize>
-        <weight>50</weight>
-        <italic>false</italic>
-        <bold>false</bold>
-        <underline>false</underline>
-        <strikeout>false</strikeout>
-       </font>
-      </property>
-      <property name="text" >
-       <string>Save</string>
-      </property>
-      <property name="checkable" >
-       <bool>false</bool>
-      </property>
-      <property name="checked" >
-       <bool>false</bool>
-      </property>
-     </widget>
      <widget class="QGroupBox" name="GBoxFort" >
       <property name="geometry" >
        <rect>
@@ -353,7 +240,7 @@
         <x>200</x>
         <y>10</y>
         <width>201</width>
-        <height>381</height>
+        <height>431</height>
        </rect>
       </property>
       <property name="title" >
@@ -365,7 +252,7 @@
          <x>10</x>
          <y>20</y>
          <width>181</width>
-         <height>351</height>
+         <height>401</height>
         </rect>
        </property>
        <property name="lineWidth" >
@@ -379,8 +266,8 @@
          <rect>
           <x>0</x>
           <y>0</y>
-          <width>163</width>
-          <height>221</height>
+          <width>181</width>
+          <height>289</height>
          </rect>
         </property>
         <attribute name="label" >
@@ -402,8 +289,8 @@
          <rect>
           <x>0</x>
           <y>0</y>
-          <width>163</width>
-          <height>221</height>
+          <width>99</width>
+          <height>29</height>
          </rect>
         </property>
         <attribute name="label" >
@@ -412,6 +299,66 @@
        </widget>
       </widget>
      </widget>
+     <widget class="QPushButton" name="BtnTeamDiscard" >
+      <property name="geometry" >
+       <rect>
+        <x>440</x>
+        <y>380</y>
+        <width>161</width>
+        <height>41</height>
+       </rect>
+      </property>
+      <property name="font" >
+       <font>
+        <family>MS Shell Dlg</family>
+        <pointsize>14</pointsize>
+        <weight>50</weight>
+        <italic>false</italic>
+        <bold>false</bold>
+        <underline>false</underline>
+        <strikeout>false</strikeout>
+       </font>
+      </property>
+      <property name="text" >
+       <string>Discard</string>
+      </property>
+      <property name="checkable" >
+       <bool>false</bool>
+      </property>
+      <property name="checked" >
+       <bool>false</bool>
+      </property>
+     </widget>
+     <widget class="QPushButton" name="BtnTeamSave" >
+      <property name="geometry" >
+       <rect>
+        <x>20</x>
+        <y>380</y>
+        <width>161</width>
+        <height>41</height>
+       </rect>
+      </property>
+      <property name="font" >
+       <font>
+        <family>MS Shell Dlg</family>
+        <pointsize>14</pointsize>
+        <weight>50</weight>
+        <italic>false</italic>
+        <bold>false</bold>
+        <underline>false</underline>
+        <strikeout>false</strikeout>
+       </font>
+      </property>
+      <property name="text" >
+       <string>Save</string>
+      </property>
+      <property name="checkable" >
+       <bool>false</bool>
+      </property>
+      <property name="checked" >
+       <bool>false</bool>
+      </property>
+     </widget>
     </widget>
     <widget class="QWidget" name="pageOpt" >
      <widget class="QGroupBox" name="groupBox" >
@@ -541,66 +488,6 @@
        <string>Fullscreen</string>
       </property>
      </widget>
-     <widget class="QPushButton" name="BtnSetupBack" >
-      <property name="geometry" >
-       <rect>
-        <x>420</x>
-        <y>380</y>
-        <width>161</width>
-        <height>41</height>
-       </rect>
-      </property>
-      <property name="font" >
-       <font>
-        <family>MS Shell Dlg</family>
-        <pointsize>14</pointsize>
-        <weight>50</weight>
-        <italic>false</italic>
-        <bold>false</bold>
-        <underline>false</underline>
-        <strikeout>false</strikeout>
-       </font>
-      </property>
-      <property name="text" >
-       <string>Back</string>
-      </property>
-      <property name="checkable" >
-       <bool>false</bool>
-      </property>
-      <property name="checked" >
-       <bool>false</bool>
-      </property>
-     </widget>
-     <widget class="QPushButton" name="BtnSaveOptions" >
-      <property name="geometry" >
-       <rect>
-        <x>30</x>
-        <y>380</y>
-        <width>161</width>
-        <height>41</height>
-       </rect>
-      </property>
-      <property name="font" >
-       <font>
-        <family>MS Shell Dlg</family>
-        <pointsize>14</pointsize>
-        <weight>50</weight>
-        <italic>false</italic>
-        <bold>false</bold>
-        <underline>false</underline>
-        <strikeout>false</strikeout>
-       </font>
-      </property>
-      <property name="text" >
-       <string>Save</string>
-      </property>
-      <property name="checkable" >
-       <bool>false</bool>
-      </property>
-      <property name="checked" >
-       <bool>false</bool>
-      </property>
-     </widget>
      <widget class="QLabel" name="label" >
       <property name="geometry" >
        <rect>
@@ -630,6 +517,66 @@
        <number>30</number>
       </property>
      </widget>
+     <widget class="QPushButton" name="BtnSaveOptions" >
+      <property name="geometry" >
+       <rect>
+        <x>20</x>
+        <y>380</y>
+        <width>161</width>
+        <height>41</height>
+       </rect>
+      </property>
+      <property name="font" >
+       <font>
+        <family>MS Shell Dlg</family>
+        <pointsize>14</pointsize>
+        <weight>50</weight>
+        <italic>false</italic>
+        <bold>false</bold>
+        <underline>false</underline>
+        <strikeout>false</strikeout>
+       </font>
+      </property>
+      <property name="text" >
+       <string>Save</string>
+      </property>
+      <property name="checkable" >
+       <bool>false</bool>
+      </property>
+      <property name="checked" >
+       <bool>false</bool>
+      </property>
+     </widget>
+     <widget class="QPushButton" name="BtnSetupBack" >
+      <property name="geometry" >
+       <rect>
+        <x>440</x>
+        <y>380</y>
+        <width>161</width>
+        <height>41</height>
+       </rect>
+      </property>
+      <property name="font" >
+       <font>
+        <family>MS Shell Dlg</family>
+        <pointsize>14</pointsize>
+        <weight>50</weight>
+        <italic>false</italic>
+        <bold>false</bold>
+        <underline>false</underline>
+        <strikeout>false</strikeout>
+       </font>
+      </property>
+      <property name="text" >
+       <string>Back</string>
+      </property>
+      <property name="checkable" >
+       <bool>false</bool>
+      </property>
+      <property name="checked" >
+       <bool>false</bool>
+      </property>
+     </widget>
     </widget>
     <widget class="QWidget" name="page" >
      <widget class="QPushButton" name="BtnMPBack" >