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