author | unc0rr |
Wed, 28 Dec 2005 22:18:11 +0000 | |
changeset 32 | 78bff13b11c0 |
parent 31 | 99888245a4e8 |
child 36 | a803a00a3272 |
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 |
{ |
|
145 |
break; |
|
146 |
} |
|
147 |
default: |
|
148 |
{ |
|
32
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
149 |
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
|
150 |
if (gameType == gtNet) |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
151 |
{ |
32
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
152 |
emit SendNet(tmpbuf); |
31
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
153 |
} |
32
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
154 |
demo->append(tmpbuf); |
25 | 155 |
} |
156 |
} |
|
157 |
} |
|
158 |
||
159 |
void HWGame::SendIPC(const char * msg, quint8 len) |
|
160 |
{ |
|
32
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
161 |
SendIPC(QByteArray::fromRawData(msg, len)); |
25 | 162 |
} |
163 |
||
164 |
void HWGame::SendIPC(const QByteArray & buf) |
|
165 |
{ |
|
28 | 166 |
if (buf.size() > MAXMSGCHARS) return; |
32
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
167 |
if (!IPCSocket) |
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
168 |
{ |
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
169 |
toSendBuf += buf; |
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
170 |
} else |
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
171 |
{ |
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
172 |
quint8 len = buf.size(); |
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
173 |
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
|
174 |
} |
25 | 175 |
} |
176 |
||
31
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
177 |
void HWGame::RawSendIPC(const QByteArray & buf) |
26 | 178 |
{ |
32
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
179 |
if (!IPCSocket) |
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
180 |
{ |
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
181 |
toSendBuf += buf; |
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
182 |
} else |
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
183 |
{ |
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
184 |
if (toSendBuf.size() > 0) |
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 |
IPCSocket->write(toSendBuf); |
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
187 |
demo->append(toSendBuf); |
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 |
IPCSocket->write(buf); |
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
190 |
demo->append(buf); |
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
191 |
} |
31
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
192 |
} |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
193 |
|
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
194 |
void HWGame::FromNet(const QByteArray & msg) |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
195 |
{ |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
196 |
RawSendIPC(msg); |
26 | 197 |
} |
198 |
||
25 | 199 |
void HWGame::ClientRead() |
200 |
{ |
|
201 |
qint64 readbytes = 1; |
|
202 |
while (readbytes > 0) |
|
203 |
{ |
|
204 |
if (msgsize == 0) |
|
205 |
{ |
|
206 |
msgbufsize = 0; |
|
207 |
readbytes = IPCSocket->read((char *)&msgsize, 1); |
|
208 |
} else |
|
209 |
{ |
|
210 |
msgbufsize += |
|
211 |
readbytes = IPCSocket->read((char *)&msgbuf[msgbufsize], msgsize - msgbufsize); |
|
212 |
if (msgbufsize = msgsize) |
|
213 |
{ |
|
214 |
ParseMessage(); |
|
215 |
msgsize = 0; |
|
216 |
} |
|
217 |
} |
|
218 |
} |
|
219 |
} |
|
220 |
||
26 | 221 |
void HWGame::Start() |
25 | 222 |
{ |
223 |
QProcess * process; |
|
224 |
QStringList arguments; |
|
225 |
process = new QProcess; |
|
26 | 226 |
arguments << resolutions[0][vid_Resolution]; |
227 |
arguments << resolutions[1][vid_Resolution]; |
|
25 | 228 |
arguments << GetThemeBySeed(); |
229 |
arguments << "46631"; |
|
230 |
arguments << seed; |
|
26 | 231 |
arguments << (vid_Fullscreen ? "1" : "0"); |
25 | 232 |
process->start("hw", arguments); |
233 |
} |
|
234 |
||
235 |
void HWGame::AddTeam(const QString & teamname) |
|
236 |
{ |
|
237 |
if (TeamCount == 5) return; |
|
238 |
teams[TeamCount] = teamname; |
|
239 |
TeamCount++; |
|
240 |
} |
|
241 |
||
242 |
QString HWGame::GetThemeBySeed() |
|
243 |
{ |
|
26 | 244 |
QFile themesfile(QString(DATA_PATH) + "/Themes/themes.cfg"); |
25 | 245 |
QStringList themes; |
246 |
if (themesfile.open(QIODevice::ReadOnly)) |
|
247 |
{ |
|
248 |
QTextStream stream(&themesfile); |
|
249 |
QString str; |
|
250 |
while (!stream.atEnd()) |
|
251 |
{ |
|
252 |
themes << stream.readLine(); |
|
253 |
} |
|
254 |
themesfile.close(); |
|
255 |
} |
|
256 |
quint32 len = themes.size(); |
|
257 |
if (len == 0) |
|
258 |
{ |
|
28 | 259 |
QMessageBox::critical(0, "Error", "Cannot access themes.cfg or bad data", "OK"); |
25 | 260 |
return "avematan"; |
261 |
} |
|
262 |
if (seed.isEmpty()) |
|
263 |
{ |
|
28 | 264 |
QMessageBox::critical(0, "Error", "seed not defined", "OK"); |
25 | 265 |
return "avematan"; |
266 |
} |
|
267 |
quint32 k = 0; |
|
268 |
for (int i = 0; i < seed.length(); i++) |
|
269 |
{ |
|
270 |
k += seed[i].unicode(); |
|
271 |
} |
|
272 |
return themes[k % len]; |
|
273 |
} |
|
274 |
||
275 |
void HWGame::SaveDemo(const QString & filename) |
|
276 |
{ |
|
277 |
QFile demofile(filename); |
|
278 |
if (!demofile.open(QIODevice::WriteOnly)) |
|
279 |
{ |
|
28 | 280 |
QMessageBox::critical(0, |
25 | 281 |
tr("Error"), |
282 |
tr("Cannot save demo to file %s").arg(filename), |
|
283 |
tr("Quit")); |
|
284 |
return ; |
|
285 |
} |
|
286 |
QDataStream stream(&demofile); |
|
287 |
stream.writeRawData(demo->constData(), demo->size()); |
|
288 |
demofile.close(); |
|
26 | 289 |
delete demo; |
25 | 290 |
} |
26 | 291 |
|
292 |
void HWGame::PlayDemo(const QString & demofilename) |
|
293 |
{ |
|
294 |
gameType = gtDemo; |
|
295 |
QFile demofile(demofilename); |
|
296 |
if (!demofile.open(QIODevice::ReadOnly)) |
|
297 |
{ |
|
28 | 298 |
QMessageBox::critical(0, |
26 | 299 |
tr("Error"), |
300 |
tr("Cannot open demofile %s").arg(demofilename), |
|
301 |
tr("Quit")); |
|
302 |
return ; |
|
303 |
} |
|
304 |
||
305 |
// read demo |
|
306 |
QDataStream stream(&demofile); |
|
307 |
char buf[512]; |
|
308 |
quint32 readbytes; |
|
309 |
do |
|
310 |
{ |
|
311 |
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
|
312 |
toSendBuf.append(QByteArray((char *)&buf, readbytes)); |
26 | 313 |
|
314 |
} while (readbytes > 0); |
|
315 |
demofile.close(); |
|
316 |
||
317 |
// cut seed |
|
32
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
318 |
quint32 index = toSendBuf.indexOf(10); |
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
319 |
if ((index < 3) || (index > 20)) |
26 | 320 |
{ |
28 | 321 |
QMessageBox::critical(0, |
26 | 322 |
tr("Error"), |
32
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
323 |
tr("Corrupted demo file %1").arg(demofilename), |
26 | 324 |
tr("Quit")); |
325 |
return ; |
|
326 |
} |
|
32
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
327 |
seed = QString(toSendBuf.left(index++)); |
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
328 |
toSendBuf.remove(0, index); |
26 | 329 |
|
32
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
330 |
toSendBuf = QByteArray::fromRawData("\x02TD", 3) + toSendBuf; |
26 | 331 |
// run engine |
332 |
demo = new QByteArray; |
|
32
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
333 |
Start(); |
26 | 334 |
} |
31
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
335 |
|
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
336 |
void HWGame::StartNet(const QString & netseed) |
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 |
gameType = gtNet; |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
339 |
seed = netseed; |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
340 |
demo = new QByteArray; |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
341 |
demo->append(seed.toLocal8Bit()); |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
342 |
demo->append(10); |
32
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
343 |
Start(); |
31
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
344 |
} |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
345 |
|
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
346 |
void HWGame::StartLocal() |
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 |
gameType = gtLocal; |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
349 |
if (TeamCount < 2) return; |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
350 |
seedgen.GenRNDStr(seed, 10); |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
351 |
demo = new QByteArray; |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
352 |
demo->append(seed.toLocal8Bit()); |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
353 |
demo->append(10); |
32
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
354 |
Start(); |
31
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
355 |
} |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
356 |
|
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
357 |
void HWGame::LocalCFG(const QString & teamname) |
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 |
QFile teamcfg(cfgdir.absolutePath() + "/" + teamname + ".cfg"); |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
360 |
if (!teamcfg.open(QIODevice::ReadOnly)) |
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 |
return ; |
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 |
QTextStream stream(&teamcfg); |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
365 |
stream.setCodec("UTF-8"); |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
366 |
QString str; |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
367 |
|
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
368 |
while (!stream.atEnd()) |
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 |
str = stream.readLine(); |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
371 |
if (str.startsWith(";") || (str.length() > 254)) continue; |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
372 |
str.prepend("e"); |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
373 |
SendIPC(str.toLocal8Bit()); |
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 |
teamcfg.close(); |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
376 |
} |