43 |
43 |
44 HWGame::HWGame(int Resolution, bool Fullscreen) |
44 HWGame::HWGame(int Resolution, bool Fullscreen) |
45 { |
45 { |
46 vid_Resolution = Resolution; |
46 vid_Resolution = Resolution; |
47 vid_Fullscreen = Fullscreen; |
47 vid_Fullscreen = Fullscreen; |
48 IPCServer = new QTcpServer(this); |
48 IPCServer.setMaxPendingConnections(1); |
49 IPCServer->setMaxPendingConnections(1); |
49 if (!IPCServer.listen(QHostAddress::LocalHost, IPC_PORT)) |
50 if (!IPCServer->listen(QHostAddress("127.0.0.1"), IPC_PORT)) |
|
51 { |
50 { |
52 QMessageBox::critical(0, tr("Error"), |
51 QMessageBox::critical(0, tr("Error"), |
53 tr("Unable to start the server: %1.") |
52 tr("Unable to start the server: %1.") |
54 .arg(IPCServer->errorString())); |
53 .arg(IPCServer.errorString())); |
55 } |
54 } |
56 connect(IPCServer, SIGNAL(newConnection()), this, SLOT(NewConnection())); |
55 connect(&IPCServer, SIGNAL(newConnection()), this, SLOT(NewConnection())); |
57 IPCSocket = 0; |
56 IPCSocket = 0; |
58 TeamCount = 0; |
57 TeamCount = 0; |
59 seed = ""; |
58 seed = ""; |
60 cfgdir.setPath(cfgdir.homePath()); |
59 cfgdir.setPath(cfgdir.homePath()); |
61 cfgdir.cd(".hedgewars"); |
60 cfgdir.cd(".hedgewars"); |
62 } |
61 } |
63 |
62 |
64 void HWGame::NewConnection() |
63 void HWGame::NewConnection() |
65 { |
64 { |
66 QTcpSocket * client = IPCServer->nextPendingConnection(); |
65 QTcpSocket * client = IPCServer.nextPendingConnection(); |
67 if(!IPCSocket) |
66 if(!IPCSocket) |
68 { |
67 { |
69 IPCSocket = client; |
68 IPCSocket = client; |
70 connect(client, SIGNAL(disconnected()), this, SLOT(ClientDisconnect())); |
69 connect(client, SIGNAL(disconnected()), this, SLOT(ClientDisconnect())); |
71 connect(client, SIGNAL(readyRead()), this, SLOT(ClientRead())); |
70 connect(client, SIGNAL(readyRead()), this, SLOT(ClientRead())); |
95 { |
94 { |
96 SENDIPC("TL"); |
95 SENDIPC("TL"); |
97 // SENDIPC("e$gmflags 0"); |
96 // SENDIPC("e$gmflags 0"); |
98 SENDIPC("eaddteam"); |
97 SENDIPC("eaddteam"); |
99 SendTeamConfig(0); |
98 SendTeamConfig(0); |
100 // if () SENDIPC("rdriven"); |
|
101 SENDIPC("ecolor 65535"); |
99 SENDIPC("ecolor 65535"); |
102 SENDIPC("eadd hh0 0"); |
100 SENDIPC("eadd hh0 0"); |
103 SENDIPC("eadd hh1 0"); |
101 SENDIPC("eadd hh1 0"); |
104 SENDIPC("eadd hh2 0"); |
102 SENDIPC("eadd hh2 0"); |
105 SENDIPC("eadd hh3 0"); |
103 SENDIPC("eadd hh3 0"); |
167 } |
165 } |
168 |
166 |
169 void HWGame::SendIPC(const QByteArray & buf) |
167 void HWGame::SendIPC(const QByteArray & buf) |
170 { |
168 { |
171 if (buf.size() > MAXMSGCHARS) return; |
169 if (buf.size() > MAXMSGCHARS) return; |
|
170 quint8 len = buf.size(); |
|
171 RawSendIPC(QByteArray::fromRawData((char *)&len, 1) + buf); |
|
172 } |
|
173 |
|
174 void HWGame::RawSendIPC(const QByteArray & buf) |
|
175 { |
172 if (!IPCSocket) |
176 if (!IPCSocket) |
173 { |
177 { |
174 toSendBuf += buf; |
178 toSendBuf += buf; |
175 } else |
179 } else |
176 { |
180 { |
177 quint8 len = buf.size(); |
|
178 RawSendIPC(QByteArray::fromRawData((char *)&len, 1) + buf); |
|
179 } |
|
180 } |
|
181 |
|
182 void HWGame::RawSendIPC(const QByteArray & buf) |
|
183 { |
|
184 if (!IPCSocket) |
|
185 { |
|
186 toSendBuf += buf; |
|
187 } else |
|
188 { |
|
189 if (toSendBuf.size() > 0) |
181 if (toSendBuf.size() > 0) |
190 { |
182 { |
191 IPCSocket->write(toSendBuf); |
183 IPCSocket->write(toSendBuf); |
192 demo->append(toSendBuf); |
184 demo->append(toSendBuf); |
|
185 toSendBuf.clear(); |
193 } |
186 } |
194 IPCSocket->write(buf); |
187 IPCSocket->write(buf); |
195 demo->append(buf); |
188 demo->append(buf); |
196 } |
189 } |
197 } |
190 } |