author | unc0rr |
Mon, 24 Jul 2006 22:37:34 +0000 | |
changeset 84 | 0f6669da2fcb |
parent 37 | 2b7f2a43b999 |
child 85 | 44d9045b26ff |
permissions | -rw-r--r-- |
28 | 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 "netclient.h" |
|
31
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
36 |
#include "game.h" |
28 | 37 |
|
84 | 38 |
HWNet::HWNet(GameConfig * config) |
28 | 39 |
: QObject() |
40 |
{ |
|
84 | 41 |
this->config = config; |
28 | 42 |
state = nsDisconnected; |
31
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
43 |
IRCmsg_cmd_text = new QRegExp("^[A-Z]+ :.+$"); |
28 | 44 |
IRCmsg_number_param = new QRegExp("^:\\S+ [0-9]{3} .+$"); |
31
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
45 |
IRCmsg_who_cmd_target = new QRegExp("^:\\S+ [A-Z]+ \\S+$"); // last \\S should mean 'the 1st char is not ":"' |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
46 |
IRCmsg_who_cmd_text = new QRegExp("^:\\S+ [A-Z]+ :.+$"); |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
47 |
IRCmsg_who_cmd_target_text = new QRegExp("^:\\S+ [A-Z]+ \\S+ :.+$"); |
29 | 48 |
isOp = false; |
31
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
49 |
teamsCount = 0; |
28 | 50 |
|
51 |
connect(&NetSocket, SIGNAL(readyRead()), this, SLOT(ClientRead())); |
|
52 |
connect(&NetSocket, SIGNAL(connected()), this, SLOT(OnConnect())); |
|
53 |
connect(&NetSocket, SIGNAL(disconnected()), this, SLOT(OnDisconnect())); |
|
54 |
connect(&NetSocket, SIGNAL(error(QAbstractSocket::SocketError)), this, |
|
55 |
SLOT(displayError(QAbstractSocket::SocketError))); |
|
56 |
} |
|
57 |
||
58 |
void HWNet::ClientRead() |
|
59 |
{ |
|
60 |
while (NetSocket.canReadLine()) |
|
61 |
{ |
|
62 |
ParseLine(NetSocket.readLine().trimmed()); |
|
63 |
} |
|
64 |
} |
|
65 |
||
66 |
void HWNet::displayError(QAbstractSocket::SocketError socketError) |
|
67 |
{ |
|
68 |
switch (socketError) |
|
69 |
{ |
|
70 |
case QAbstractSocket::RemoteHostClosedError: |
|
71 |
break; |
|
72 |
case QAbstractSocket::HostNotFoundError: |
|
73 |
QMessageBox::information(0, tr("Error"), |
|
74 |
tr("The host was not found. Please check the host name and port settings.")); |
|
75 |
break; |
|
76 |
case QAbstractSocket::ConnectionRefusedError: |
|
77 |
QMessageBox::information(0, tr("Error"), |
|
78 |
tr("Connection refused")); |
|
79 |
break; |
|
80 |
default: |
|
81 |
QMessageBox::information(0, tr("Error"), |
|
82 |
NetSocket.errorString()); |
|
83 |
} |
|
84 |
} |
|
85 |
||
29 | 86 |
void HWNet::Connect(const QString & hostName, quint16 port, const QString & nick) |
28 | 87 |
{ |
88 |
state = nsConnecting; |
|
89 |
NetSocket.connectToHost(hostName, port); |
|
29 | 90 |
mynick = nick; |
91 |
opnick = ""; |
|
92 |
opCount = 0; |
|
28 | 93 |
} |
94 |
||
95 |
||
96 |
void HWNet::OnConnect() |
|
97 |
{ |
|
98 |
state = nsConnected; |
|
31
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
99 |
RawSendNet(QString("USER hwgame 1 2 Hedgewars game")); |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
100 |
RawSendNet(QString("NICK %1").arg(mynick)); |
28 | 101 |
} |
102 |
||
103 |
void HWNet::OnDisconnect() |
|
104 |
{ |
|
105 |
state = nsDisconnected; |
|
106 |
} |
|
107 |
||
108 |
void HWNet::Perform() |
|
109 |
{ |
|
31
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
110 |
|
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
111 |
} |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
112 |
|
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
113 |
void HWNet::JoinGame(const QString & game) |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
114 |
{ |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
115 |
state = nsJoining; |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
116 |
RawSendNet(QString("JOIN %1").arg(game)); |
28 | 117 |
} |
118 |
||
119 |
void HWNet::Disconnect() |
|
120 |
{ |
|
121 |
switch (state) |
|
122 |
{ |
|
123 |
case nsDisconnected: |
|
124 |
{ |
|
125 |
break; |
|
126 |
} |
|
127 |
case nsConnecting: |
|
128 |
case nsQuitting: |
|
129 |
{ |
|
130 |
NetSocket.disconnect(); |
|
131 |
break; |
|
132 |
} |
|
133 |
default: |
|
134 |
{ |
|
135 |
state = nsQuitting; |
|
31
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
136 |
RawSendNet(QString("QUIT :oops")); |
28 | 137 |
} |
138 |
} |
|
139 |
} |
|
140 |
||
31
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
141 |
void HWNet::RawSendNet(const QString & str) |
28 | 142 |
{ |
31
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
143 |
RawSendNet(str.toLatin1()); |
28 | 144 |
} |
145 |
||
31
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
146 |
void HWNet::RawSendNet(const QByteArray & buf) |
28 | 147 |
{ |
148 |
if (buf.size() > 510) return; |
|
149 |
NetSocket.write(buf); |
|
150 |
NetSocket.write("\x0d\x0a", 2); |
|
151 |
} |
|
152 |
||
31
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
153 |
void HWNet::SendNet(const QByteArray & buf) |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
154 |
{ |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
155 |
if ((state == nsGaming) || (state == nsStarting)) |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
156 |
{ |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
157 |
QString msg = QString(buf.toBase64()); |
32
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
158 |
if ((msg == "AUM=") && (mynick == opnick)) |
31
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
159 |
{ |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
160 |
ConfigAsked(); |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
161 |
} else |
32
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
162 |
if (msg == "AT8=") |
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
163 |
{ |
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
164 |
// its ping ("?") |
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
165 |
} else |
31
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
166 |
{ |
36 | 167 |
if (state == nsGaming) |
168 |
{ |
|
169 |
NetBuffer += buf; |
|
170 |
} else |
|
171 |
{ |
|
172 |
RawSendNet(QString("PRIVMSG %1 :"MAGIC_CHAR MAGIC_CHAR"%2").arg(channel, msg)); |
|
173 |
} |
|
31
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
174 |
} |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
175 |
} |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
176 |
} |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
177 |
|
36 | 178 |
void HWNet::FlushNetBuf() |
179 |
{ |
|
180 |
if (NetBuffer.size() > 0) |
|
181 |
{ |
|
182 |
RawSendNet(QString("PRIVMSG %1 :"MAGIC_CHAR MAGIC_CHAR"%2").arg(channel, QString(NetBuffer.toBase64()))); |
|
183 |
NetBuffer.clear(); |
|
184 |
} |
|
185 |
} |
|
186 |
||
28 | 187 |
void HWNet::ParseLine(const QString & msg) |
188 |
{ |
|
29 | 189 |
//QMessageBox::information(0, "", msg); |
31
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
190 |
if (IRCmsg_cmd_text->exactMatch(msg)) |
28 | 191 |
{ |
31
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
192 |
msgcmd_textHandler(msg); |
28 | 193 |
} else |
194 |
if (IRCmsg_number_param->exactMatch(msg)) |
|
195 |
{ |
|
196 |
msgnumber_paramHandler(msg); |
|
29 | 197 |
} else |
31
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
198 |
if (IRCmsg_who_cmd_text->exactMatch(msg)) |
29 | 199 |
{ |
31
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
200 |
msgwho_cmd_textHandler(msg); |
29 | 201 |
} else |
31
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
202 |
if (IRCmsg_who_cmd_target->exactMatch(msg)) |
29 | 203 |
{ |
31
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
204 |
msgwho_cmd_targetHandler(msg); |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
205 |
} else |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
206 |
if (IRCmsg_who_cmd_target_text->exactMatch(msg)) |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
207 |
{ |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
208 |
msgwho_cmd_target_textHandler(msg); |
28 | 209 |
} |
210 |
} |
|
211 |
||
31
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
212 |
void HWNet::msgcmd_textHandler(const QString & msg) |
28 | 213 |
{ |
214 |
QStringList list = msg.split(" :"); |
|
215 |
if (list[0] == "PING") |
|
216 |
{ |
|
31
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
217 |
RawSendNet(QString("PONG %1").arg(list[1])); |
28 | 218 |
} |
219 |
} |
|
220 |
||
221 |
void HWNet::msgnumber_paramHandler(const QString & msg) |
|
222 |
{ |
|
29 | 223 |
int pos = msg.indexOf(" :"); |
224 |
QString text = msg.mid(pos + 2); |
|
225 |
QStringList list = msg.mid(0, pos).split(" "); |
|
28 | 226 |
bool ok; |
227 |
quint16 number = list[1].toInt(&ok); |
|
228 |
if (!ok) |
|
229 |
return ; |
|
230 |
switch (number) |
|
231 |
{ |
|
232 |
case 001 : |
|
233 |
{ |
|
234 |
Perform(); |
|
235 |
emit Connected(); |
|
236 |
break; |
|
237 |
} |
|
29 | 238 |
case 322 : // RPL_LIST |
28 | 239 |
{ |
240 |
emit AddGame(list[3]); |
|
29 | 241 |
break; |
242 |
} |
|
243 |
case 353 : // RPL_NAMREPLY |
|
244 |
{ |
|
245 |
QStringList ops = text.split(" ").filter(QRegExp("^@\\S+$")); |
|
246 |
opCount += ops.size(); |
|
247 |
if (ops.size() == 1) |
|
248 |
{ |
|
249 |
opnick = ops[0].mid(1); |
|
250 |
} |
|
251 |
break; |
|
252 |
} |
|
253 |
case 366 : // RPL_ENDOFNAMES |
|
254 |
{ |
|
255 |
if (opCount != 1) |
|
256 |
{ |
|
257 |
opnick = ""; |
|
258 |
} |
|
259 |
opCount = 0; |
|
260 |
break; |
|
261 |
} |
|
262 |
case 432 : // ERR_ERRONEUSNICKNAME |
|
263 |
case 433 : // ERR_NICKNAMEINUSE |
|
264 |
{ |
|
265 |
// ask for another nick |
|
28 | 266 |
} |
267 |
} |
|
268 |
} |
|
29 | 269 |
|
31
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
270 |
void HWNet::msgwho_cmd_targetHandler(const QString & msg) |
29 | 271 |
{ |
272 |
QStringList list = msg.split(" "); |
|
273 |
QString who = list[0].mid(1).split("!")[0]; |
|
274 |
if (list[1] == "NICK") |
|
275 |
{ |
|
276 |
if (mynick == who) |
|
277 |
mynick = list[2]; |
|
278 |
if (opnick == who) |
|
279 |
opnick = list[2]; |
|
280 |
} |
|
281 |
} |
|
282 |
||
31
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
283 |
void HWNet::msgwho_cmd_textHandler(const QString & msg) |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
284 |
{ |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
285 |
int pos = msg.indexOf(" :"); |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
286 |
QString text = msg.mid(pos + 2); |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
287 |
QStringList list = msg.mid(0, pos).split(" "); |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
288 |
QString who = list[0].mid(1).split("!")[0]; |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
289 |
if (list[1] == "JOIN") |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
290 |
{ |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
291 |
if (who == mynick) |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
292 |
{ |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
293 |
channel = text; |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
294 |
state = nsJoined; |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
295 |
emit EnteredGame(); |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
296 |
RawSendNet(QString("PRIVMSG %1 :Hello!").arg(channel)); |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
297 |
} |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
298 |
} |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
299 |
} |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
300 |
void HWNet::msgwho_cmd_target_textHandler(const QString & msg) |
29 | 301 |
{ |
302 |
int pos = msg.indexOf(" :"); |
|
303 |
QString text = msg.mid(pos + 2); |
|
304 |
QStringList list = msg.mid(0, pos).split(" "); |
|
305 |
QString who = list[0].mid(1).split("!")[0]; |
|
306 |
if (list[1] == "PRIVMSG") |
|
307 |
{ |
|
31
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
308 |
if (list[2] == opnick) |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
309 |
{ |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
310 |
hwp_opmsg(who, text); |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
311 |
} else |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
312 |
if (list[2] == channel) |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
313 |
{ |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
314 |
hwp_chanmsg(who, text); |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
315 |
} |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
316 |
} |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
317 |
} |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
318 |
|
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
319 |
void HWNet::hwp_opmsg(const QString & who, const QString & msg) |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
320 |
{ |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
321 |
if (state != nsJoined) |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
322 |
return ; |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
323 |
if (!msg.startsWith(MAGIC_CHAR)) |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
324 |
return ; |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
325 |
QStringList list = msg.split(MAGIC_CHAR, QString::SkipEmptyParts); |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
326 |
if (list[0] == "A") |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
327 |
{ |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
328 |
list.removeFirst(); |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
329 |
if (list.size() != 9) |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
330 |
return ; |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
331 |
if (teamsCount < 5) |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
332 |
{ |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
333 |
teams[teamsCount].nick = who; |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
334 |
teams[teamsCount].hhs = list; |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
335 |
teamsCount++; |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
336 |
QString teamnames; |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
337 |
for(int i = 0; i < teamsCount; i++) |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
338 |
{ |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
339 |
teamnames += MAGIC_CHAR; |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
340 |
teamnames += teams[i].hhs[0]; |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
341 |
} |
32
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
342 |
QString tmsg = QString(MAGIC_CHAR"=%2").arg(teamnames); |
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
343 |
RawSendNet(QString("PRIVMSG %1 :").arg(channel) + tmsg); |
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
344 |
hwp_chanmsg(mynick, tmsg); |
31
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
345 |
} |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
346 |
} |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
347 |
} |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
348 |
|
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
349 |
void HWNet::ConfigAsked() |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
350 |
{ |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
351 |
configasks++; |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
352 |
if (configasks == playerscnt) |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
353 |
{ |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
354 |
quint32 color = 65535; |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
355 |
for (int i = 0; i < teamsCount; i++) |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
356 |
{ |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
357 |
QString msg; |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
358 |
msg = MAGIC_CHAR "T" MAGIC_CHAR + teams[i].nick + MAGIC_CHAR + teams[i].hhs.join(MAGIC_CHAR); |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
359 |
RawSendNet(QString("PRIVMSG %1 :%2").arg(channel, msg)); |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
360 |
hwp_chanmsg(mynick, msg); |
36 | 361 |
QByteArray cache; |
362 |
#define ADD(a) { \ |
|
363 |
QByteArray strmsg; \ |
|
364 |
strmsg.append(a); \ |
|
365 |
quint8 sz = strmsg.size(); \ |
|
366 |
cache.append(QByteArray((char *)&sz, 1)); \ |
|
367 |
cache.append(strmsg); \ |
|
368 |
} |
|
369 |
ADD(QString("ecolor %1").arg(color)); |
|
370 |
ADD("eadd hh0 0"); |
|
371 |
ADD("eadd hh1 0"); |
|
372 |
ADD("eadd hh2 0"); |
|
373 |
ADD("eadd hh3 0"); |
|
374 |
ADD("eadd hh4 0"); |
|
375 |
#undef ADD |
|
376 |
QString _msg = MAGIC_CHAR MAGIC_CHAR + QString(cache.toBase64()); |
|
377 |
hwp_chanmsg(mynick, _msg); |
|
378 |
RawSendNet(QString("PRIVMSG %1 :").arg(channel) + _msg); |
|
31
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
379 |
color <<= 8; |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
380 |
} |
32
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
381 |
SENDCFGSTRNET("!"); |
29 | 382 |
} |
383 |
} |
|
31
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
384 |
|
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
385 |
void HWNet::hwp_chanmsg(const QString & who, const QString & msg) |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
386 |
{ |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
387 |
if ((state < nsJoined) || (state > nsGaming)) |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
388 |
{ |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
389 |
return ; |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
390 |
} |
32
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
391 |
if (state == nsJoined) |
31
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
392 |
{ |
32
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
393 |
if (msg.startsWith(MAGIC_CHAR"Start!"MAGIC_CHAR) && (who == opnick)) |
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
394 |
{ |
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
395 |
state = nsStarting; |
37 | 396 |
RunGame(msg.mid(8)); |
32
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
397 |
return ; |
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
398 |
} |
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
399 |
if (msg.startsWith(MAGIC_CHAR"="MAGIC_CHAR) && (who == opnick)) |
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
400 |
{ |
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
401 |
emit ChangeInTeams(msg.mid(3).split(MAGIC_CHAR)); |
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
402 |
} |
31
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
403 |
} |
32
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
404 |
if (state == nsStarting) |
31
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
405 |
{ |
32
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
406 |
if (msg == MAGIC_CHAR MAGIC_CHAR "AUM=") |
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
407 |
{ |
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
408 |
if (mynick == opnick) ConfigAsked(); |
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
409 |
return ; |
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
410 |
} |
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
411 |
if (msg == MAGIC_CHAR MAGIC_CHAR "ASE=") |
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
412 |
{ |
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
413 |
state = nsGaming; |
36 | 414 |
TimerFlusher = new QTimer(); |
415 |
connect(TimerFlusher, SIGNAL(timeout()), this, SLOT(FlushNetBuf())); |
|
416 |
TimerFlusher->start(2000); |
|
32
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
417 |
} |
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
418 |
if (msg.startsWith(MAGIC_CHAR"T"MAGIC_CHAR)) |
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
419 |
{ |
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
420 |
NetTeamAdded(msg.mid(3)); |
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
421 |
} |
31
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
422 |
} |
36 | 423 |
if ((state < nsStarting) || (state > nsGaming)) |
31
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
424 |
{ |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
425 |
return; |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
426 |
} |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
427 |
if (msg.startsWith(MAGIC_CHAR MAGIC_CHAR)) // HWP message |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
428 |
{ |
32
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
429 |
QByteArray em = QByteArray::fromBase64(msg.mid(2).toLocal8Bit()); |
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
430 |
emit FromNet(em); |
31
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
431 |
} else // smth other |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
432 |
{ |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
433 |
|
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
434 |
} |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
435 |
} |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
436 |
|
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
437 |
void HWNet::NetTeamAdded(const QString & msg) |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
438 |
{ |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
439 |
QStringList list = msg.split(MAGIC_CHAR, QString::SkipEmptyParts); |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
440 |
if (list.size() != 10) |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
441 |
return ; |
32
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
442 |
SENDCFGSTRLOC("eaddteam"); |
31
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
443 |
if (list[0] == mynick) |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
444 |
{ |
32
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
445 |
emit LocalCFG(list[1]); |
31
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
446 |
} else |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
447 |
{ |
32
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
448 |
SENDCFGSTRLOC("erdriven"); |
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
449 |
SENDCFGSTRLOC(QString("ename team %1").arg(list[1])); |
31
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
450 |
for (int i = 0; i < 8; i++) |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
451 |
{ |
32
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
452 |
SENDCFGSTRLOC(QString("ename hh%1 ").arg(i) + list[i + 2]); |
31
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
453 |
} |
32
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
454 |
} |
31
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
455 |
} |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
456 |
|
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
457 |
void HWNet::AddTeam(const HWTeam & team) |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
458 |
{ |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
459 |
if (state != nsJoined) |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
460 |
{ |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
461 |
return ; |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
462 |
} |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
463 |
RawSendNet(QString("PRIVMSG %1 :").arg(opnick) + MAGIC_CHAR "A" MAGIC_CHAR + |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
464 |
team.TeamName + MAGIC_CHAR + team.HHName[0] + MAGIC_CHAR + team.HHName[1] + MAGIC_CHAR + |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
465 |
team.HHName[2] + MAGIC_CHAR + team.HHName[3] + MAGIC_CHAR + team.HHName[4] + MAGIC_CHAR + |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
466 |
team.HHName[5] + MAGIC_CHAR + team.HHName[6] + MAGIC_CHAR + team.HHName[7]); |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
467 |
} |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
468 |
|
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
469 |
void HWNet::StartGame() |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
470 |
{ |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
471 |
if ((opnick != mynick) || (state != nsJoined)) |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
472 |
{ |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
473 |
return ; |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
474 |
} |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
475 |
QStringList players; |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
476 |
for (int i = 0; i < teamsCount; i++) |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
477 |
{ |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
478 |
if (!players.contains(teams[i].nick)) |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
479 |
{ |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
480 |
players.append(teams[i].nick); |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
481 |
} |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
482 |
} |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
483 |
playerscnt = players.size(); |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
484 |
configasks = 0; |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
485 |
|
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
486 |
QString seed; |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
487 |
seedgen.GenRNDStr(seed, 10); |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
488 |
QString msg = QString(MAGIC_CHAR"Start!"MAGIC_CHAR"%1").arg(seed); |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
489 |
RawSendNet(QString("PRIVMSG %1 :%2").arg(channel, msg)); |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
490 |
hwp_chanmsg(mynick, msg); |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
491 |
} |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
492 |
|
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
493 |
void HWNet::RunGame(const QString & seed) |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
494 |
{ |
84 | 495 |
HWGame * game = new HWGame(config); |
31
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
496 |
connect(game, SIGNAL(SendNet(const QByteArray &)), this, SLOT(SendNet(const QByteArray &))); |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
497 |
connect(this, SIGNAL(FromNet(const QByteArray &)), game, SLOT(FromNet(const QByteArray &))); |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
498 |
connect(this, SIGNAL(LocalCFG(const QString &)), game, SLOT(LocalCFG(const QString &))); |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
499 |
game->StartNet(seed); |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
500 |
} |