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