author | unc0rr |
Fri, 02 Jan 2009 19:44:52 +0000 | |
changeset 1566 | 6b63c75fdc68 |
parent 1560 | e140bc57ff68 |
child 1568 | 15a446307993 |
permissions | -rw-r--r-- |
315 | 1 |
/* |
1066 | 2 |
* Hedgewars, a free turn based strategy game |
883 | 3 |
* Copyright (c) 2006-2008 Ulyanov Igor <iulyanov@gmail.com> |
315 | 4 |
* |
5 |
* This program is free software; you can redistribute it and/or modify |
|
6 |
* it under the terms of the GNU General Public License as published by |
|
7 |
* the Free Software Foundation; version 2 of the License |
|
8 |
* |
|
9 |
* This program is distributed in the hope that it will be useful, |
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 |
* GNU General Public License for more details. |
|
13 |
* |
|
14 |
* You should have received a copy of the GNU General Public License |
|
15 |
* along with this program; if not, write to the Free Software |
|
16 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
|
17 |
*/ |
|
18 |
||
19 |
#include <QMessageBox> |
|
1189
f66cdbbfc4b6
Fix compile under Ubuntu (why it compiles everywhere else?)
unc0rr
parents:
1083
diff
changeset
|
20 |
#include <QDebug> |
315 | 21 |
|
697 | 22 |
#include "hwconsts.h" |
315 | 23 |
#include "newnetclient.h" |
24 |
#include "proto.h" |
|
25 |
#include "gameuiconfig.h" |
|
26 |
#include "game.h" |
|
334 | 27 |
#include "gamecfgwidget.h" |
347 | 28 |
#include "teamselect.h" |
315 | 29 |
|
1082 | 30 |
char delimeter='\n'; |
315 | 31 |
|
339
7535ab6c3820
Run game message added, team and config info provided for net game
displacer
parents:
338
diff
changeset
|
32 |
HWNewNet::HWNewNet(GameUIConfig * config, GameCFGWidget* pGameCFGWidget, TeamSelWidget* pTeamSelWidget) : |
334 | 33 |
config(config), |
34 |
m_pGameCFGWidget(pGameCFGWidget), |
|
339
7535ab6c3820
Run game message added, team and config info provided for net game
displacer
parents:
338
diff
changeset
|
35 |
m_pTeamSelWidget(pTeamSelWidget), |
383 | 36 |
isChief(false), |
1313
f4c54e9e1b8c
- Introduce a bit of state miachine in client code (should be more robust and verbosive now)
unc0rr
parents:
1311
diff
changeset
|
37 |
m_game_connected(false), |
f4c54e9e1b8c
- Introduce a bit of state miachine in client code (should be more robust and verbosive now)
unc0rr
parents:
1311
diff
changeset
|
38 |
loginStep(0), |
f4c54e9e1b8c
- Introduce a bit of state miachine in client code (should be more robust and verbosive now)
unc0rr
parents:
1311
diff
changeset
|
39 |
netClientState(0) |
315 | 40 |
{ |
1418 | 41 |
connect(&NetSocket, SIGNAL(readyRead()), this, SLOT(ClientRead())); |
42 |
connect(&NetSocket, SIGNAL(connected()), this, SLOT(OnConnect())); |
|
43 |
connect(&NetSocket, SIGNAL(disconnected()), this, SLOT(OnDisconnect())); |
|
44 |
connect(&NetSocket, SIGNAL(error(QAbstractSocket::SocketError)), this, |
|
45 |
SLOT(displayError(QAbstractSocket::SocketError))); |
|
315 | 46 |
} |
47 |
||
1526
18e412dd7d50
Send QUIT message to server when netclient object is destroyed
unc0rr
parents:
1512
diff
changeset
|
48 |
HWNewNet::~HWNewNet() |
18e412dd7d50
Send QUIT message to server when netclient object is destroyed
unc0rr
parents:
1512
diff
changeset
|
49 |
{ |
18e412dd7d50
Send QUIT message to server when netclient object is destroyed
unc0rr
parents:
1512
diff
changeset
|
50 |
if (m_game_connected) |
18e412dd7d50
Send QUIT message to server when netclient object is destroyed
unc0rr
parents:
1512
diff
changeset
|
51 |
RawSendNet(QString("QUIT%1%2").arg(delimeter).arg("User quit")); |
18e412dd7d50
Send QUIT message to server when netclient object is destroyed
unc0rr
parents:
1512
diff
changeset
|
52 |
NetSocket.flush(); |
18e412dd7d50
Send QUIT message to server when netclient object is destroyed
unc0rr
parents:
1512
diff
changeset
|
53 |
} |
18e412dd7d50
Send QUIT message to server when netclient object is destroyed
unc0rr
parents:
1512
diff
changeset
|
54 |
|
315 | 55 |
void HWNewNet::Connect(const QString & hostName, quint16 port, const QString & nick) |
56 |
{ |
|
1418 | 57 |
mynick = nick; |
58 |
NetSocket.connectToHost(hostName, port); |
|
315 | 59 |
} |
60 |
||
61 |
void HWNewNet::Disconnect() |
|
62 |
{ |
|
1354
a8dcdeb88a43
Various small insignificant improvements everywhere
unc0rr
parents:
1351
diff
changeset
|
63 |
if (m_game_connected) |
1526
18e412dd7d50
Send QUIT message to server when netclient object is destroyed
unc0rr
parents:
1512
diff
changeset
|
64 |
RawSendNet(QString("QUIT%1%2").arg(delimeter).arg("User quit")); |
1354
a8dcdeb88a43
Various small insignificant improvements everywhere
unc0rr
parents:
1351
diff
changeset
|
65 |
m_game_connected = false; |
a8dcdeb88a43
Various small insignificant improvements everywhere
unc0rr
parents:
1351
diff
changeset
|
66 |
NetSocket.disconnectFromHost(); |
315 | 67 |
} |
68 |
||
1082 | 69 |
void HWNewNet::CreateRoom(const QString & room) |
315 | 70 |
{ |
1313
f4c54e9e1b8c
- Introduce a bit of state miachine in client code (should be more robust and verbosive now)
unc0rr
parents:
1311
diff
changeset
|
71 |
if(netClientState != 2) |
f4c54e9e1b8c
- Introduce a bit of state miachine in client code (should be more robust and verbosive now)
unc0rr
parents:
1311
diff
changeset
|
72 |
{ |
1321 | 73 |
qWarning("Illegal try to create room!"); |
1313
f4c54e9e1b8c
- Introduce a bit of state miachine in client code (should be more robust and verbosive now)
unc0rr
parents:
1311
diff
changeset
|
74 |
return; |
f4c54e9e1b8c
- Introduce a bit of state miachine in client code (should be more robust and verbosive now)
unc0rr
parents:
1311
diff
changeset
|
75 |
} |
f4c54e9e1b8c
- Introduce a bit of state miachine in client code (should be more robust and verbosive now)
unc0rr
parents:
1311
diff
changeset
|
76 |
|
1082 | 77 |
RawSendNet(QString("CREATE%1%2").arg(delimeter).arg(room)); |
1336
4e88eccbe7f6
Fix team colors mismatch on some conditions (just synchronize them when team is added)
unc0rr
parents:
1333
diff
changeset
|
78 |
m_pGameCFGWidget->setEnabled(true); |
1475
bab5650fc894
- Fix ConfigAsked not sending full config (leads to team divide checkbox inconsistency)
unc0rr
parents:
1471
diff
changeset
|
79 |
m_pTeamSelWidget->setInteractivity(true); |
1313
f4c54e9e1b8c
- Introduce a bit of state miachine in client code (should be more robust and verbosive now)
unc0rr
parents:
1311
diff
changeset
|
80 |
isChief = true; |
1082 | 81 |
} |
82 |
||
83 |
void HWNewNet::JoinRoom(const QString & room) |
|
84 |
{ |
|
1313
f4c54e9e1b8c
- Introduce a bit of state miachine in client code (should be more robust and verbosive now)
unc0rr
parents:
1311
diff
changeset
|
85 |
if(netClientState != 2) |
f4c54e9e1b8c
- Introduce a bit of state miachine in client code (should be more robust and verbosive now)
unc0rr
parents:
1311
diff
changeset
|
86 |
{ |
1321 | 87 |
qWarning("Illegal try to join room!"); |
1313
f4c54e9e1b8c
- Introduce a bit of state miachine in client code (should be more robust and verbosive now)
unc0rr
parents:
1311
diff
changeset
|
88 |
return; |
f4c54e9e1b8c
- Introduce a bit of state miachine in client code (should be more robust and verbosive now)
unc0rr
parents:
1311
diff
changeset
|
89 |
} |
f4c54e9e1b8c
- Introduce a bit of state miachine in client code (should be more robust and verbosive now)
unc0rr
parents:
1311
diff
changeset
|
90 |
|
f4c54e9e1b8c
- Introduce a bit of state miachine in client code (should be more robust and verbosive now)
unc0rr
parents:
1311
diff
changeset
|
91 |
loginStep++; |
f4c54e9e1b8c
- Introduce a bit of state miachine in client code (should be more robust and verbosive now)
unc0rr
parents:
1311
diff
changeset
|
92 |
|
1082 | 93 |
RawSendNet(QString("JOIN%1%2").arg(delimeter).arg(room)); |
1313
f4c54e9e1b8c
- Introduce a bit of state miachine in client code (should be more robust and verbosive now)
unc0rr
parents:
1311
diff
changeset
|
94 |
m_pGameCFGWidget->setEnabled(false); |
1475
bab5650fc894
- Fix ConfigAsked not sending full config (leads to team divide checkbox inconsistency)
unc0rr
parents:
1471
diff
changeset
|
95 |
m_pTeamSelWidget->setInteractivity(false); |
1313
f4c54e9e1b8c
- Introduce a bit of state miachine in client code (should be more robust and verbosive now)
unc0rr
parents:
1311
diff
changeset
|
96 |
isChief = false; |
315 | 97 |
} |
98 |
||
99 |
void HWNewNet::AddTeam(const HWTeam & team) |
|
100 |
{ |
|
1327 | 101 |
QString cmd = QString("ADD_TEAM") + delimeter + |
382
e7220e48ead1
colors changing config fully working (still need disabling in slaves)
displacer
parents:
373
diff
changeset
|
102 |
team.TeamName + delimeter + |
e7220e48ead1
colors changing config fully working (still need disabling in slaves)
displacer
parents:
373
diff
changeset
|
103 |
team.teamColor.name() + delimeter + |
443
eec37eb7f5db
fort, grave and difficulty information for net team
displacer
parents:
431
diff
changeset
|
104 |
team.Grave + delimeter + |
eec37eb7f5db
fort, grave and difficulty information for net team
displacer
parents:
431
diff
changeset
|
105 |
team.Fort + delimeter + |
1245
d2eca4a053f5
Send hats info via net. Hats implementation complete now.
unc0rr
parents:
1189
diff
changeset
|
106 |
QString::number(team.difficulty); |
d2eca4a053f5
Send hats info via net. Hats implementation complete now.
unc0rr
parents:
1189
diff
changeset
|
107 |
|
d2eca4a053f5
Send hats info via net. Hats implementation complete now.
unc0rr
parents:
1189
diff
changeset
|
108 |
for(int i = 0; i < 8; ++i) |
d2eca4a053f5
Send hats info via net. Hats implementation complete now.
unc0rr
parents:
1189
diff
changeset
|
109 |
{ |
d2eca4a053f5
Send hats info via net. Hats implementation complete now.
unc0rr
parents:
1189
diff
changeset
|
110 |
cmd.append(delimeter); |
d2eca4a053f5
Send hats info via net. Hats implementation complete now.
unc0rr
parents:
1189
diff
changeset
|
111 |
cmd.append(team.HHName[i]); |
d2eca4a053f5
Send hats info via net. Hats implementation complete now.
unc0rr
parents:
1189
diff
changeset
|
112 |
cmd.append(delimeter); |
d2eca4a053f5
Send hats info via net. Hats implementation complete now.
unc0rr
parents:
1189
diff
changeset
|
113 |
cmd.append(team.HHHat[i]); |
d2eca4a053f5
Send hats info via net. Hats implementation complete now.
unc0rr
parents:
1189
diff
changeset
|
114 |
} |
d2eca4a053f5
Send hats info via net. Hats implementation complete now.
unc0rr
parents:
1189
diff
changeset
|
115 |
RawSendNet(cmd); |
315 | 116 |
} |
117 |
||
347 | 118 |
void HWNewNet::RemoveTeam(const HWTeam & team) |
119 |
{ |
|
1329 | 120 |
RawSendNet(QString("REMOVE_TEAM") + delimeter + team.TeamName); |
347 | 121 |
} |
122 |
||
1404 | 123 |
void HWNewNet::ToggleReady() |
315 | 124 |
{ |
1404 | 125 |
RawSendNet(QString("TOGGLE_READY")); |
315 | 126 |
} |
127 |
||
128 |
void HWNewNet::SendNet(const QByteArray & buf) |
|
129 |
{ |
|
130 |
QString msg = QString(buf.toBase64()); |
|
131 |
||
1311 | 132 |
RawSendNet(QString("GAMEMSG%1%2").arg(delimeter).arg(msg)); |
315 | 133 |
} |
134 |
||
135 |
void HWNewNet::RawSendNet(const QString & str) |
|
136 |
{ |
|
137 |
RawSendNet(str.toUtf8()); |
|
138 |
} |
|
139 |
||
140 |
void HWNewNet::RawSendNet(const QByteArray & buf) |
|
141 |
{ |
|
1369 | 142 |
//qDebug() << "Client: " << QString(buf).split("\n"); |
143 |
NetSocket.write(buf); |
|
144 |
NetSocket.write("\n\n", 2); |
|
315 | 145 |
} |
146 |
||
147 |
void HWNewNet::ClientRead() |
|
148 |
{ |
|
1082 | 149 |
while (NetSocket.canReadLine()) { |
150 |
QString s = QString::fromUtf8(NetSocket.readLine().trimmed()); |
|
151 |
||
152 |
if (s.size() == 0) { |
|
153 |
ParseCmd(cmdbuf); |
|
154 |
cmdbuf.clear(); |
|
155 |
} else |
|
156 |
cmdbuf << s; |
|
157 |
} |
|
315 | 158 |
} |
159 |
||
160 |
void HWNewNet::OnConnect() |
|
161 |
{ |
|
162 |
} |
|
163 |
||
164 |
void HWNewNet::OnDisconnect() |
|
165 |
{ |
|
338
d1e75dcd285f
multiple teams now available per host (still alpha)
displacer
parents:
335
diff
changeset
|
166 |
//emit ChangeInTeams(QStringList()); |
383 | 167 |
if(m_game_connected) emit Disconnected(); |
1354
a8dcdeb88a43
Various small insignificant improvements everywhere
unc0rr
parents:
1351
diff
changeset
|
168 |
m_game_connected = false; |
315 | 169 |
} |
170 |
||
171 |
void HWNewNet::displayError(QAbstractSocket::SocketError socketError) |
|
172 |
{ |
|
1302 | 173 |
switch (socketError) { |
174 |
case QAbstractSocket::RemoteHostClosedError: |
|
175 |
break; |
|
176 |
case QAbstractSocket::HostNotFoundError: |
|
177 |
QMessageBox::information(0, tr("Error"), |
|
178 |
tr("The host was not found. Please check the host name and port settings.")); |
|
179 |
break; |
|
180 |
case QAbstractSocket::ConnectionRefusedError: |
|
181 |
QMessageBox::information(0, tr("Error"), |
|
182 |
tr("Connection refused")); |
|
183 |
break; |
|
184 |
default: |
|
185 |
QMessageBox::information(0, tr("Error"), |
|
186 |
NetSocket.errorString()); |
|
187 |
} |
|
315 | 188 |
} |
189 |
||
1082 | 190 |
void HWNewNet::ParseCmd(const QStringList & lst) |
315 | 191 |
{ |
1566
6b63c75fdc68
Start work on lobby: add/remove nick from the list on join/quit
unc0rr
parents:
1560
diff
changeset
|
192 |
qDebug() << "Server: " << lst; |
1305 | 193 |
|
194 |
if(!lst.size()) |
|
195 |
{ |
|
196 |
qWarning("Net client: Bad message"); |
|
197 |
return; |
|
198 |
} |
|
320 | 199 |
|
1308
d5dcd6cfa5e2
Fix another server failure (when second client in room disconnects)
unc0rr
parents:
1307
diff
changeset
|
200 |
if ((lst[0] == "NICK") || (lst[0] == "PROTO")) |
1313
f4c54e9e1b8c
- Introduce a bit of state miachine in client code (should be more robust and verbosive now)
unc0rr
parents:
1311
diff
changeset
|
201 |
{ |
f4c54e9e1b8c
- Introduce a bit of state miachine in client code (should be more robust and verbosive now)
unc0rr
parents:
1311
diff
changeset
|
202 |
loginStep++; |
f4c54e9e1b8c
- Introduce a bit of state miachine in client code (should be more robust and verbosive now)
unc0rr
parents:
1311
diff
changeset
|
203 |
if (loginStep == 2) |
f4c54e9e1b8c
- Introduce a bit of state miachine in client code (should be more robust and verbosive now)
unc0rr
parents:
1311
diff
changeset
|
204 |
{ |
f4c54e9e1b8c
- Introduce a bit of state miachine in client code (should be more robust and verbosive now)
unc0rr
parents:
1311
diff
changeset
|
205 |
netClientState = 2; |
f4c54e9e1b8c
- Introduce a bit of state miachine in client code (should be more robust and verbosive now)
unc0rr
parents:
1311
diff
changeset
|
206 |
RawSendNet(QString("LIST")); |
f4c54e9e1b8c
- Introduce a bit of state miachine in client code (should be more robust and verbosive now)
unc0rr
parents:
1311
diff
changeset
|
207 |
} |
1308
d5dcd6cfa5e2
Fix another server failure (when second client in room disconnects)
unc0rr
parents:
1307
diff
changeset
|
208 |
return ; |
1313
f4c54e9e1b8c
- Introduce a bit of state miachine in client code (should be more robust and verbosive now)
unc0rr
parents:
1311
diff
changeset
|
209 |
} |
1308
d5dcd6cfa5e2
Fix another server failure (when second client in room disconnects)
unc0rr
parents:
1307
diff
changeset
|
210 |
|
1305 | 211 |
if (lst[0] == "ERROR") { |
212 |
if (lst.size() == 2) |
|
1307 | 213 |
QMessageBox::information(0, 0, "Error: " + lst[1]); |
1305 | 214 |
else |
215 |
QMessageBox::information(0, 0, "Unknown error"); |
|
216 |
return; |
|
217 |
} |
|
315 | 218 |
|
1307 | 219 |
if (lst[0] == "WARNING") { |
220 |
if (lst.size() == 2) |
|
221 |
QMessageBox::information(0, 0, "Warning: " + lst[1]); |
|
222 |
else |
|
223 |
QMessageBox::information(0, 0, "Unknown warning"); |
|
224 |
return; |
|
225 |
} |
|
226 |
||
1308
d5dcd6cfa5e2
Fix another server failure (when second client in room disconnects)
unc0rr
parents:
1307
diff
changeset
|
227 |
if (lst[0] == "CONNECTED") { |
1471 | 228 |
RawSendNet(QString("NICK%1%2").arg(delimeter).arg(mynick)); |
229 |
RawSendNet(QString("PROTO%1%2").arg(delimeter).arg(*cProtoVer)); |
|
1313
f4c54e9e1b8c
- Introduce a bit of state miachine in client code (should be more robust and verbosive now)
unc0rr
parents:
1311
diff
changeset
|
230 |
netClientState = 1; |
f4c54e9e1b8c
- Introduce a bit of state miachine in client code (should be more robust and verbosive now)
unc0rr
parents:
1311
diff
changeset
|
231 |
m_game_connected = true; |
1308
d5dcd6cfa5e2
Fix another server failure (when second client in room disconnects)
unc0rr
parents:
1307
diff
changeset
|
232 |
emit Connected(); |
d5dcd6cfa5e2
Fix another server failure (when second client in room disconnects)
unc0rr
parents:
1307
diff
changeset
|
233 |
return; |
d5dcd6cfa5e2
Fix another server failure (when second client in room disconnects)
unc0rr
parents:
1307
diff
changeset
|
234 |
} |
315 | 235 |
|
1462 | 236 |
if (lst[0] == "PING") { |
237 |
RawSendNet(QString("PONG")); |
|
238 |
return; |
|
239 |
} |
|
240 |
||
1313
f4c54e9e1b8c
- Introduce a bit of state miachine in client code (should be more robust and verbosive now)
unc0rr
parents:
1311
diff
changeset
|
241 |
if (lst[0] == "ROOMS") { |
f4c54e9e1b8c
- Introduce a bit of state miachine in client code (should be more robust and verbosive now)
unc0rr
parents:
1311
diff
changeset
|
242 |
QStringList tmp = lst; |
f4c54e9e1b8c
- Introduce a bit of state miachine in client code (should be more robust and verbosive now)
unc0rr
parents:
1311
diff
changeset
|
243 |
tmp.removeFirst(); |
f4c54e9e1b8c
- Introduce a bit of state miachine in client code (should be more robust and verbosive now)
unc0rr
parents:
1311
diff
changeset
|
244 |
emit roomsList(tmp); |
f4c54e9e1b8c
- Introduce a bit of state miachine in client code (should be more robust and verbosive now)
unc0rr
parents:
1311
diff
changeset
|
245 |
return; |
f4c54e9e1b8c
- Introduce a bit of state miachine in client code (should be more robust and verbosive now)
unc0rr
parents:
1311
diff
changeset
|
246 |
} |
f4c54e9e1b8c
- Introduce a bit of state miachine in client code (should be more robust and verbosive now)
unc0rr
parents:
1311
diff
changeset
|
247 |
|
1377 | 248 |
if (lst[0] == "SERVER_MESSAGE") { |
249 |
if(lst.size() < 2) |
|
250 |
{ |
|
251 |
qWarning("Net: Empty SERVERMESSAGE message"); |
|
252 |
return; |
|
253 |
} |
|
254 |
emit serverMessage(lst[1]); |
|
255 |
return; |
|
256 |
} |
|
257 |
||
1308
d5dcd6cfa5e2
Fix another server failure (when second client in room disconnects)
unc0rr
parents:
1307
diff
changeset
|
258 |
if (lst[0] == "CHAT_STRING") { |
d5dcd6cfa5e2
Fix another server failure (when second client in room disconnects)
unc0rr
parents:
1307
diff
changeset
|
259 |
if(lst.size() < 3) |
d5dcd6cfa5e2
Fix another server failure (when second client in room disconnects)
unc0rr
parents:
1307
diff
changeset
|
260 |
{ |
1377 | 261 |
qWarning("Net: Empty CHAT_STRING message"); |
262 |
return; |
|
1308
d5dcd6cfa5e2
Fix another server failure (when second client in room disconnects)
unc0rr
parents:
1307
diff
changeset
|
263 |
} |
1378 | 264 |
emit chatStringFromNet(formatChatMsg(lst[1], lst[2])); |
1308
d5dcd6cfa5e2
Fix another server failure (when second client in room disconnects)
unc0rr
parents:
1307
diff
changeset
|
265 |
return; |
d5dcd6cfa5e2
Fix another server failure (when second client in room disconnects)
unc0rr
parents:
1307
diff
changeset
|
266 |
} |
453 | 267 |
|
1405 | 268 |
if (lst[0] == "READY") { |
269 |
if(lst.size() != 2) |
|
270 |
{ |
|
271 |
qWarning("Net: Malformed READY message"); |
|
272 |
return; |
|
273 |
} |
|
274 |
emit setReadyStatus(lst[1], true); |
|
275 |
return; |
|
276 |
} |
|
277 |
if (lst[0] == "NOT_READY") { |
|
278 |
if(lst.size() != 2) |
|
279 |
{ |
|
280 |
qWarning("Net: Malformed NOT_READY message"); |
|
281 |
return; |
|
282 |
} |
|
283 |
emit setReadyStatus(lst[1], false); |
|
284 |
return; |
|
285 |
} |
|
286 |
||
1325 | 287 |
if (lst[0] == "ADD_TEAM") { |
288 |
if(lst.size() != 21) |
|
1321 | 289 |
{ |
1325 | 290 |
qWarning("Net: Bad ADDTEAM message"); |
1321 | 291 |
return; |
292 |
} |
|
293 |
QStringList tmp = lst; |
|
294 |
tmp.removeFirst(); |
|
295 |
emit AddNetTeam(tmp); |
|
296 |
return; |
|
297 |
} |
|
315 | 298 |
|
1338 | 299 |
if (lst[0] == "REMOVE_TEAM") { |
300 |
if(lst.size() != 2) |
|
301 |
{ |
|
302 |
qWarning("Net: Bad REMOVETEAM message"); |
|
303 |
return; |
|
304 |
} |
|
305 |
m_pTeamSelWidget->removeNetTeam(HWTeam(lst[1])); |
|
1351
aa7aefec5c1b
Add partial implementation of handling disconnects while playing via network
unc0rr
parents:
1344
diff
changeset
|
306 |
if (netClientState == 5) // we're in game, need to tell the engine about this |
aa7aefec5c1b
Add partial implementation of handling disconnects while playing via network
unc0rr
parents:
1344
diff
changeset
|
307 |
{ |
aa7aefec5c1b
Add partial implementation of handling disconnects while playing via network
unc0rr
parents:
1344
diff
changeset
|
308 |
QByteArray em; |
aa7aefec5c1b
Add partial implementation of handling disconnects while playing via network
unc0rr
parents:
1344
diff
changeset
|
309 |
HWProto::addStringToBuffer(em, "F" + lst[1]); |
aa7aefec5c1b
Add partial implementation of handling disconnects while playing via network
unc0rr
parents:
1344
diff
changeset
|
310 |
emit FromNet(em); |
aa7aefec5c1b
Add partial implementation of handling disconnects while playing via network
unc0rr
parents:
1344
diff
changeset
|
311 |
} |
1338 | 312 |
return; |
313 |
} |
|
347 | 314 |
|
1308
d5dcd6cfa5e2
Fix another server failure (when second client in room disconnects)
unc0rr
parents:
1307
diff
changeset
|
315 |
if(lst[0]=="JOINED") { |
d5dcd6cfa5e2
Fix another server failure (when second client in room disconnects)
unc0rr
parents:
1307
diff
changeset
|
316 |
if(lst.size() < 2) |
d5dcd6cfa5e2
Fix another server failure (when second client in room disconnects)
unc0rr
parents:
1307
diff
changeset
|
317 |
{ |
d5dcd6cfa5e2
Fix another server failure (when second client in room disconnects)
unc0rr
parents:
1307
diff
changeset
|
318 |
qWarning("Net: Bad JOINED message"); |
d5dcd6cfa5e2
Fix another server failure (when second client in room disconnects)
unc0rr
parents:
1307
diff
changeset
|
319 |
return; |
d5dcd6cfa5e2
Fix another server failure (when second client in room disconnects)
unc0rr
parents:
1307
diff
changeset
|
320 |
} |
1311 | 321 |
|
1308
d5dcd6cfa5e2
Fix another server failure (when second client in room disconnects)
unc0rr
parents:
1307
diff
changeset
|
322 |
for(int i = 1; i < lst.size(); ++i) |
1311 | 323 |
{ |
1313
f4c54e9e1b8c
- Introduce a bit of state miachine in client code (should be more robust and verbosive now)
unc0rr
parents:
1311
diff
changeset
|
324 |
if (lst[i] == mynick) |
f4c54e9e1b8c
- Introduce a bit of state miachine in client code (should be more robust and verbosive now)
unc0rr
parents:
1311
diff
changeset
|
325 |
{ |
f4c54e9e1b8c
- Introduce a bit of state miachine in client code (should be more robust and verbosive now)
unc0rr
parents:
1311
diff
changeset
|
326 |
netClientState = 3; |
f4c54e9e1b8c
- Introduce a bit of state miachine in client code (should be more robust and verbosive now)
unc0rr
parents:
1311
diff
changeset
|
327 |
emit EnteredGame(); |
1316 | 328 |
if (isChief) |
329 |
ConfigAsked(); |
|
1313
f4c54e9e1b8c
- Introduce a bit of state miachine in client code (should be more robust and verbosive now)
unc0rr
parents:
1311
diff
changeset
|
330 |
} |
1308
d5dcd6cfa5e2
Fix another server failure (when second client in room disconnects)
unc0rr
parents:
1307
diff
changeset
|
331 |
emit nickAdded(lst[i]); |
1378 | 332 |
emit chatStringFromNet(QString(tr("*** %1 joined")).arg(lst[i])); |
1311 | 333 |
} |
1308
d5dcd6cfa5e2
Fix another server failure (when second client in room disconnects)
unc0rr
parents:
1307
diff
changeset
|
334 |
return; |
d5dcd6cfa5e2
Fix another server failure (when second client in room disconnects)
unc0rr
parents:
1307
diff
changeset
|
335 |
} |
455 | 336 |
|
1566
6b63c75fdc68
Start work on lobby: add/remove nick from the list on join/quit
unc0rr
parents:
1560
diff
changeset
|
337 |
if(lst[0]=="LOBBY:JOINED") { |
6b63c75fdc68
Start work on lobby: add/remove nick from the list on join/quit
unc0rr
parents:
1560
diff
changeset
|
338 |
if(lst.size() < 2) |
6b63c75fdc68
Start work on lobby: add/remove nick from the list on join/quit
unc0rr
parents:
1560
diff
changeset
|
339 |
{ |
6b63c75fdc68
Start work on lobby: add/remove nick from the list on join/quit
unc0rr
parents:
1560
diff
changeset
|
340 |
qWarning("Net: Bad JOINED message"); |
6b63c75fdc68
Start work on lobby: add/remove nick from the list on join/quit
unc0rr
parents:
1560
diff
changeset
|
341 |
return; |
6b63c75fdc68
Start work on lobby: add/remove nick from the list on join/quit
unc0rr
parents:
1560
diff
changeset
|
342 |
} |
6b63c75fdc68
Start work on lobby: add/remove nick from the list on join/quit
unc0rr
parents:
1560
diff
changeset
|
343 |
|
6b63c75fdc68
Start work on lobby: add/remove nick from the list on join/quit
unc0rr
parents:
1560
diff
changeset
|
344 |
for(int i = 1; i < lst.size(); ++i) |
6b63c75fdc68
Start work on lobby: add/remove nick from the list on join/quit
unc0rr
parents:
1560
diff
changeset
|
345 |
{ |
6b63c75fdc68
Start work on lobby: add/remove nick from the list on join/quit
unc0rr
parents:
1560
diff
changeset
|
346 |
emit nickAddedLobby(lst[i]); |
6b63c75fdc68
Start work on lobby: add/remove nick from the list on join/quit
unc0rr
parents:
1560
diff
changeset
|
347 |
//emit chatStringFromNet(QString(tr("*** %1 joined")).arg(lst[i])); |
6b63c75fdc68
Start work on lobby: add/remove nick from the list on join/quit
unc0rr
parents:
1560
diff
changeset
|
348 |
} |
6b63c75fdc68
Start work on lobby: add/remove nick from the list on join/quit
unc0rr
parents:
1560
diff
changeset
|
349 |
return; |
6b63c75fdc68
Start work on lobby: add/remove nick from the list on join/quit
unc0rr
parents:
1560
diff
changeset
|
350 |
} |
6b63c75fdc68
Start work on lobby: add/remove nick from the list on join/quit
unc0rr
parents:
1560
diff
changeset
|
351 |
|
1325 | 352 |
if(lst[0] == "LEFT") { |
1310 | 353 |
if(lst.size() < 2) |
354 |
{ |
|
355 |
qWarning("Net: Bad LEFT message"); |
|
356 |
return; |
|
357 |
} |
|
358 |
emit nickRemoved(lst[1]); |
|
1512
43742041c211
- Don't send 'Bad param' msg, as the only reason of it is just some lag
unc0rr
parents:
1475
diff
changeset
|
359 |
if (lst.size() < 3) |
43742041c211
- Don't send 'Bad param' msg, as the only reason of it is just some lag
unc0rr
parents:
1475
diff
changeset
|
360 |
emit chatStringFromNet(QString(tr("*** %1 left")).arg(lst[1])); |
43742041c211
- Don't send 'Bad param' msg, as the only reason of it is just some lag
unc0rr
parents:
1475
diff
changeset
|
361 |
else |
43742041c211
- Don't send 'Bad param' msg, as the only reason of it is just some lag
unc0rr
parents:
1475
diff
changeset
|
362 |
emit chatStringFromNet(QString(tr("*** %1 left (%2)")).arg(lst[1], lst[2])); |
1310 | 363 |
return; |
364 |
} |
|
461 | 365 |
|
1566
6b63c75fdc68
Start work on lobby: add/remove nick from the list on join/quit
unc0rr
parents:
1560
diff
changeset
|
366 |
if(lst[0] == "LOBBY:LEFT") { |
6b63c75fdc68
Start work on lobby: add/remove nick from the list on join/quit
unc0rr
parents:
1560
diff
changeset
|
367 |
if(lst.size() < 2) |
6b63c75fdc68
Start work on lobby: add/remove nick from the list on join/quit
unc0rr
parents:
1560
diff
changeset
|
368 |
{ |
6b63c75fdc68
Start work on lobby: add/remove nick from the list on join/quit
unc0rr
parents:
1560
diff
changeset
|
369 |
qWarning("Net: Bad LEFT message"); |
6b63c75fdc68
Start work on lobby: add/remove nick from the list on join/quit
unc0rr
parents:
1560
diff
changeset
|
370 |
return; |
6b63c75fdc68
Start work on lobby: add/remove nick from the list on join/quit
unc0rr
parents:
1560
diff
changeset
|
371 |
} |
6b63c75fdc68
Start work on lobby: add/remove nick from the list on join/quit
unc0rr
parents:
1560
diff
changeset
|
372 |
emit nickRemovedLobby(lst[1]); |
6b63c75fdc68
Start work on lobby: add/remove nick from the list on join/quit
unc0rr
parents:
1560
diff
changeset
|
373 |
/*if (lst.size() < 3) |
6b63c75fdc68
Start work on lobby: add/remove nick from the list on join/quit
unc0rr
parents:
1560
diff
changeset
|
374 |
emit chatStringFromNet(QString(tr("*** %1 left")).arg(lst[1])); |
6b63c75fdc68
Start work on lobby: add/remove nick from the list on join/quit
unc0rr
parents:
1560
diff
changeset
|
375 |
else |
6b63c75fdc68
Start work on lobby: add/remove nick from the list on join/quit
unc0rr
parents:
1560
diff
changeset
|
376 |
emit chatStringFromNet(QString(tr("*** %1 left (%2)")).arg(lst[1], lst[2]));*/ |
6b63c75fdc68
Start work on lobby: add/remove nick from the list on join/quit
unc0rr
parents:
1560
diff
changeset
|
377 |
return; |
6b63c75fdc68
Start work on lobby: add/remove nick from the list on join/quit
unc0rr
parents:
1560
diff
changeset
|
378 |
} |
6b63c75fdc68
Start work on lobby: add/remove nick from the list on join/quit
unc0rr
parents:
1560
diff
changeset
|
379 |
|
1338 | 380 |
if (lst[0] == "RUN_GAME") { |
1351
aa7aefec5c1b
Add partial implementation of handling disconnects while playing via network
unc0rr
parents:
1344
diff
changeset
|
381 |
netClientState = 5; |
1325 | 382 |
RunGame(); |
383 |
return; |
|
384 |
} |
|
339
7535ab6c3820
Run game message added, team and config info provided for net game
displacer
parents:
338
diff
changeset
|
385 |
|
1325 | 386 |
if (lst[0] == "TEAM_ACCEPTED") { |
387 |
if (lst.size() != 2) |
|
388 |
{ |
|
389 |
qWarning("Net: Bad TEAM_ACCEPTED message"); |
|
390 |
return; |
|
391 |
} |
|
392 |
m_pTeamSelWidget->changeTeamStatus(lst[1]); |
|
393 |
return; |
|
394 |
} |
|
354
60e4af0a4375
network to local teams map, addteams from server before team config bug, fixed some segfaults
displacer
parents:
352
diff
changeset
|
395 |
|
1333
b0b0510eb82d
- Fix a bug with chosen map (new clinet gets wrong information)
unc0rr
parents:
1330
diff
changeset
|
396 |
if (lst[0] == "MAP") { |
b0b0510eb82d
- Fix a bug with chosen map (new clinet gets wrong information)
unc0rr
parents:
1330
diff
changeset
|
397 |
if (lst.size() != 2) |
b0b0510eb82d
- Fix a bug with chosen map (new clinet gets wrong information)
unc0rr
parents:
1330
diff
changeset
|
398 |
{ |
b0b0510eb82d
- Fix a bug with chosen map (new clinet gets wrong information)
unc0rr
parents:
1330
diff
changeset
|
399 |
qWarning("Net: Bad MAP message"); |
b0b0510eb82d
- Fix a bug with chosen map (new clinet gets wrong information)
unc0rr
parents:
1330
diff
changeset
|
400 |
return; |
b0b0510eb82d
- Fix a bug with chosen map (new clinet gets wrong information)
unc0rr
parents:
1330
diff
changeset
|
401 |
} |
b0b0510eb82d
- Fix a bug with chosen map (new clinet gets wrong information)
unc0rr
parents:
1330
diff
changeset
|
402 |
emit mapChanged(lst[1]); |
b0b0510eb82d
- Fix a bug with chosen map (new clinet gets wrong information)
unc0rr
parents:
1330
diff
changeset
|
403 |
return; |
b0b0510eb82d
- Fix a bug with chosen map (new clinet gets wrong information)
unc0rr
parents:
1330
diff
changeset
|
404 |
} |
b0b0510eb82d
- Fix a bug with chosen map (new clinet gets wrong information)
unc0rr
parents:
1330
diff
changeset
|
405 |
|
b0b0510eb82d
- Fix a bug with chosen map (new clinet gets wrong information)
unc0rr
parents:
1330
diff
changeset
|
406 |
|
1319 | 407 |
if (lst[0] == "CONFIG_PARAM") { |
408 |
if(lst.size() < 3) |
|
409 |
{ |
|
410 |
qWarning("Net: Bad CONFIG_PARAM message"); |
|
411 |
return; |
|
412 |
} |
|
413 |
if (lst[1] == "SEED") { |
|
414 |
emit seedChanged(lst[2]); |
|
415 |
return; |
|
416 |
} |
|
417 |
if (lst[1] == "THEME") { |
|
418 |
emit themeChanged(lst[2]); |
|
419 |
return; |
|
420 |
} |
|
421 |
if (lst[1] == "HEALTH") { |
|
422 |
emit initHealthChanged(lst[2].toUInt()); |
|
423 |
return; |
|
424 |
} |
|
425 |
if (lst[1] == "TURNTIME") { |
|
426 |
emit turnTimeChanged(lst[2].toUInt()); |
|
427 |
return; |
|
428 |
} |
|
429 |
if (lst[1] == "FORTSMODE") { |
|
430 |
emit fortsModeChanged(lst[2].toInt() != 0); |
|
431 |
return; |
|
432 |
} |
|
1427 | 433 |
if (lst[1] == "DIVIDETEAMS") { |
434 |
emit teamsDivideChanged(lst[2].toInt() != 0); |
|
435 |
return; |
|
436 |
} |
|
1530 | 437 |
if (lst[1] == "SOLIDLAND") { |
438 |
emit solidChanged(lst[2].toInt() != 0); |
|
439 |
return; |
|
440 |
} |
|
1319 | 441 |
if (lst[1] == "AMMO") { |
442 |
if(lst.size() < 4) return; |
|
443 |
emit ammoChanged(lst[3], lst[2]); |
|
444 |
return; |
|
445 |
} |
|
446 |
qWarning() << "Net: Unknown 'CONFIG_PARAM' message:" << lst; |
|
447 |
return; |
|
697 | 448 |
} |
329
4c3aad46baa5
Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents:
322
diff
changeset
|
449 |
|
1327 | 450 |
if (lst[0] == "HH_NUM") { |
451 |
if (lst.size() != 3) |
|
452 |
{ |
|
453 |
qWarning("Net: Bad TEAM_ACCEPTED message"); |
|
454 |
return; |
|
455 |
} |
|
456 |
HWTeam tmptm(lst[1]); |
|
457 |
tmptm.numHedgehogs = lst[2].toUInt(); |
|
458 |
emit hhnumChanged(tmptm); |
|
459 |
return; |
|
460 |
} |
|
329
4c3aad46baa5
Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents:
322
diff
changeset
|
461 |
|
1330 | 462 |
if (lst[0] == "TEAM_COLOR") { |
463 |
if (lst.size() != 3) |
|
464 |
{ |
|
465 |
qWarning("Net: Bad TEAM_COLOR message"); |
|
466 |
return; |
|
467 |
} |
|
468 |
HWTeam tmptm(lst[1]); |
|
469 |
tmptm.teamColor = QColor(lst[2]); |
|
470 |
emit teamColorChanged(tmptm); |
|
471 |
return; |
|
472 |
} |
|
473 |
||
1351
aa7aefec5c1b
Add partial implementation of handling disconnects while playing via network
unc0rr
parents:
1344
diff
changeset
|
474 |
if (lst[0] == "GAMEMSG") { |
aa7aefec5c1b
Add partial implementation of handling disconnects while playing via network
unc0rr
parents:
1344
diff
changeset
|
475 |
if(lst.size() < 2) |
aa7aefec5c1b
Add partial implementation of handling disconnects while playing via network
unc0rr
parents:
1344
diff
changeset
|
476 |
{ |
aa7aefec5c1b
Add partial implementation of handling disconnects while playing via network
unc0rr
parents:
1344
diff
changeset
|
477 |
qWarning("Net: Bad GAMEMSG message"); |
aa7aefec5c1b
Add partial implementation of handling disconnects while playing via network
unc0rr
parents:
1344
diff
changeset
|
478 |
return; |
aa7aefec5c1b
Add partial implementation of handling disconnects while playing via network
unc0rr
parents:
1344
diff
changeset
|
479 |
} |
1558
3370b7ffeb5c
- Send previous moves info to newly connected client when it joins a room with already started game
unc0rr
parents:
1541
diff
changeset
|
480 |
for(int i = 1; i < lst.size(); ++i) |
3370b7ffeb5c
- Send previous moves info to newly connected client when it joins a room with already started game
unc0rr
parents:
1541
diff
changeset
|
481 |
{ |
1559
71e1f67dcfe7
Now spectating works for those who joined after game start
unc0rr
parents:
1558
diff
changeset
|
482 |
QByteArray em = QByteArray::fromBase64(lst[i].toAscii()); |
1558
3370b7ffeb5c
- Send previous moves info to newly connected client when it joins a room with already started game
unc0rr
parents:
1541
diff
changeset
|
483 |
emit FromNet(em); |
3370b7ffeb5c
- Send previous moves info to newly connected client when it joins a room with already started game
unc0rr
parents:
1541
diff
changeset
|
484 |
} |
1351
aa7aefec5c1b
Add partial implementation of handling disconnects while playing via network
unc0rr
parents:
1344
diff
changeset
|
485 |
return; |
aa7aefec5c1b
Add partial implementation of handling disconnects while playing via network
unc0rr
parents:
1344
diff
changeset
|
486 |
} |
573 | 487 |
|
1512
43742041c211
- Don't send 'Bad param' msg, as the only reason of it is just some lag
unc0rr
parents:
1475
diff
changeset
|
488 |
if (lst[0] == "BYE") { |
43742041c211
- Don't send 'Bad param' msg, as the only reason of it is just some lag
unc0rr
parents:
1475
diff
changeset
|
489 |
if (lst.size() < 2) |
43742041c211
- Don't send 'Bad param' msg, as the only reason of it is just some lag
unc0rr
parents:
1475
diff
changeset
|
490 |
{ |
43742041c211
- Don't send 'Bad param' msg, as the only reason of it is just some lag
unc0rr
parents:
1475
diff
changeset
|
491 |
qWarning("Net: Bad BYE message"); |
43742041c211
- Don't send 'Bad param' msg, as the only reason of it is just some lag
unc0rr
parents:
1475
diff
changeset
|
492 |
return; |
43742041c211
- Don't send 'Bad param' msg, as the only reason of it is just some lag
unc0rr
parents:
1475
diff
changeset
|
493 |
} |
43742041c211
- Don't send 'Bad param' msg, as the only reason of it is just some lag
unc0rr
parents:
1475
diff
changeset
|
494 |
emit showMessage(HWNewNet::tr("Quit reason: ") + lst[1]); |
43742041c211
- Don't send 'Bad param' msg, as the only reason of it is just some lag
unc0rr
parents:
1475
diff
changeset
|
495 |
return; |
43742041c211
- Don't send 'Bad param' msg, as the only reason of it is just some lag
unc0rr
parents:
1475
diff
changeset
|
496 |
} |
43742041c211
- Don't send 'Bad param' msg, as the only reason of it is just some lag
unc0rr
parents:
1475
diff
changeset
|
497 |
|
1351
aa7aefec5c1b
Add partial implementation of handling disconnects while playing via network
unc0rr
parents:
1344
diff
changeset
|
498 |
qWarning() << "Net: Unknown message:" << lst; |
315 | 499 |
} |
500 |
||
501 |
||
502 |
void HWNewNet::ConfigAsked() |
|
503 |
{ |
|
1310 | 504 |
QString map = m_pGameCFGWidget->getCurrentMap(); |
505 |
if (map.size()) |
|
506 |
onMapChanged(map); |
|
574 | 507 |
|
1310 | 508 |
onSeedChanged(m_pGameCFGWidget->getCurrentSeed()); |
509 |
onThemeChanged(m_pGameCFGWidget->getCurrentTheme()); |
|
510 |
onInitHealthChanged(m_pGameCFGWidget->getInitHealth()); |
|
511 |
onTurnTimeChanged(m_pGameCFGWidget->getTurnTime()); |
|
512 |
onFortsModeChanged(m_pGameCFGWidget->getGameFlags() & 0x1); |
|
1475
bab5650fc894
- Fix ConfigAsked not sending full config (leads to team divide checkbox inconsistency)
unc0rr
parents:
1471
diff
changeset
|
513 |
onTeamsDivideChanged(m_pGameCFGWidget->getGameFlags() & 0x10); |
1530 | 514 |
onSolidChanged(m_pGameCFGWidget->getGameFlags() & 0x04); |
1310 | 515 |
// always initialize with default ammo (also avoiding complicated cross-class dependencies) |
1541 | 516 |
QString name = m_pGameCFGWidget->WeaponsName->currentText(); |
517 |
QString ammo = m_pGameCFGWidget->WeaponsName->itemData( |
|
518 |
m_pGameCFGWidget->WeaponsName->currentIndex() |
|
519 |
).toString(); |
|
520 |
onWeaponsNameChanged(name, ammo); |
|
315 | 521 |
} |
522 |
||
523 |
void HWNewNet::RunGame() |
|
524 |
{ |
|
1310 | 525 |
emit AskForRunGame(); |
431 | 526 |
} |
527 |
||
352 | 528 |
void HWNewNet::onHedgehogsNumChanged(const HWTeam& team) |
529 |
{ |
|
1330 | 530 |
if (isChief) |
1327 | 531 |
RawSendNet(QString("HH_NUM%1%2%1%3") |
1324 | 532 |
.arg(delimeter) |
533 |
.arg(team.TeamName) |
|
1321 | 534 |
.arg(team.numHedgehogs)); |
352 | 535 |
} |
536 |
||
372 | 537 |
void HWNewNet::onTeamColorChanged(const HWTeam& team) |
538 |
{ |
|
1330 | 539 |
if (isChief) |
540 |
RawSendNet(QString("TEAM_COLOR%1%2%1%3") |
|
1324 | 541 |
.arg(delimeter) |
542 |
.arg(team.TeamName) |
|
1321 | 543 |
.arg(team.teamColor.name())); |
372 | 544 |
} |
545 |
||
329
4c3aad46baa5
Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents:
322
diff
changeset
|
546 |
void HWNewNet::onSeedChanged(const QString & seed) |
4c3aad46baa5
Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents:
322
diff
changeset
|
547 |
{ |
1530 | 548 |
if (isChief) RawSendNet(QString("CONFIG_PARAM%1SEED%1%2").arg(delimeter).arg(seed)); |
329
4c3aad46baa5
Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents:
322
diff
changeset
|
549 |
} |
4c3aad46baa5
Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents:
322
diff
changeset
|
550 |
|
4c3aad46baa5
Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents:
322
diff
changeset
|
551 |
void HWNewNet::onMapChanged(const QString & map) |
4c3aad46baa5
Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents:
322
diff
changeset
|
552 |
{ |
1530 | 553 |
if (isChief) RawSendNet(QString("MAP%1%2").arg(delimeter).arg(map)); |
329
4c3aad46baa5
Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents:
322
diff
changeset
|
554 |
} |
4c3aad46baa5
Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents:
322
diff
changeset
|
555 |
|
4c3aad46baa5
Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents:
322
diff
changeset
|
556 |
void HWNewNet::onThemeChanged(const QString & theme) |
4c3aad46baa5
Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents:
322
diff
changeset
|
557 |
{ |
1530 | 558 |
if (isChief) RawSendNet(QString("CONFIG_PARAM%1THEME%1%2").arg(delimeter).arg(theme)); |
329
4c3aad46baa5
Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents:
322
diff
changeset
|
559 |
} |
4c3aad46baa5
Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents:
322
diff
changeset
|
560 |
|
1427 | 561 |
void HWNewNet::onInitHealthChanged(int health) |
329
4c3aad46baa5
Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents:
322
diff
changeset
|
562 |
{ |
1530 | 563 |
if (isChief) RawSendNet(QString("CONFIG_PARAM%1HEALTH%1%2").arg(delimeter).arg(health)); |
329
4c3aad46baa5
Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents:
322
diff
changeset
|
564 |
} |
4c3aad46baa5
Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents:
322
diff
changeset
|
565 |
|
1427 | 566 |
void HWNewNet::onTurnTimeChanged(int time) |
329
4c3aad46baa5
Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents:
322
diff
changeset
|
567 |
{ |
1530 | 568 |
if (isChief) RawSendNet(QString("CONFIG_PARAM%1TURNTIME%1%2").arg(delimeter).arg(time)); |
329
4c3aad46baa5
Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents:
322
diff
changeset
|
569 |
} |
4c3aad46baa5
Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents:
322
diff
changeset
|
570 |
|
4c3aad46baa5
Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents:
322
diff
changeset
|
571 |
void HWNewNet::onFortsModeChanged(bool value) |
4c3aad46baa5
Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents:
322
diff
changeset
|
572 |
{ |
1530 | 573 |
if (isChief) RawSendNet(QString("CONFIG_PARAM%1FORTSMODE%1%2").arg(delimeter).arg(value)); |
329
4c3aad46baa5
Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents:
322
diff
changeset
|
574 |
} |
453 | 575 |
|
1427 | 576 |
void HWNewNet::onTeamsDivideChanged(bool value) |
577 |
{ |
|
1530 | 578 |
if (isChief) RawSendNet(QString("CONFIG_PARAM%1DIVIDETEAMS%1%2").arg(delimeter).arg(value)); |
579 |
} |
|
580 |
||
581 |
void HWNewNet::onSolidChanged(bool value) |
|
582 |
{ |
|
583 |
if (isChief) RawSendNet(QString("CONFIG_PARAM%1SOLIDLAND%1%2").arg(delimeter).arg(value)); |
|
1427 | 584 |
} |
585 |
||
703 | 586 |
void HWNewNet::onWeaponsNameChanged(const QString& name, const QString& ammo) |
697 | 587 |
{ |
1530 | 588 |
if (isChief) RawSendNet(QString("CONFIG_PARAM%1AMMO%1%2%1%3").arg(delimeter).arg(ammo).arg(name)); |
697 | 589 |
} |
590 |
||
453 | 591 |
void HWNewNet::chatLineToNet(const QString& str) |
592 |
{ |
|
593 |
if(str!="") { |
|
1322
c624b04699fb
Fix protocol implementation to conform documentation
unc0rr
parents:
1321
diff
changeset
|
594 |
RawSendNet(QString("CHAT_STRING")+delimeter+str); |
1378 | 595 |
emit(chatStringFromMe(formatChatMsg(mynick, str))); |
453 | 596 |
} |
597 |
} |
|
1315 | 598 |
|
599 |
void HWNewNet::askRoomsList() |
|
600 |
{ |
|
601 |
if(netClientState != 2) |
|
602 |
{ |
|
1321 | 603 |
qWarning("Illegal try to get rooms list!"); |
1315 | 604 |
return; |
605 |
} |
|
606 |
RawSendNet(QString("LIST")); |
|
607 |
} |
|
1339 | 608 |
|
609 |
bool HWNewNet::isRoomChief() |
|
610 |
{ |
|
611 |
return isChief; |
|
612 |
} |
|
1344
4004e597f1bf
Clients send roundfinished message to server when the round is over
unc0rr
parents:
1339
diff
changeset
|
613 |
|
4004e597f1bf
Clients send roundfinished message to server when the round is over
unc0rr
parents:
1339
diff
changeset
|
614 |
void HWNewNet::gameFinished() |
4004e597f1bf
Clients send roundfinished message to server when the round is over
unc0rr
parents:
1339
diff
changeset
|
615 |
{ |
1351
aa7aefec5c1b
Add partial implementation of handling disconnects while playing via network
unc0rr
parents:
1344
diff
changeset
|
616 |
netClientState = 3; |
1344
4004e597f1bf
Clients send roundfinished message to server when the round is over
unc0rr
parents:
1339
diff
changeset
|
617 |
RawSendNet(QString("ROUNDFINISHED")); |
4004e597f1bf
Clients send roundfinished message to server when the round is over
unc0rr
parents:
1339
diff
changeset
|
618 |
} |
1378 | 619 |
|
620 |
QString HWNewNet::formatChatMsg(const QString & nick, const QString & msg) |
|
621 |
{ |
|
622 |
if(msg.left(4) == "/me ") |
|
623 |
return QString("* %1 %2").arg(nick).arg(msg.mid(4)); |
|
624 |
else |
|
625 |
return QString("%1: %2").arg(nick).arg(msg); |
|
626 |
} |
|
1391 | 627 |
|
628 |
void HWNewNet::kickPlayer(const QString & nick) |
|
629 |
{ |
|
630 |
RawSendNet(QString("KICK%1%2").arg(delimeter).arg(nick)); |
|
631 |
} |
|
1410
eece43296890
Send appropriate messages to server on control menu actions
unc0rr
parents:
1405
diff
changeset
|
632 |
|
eece43296890
Send appropriate messages to server on control menu actions
unc0rr
parents:
1405
diff
changeset
|
633 |
void HWNewNet::startGame() |
eece43296890
Send appropriate messages to server on control menu actions
unc0rr
parents:
1405
diff
changeset
|
634 |
{ |
eece43296890
Send appropriate messages to server on control menu actions
unc0rr
parents:
1405
diff
changeset
|
635 |
RawSendNet(QString("START_GAME")); |
eece43296890
Send appropriate messages to server on control menu actions
unc0rr
parents:
1405
diff
changeset
|
636 |
} |
eece43296890
Send appropriate messages to server on control menu actions
unc0rr
parents:
1405
diff
changeset
|
637 |
|
eece43296890
Send appropriate messages to server on control menu actions
unc0rr
parents:
1405
diff
changeset
|
638 |
void HWNewNet::toggleRestrictJoins() |
eece43296890
Send appropriate messages to server on control menu actions
unc0rr
parents:
1405
diff
changeset
|
639 |
{ |
eece43296890
Send appropriate messages to server on control menu actions
unc0rr
parents:
1405
diff
changeset
|
640 |
RawSendNet(QString("TOGGLE_RESTRICT_JOINS")); |
eece43296890
Send appropriate messages to server on control menu actions
unc0rr
parents:
1405
diff
changeset
|
641 |
} |
eece43296890
Send appropriate messages to server on control menu actions
unc0rr
parents:
1405
diff
changeset
|
642 |
|
eece43296890
Send appropriate messages to server on control menu actions
unc0rr
parents:
1405
diff
changeset
|
643 |
void HWNewNet::toggleRestrictTeamAdds() |
eece43296890
Send appropriate messages to server on control menu actions
unc0rr
parents:
1405
diff
changeset
|
644 |
{ |
eece43296890
Send appropriate messages to server on control menu actions
unc0rr
parents:
1405
diff
changeset
|
645 |
RawSendNet(QString("TOGGLE_RESTRICT_TEAMS")); |
eece43296890
Send appropriate messages to server on control menu actions
unc0rr
parents:
1405
diff
changeset
|
646 |
} |