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