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