author | unc0rr |
Sat, 31 Dec 2005 13:46:49 +0000 | |
changeset 36 | a803a00a3272 |
parent 32 | 78bff13b11c0 |
child 40 | 416d54ce0c34 |
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 |
IPCServer = new QTcpServer(this); |
49 |
IPCServer->setMaxPendingConnections(1); |
|
50 |
if (!IPCServer->listen(QHostAddress("127.0.0.1"), IPC_PORT)) |
|
51 |
{ |
|
28 | 52 |
QMessageBox::critical(0, tr("Error"), |
25 | 53 |
tr("Unable to start the server: %1.") |
54 |
.arg(IPCServer->errorString())); |
|
55 |
} |
|
56 |
connect(IPCServer, SIGNAL(newConnection()), this, SLOT(NewConnection())); |
|
57 |
IPCSocket = 0; |
|
58 |
TeamCount = 0; |
|
26 | 59 |
seed = ""; |
31
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
60 |
cfgdir.setPath(cfgdir.homePath()); |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
61 |
cfgdir.cd(".hedgewars"); |
25 | 62 |
} |
63 |
||
64 |
void HWGame::NewConnection() |
|
65 |
{ |
|
66 |
QTcpSocket * client = IPCServer->nextPendingConnection(); |
|
67 |
if(!IPCSocket) |
|
68 |
{ |
|
69 |
IPCSocket = client; |
|
70 |
connect(client, SIGNAL(disconnected()), this, SLOT(ClientDisconnect())); |
|
71 |
connect(client, SIGNAL(readyRead()), this, SLOT(ClientRead())); |
|
72 |
msgsize = 0; |
|
32
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
73 |
if (toSendBuf.size() > 0) |
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
74 |
SENDIPC("?"); |
25 | 75 |
} else |
76 |
{ |
|
77 |
client->disconnectFromHost(); |
|
78 |
delete client; |
|
79 |
} |
|
80 |
} |
|
81 |
||
82 |
void HWGame::ClientDisconnect() |
|
83 |
{ |
|
84 |
IPCSocket = 0; |
|
85 |
SaveDemo("demo.hwd_1"); |
|
86 |
delete this; |
|
87 |
} |
|
88 |
||
89 |
void HWGame::SendTeamConfig(int index) |
|
90 |
{ |
|
31
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
91 |
LocalCFG(teams[index]); |
25 | 92 |
} |
93 |
||
94 |
void HWGame::SendConfig() |
|
95 |
{ |
|
96 |
SENDIPC("TL"); |
|
31
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
97 |
// SENDIPC("e$gmflags 0"); |
25 | 98 |
SENDIPC("eaddteam"); |
99 |
SendTeamConfig(0); |
|
31
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
100 |
// if () SENDIPC("rdriven"); |
25 | 101 |
SENDIPC("ecolor 65535"); |
102 |
SENDIPC("eadd hh0 0"); |
|
103 |
SENDIPC("eadd hh1 0"); |
|
104 |
SENDIPC("eadd hh2 0"); |
|
105 |
SENDIPC("eadd hh3 0"); |
|
28 | 106 |
SENDIPC("eadd hh4 0"); |
25 | 107 |
SENDIPC("eaddteam"); |
108 |
SendTeamConfig(1); |
|
109 |
SENDIPC("ecolor 16776960"); |
|
110 |
SENDIPC("eadd hh0 1"); |
|
111 |
SENDIPC("eadd hh1 1"); |
|
112 |
SENDIPC("eadd hh2 1"); |
|
113 |
SENDIPC("eadd hh3 1"); |
|
28 | 114 |
SENDIPC("eadd hh4 1"); |
25 | 115 |
} |
116 |
||
117 |
void HWGame::ParseMessage() |
|
118 |
{ |
|
119 |
switch(msgbuf[0]) |
|
120 |
{ |
|
121 |
case '?': |
|
122 |
{ |
|
31
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
123 |
if (gameType == gtNet) |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
124 |
emit SendNet(QByteArray("\x01""?")); |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
125 |
else |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
126 |
SENDIPC("!"); |
25 | 127 |
break; |
128 |
} |
|
129 |
case 'C': |
|
130 |
{ |
|
31
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
131 |
if (gameType == gtNet) |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
132 |
{ |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
133 |
SENDIPC("TN"); |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
134 |
emit SendNet(QByteArray("\x01""C")); |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
135 |
} |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
136 |
else |
32
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
137 |
{ |
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
138 |
if (gameType == gtLocal) |
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
139 |
SendConfig(); |
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
140 |
} |
25 | 141 |
break; |
142 |
} |
|
143 |
case '+': |
|
144 |
{ |
|
36 | 145 |
if (gameType == gtNet) |
146 |
{ |
|
147 |
QByteArray tmpbuf = QByteArray::fromRawData((char *)&msgsize, 1) + QByteArray::fromRawData(msgbuf, msgsize); |
|
148 |
emit SendNet(tmpbuf); |
|
149 |
} |
|
25 | 150 |
break; |
151 |
} |
|
152 |
default: |
|
153 |
{ |
|
32
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
154 |
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
|
155 |
if (gameType == gtNet) |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
156 |
{ |
32
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
157 |
emit SendNet(tmpbuf); |
31
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
158 |
} |
32
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
159 |
demo->append(tmpbuf); |
25 | 160 |
} |
161 |
} |
|
162 |
} |
|
163 |
||
164 |
void HWGame::SendIPC(const char * msg, quint8 len) |
|
165 |
{ |
|
32
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
166 |
SendIPC(QByteArray::fromRawData(msg, len)); |
25 | 167 |
} |
168 |
||
169 |
void HWGame::SendIPC(const QByteArray & buf) |
|
170 |
{ |
|
28 | 171 |
if (buf.size() > MAXMSGCHARS) return; |
32
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
172 |
if (!IPCSocket) |
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 |
toSendBuf += buf; |
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
175 |
} else |
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
176 |
{ |
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
177 |
quint8 len = buf.size(); |
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
178 |
RawSendIPC(QByteArray::fromRawData((char *)&len, 1) + buf); |
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
179 |
} |
25 | 180 |
} |
181 |
||
31
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
182 |
void HWGame::RawSendIPC(const QByteArray & buf) |
26 | 183 |
{ |
32
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
184 |
if (!IPCSocket) |
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
185 |
{ |
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
186 |
toSendBuf += buf; |
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
187 |
} else |
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
188 |
{ |
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
189 |
if (toSendBuf.size() > 0) |
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
190 |
{ |
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
191 |
IPCSocket->write(toSendBuf); |
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
192 |
demo->append(toSendBuf); |
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
193 |
} |
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
194 |
IPCSocket->write(buf); |
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
195 |
demo->append(buf); |
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
196 |
} |
31
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
197 |
} |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
198 |
|
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
199 |
void HWGame::FromNet(const QByteArray & msg) |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
200 |
{ |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
201 |
RawSendIPC(msg); |
26 | 202 |
} |
203 |
||
25 | 204 |
void HWGame::ClientRead() |
205 |
{ |
|
206 |
qint64 readbytes = 1; |
|
207 |
while (readbytes > 0) |
|
208 |
{ |
|
209 |
if (msgsize == 0) |
|
210 |
{ |
|
211 |
msgbufsize = 0; |
|
212 |
readbytes = IPCSocket->read((char *)&msgsize, 1); |
|
213 |
} else |
|
214 |
{ |
|
215 |
msgbufsize += |
|
216 |
readbytes = IPCSocket->read((char *)&msgbuf[msgbufsize], msgsize - msgbufsize); |
|
217 |
if (msgbufsize = msgsize) |
|
218 |
{ |
|
219 |
ParseMessage(); |
|
220 |
msgsize = 0; |
|
221 |
} |
|
222 |
} |
|
223 |
} |
|
224 |
} |
|
225 |
||
26 | 226 |
void HWGame::Start() |
25 | 227 |
{ |
228 |
QProcess * process; |
|
229 |
QStringList arguments; |
|
230 |
process = new QProcess; |
|
26 | 231 |
arguments << resolutions[0][vid_Resolution]; |
232 |
arguments << resolutions[1][vid_Resolution]; |
|
25 | 233 |
arguments << GetThemeBySeed(); |
234 |
arguments << "46631"; |
|
235 |
arguments << seed; |
|
26 | 236 |
arguments << (vid_Fullscreen ? "1" : "0"); |
25 | 237 |
process->start("hw", arguments); |
238 |
} |
|
239 |
||
240 |
void HWGame::AddTeam(const QString & teamname) |
|
241 |
{ |
|
242 |
if (TeamCount == 5) return; |
|
243 |
teams[TeamCount] = teamname; |
|
244 |
TeamCount++; |
|
245 |
} |
|
246 |
||
247 |
QString HWGame::GetThemeBySeed() |
|
248 |
{ |
|
26 | 249 |
QFile themesfile(QString(DATA_PATH) + "/Themes/themes.cfg"); |
25 | 250 |
QStringList themes; |
251 |
if (themesfile.open(QIODevice::ReadOnly)) |
|
252 |
{ |
|
253 |
QTextStream stream(&themesfile); |
|
254 |
QString str; |
|
255 |
while (!stream.atEnd()) |
|
256 |
{ |
|
257 |
themes << stream.readLine(); |
|
258 |
} |
|
259 |
themesfile.close(); |
|
260 |
} |
|
261 |
quint32 len = themes.size(); |
|
262 |
if (len == 0) |
|
263 |
{ |
|
28 | 264 |
QMessageBox::critical(0, "Error", "Cannot access themes.cfg or bad data", "OK"); |
25 | 265 |
return "avematan"; |
266 |
} |
|
267 |
if (seed.isEmpty()) |
|
268 |
{ |
|
28 | 269 |
QMessageBox::critical(0, "Error", "seed not defined", "OK"); |
25 | 270 |
return "avematan"; |
271 |
} |
|
272 |
quint32 k = 0; |
|
273 |
for (int i = 0; i < seed.length(); i++) |
|
274 |
{ |
|
275 |
k += seed[i].unicode(); |
|
276 |
} |
|
277 |
return themes[k % len]; |
|
278 |
} |
|
279 |
||
280 |
void HWGame::SaveDemo(const QString & filename) |
|
281 |
{ |
|
282 |
QFile demofile(filename); |
|
283 |
if (!demofile.open(QIODevice::WriteOnly)) |
|
284 |
{ |
|
28 | 285 |
QMessageBox::critical(0, |
25 | 286 |
tr("Error"), |
287 |
tr("Cannot save demo to file %s").arg(filename), |
|
288 |
tr("Quit")); |
|
289 |
return ; |
|
290 |
} |
|
291 |
QDataStream stream(&demofile); |
|
292 |
stream.writeRawData(demo->constData(), demo->size()); |
|
293 |
demofile.close(); |
|
26 | 294 |
delete demo; |
25 | 295 |
} |
26 | 296 |
|
297 |
void HWGame::PlayDemo(const QString & demofilename) |
|
298 |
{ |
|
299 |
gameType = gtDemo; |
|
300 |
QFile demofile(demofilename); |
|
301 |
if (!demofile.open(QIODevice::ReadOnly)) |
|
302 |
{ |
|
28 | 303 |
QMessageBox::critical(0, |
26 | 304 |
tr("Error"), |
305 |
tr("Cannot open demofile %s").arg(demofilename), |
|
306 |
tr("Quit")); |
|
307 |
return ; |
|
308 |
} |
|
309 |
||
310 |
// read demo |
|
311 |
QDataStream stream(&demofile); |
|
312 |
char buf[512]; |
|
313 |
quint32 readbytes; |
|
314 |
do |
|
315 |
{ |
|
316 |
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
|
317 |
toSendBuf.append(QByteArray((char *)&buf, readbytes)); |
26 | 318 |
|
319 |
} while (readbytes > 0); |
|
320 |
demofile.close(); |
|
321 |
||
322 |
// cut seed |
|
32
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
323 |
quint32 index = toSendBuf.indexOf(10); |
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
324 |
if ((index < 3) || (index > 20)) |
26 | 325 |
{ |
28 | 326 |
QMessageBox::critical(0, |
26 | 327 |
tr("Error"), |
32
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
328 |
tr("Corrupted demo file %1").arg(demofilename), |
26 | 329 |
tr("Quit")); |
330 |
return ; |
|
331 |
} |
|
32
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
332 |
seed = QString(toSendBuf.left(index++)); |
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
333 |
toSendBuf.remove(0, index); |
26 | 334 |
|
32
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
335 |
toSendBuf = QByteArray::fromRawData("\x02TD", 3) + toSendBuf; |
26 | 336 |
// run engine |
337 |
demo = new QByteArray; |
|
32
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
338 |
Start(); |
26 | 339 |
} |
31
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
340 |
|
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
341 |
void HWGame::StartNet(const QString & netseed) |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
342 |
{ |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
343 |
gameType = gtNet; |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
344 |
seed = netseed; |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
345 |
demo = new QByteArray; |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
346 |
demo->append(seed.toLocal8Bit()); |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
347 |
demo->append(10); |
32
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
348 |
Start(); |
31
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 |
|
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
351 |
void HWGame::StartLocal() |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
352 |
{ |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
353 |
gameType = gtLocal; |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
354 |
if (TeamCount < 2) return; |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
355 |
seedgen.GenRNDStr(seed, 10); |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
356 |
demo = new QByteArray; |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
357 |
demo->append(seed.toLocal8Bit()); |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
358 |
demo->append(10); |
32
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
359 |
Start(); |
31
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 |
|
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
362 |
void HWGame::LocalCFG(const QString & teamname) |
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 |
QFile teamcfg(cfgdir.absolutePath() + "/" + teamname + ".cfg"); |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
365 |
if (!teamcfg.open(QIODevice::ReadOnly)) |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
366 |
{ |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
367 |
return ; |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
368 |
} |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
369 |
QTextStream stream(&teamcfg); |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
370 |
stream.setCodec("UTF-8"); |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
371 |
QString str; |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
372 |
|
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
373 |
while (!stream.atEnd()) |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
374 |
{ |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
375 |
str = stream.readLine(); |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
376 |
if (str.startsWith(";") || (str.length() > 254)) continue; |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
377 |
str.prepend("e"); |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
378 |
SendIPC(str.toLocal8Bit()); |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
379 |
} |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
380 |
teamcfg.close(); |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
381 |
} |