author | unc0rr |
Sun, 05 Oct 2008 16:38:26 +0000 | |
changeset 1303 | f90bf2276639 |
parent 1302 | 4290ba4a14ca |
permissions | -rw-r--r-- |
420
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
1 |
/* |
1066 | 2 |
* Hedgewars, a free turn based strategy game |
883 | 3 |
* Copyright (c) 2006-2008 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 <QTcpServer> |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
20 |
#include <QTcpSocket> |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
21 |
#include <QStringList> |
888 | 22 |
#include <QDebug> |
23 |
||
24 |
#include "netconnectedclient.h" |
|
25 |
#include "netserver.h" |
|
420
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
26 |
|
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
27 |
extern char delimeter; |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
28 |
|
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
29 |
HWConnectedClient::HWConnectedClient(HWNetServer* hwserver, QTcpSocket* client) : |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
30 |
readyToStart(false), |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
31 |
m_hwserver(hwserver), |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
32 |
m_client(client) |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
33 |
{ |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
34 |
connect(client, SIGNAL(disconnected()), this, SLOT(ClientDisconnect())); |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
35 |
connect(client, SIGNAL(readyRead()), this, SLOT(ClientRead())); |
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 |
|
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
38 |
HWConnectedClient::~HWConnectedClient() |
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 |
|
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
42 |
void HWConnectedClient::ClientDisconnect() |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
43 |
{ |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
44 |
emit(HWClientDisconnected(this)); |
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 |
|
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
47 |
void HWConnectedClient::ClientRead() |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
48 |
{ |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
49 |
try { |
1082 | 50 |
while (m_client->canReadLine()) { |
51 |
QString s = QString::fromUtf8(m_client->readLine().trimmed()); |
|
52 |
if (s.size() == 0) { |
|
53 |
ParseCmd(cmdbuf); |
|
54 |
cmdbuf.clear(); |
|
55 |
} else |
|
56 |
cmdbuf << s; |
|
57 |
} |
|
420
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
58 |
} catch(ShouldDisconnectException& e) { |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
59 |
m_client->close(); |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
60 |
} |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
61 |
} |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
62 |
|
1082 | 63 |
void HWConnectedClient::ParseCmd(const QStringList & lst) |
420
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
64 |
{ |
1301
c6fe8a4bfd34
Fix a bug screwing team selection up in network game
unc0rr
parents:
1082
diff
changeset
|
65 |
//qDebug() << "Server: Parsing:" << lst; |
569
4e41c9e9e4d1
Highlight some bad behavior of network server/clients
unc0rr
parents:
468
diff
changeset
|
66 |
if(!lst.size()) |
4e41c9e9e4d1
Highlight some bad behavior of network server/clients
unc0rr
parents:
468
diff
changeset
|
67 |
{ |
574 | 68 |
qWarning("Net server: Bad message"); |
569
4e41c9e9e4d1
Highlight some bad behavior of network server/clients
unc0rr
parents:
468
diff
changeset
|
69 |
return; |
4e41c9e9e4d1
Highlight some bad behavior of network server/clients
unc0rr
parents:
468
diff
changeset
|
70 |
} |
420
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
71 |
if (lst[0] == "NICK") { |
569
4e41c9e9e4d1
Highlight some bad behavior of network server/clients
unc0rr
parents:
468
diff
changeset
|
72 |
if(lst.size() < 2) |
4e41c9e9e4d1
Highlight some bad behavior of network server/clients
unc0rr
parents:
468
diff
changeset
|
73 |
{ |
574 | 74 |
qWarning("Net server: Bad 'NICK' message"); |
569
4e41c9e9e4d1
Highlight some bad behavior of network server/clients
unc0rr
parents:
468
diff
changeset
|
75 |
return; |
4e41c9e9e4d1
Highlight some bad behavior of network server/clients
unc0rr
parents:
468
diff
changeset
|
76 |
} |
420
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
77 |
if(m_hwserver->haveNick(lst[1])) { |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
78 |
RawSendNet(QString("ERRONEUSNICKNAME")); |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
79 |
throw ShouldDisconnectException(); |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
80 |
} |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
81 |
|
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
82 |
client_nick=lst[1]; |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
83 |
RawSendNet(QString("CONNECTED")); |
465 | 84 |
if(m_hwserver->isChiefClient(this)) { |
85 |
RawSendNet(QString("CONFIGASKED")); |
|
86 |
} |
|
420
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
87 |
else { |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
88 |
RawSendNet(QString("SLAVE")); |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
89 |
// send teams |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
90 |
QList<QStringList> team_conf=m_hwserver->getTeamsConfig(); |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
91 |
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
|
92 |
RawSendNet(QString("ADDTEAM:")+delimeter+tmit->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 |
// send config |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
95 |
QMap<QString, QStringList> conf=m_hwserver->getGameCfg(); |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
96 |
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
|
97 |
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
|
98 |
} |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
99 |
} |
465 | 100 |
m_hwserver->sendNicks(this); |
461 | 101 |
m_hwserver->sendOthers(this, QString("JOINED")+delimeter+client_nick); |
420
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
102 |
return; |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
103 |
} |
569
4e41c9e9e4d1
Highlight some bad behavior of network server/clients
unc0rr
parents:
468
diff
changeset
|
104 |
|
573 | 105 |
if(client_nick=="") |
106 |
{ |
|
1082 | 107 |
qWarning() << "Net server: Message from unnamed client:" << lst; |
573 | 108 |
return; |
109 |
} |
|
420
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
110 |
|
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
111 |
if (lst[0]=="START:") { |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
112 |
readyToStart=true; |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
113 |
if(m_hwserver->shouldStart(this)) { |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
114 |
// start |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
115 |
m_hwserver->sendAll("RUNGAME"); |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
116 |
m_hwserver->resetStart(); |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
117 |
} |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
118 |
return; |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
119 |
} |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
120 |
|
455 | 121 |
if(lst[0]=="HHNUM") { |
571 | 122 |
if (lst.size()<4) { |
1082 | 123 |
qWarning() << "Net server: Bad 'HHNUM' message:" << lst; |
571 | 124 |
return; |
125 |
} |
|
126 |
if(!m_hwserver->isChiefClient(this)) |
|
569
4e41c9e9e4d1
Highlight some bad behavior of network server/clients
unc0rr
parents:
468
diff
changeset
|
127 |
{ |
571 | 128 |
return; // permission denied |
129 |
} |
|
455 | 130 |
const QString confstr=lst[0]+"+"+lst[1]+"+"+lst[2]; |
131 |
QMap<QString, QStringList>::iterator it=m_hwserver->m_gameCfg.find(confstr); |
|
132 |
int oldTeamHHNum = it==m_hwserver->m_gameCfg.end() ? 0 : it.value()[0].toUInt(); |
|
133 |
int newTeamHHNum = lst[3].toUInt(); |
|
134 |
m_hwserver->hhnum+=newTeamHHNum-oldTeamHHNum; |
|
1078
8f891269392f
Add a few debug message which show the problem with total hedgehogs number counting
unc0rr
parents:
1066
diff
changeset
|
135 |
qDebug() << "HHNUM hhnum = " << m_hwserver->hhnum; |
455 | 136 |
// create CONFIG_PARAM to save HHNUM at server from lst |
1082 | 137 |
QStringList tmp = lst; |
138 |
tmp=QStringList("CONFIG_PARAM") << confstr << lst[3]; |
|
139 |
m_hwserver->sendOthers(this, tmp.join(QString(delimeter))); |
|
140 |
m_hwserver->m_gameCfg[tmp[1]]=tmp.mid(2); |
|
1301
c6fe8a4bfd34
Fix a bug screwing team selection up in network game
unc0rr
parents:
1082
diff
changeset
|
141 |
qDebug() << QString("[%1] = %2").arg(tmp[1]).arg(tmp.mid(2)[0]); |
747 | 142 |
return; |
455 | 143 |
} |
144 |
||
420
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
145 |
if(lst[0]=="CONFIG_PARAM") { |
571 | 146 |
if (lst.size()<3) { |
1082 | 147 |
qWarning() << "Net server: Bad 'CONFIG_PARAM' message:" << lst; |
571 | 148 |
return; |
149 |
} |
|
573 | 150 |
|
571 | 151 |
if(!m_hwserver->isChiefClient(this)) |
152 |
{ |
|
153 |
return; // permission denied |
|
154 |
} |
|
420
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
155 |
else m_hwserver->m_gameCfg[lst[1]]=lst.mid(2); |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
156 |
} |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
157 |
|
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
158 |
if(lst[0]=="ADDTEAM:") { |
569
4e41c9e9e4d1
Highlight some bad behavior of network server/clients
unc0rr
parents:
468
diff
changeset
|
159 |
if(lst.size() < 14) |
4e41c9e9e4d1
Highlight some bad behavior of network server/clients
unc0rr
parents:
468
diff
changeset
|
160 |
{ |
574 | 161 |
qWarning("Net server: Bad 'ADDTEAM' message"); |
569
4e41c9e9e4d1
Highlight some bad behavior of network server/clients
unc0rr
parents:
468
diff
changeset
|
162 |
return; |
4e41c9e9e4d1
Highlight some bad behavior of network server/clients
unc0rr
parents:
468
diff
changeset
|
163 |
} |
1082 | 164 |
QStringList tmp = lst; |
165 |
tmp.pop_front(); |
|
569
4e41c9e9e4d1
Highlight some bad behavior of network server/clients
unc0rr
parents:
468
diff
changeset
|
166 |
|
420
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
167 |
// add team ID |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
168 |
static unsigned int netTeamID=0; |
1082 | 169 |
tmp.insert(1, QString::number(++netTeamID)); |
420
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
170 |
|
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
171 |
// hedgehogs num count |
1301
c6fe8a4bfd34
Fix a bug screwing team selection up in network game
unc0rr
parents:
1082
diff
changeset
|
172 |
int maxAdd = 18 - m_hwserver->hhnum; |
c6fe8a4bfd34
Fix a bug screwing team selection up in network game
unc0rr
parents:
1082
diff
changeset
|
173 |
if (maxAdd <= 0) |
569
4e41c9e9e4d1
Highlight some bad behavior of network server/clients
unc0rr
parents:
468
diff
changeset
|
174 |
{ |
574 | 175 |
qWarning("Net server: 'ADDTEAM' message: rejecting"); |
569
4e41c9e9e4d1
Highlight some bad behavior of network server/clients
unc0rr
parents:
468
diff
changeset
|
176 |
return; // reject command |
4e41c9e9e4d1
Highlight some bad behavior of network server/clients
unc0rr
parents:
468
diff
changeset
|
177 |
} |
1302 | 178 |
if (netIDbyTeamName(tmp[0]) > 0) |
179 |
{ |
|
180 |
qWarning("Net server: 'ADDTEAM' message: rejecting (have team with same name)"); |
|
181 |
return; // reject command |
|
182 |
||
183 |
} |
|
1301
c6fe8a4bfd34
Fix a bug screwing team selection up in network game
unc0rr
parents:
1082
diff
changeset
|
184 |
int toAdd=maxAdd < 4 ? maxAdd : 4; |
420
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
185 |
m_hwserver->hhnum+=toAdd; |
1078
8f891269392f
Add a few debug message which show the problem with total hedgehogs number counting
unc0rr
parents:
1066
diff
changeset
|
186 |
qDebug() << "to add = " << toAdd << "m_hwserver->hhnum = " << m_hwserver->hhnum; |
420
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
187 |
// hedgehogs num config |
1082 | 188 |
QString hhnumCfg=QString("CONFIG_PARAM%1HHNUM+%2+%3%1%4").arg(delimeter).arg(tmp[0])\ |
420
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
189 |
.arg(netTeamID)\ |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
190 |
.arg(toAdd); |
569
4e41c9e9e4d1
Highlight some bad behavior of network server/clients
unc0rr
parents:
468
diff
changeset
|
191 |
|
420
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
192 |
// creating color config for new team |
1082 | 193 |
QString colorCfg=QString("CONFIG_PARAM%1TEAM_COLOR+%2+%3%1%4").arg(delimeter).arg(tmp[0])\ |
420
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
194 |
.arg(netTeamID)\ |
1082 | 195 |
.arg(tmp.takeAt(2)); |
420
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
196 |
|
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
197 |
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
|
198 |
m_hwserver->m_gameCfg[hhnumCfg.split(delimeter)[1]]=hhnumCfg.split(delimeter).mid(2); |
1082 | 199 |
m_teamsCfg.push_back(tmp); |
1301
c6fe8a4bfd34
Fix a bug screwing team selection up in network game
unc0rr
parents:
1082
diff
changeset
|
200 |
qDebug() << QString("[%1] = %2").arg(hhnumCfg.split(delimeter)[1]).arg(hhnumCfg.split(delimeter).mid(2)[0]); |
1082 | 201 |
m_hwserver->sendOthers(this, QString("ADDTEAM:")+delimeter+tmp.join(QString(delimeter))); |
202 |
RawSendNet(QString("TEAM_ACCEPTED%1%2%1%3").arg(delimeter).arg(tmp[0]).arg(tmp[1])); |
|
420
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
203 |
m_hwserver->sendAll(colorCfg); |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
204 |
m_hwserver->sendAll(hhnumCfg); |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
205 |
return; |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
206 |
} |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
207 |
|
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
208 |
if(lst[0]=="REMOVETEAM:") { |
569
4e41c9e9e4d1
Highlight some bad behavior of network server/clients
unc0rr
parents:
468
diff
changeset
|
209 |
if(lst.size() < 2) |
4e41c9e9e4d1
Highlight some bad behavior of network server/clients
unc0rr
parents:
468
diff
changeset
|
210 |
{ |
574 | 211 |
qWarning("Net server: Bad 'REMOVETEAM' message"); |
1078
8f891269392f
Add a few debug message which show the problem with total hedgehogs number counting
unc0rr
parents:
1066
diff
changeset
|
212 |
return; |
569
4e41c9e9e4d1
Highlight some bad behavior of network server/clients
unc0rr
parents:
468
diff
changeset
|
213 |
} |
4e41c9e9e4d1
Highlight some bad behavior of network server/clients
unc0rr
parents:
468
diff
changeset
|
214 |
|
1303
f90bf2276639
Don't allow team with the same name from the same client (helps with double add due to lags)
unc0rr
parents:
1302
diff
changeset
|
215 |
for(QMap<QString, QStringList>::iterator it=m_hwserver->m_gameCfg.begin(); it!=m_hwserver->m_gameCfg.end(); ++it) |
f90bf2276639
Don't allow team with the same name from the same client (helps with double add due to lags)
unc0rr
parents:
1302
diff
changeset
|
216 |
{ |
f90bf2276639
Don't allow team with the same name from the same client (helps with double add due to lags)
unc0rr
parents:
1302
diff
changeset
|
217 |
QStringList hhTmpList=it.key().split('+'); |
f90bf2276639
Don't allow team with the same name from the same client (helps with double add due to lags)
unc0rr
parents:
1302
diff
changeset
|
218 |
if(hhTmpList[0] == "HHNUM") |
f90bf2276639
Don't allow team with the same name from the same client (helps with double add due to lags)
unc0rr
parents:
1302
diff
changeset
|
219 |
{ |
f90bf2276639
Don't allow team with the same name from the same client (helps with double add due to lags)
unc0rr
parents:
1302
diff
changeset
|
220 |
if(hhTmpList[1]==lst[1]) |
f90bf2276639
Don't allow team with the same name from the same client (helps with double add due to lags)
unc0rr
parents:
1302
diff
changeset
|
221 |
{ |
f90bf2276639
Don't allow team with the same name from the same client (helps with double add due to lags)
unc0rr
parents:
1302
diff
changeset
|
222 |
m_hwserver->hhnum-=it.value()[0].toUInt(); |
f90bf2276639
Don't allow team with the same name from the same client (helps with double add due to lags)
unc0rr
parents:
1302
diff
changeset
|
223 |
m_hwserver->m_gameCfg.remove(it.key()); |
f90bf2276639
Don't allow team with the same name from the same client (helps with double add due to lags)
unc0rr
parents:
1302
diff
changeset
|
224 |
|
f90bf2276639
Don't allow team with the same name from the same client (helps with double add due to lags)
unc0rr
parents:
1302
diff
changeset
|
225 |
for(QList<QStringList>::iterator it=m_teamsCfg.begin(); it!=m_teamsCfg.end(); ++it) |
f90bf2276639
Don't allow team with the same name from the same client (helps with double add due to lags)
unc0rr
parents:
1302
diff
changeset
|
226 |
if((*it)[0] == lst[1]) |
f90bf2276639
Don't allow team with the same name from the same client (helps with double add due to lags)
unc0rr
parents:
1302
diff
changeset
|
227 |
m_teamsCfg.erase(it); |
f90bf2276639
Don't allow team with the same name from the same client (helps with double add due to lags)
unc0rr
parents:
1302
diff
changeset
|
228 |
|
f90bf2276639
Don't allow team with the same name from the same client (helps with double add due to lags)
unc0rr
parents:
1302
diff
changeset
|
229 |
qDebug() << "REMOVETEAM hhnum = " << m_hwserver->hhnum; |
f90bf2276639
Don't allow team with the same name from the same client (helps with double add due to lags)
unc0rr
parents:
1302
diff
changeset
|
230 |
break; |
f90bf2276639
Don't allow team with the same name from the same client (helps with double add due to lags)
unc0rr
parents:
1302
diff
changeset
|
231 |
} |
f90bf2276639
Don't allow team with the same name from the same client (helps with double add due to lags)
unc0rr
parents:
1302
diff
changeset
|
232 |
} |
f90bf2276639
Don't allow team with the same name from the same client (helps with double add due to lags)
unc0rr
parents:
1302
diff
changeset
|
233 |
} |
420
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
234 |
|
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
235 |
unsigned int netID=removeTeam(lst[1]); |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
236 |
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
|
237 |
return; |
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 |
|
1082 | 240 |
m_hwserver->sendOthers(this, lst.join(QString(delimeter))); |
420
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 |
|
1302 | 243 |
unsigned int HWConnectedClient::netIDbyTeamName(const QString& tname) |
244 |
{ |
|
245 |
for(QList<QStringList>::iterator it=m_teamsCfg.begin(); it!=m_teamsCfg.end(); ++it) |
|
246 |
if((*it)[0]==tname) |
|
247 |
return (*it)[1].toUInt(); |
|
248 |
||
249 |
return 0; |
|
250 |
} |
|
251 |
||
420
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
252 |
unsigned int HWConnectedClient::removeTeam(const QString& tname) |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
253 |
{ |
1302 | 254 |
unsigned int netID = netIDbyTeamName(tname); |
255 |
||
884 | 256 |
if (netID == 0) |
257 |
qDebug() << QString("removeTeam: team '%1' not found").arg(tname); |
|
258 |
||
259 |
return netID; |
|
420
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
260 |
} |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
261 |
|
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
262 |
QList<QStringList> HWConnectedClient::getTeamNames() const |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
263 |
{ |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
264 |
return m_teamsCfg; |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
265 |
} |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
266 |
|
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
267 |
void HWConnectedClient::RawSendNet(const QString & str) |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
268 |
{ |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
269 |
RawSendNet(str.toUtf8()); |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
270 |
} |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
271 |
|
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
272 |
void HWConnectedClient::RawSendNet(const QByteArray & buf) |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
273 |
{ |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
274 |
m_client->write(buf); |
1082 | 275 |
m_client->write("\n\n", 2); |
420
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
276 |
} |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
277 |
|
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
278 |
QString HWConnectedClient::getClientNick() const |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
279 |
{ |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
280 |
return client_nick; |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
281 |
} |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
282 |
|
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
283 |
bool HWConnectedClient::isReady() const |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
284 |
{ |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
285 |
return readyToStart; |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
286 |
} |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
287 |
|
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
288 |
QString HWConnectedClient::getHedgehogsDescription() const |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
289 |
{ |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
290 |
return QString();//pclent_team->TeamGameConfig(65535, 4, 100, true).join((QString)delimeter); |
6cdfc07dceed
netserver and netonnectedclient splited to different files
displacer
parents:
diff
changeset
|
291 |
} |