32 HWNewNet::HWNewNet(GameUIConfig * config, GameCFGWidget* pGameCFGWidget, TeamSelWidget* pTeamSelWidget) : |
32 HWNewNet::HWNewNet(GameUIConfig * config, GameCFGWidget* pGameCFGWidget, TeamSelWidget* pTeamSelWidget) : |
33 config(config), |
33 config(config), |
34 m_pGameCFGWidget(pGameCFGWidget), |
34 m_pGameCFGWidget(pGameCFGWidget), |
35 m_pTeamSelWidget(pTeamSelWidget), |
35 m_pTeamSelWidget(pTeamSelWidget), |
36 isChief(false), |
36 isChief(false), |
37 m_game_connected(false) |
37 m_game_connected(false), |
|
38 loginStep(0), |
|
39 netClientState(0) |
38 { |
40 { |
39 connect(&NetSocket, SIGNAL(readyRead()), this, SLOT(ClientRead())); |
41 connect(&NetSocket, SIGNAL(readyRead()), this, SLOT(ClientRead())); |
40 connect(&NetSocket, SIGNAL(connected()), this, SLOT(OnConnect())); |
42 connect(&NetSocket, SIGNAL(connected()), this, SLOT(OnConnect())); |
41 connect(&NetSocket, SIGNAL(disconnected()), this, SLOT(OnDisconnect())); |
43 connect(&NetSocket, SIGNAL(disconnected()), this, SLOT(OnDisconnect())); |
42 connect(&NetSocket, SIGNAL(error(QAbstractSocket::SocketError)), this, |
44 connect(&NetSocket, SIGNAL(error(QAbstractSocket::SocketError)), this, |
55 NetSocket.disconnectFromHost(); |
57 NetSocket.disconnectFromHost(); |
56 } |
58 } |
57 |
59 |
58 void HWNewNet::CreateRoom(const QString & room) |
60 void HWNewNet::CreateRoom(const QString & room) |
59 { |
61 { |
|
62 if(netClientState != 2) |
|
63 { |
|
64 qDebug("Illegal try to create room!"); |
|
65 return; |
|
66 } |
|
67 |
60 RawSendNet(QString("CREATE%1%2").arg(delimeter).arg(room)); |
68 RawSendNet(QString("CREATE%1%2").arg(delimeter).arg(room)); |
|
69 isChief = true; |
61 } |
70 } |
62 |
71 |
63 void HWNewNet::JoinRoom(const QString & room) |
72 void HWNewNet::JoinRoom(const QString & room) |
64 { |
73 { |
|
74 if(netClientState != 2) |
|
75 { |
|
76 qDebug("Illegal try to join room!"); |
|
77 return; |
|
78 } |
|
79 |
|
80 loginStep++; |
|
81 |
65 RawSendNet(QString("JOIN%1%2").arg(delimeter).arg(room)); |
82 RawSendNet(QString("JOIN%1%2").arg(delimeter).arg(room)); |
|
83 m_pGameCFGWidget->setEnabled(false); |
|
84 m_pTeamSelWidget->setNonInteractive(); |
|
85 isChief = false; |
66 } |
86 } |
67 |
87 |
68 void HWNewNet::AddTeam(const HWTeam & team) |
88 void HWNewNet::AddTeam(const HWTeam & team) |
69 { |
89 { |
70 QString cmd = QString("ADDTEAM") + delimeter + |
90 QString cmd = QString("ADDTEAM") + delimeter + |
129 |
149 |
130 void HWNewNet::OnConnect() |
150 void HWNewNet::OnConnect() |
131 { |
151 { |
132 RawSendNet(QString("NICK%1%2").arg(delimeter).arg(mynick)); |
152 RawSendNet(QString("NICK%1%2").arg(delimeter).arg(mynick)); |
133 RawSendNet(QString("PROTO%1%2").arg(delimeter).arg(*cProtoVer)); |
153 RawSendNet(QString("PROTO%1%2").arg(delimeter).arg(*cProtoVer)); |
134 RawSendNet(QString("CREATE%1%2").arg(delimeter).arg("myroom")); |
|
135 RawSendNet(QString("JOIN%1%2").arg(delimeter).arg("myroom")); |
|
136 } |
154 } |
137 |
155 |
138 void HWNewNet::OnDisconnect() |
156 void HWNewNet::OnDisconnect() |
139 { |
157 { |
140 //emit ChangeInTeams(QStringList()); |
158 //emit ChangeInTeams(QStringList()); |
170 qWarning("Net client: Bad message"); |
188 qWarning("Net client: Bad message"); |
171 return; |
189 return; |
172 } |
190 } |
173 |
191 |
174 if ((lst[0] == "NICK") || (lst[0] == "PROTO")) |
192 if ((lst[0] == "NICK") || (lst[0] == "PROTO")) |
|
193 { |
|
194 loginStep++; |
|
195 if (loginStep == 2) |
|
196 { |
|
197 netClientState = 2; |
|
198 RawSendNet(QString("LIST")); |
|
199 } |
175 return ; |
200 return ; |
|
201 } |
176 |
202 |
177 if (lst[0] == "ERROR") { |
203 if (lst[0] == "ERROR") { |
178 if (lst.size() == 2) |
204 if (lst.size() == 2) |
179 QMessageBox::information(0, 0, "Error: " + lst[1]); |
205 QMessageBox::information(0, 0, "Error: " + lst[1]); |
180 else |
206 else |
189 QMessageBox::information(0, 0, "Unknown warning"); |
215 QMessageBox::information(0, 0, "Unknown warning"); |
190 return; |
216 return; |
191 } |
217 } |
192 |
218 |
193 if (lst[0] == "CONNECTED") { |
219 if (lst[0] == "CONNECTED") { |
194 m_game_connected=true; |
220 netClientState = 1; |
|
221 m_game_connected = true; |
195 emit Connected(); |
222 emit Connected(); |
|
223 return; |
|
224 } |
|
225 |
|
226 if (lst[0] == "ROOMS") { |
|
227 QStringList tmp = lst; |
|
228 tmp.removeFirst(); |
|
229 emit roomsList(tmp); |
196 return; |
230 return; |
197 } |
231 } |
198 |
232 |
199 if (lst[0] == "CHAT_STRING") { |
233 if (lst[0] == "CHAT_STRING") { |
200 if(lst.size() < 3) |
234 if(lst.size() < 3) |
227 return; |
261 return; |
228 } |
262 } |
229 m_pTeamSelWidget->removeNetTeam(HWTeam(lst[1], lst[2].toUInt())); |
263 m_pTeamSelWidget->removeNetTeam(HWTeam(lst[1], lst[2].toUInt())); |
230 return; |
264 return; |
231 } |
265 } |
232 |
|
233 /* if(lst[0] == "SLAVE") { // клиент знает CREATE он делал или JOIN |
|
234 m_pGameCFGWidget->setEnabled(false); |
|
235 m_pTeamSelWidget->setNonInteractive(); |
|
236 return; |
|
237 }*/ |
|
238 |
266 |
239 if(lst[0]=="JOINED") { |
267 if(lst[0]=="JOINED") { |
240 if(lst.size() < 2) |
268 if(lst.size() < 2) |
241 { |
269 { |
242 qWarning("Net: Bad JOINED message"); |
270 qWarning("Net: Bad JOINED message"); |
243 return; |
271 return; |
244 } |
272 } |
245 |
273 |
246 for(int i = 1; i < lst.size(); ++i) |
274 for(int i = 1; i < lst.size(); ++i) |
247 { |
275 { |
248 if (lst[i] == mynick) emit EnteredGame(); |
276 if (lst[i] == mynick) |
|
277 { |
|
278 netClientState = 3; |
|
279 emit EnteredGame(); |
|
280 ConfigAsked(); |
|
281 } |
249 emit nickAdded(lst[i]); |
282 emit nickAdded(lst[i]); |
250 } |
283 } |
251 return; |
284 return; |
252 } |
285 } |
253 |
286 |