author | unc0rr |
Mon, 09 Jan 2006 20:33:12 +0000 | |
changeset 42 | 72ffe21f027c |
parent 41 | 5d7a505875cd |
child 43 | e297fea1a2f3 |
permissions | -rw-r--r-- |
25 | 1 |
/* |
2 |
* Hedgewars, a worms-like game |
|
3 |
* Copyright (c) 2005 Andrey Korotaev <unC0Rr@gmail.com> |
|
4 |
* |
|
5 |
* Distributed under the terms of the BSD-modified licence: |
|
6 |
* |
|
7 |
* Permission is hereby granted, free of charge, to any person obtaining a copy |
|
8 |
* of this software and associated documentation files (the "Software"), to deal |
|
9 |
* with the Software without restriction, including without limitation the |
|
10 |
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or |
|
11 |
* sell copies of the Software, and to permit persons to whom the Software is |
|
12 |
* furnished to do so, subject to the following conditions: |
|
13 |
* |
|
14 |
* 1. Redistributions of source code must retain the above copyright notice, |
|
15 |
* this list of conditions and the following disclaimer. |
|
16 |
* 2. Redistributions in binary form must reproduce the above copyright notice, |
|
17 |
* this list of conditions and the following disclaimer in the documentation |
|
18 |
* and/or other materials provided with the distribution. |
|
19 |
* 3. The name of the author may not be used to endorse or promote products |
|
20 |
* derived from this software without specific prior written permission. |
|
21 |
* |
|
22 |
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED |
|
23 |
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
|
24 |
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO |
|
25 |
* EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
26 |
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
|
27 |
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; |
|
28 |
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
|
29 |
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
|
30 |
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
|
31 |
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
32 |
*/ |
|
33 |
||
34 |
#include <QMessageBox> |
|
35 |
#include <QProcess> |
|
36 |
#include <QTimer> |
|
37 |
#include <QString> |
|
38 |
#include <QByteArray> |
|
39 |
#include <QTextStream> |
|
40 |
#include <QFile> |
|
41 |
#include "game.h" |
|
42 |
#include "hwconsts.h" |
|
43 |
||
26 | 44 |
HWGame::HWGame(int Resolution, bool Fullscreen) |
25 | 45 |
{ |
26 | 46 |
vid_Resolution = Resolution; |
47 |
vid_Fullscreen = Fullscreen; |
|
25 | 48 |
TeamCount = 0; |
26 | 49 |
seed = ""; |
31
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
50 |
cfgdir.setPath(cfgdir.homePath()); |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
51 |
cfgdir.cd(".hedgewars"); |
25 | 52 |
} |
53 |
||
54 |
void HWGame::NewConnection() |
|
55 |
{ |
|
41 | 56 |
QTcpSocket * client = IPCServer->nextPendingConnection(); |
25 | 57 |
if(!IPCSocket) |
58 |
{ |
|
41 | 59 |
IPCServer->close(); |
25 | 60 |
IPCSocket = client; |
61 |
connect(client, SIGNAL(disconnected()), this, SLOT(ClientDisconnect())); |
|
62 |
connect(client, SIGNAL(readyRead()), this, SLOT(ClientRead())); |
|
63 |
msgsize = 0; |
|
32
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
64 |
if (toSendBuf.size() > 0) |
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
65 |
SENDIPC("?"); |
25 | 66 |
} else |
67 |
{ |
|
41 | 68 |
qWarning("2nd IPC client?!"); |
25 | 69 |
client->disconnectFromHost(); |
70 |
} |
|
71 |
} |
|
72 |
||
73 |
void HWGame::ClientDisconnect() |
|
74 |
{ |
|
41 | 75 |
SaveDemo("demo.hwd_1"); |
76 |
IPCSocket->deleteLater(); |
|
25 | 77 |
IPCSocket = 0; |
41 | 78 |
deleteLater(); |
25 | 79 |
} |
80 |
||
81 |
void HWGame::SendTeamConfig(int index) |
|
82 |
{ |
|
31
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
83 |
LocalCFG(teams[index]); |
25 | 84 |
} |
85 |
||
86 |
void HWGame::SendConfig() |
|
87 |
{ |
|
88 |
SENDIPC("TL"); |
|
31
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
89 |
// SENDIPC("e$gmflags 0"); |
25 | 90 |
SENDIPC("eaddteam"); |
91 |
SendTeamConfig(0); |
|
92 |
SENDIPC("ecolor 65535"); |
|
93 |
SENDIPC("eadd hh0 0"); |
|
94 |
SENDIPC("eadd hh1 0"); |
|
95 |
SENDIPC("eadd hh2 0"); |
|
96 |
SENDIPC("eadd hh3 0"); |
|
28 | 97 |
SENDIPC("eadd hh4 0"); |
25 | 98 |
SENDIPC("eaddteam"); |
99 |
SendTeamConfig(1); |
|
100 |
SENDIPC("ecolor 16776960"); |
|
101 |
SENDIPC("eadd hh0 1"); |
|
102 |
SENDIPC("eadd hh1 1"); |
|
103 |
SENDIPC("eadd hh2 1"); |
|
104 |
SENDIPC("eadd hh3 1"); |
|
28 | 105 |
SENDIPC("eadd hh4 1"); |
25 | 106 |
} |
107 |
||
108 |
void HWGame::ParseMessage() |
|
109 |
{ |
|
110 |
switch(msgbuf[0]) |
|
111 |
{ |
|
112 |
case '?': |
|
113 |
{ |
|
31
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
114 |
if (gameType == gtNet) |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
115 |
emit SendNet(QByteArray("\x01""?")); |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
116 |
else |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
117 |
SENDIPC("!"); |
25 | 118 |
break; |
119 |
} |
|
120 |
case 'C': |
|
121 |
{ |
|
31
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
122 |
if (gameType == gtNet) |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
123 |
{ |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
124 |
SENDIPC("TN"); |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
125 |
emit SendNet(QByteArray("\x01""C")); |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
126 |
} |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
127 |
else |
32
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
128 |
{ |
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
129 |
if (gameType == gtLocal) |
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
130 |
SendConfig(); |
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
131 |
} |
25 | 132 |
break; |
133 |
} |
|
134 |
case '+': |
|
135 |
{ |
|
36 | 136 |
if (gameType == gtNet) |
137 |
{ |
|
138 |
QByteArray tmpbuf = QByteArray::fromRawData((char *)&msgsize, 1) + QByteArray::fromRawData(msgbuf, msgsize); |
|
139 |
emit SendNet(tmpbuf); |
|
140 |
} |
|
25 | 141 |
break; |
142 |
} |
|
143 |
default: |
|
144 |
{ |
|
32
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
145 |
QByteArray tmpbuf = QByteArray::fromRawData((char *)&msgsize, 1) + QByteArray::fromRawData(msgbuf, msgsize); |
31
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
146 |
if (gameType == gtNet) |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
147 |
{ |
32
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
148 |
emit SendNet(tmpbuf); |
31
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
149 |
} |
32
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
150 |
demo->append(tmpbuf); |
25 | 151 |
} |
152 |
} |
|
153 |
} |
|
154 |
||
155 |
void HWGame::SendIPC(const char * msg, quint8 len) |
|
156 |
{ |
|
32
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
157 |
SendIPC(QByteArray::fromRawData(msg, len)); |
25 | 158 |
} |
159 |
||
160 |
void HWGame::SendIPC(const QByteArray & buf) |
|
161 |
{ |
|
28 | 162 |
if (buf.size() > MAXMSGCHARS) return; |
40 | 163 |
quint8 len = buf.size(); |
164 |
RawSendIPC(QByteArray::fromRawData((char *)&len, 1) + buf); |
|
25 | 165 |
} |
166 |
||
31
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
167 |
void HWGame::RawSendIPC(const QByteArray & buf) |
26 | 168 |
{ |
32
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
169 |
if (!IPCSocket) |
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
170 |
{ |
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
171 |
toSendBuf += buf; |
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
172 |
} else |
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
173 |
{ |
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
174 |
if (toSendBuf.size() > 0) |
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
175 |
{ |
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
176 |
IPCSocket->write(toSendBuf); |
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
177 |
demo->append(toSendBuf); |
40 | 178 |
toSendBuf.clear(); |
32
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
179 |
} |
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
180 |
IPCSocket->write(buf); |
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
181 |
demo->append(buf); |
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
182 |
} |
31
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
183 |
} |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
184 |
|
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
185 |
void HWGame::FromNet(const QByteArray & msg) |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
186 |
{ |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
187 |
RawSendIPC(msg); |
26 | 188 |
} |
189 |
||
25 | 190 |
void HWGame::ClientRead() |
191 |
{ |
|
192 |
qint64 readbytes = 1; |
|
193 |
while (readbytes > 0) |
|
194 |
{ |
|
195 |
if (msgsize == 0) |
|
196 |
{ |
|
197 |
msgbufsize = 0; |
|
198 |
readbytes = IPCSocket->read((char *)&msgsize, 1); |
|
199 |
} else |
|
200 |
{ |
|
201 |
msgbufsize += |
|
202 |
readbytes = IPCSocket->read((char *)&msgbuf[msgbufsize], msgsize - msgbufsize); |
|
203 |
if (msgbufsize = msgsize) |
|
204 |
{ |
|
205 |
ParseMessage(); |
|
206 |
msgsize = 0; |
|
207 |
} |
|
208 |
} |
|
209 |
} |
|
210 |
} |
|
211 |
||
26 | 212 |
void HWGame::Start() |
25 | 213 |
{ |
41 | 214 |
IPCServer = new QTcpServer(this); |
215 |
connect(IPCServer, SIGNAL(newConnection()), this, SLOT(NewConnection())); |
|
216 |
IPCServer->setMaxPendingConnections(1); |
|
217 |
IPCSocket = 0; |
|
218 |
if (!IPCServer->listen(QHostAddress::LocalHost, IPC_PORT)) |
|
219 |
{ |
|
220 |
QMessageBox::critical(0, tr("Error"), |
|
221 |
tr("Unable to start the server: %1.") |
|
222 |
.arg(IPCServer->errorString())); |
|
223 |
} |
|
224 |
||
25 | 225 |
QProcess * process; |
226 |
QStringList arguments; |
|
227 |
process = new QProcess; |
|
26 | 228 |
arguments << resolutions[0][vid_Resolution]; |
229 |
arguments << resolutions[1][vid_Resolution]; |
|
25 | 230 |
arguments << GetThemeBySeed(); |
231 |
arguments << "46631"; |
|
232 |
arguments << seed; |
|
26 | 233 |
arguments << (vid_Fullscreen ? "1" : "0"); |
41 | 234 |
process->start("./hw", arguments); |
25 | 235 |
} |
236 |
||
237 |
void HWGame::AddTeam(const QString & teamname) |
|
238 |
{ |
|
239 |
if (TeamCount == 5) return; |
|
240 |
teams[TeamCount] = teamname; |
|
241 |
TeamCount++; |
|
242 |
} |
|
243 |
||
244 |
QString HWGame::GetThemeBySeed() |
|
245 |
{ |
|
26 | 246 |
QFile themesfile(QString(DATA_PATH) + "/Themes/themes.cfg"); |
25 | 247 |
QStringList themes; |
248 |
if (themesfile.open(QIODevice::ReadOnly)) |
|
249 |
{ |
|
250 |
QTextStream stream(&themesfile); |
|
251 |
QString str; |
|
252 |
while (!stream.atEnd()) |
|
253 |
{ |
|
254 |
themes << stream.readLine(); |
|
255 |
} |
|
256 |
themesfile.close(); |
|
257 |
} |
|
258 |
quint32 len = themes.size(); |
|
259 |
if (len == 0) |
|
260 |
{ |
|
28 | 261 |
QMessageBox::critical(0, "Error", "Cannot access themes.cfg or bad data", "OK"); |
25 | 262 |
return "avematan"; |
263 |
} |
|
264 |
if (seed.isEmpty()) |
|
265 |
{ |
|
28 | 266 |
QMessageBox::critical(0, "Error", "seed not defined", "OK"); |
25 | 267 |
return "avematan"; |
268 |
} |
|
269 |
quint32 k = 0; |
|
270 |
for (int i = 0; i < seed.length(); i++) |
|
271 |
{ |
|
41 | 272 |
k += seed[i].cell(); |
25 | 273 |
} |
274 |
return themes[k % len]; |
|
275 |
} |
|
276 |
||
277 |
void HWGame::SaveDemo(const QString & filename) |
|
278 |
{ |
|
279 |
QFile demofile(filename); |
|
280 |
if (!demofile.open(QIODevice::WriteOnly)) |
|
281 |
{ |
|
28 | 282 |
QMessageBox::critical(0, |
25 | 283 |
tr("Error"), |
284 |
tr("Cannot save demo to file %s").arg(filename), |
|
285 |
tr("Quit")); |
|
286 |
return ; |
|
287 |
} |
|
288 |
QDataStream stream(&demofile); |
|
289 |
stream.writeRawData(demo->constData(), demo->size()); |
|
290 |
demofile.close(); |
|
26 | 291 |
delete demo; |
25 | 292 |
} |
26 | 293 |
|
294 |
void HWGame::PlayDemo(const QString & demofilename) |
|
295 |
{ |
|
296 |
gameType = gtDemo; |
|
297 |
QFile demofile(demofilename); |
|
298 |
if (!demofile.open(QIODevice::ReadOnly)) |
|
299 |
{ |
|
28 | 300 |
QMessageBox::critical(0, |
26 | 301 |
tr("Error"), |
302 |
tr("Cannot open demofile %s").arg(demofilename), |
|
303 |
tr("Quit")); |
|
304 |
return ; |
|
305 |
} |
|
306 |
||
307 |
// read demo |
|
308 |
QDataStream stream(&demofile); |
|
309 |
char buf[512]; |
|
310 |
quint32 readbytes; |
|
311 |
do |
|
312 |
{ |
|
313 |
readbytes = stream.readRawData((char *)&buf, 512); |
|
32
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
314 |
toSendBuf.append(QByteArray((char *)&buf, readbytes)); |
26 | 315 |
|
316 |
} while (readbytes > 0); |
|
317 |
demofile.close(); |
|
318 |
||
319 |
// cut seed |
|
32
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
320 |
quint32 index = toSendBuf.indexOf(10); |
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
321 |
if ((index < 3) || (index > 20)) |
26 | 322 |
{ |
28 | 323 |
QMessageBox::critical(0, |
26 | 324 |
tr("Error"), |
32
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
325 |
tr("Corrupted demo file %1").arg(demofilename), |
26 | 326 |
tr("Quit")); |
327 |
return ; |
|
328 |
} |
|
32
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
329 |
seed = QString(toSendBuf.left(index++)); |
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
330 |
toSendBuf.remove(0, index); |
26 | 331 |
|
32
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
332 |
toSendBuf = QByteArray::fromRawData("\x02TD", 3) + toSendBuf; |
26 | 333 |
// run engine |
334 |
demo = new QByteArray; |
|
32
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
335 |
Start(); |
26 | 336 |
} |
31
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
337 |
|
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
338 |
void HWGame::StartNet(const QString & netseed) |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
339 |
{ |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
340 |
gameType = gtNet; |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
341 |
seed = netseed; |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
342 |
demo = new QByteArray; |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
343 |
demo->append(seed.toLocal8Bit()); |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
344 |
demo->append(10); |
32
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
345 |
Start(); |
31
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
346 |
} |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
347 |
|
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
348 |
void HWGame::StartLocal() |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
349 |
{ |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
350 |
gameType = gtLocal; |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
351 |
if (TeamCount < 2) return; |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
352 |
seedgen.GenRNDStr(seed, 10); |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
353 |
demo = new QByteArray; |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
354 |
demo->append(seed.toLocal8Bit()); |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
355 |
demo->append(10); |
32
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
356 |
Start(); |
31
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
357 |
} |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
358 |
|
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
359 |
void HWGame::LocalCFG(const QString & teamname) |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
360 |
{ |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
361 |
QFile teamcfg(cfgdir.absolutePath() + "/" + teamname + ".cfg"); |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
362 |
if (!teamcfg.open(QIODevice::ReadOnly)) |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
363 |
{ |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
364 |
return ; |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
365 |
} |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
366 |
QTextStream stream(&teamcfg); |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
367 |
stream.setCodec("UTF-8"); |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
368 |
QString str; |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
369 |
|
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
370 |
while (!stream.atEnd()) |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
371 |
{ |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
372 |
str = stream.readLine(); |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
373 |
if (str.startsWith(";") || (str.length() > 254)) continue; |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
374 |
str.prepend("e"); |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
375 |
SendIPC(str.toLocal8Bit()); |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
376 |
} |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
377 |
teamcfg.close(); |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
378 |
} |