author | displacer |
Wed, 09 Jan 2008 21:22:22 +0000 | |
changeset 696 | d6f32ed6edc8 |
parent 574 | 1cafd9eb1a21 |
child 746 | 980240306370 |
permissions | -rw-r--r-- |
420
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
1 |
/* |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
2 |
* Hedgewars, a worms-like game |
574 | 3 |
* Copyright (c) 2006-2007 Igor Ulyanov <iulyanov@gmail.com> |
420
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
4 |
* |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
5 |
* This program is free software; you can redistribute it and/or modify |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
6 |
* it under the terms of the GNU General Public License as published by |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
7 |
* the Free Software Foundation; version 2 of the License |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
8 |
* |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
9 |
* This program is distributed in the hope that it will be useful, |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
12 |
* GNU General Public License for more details. |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
13 |
* |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
14 |
* You should have received a copy of the GNU General Public License |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
15 |
* along with this program; if not, write to the Free Software |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
16 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
17 |
*/ |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
18 |
|
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
19 |
#include "netconnectedclient.h" |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
20 |
#include "netserver.h" |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
21 |
|
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
22 |
#include <QTcpServer> |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
23 |
#include <QTcpSocket> |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
24 |
#include <QStringList> |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
25 |
|
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
26 |
extern char delimeter; |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
27 |
|
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
28 |
HWConnectedClient::HWConnectedClient(HWNetServer* hwserver, QTcpSocket* client) : |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
29 |
readyToStart(false), |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
30 |
m_hwserver(hwserver), |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
31 |
m_client(client) |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
32 |
{ |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
33 |
connect(client, SIGNAL(disconnected()), this, SLOT(ClientDisconnect())); |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
34 |
connect(client, SIGNAL(readyRead()), this, SLOT(ClientRead())); |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
35 |
} |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
36 |
|
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
37 |
HWConnectedClient::~HWConnectedClient() |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
38 |
{ |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
39 |
} |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
40 |
|
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
41 |
void HWConnectedClient::ClientDisconnect() |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
42 |
{ |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
43 |
emit(HWClientDisconnected(this)); |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
44 |
} |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
45 |
|
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
46 |
void HWConnectedClient::ClientRead() |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
47 |
{ |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
48 |
try { |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
49 |
while (m_client->canReadLine()) { |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
50 |
ParseLine(m_client->readLine().trimmed()); |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
51 |
} |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
52 |
} catch(ShouldDisconnectException& e) { |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
53 |
m_client->close(); |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
54 |
} |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
55 |
} |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
56 |
|
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
57 |
void HWConnectedClient::ParseLine(const QByteArray & line) |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
58 |
{ |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
59 |
QString msg = QString::fromUtf8 (line.data(), line.size()); |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
60 |
QStringList lst = msg.split(delimeter); |
569
4e41c9e9e4d1
Highlight some bad behavior of network server/clients
unc0rr
parents:
468
diff
changeset
|
61 |
if(!lst.size()) |
4e41c9e9e4d1
Highlight some bad behavior of network server/clients
unc0rr
parents:
468
diff
changeset
|
62 |
{ |
574 | 63 |
qWarning("Net server: Bad message"); |
569
4e41c9e9e4d1
Highlight some bad behavior of network server/clients
unc0rr
parents:
468
diff
changeset
|
64 |
return; |
4e41c9e9e4d1
Highlight some bad behavior of network server/clients
unc0rr
parents:
468
diff
changeset
|
65 |
} |
420
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
66 |
if (lst[0] == "NICK") { |
569
4e41c9e9e4d1
Highlight some bad behavior of network server/clients
unc0rr
parents:
468
diff
changeset
|
67 |
if(lst.size() < 2) |
4e41c9e9e4d1
Highlight some bad behavior of network server/clients
unc0rr
parents:
468
diff
changeset
|
68 |
{ |
574 | 69 |
qWarning("Net server: Bad 'NICK' message"); |
569
4e41c9e9e4d1
Highlight some bad behavior of network server/clients
unc0rr
parents:
468
diff
changeset
|
70 |
return; |
4e41c9e9e4d1
Highlight some bad behavior of network server/clients
unc0rr
parents:
468
diff
changeset
|
71 |
} |
420
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
72 |
if(m_hwserver->haveNick(lst[1])) { |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
73 |
RawSendNet(QString("ERRONEUSNICKNAME")); |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
74 |
throw ShouldDisconnectException(); |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
75 |
} |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
76 |
|
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
77 |
client_nick=lst[1]; |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
78 |
RawSendNet(QString("CONNECTED")); |
465 | 79 |
if(m_hwserver->isChiefClient(this)) { |
80 |
RawSendNet(QString("CONFIGASKED")); |
|
81 |
} |
|
420
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
82 |
else { |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
83 |
RawSendNet(QString("SLAVE")); |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
84 |
// send teams |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
85 |
QList<QStringList> team_conf=m_hwserver->getTeamsConfig(); |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
86 |
for(QList<QStringList>::iterator tmit=team_conf.begin(); tmit!=team_conf.end(); ++tmit) { |
569
4e41c9e9e4d1
Highlight some bad behavior of network server/clients
unc0rr
parents:
468
diff
changeset
|
87 |
RawSendNet(QString("ADDTEAM:")+delimeter+tmit->join(QString(delimeter))); |
420
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
88 |
} |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
89 |
// send config |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
90 |
QMap<QString, QStringList> conf=m_hwserver->getGameCfg(); |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
91 |
for(QMap<QString, QStringList>::iterator it=conf.begin(); it!=conf.end(); ++it) { |
569
4e41c9e9e4d1
Highlight some bad behavior of network server/clients
unc0rr
parents:
468
diff
changeset
|
92 |
RawSendNet(QString("CONFIG_PARAM")+delimeter+it.key()+delimeter+it.value().join(QString(delimeter))); |
420
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
93 |
} |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
94 |
} |
465 | 95 |
m_hwserver->sendNicks(this); |
461 | 96 |
m_hwserver->sendOthers(this, QString("JOINED")+delimeter+client_nick); |
420
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
97 |
return; |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
98 |
} |
569
4e41c9e9e4d1
Highlight some bad behavior of network server/clients
unc0rr
parents:
468
diff
changeset
|
99 |
|
573 | 100 |
if(client_nick=="") |
101 |
{ |
|
574 | 102 |
qWarning(QString("Net server: Message from unnamed client: '%1'").arg(msg).toAscii().data()); |
573 | 103 |
return; |
104 |
} |
|
420
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
105 |
|
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
106 |
if (lst[0]=="START:") { |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
107 |
readyToStart=true; |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
108 |
if(m_hwserver->shouldStart(this)) { |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
109 |
// start |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
110 |
m_hwserver->sendAll("RUNGAME"); |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
111 |
m_hwserver->resetStart(); |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
112 |
} |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
113 |
return; |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
114 |
} |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
115 |
|
455 | 116 |
if(lst[0]=="HHNUM") { |
571 | 117 |
if (lst.size()<4) { |
574 | 118 |
qWarning((QString("Net server: Bad 'HHNUM' message: ")+msg+" size="+QString("%1").arg(lst.size())).toAscii().data()); |
571 | 119 |
return; |
120 |
} |
|
121 |
if(!m_hwserver->isChiefClient(this)) |
|
569
4e41c9e9e4d1
Highlight some bad behavior of network server/clients
unc0rr
parents:
468
diff
changeset
|
122 |
{ |
571 | 123 |
return; // permission denied |
124 |
} |
|
455 | 125 |
const QString confstr=lst[0]+"+"+lst[1]+"+"+lst[2]; |
126 |
QMap<QString, QStringList>::iterator it=m_hwserver->m_gameCfg.find(confstr); |
|
127 |
int oldTeamHHNum = it==m_hwserver->m_gameCfg.end() ? 0 : it.value()[0].toUInt(); |
|
128 |
int newTeamHHNum = lst[3].toUInt(); |
|
129 |
m_hwserver->hhnum+=newTeamHHNum-oldTeamHHNum; |
|
130 |
// create CONFIG_PARAM to save HHNUM at server from lst |
|
131 |
lst=QStringList("CONFIG_PARAM") << confstr << lst[3]; |
|
571 | 132 |
m_hwserver->sendOthers(this, lst.join(QString(delimeter))); |
573 | 133 |
return; |
455 | 134 |
} |
135 |
||
420
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
136 |
if(lst[0]=="CONFIG_PARAM") { |
571 | 137 |
if (lst.size()<3) { |
574 | 138 |
qWarning((QString("Net server: Bad 'CONFIG_PARAM' message: ")+msg).toAscii().data()); |
571 | 139 |
return; |
140 |
} |
|
573 | 141 |
|
571 | 142 |
if(!m_hwserver->isChiefClient(this)) |
143 |
{ |
|
144 |
return; // permission denied |
|
145 |
} |
|
420
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
146 |
else m_hwserver->m_gameCfg[lst[1]]=lst.mid(2); |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
147 |
} |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
148 |
|
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
149 |
if(lst[0]=="ADDTEAM:") { |
569
4e41c9e9e4d1
Highlight some bad behavior of network server/clients
unc0rr
parents:
468
diff
changeset
|
150 |
if(lst.size() < 14) |
4e41c9e9e4d1
Highlight some bad behavior of network server/clients
unc0rr
parents:
468
diff
changeset
|
151 |
{ |
574 | 152 |
qWarning("Net server: Bad 'ADDTEAM' message"); |
569
4e41c9e9e4d1
Highlight some bad behavior of network server/clients
unc0rr
parents:
468
diff
changeset
|
153 |
return; |
4e41c9e9e4d1
Highlight some bad behavior of network server/clients
unc0rr
parents:
468
diff
changeset
|
154 |
} |
420
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
155 |
lst.pop_front(); |
569
4e41c9e9e4d1
Highlight some bad behavior of network server/clients
unc0rr
parents:
468
diff
changeset
|
156 |
|
420
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
157 |
// add team ID |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
158 |
static unsigned int netTeamID=0; |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
159 |
lst.insert(1, QString::number(++netTeamID)); |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
160 |
|
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
161 |
// hedgehogs num count |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
162 |
int maxAdd=18-m_hwserver->hhnum; |
569
4e41c9e9e4d1
Highlight some bad behavior of network server/clients
unc0rr
parents:
468
diff
changeset
|
163 |
if (maxAdd<=0) |
4e41c9e9e4d1
Highlight some bad behavior of network server/clients
unc0rr
parents:
468
diff
changeset
|
164 |
{ |
574 | 165 |
qWarning("Net server: 'ADDTEAM' message: rejecting"); |
569
4e41c9e9e4d1
Highlight some bad behavior of network server/clients
unc0rr
parents:
468
diff
changeset
|
166 |
return; // reject command |
4e41c9e9e4d1
Highlight some bad behavior of network server/clients
unc0rr
parents:
468
diff
changeset
|
167 |
} |
420
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
168 |
int toAdd=maxAdd<4 ? maxAdd : 4; |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
169 |
m_hwserver->hhnum+=toAdd; |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
170 |
// hedgehogs num config |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
171 |
QString hhnumCfg=QString("CONFIG_PARAM%1HHNUM+%2+%3%1%4").arg(delimeter).arg(lst[0])\ |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
172 |
.arg(netTeamID)\ |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
173 |
.arg(toAdd); |
569
4e41c9e9e4d1
Highlight some bad behavior of network server/clients
unc0rr
parents:
468
diff
changeset
|
174 |
|
420
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
175 |
// creating color config for new team |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
176 |
QString colorCfg=QString("CONFIG_PARAM%1TEAM_COLOR+%2+%3%1%4").arg(delimeter).arg(lst[0])\ |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
177 |
.arg(netTeamID)\ |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
178 |
.arg(lst.takeAt(2)); |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
179 |
|
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
180 |
m_hwserver->m_gameCfg[colorCfg.split(delimeter)[1]]=colorCfg.split(delimeter).mid(2); |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
181 |
m_hwserver->m_gameCfg[hhnumCfg.split(delimeter)[1]]=hhnumCfg.split(delimeter).mid(2); |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
182 |
m_teamsCfg.push_back(lst); |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
183 |
|
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
184 |
m_hwserver->sendOthers(this, QString("ADDTEAM:")+delimeter+lst.join(QString(delimeter))); |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
185 |
RawSendNet(QString("TEAM_ACCEPTED%1%2%1%3").arg(delimeter).arg(lst[0]).arg(lst[1])); |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
186 |
m_hwserver->sendAll(colorCfg); |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
187 |
m_hwserver->sendAll(hhnumCfg); |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
188 |
return; |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
189 |
} |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
190 |
|
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
191 |
if(lst[0]=="REMOVETEAM:") { |
569
4e41c9e9e4d1
Highlight some bad behavior of network server/clients
unc0rr
parents:
468
diff
changeset
|
192 |
if(lst.size() < 2) |
4e41c9e9e4d1
Highlight some bad behavior of network server/clients
unc0rr
parents:
468
diff
changeset
|
193 |
{ |
574 | 194 |
qWarning("Net server: Bad 'REMOVETEAM' message"); |
569
4e41c9e9e4d1
Highlight some bad behavior of network server/clients
unc0rr
parents:
468
diff
changeset
|
195 |
return; |
4e41c9e9e4d1
Highlight some bad behavior of network server/clients
unc0rr
parents:
468
diff
changeset
|
196 |
} |
4e41c9e9e4d1
Highlight some bad behavior of network server/clients
unc0rr
parents:
468
diff
changeset
|
197 |
|
4e41c9e9e4d1
Highlight some bad behavior of network server/clients
unc0rr
parents:
468
diff
changeset
|
198 |
for(QMap<QString, QStringList>::iterator it=m_hwserver->m_gameCfg.begin(); it!=m_hwserver->m_gameCfg.end(); ++it) |
4e41c9e9e4d1
Highlight some bad behavior of network server/clients
unc0rr
parents:
468
diff
changeset
|
199 |
{ |
420
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
200 |
QStringList hhTmpList=it.key().split('+'); |
569
4e41c9e9e4d1
Highlight some bad behavior of network server/clients
unc0rr
parents:
468
diff
changeset
|
201 |
if(hhTmpList[0] == "HHNUM") |
4e41c9e9e4d1
Highlight some bad behavior of network server/clients
unc0rr
parents:
468
diff
changeset
|
202 |
{ |
4e41c9e9e4d1
Highlight some bad behavior of network server/clients
unc0rr
parents:
468
diff
changeset
|
203 |
if(hhTmpList[1]==lst[1]) |
4e41c9e9e4d1
Highlight some bad behavior of network server/clients
unc0rr
parents:
468
diff
changeset
|
204 |
{ |
4e41c9e9e4d1
Highlight some bad behavior of network server/clients
unc0rr
parents:
468
diff
changeset
|
205 |
m_hwserver->hhnum-=it.value()[0].toUInt(); |
4e41c9e9e4d1
Highlight some bad behavior of network server/clients
unc0rr
parents:
468
diff
changeset
|
206 |
break; |
4e41c9e9e4d1
Highlight some bad behavior of network server/clients
unc0rr
parents:
468
diff
changeset
|
207 |
} |
420
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
208 |
} |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
209 |
} |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
210 |
|
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
211 |
unsigned int netID=removeTeam(lst[1]); |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
212 |
m_hwserver->sendOthers(this, QString("REMOVETEAM:")+delimeter+lst[1]+delimeter+QString::number(netID)); |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
213 |
return; |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
214 |
} |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
215 |
|
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
216 |
m_hwserver->sendOthers(this, msg); |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
217 |
} |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
218 |
|
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
219 |
unsigned int HWConnectedClient::removeTeam(const QString& tname) |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
220 |
{ |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
221 |
unsigned int netID=0; |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
222 |
for(QList<QStringList>::iterator it=m_teamsCfg.begin(); it!=m_teamsCfg.end(); ++it) { |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
223 |
if((*it)[0]==tname) { |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
224 |
netID=(*it)[1].toUInt(); |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
225 |
m_teamsCfg.erase(it); |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
226 |
break; |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
227 |
} |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
228 |
} |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
229 |
return netID; |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
230 |
} |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
231 |
|
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
232 |
QList<QStringList> HWConnectedClient::getTeamNames() const |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
233 |
{ |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
234 |
return m_teamsCfg; |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
235 |
} |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
236 |
|
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
237 |
void HWConnectedClient::RawSendNet(const QString & str) |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
238 |
{ |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
239 |
RawSendNet(str.toUtf8()); |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
240 |
} |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
241 |
|
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
242 |
void HWConnectedClient::RawSendNet(const QByteArray & buf) |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
243 |
{ |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
244 |
m_client->write(buf); |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
245 |
m_client->write("\n", 1); |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
246 |
} |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
247 |
|
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
248 |
QString HWConnectedClient::getClientNick() const |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
249 |
{ |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
250 |
return client_nick; |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
251 |
} |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
252 |
|
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
253 |
bool HWConnectedClient::isReady() const |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
254 |
{ |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
255 |
return readyToStart; |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
256 |
} |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
257 |
|
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
258 |
QString HWConnectedClient::getHedgehogsDescription() const |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
259 |
{ |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
260 |
return QString();//pclent_team->TeamGameConfig(65535, 4, 100, true).join((QString)delimeter); |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
261 |
} |