QTfrontend/netconnectedclient.cpp
author unc0rr
Sun, 13 Jul 2008 11:39:02 +0000
changeset 1078 8f891269392f
parent 1066 1f1b3686a2b0
child 1082 596b1dcdc1df
permissions -rw-r--r--
Add a few debug message which show the problem with total hedgehogs number counting
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
420
6cdfc07dceed netserver and netonnectedclient splited to different files
displacer
parents:
diff changeset
     1
/*
1066
1f1b3686a2b0 Update copyright headers a bit
unc0rr
parents: 888
diff changeset
     2
 * Hedgewars, a free turn based strategy game
883
07a568ba44e0 Update copyright info in source files headers
unc0rr
parents: 747
diff changeset
     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
9b2abea1071f Fix version number on about page
unc0rr
parents: 884
diff changeset
    22
#include <QDebug>
9b2abea1071f Fix version number on about page
unc0rr
parents: 884
diff changeset
    23
9b2abea1071f Fix version number on about page
unc0rr
parents: 884
diff changeset
    24
#include "netconnectedclient.h"
9b2abea1071f Fix version number on about page
unc0rr
parents: 884
diff changeset
    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 {
6cdfc07dceed netserver and netonnectedclient splited to different files
displacer
parents:
diff changeset
    50
    while (m_client->canReadLine()) {
6cdfc07dceed netserver and netonnectedclient splited to different files
displacer
parents:
diff changeset
    51
      ParseLine(m_client->readLine().trimmed());
6cdfc07dceed netserver and netonnectedclient splited to different files
displacer
parents:
diff changeset
    52
    }
6cdfc07dceed netserver and netonnectedclient splited to different files
displacer
parents:
diff changeset
    53
  } catch(ShouldDisconnectException& e) {
6cdfc07dceed netserver and netonnectedclient splited to different files
displacer
parents:
diff changeset
    54
    m_client->close();
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
6cdfc07dceed netserver and netonnectedclient splited to different files
displacer
parents:
diff changeset
    58
void HWConnectedClient::ParseLine(const QByteArray & line)
6cdfc07dceed netserver and netonnectedclient splited to different files
displacer
parents:
diff changeset
    59
{
6cdfc07dceed netserver and netonnectedclient splited to different files
displacer
parents:
diff changeset
    60
  QString msg = QString::fromUtf8 (line.data(), line.size());
6cdfc07dceed netserver and netonnectedclient splited to different files
displacer
parents:
diff changeset
    61
  QStringList lst = msg.split(delimeter);
884
99cc72c8a812 - Some debug info
unc0rr
parents: 883
diff changeset
    62
//qDebug() << "Parsing: " << lst;
569
4e41c9e9e4d1 Highlight some bad behavior of network server/clients
unc0rr
parents: 468
diff changeset
    63
  if(!lst.size())
4e41c9e9e4d1 Highlight some bad behavior of network server/clients
unc0rr
parents: 468
diff changeset
    64
  {
574
1cafd9eb1a21 - Update copyright header
unc0rr
parents: 573
diff changeset
    65
    qWarning("Net server: Bad message");
569
4e41c9e9e4d1 Highlight some bad behavior of network server/clients
unc0rr
parents: 468
diff changeset
    66
    return;
4e41c9e9e4d1 Highlight some bad behavior of network server/clients
unc0rr
parents: 468
diff changeset
    67
  }
420
6cdfc07dceed netserver and netonnectedclient splited to different files
displacer
parents:
diff changeset
    68
  if (lst[0] == "NICK") {
569
4e41c9e9e4d1 Highlight some bad behavior of network server/clients
unc0rr
parents: 468
diff changeset
    69
    if(lst.size() < 2)
4e41c9e9e4d1 Highlight some bad behavior of network server/clients
unc0rr
parents: 468
diff changeset
    70
    {
574
1cafd9eb1a21 - Update copyright header
unc0rr
parents: 573
diff changeset
    71
      qWarning("Net server: Bad 'NICK' message");
569
4e41c9e9e4d1 Highlight some bad behavior of network server/clients
unc0rr
parents: 468
diff changeset
    72
	  return;
4e41c9e9e4d1 Highlight some bad behavior of network server/clients
unc0rr
parents: 468
diff changeset
    73
    }
420
6cdfc07dceed netserver and netonnectedclient splited to different files
displacer
parents:
diff changeset
    74
    if(m_hwserver->haveNick(lst[1])) {
6cdfc07dceed netserver and netonnectedclient splited to different files
displacer
parents:
diff changeset
    75
      RawSendNet(QString("ERRONEUSNICKNAME"));
6cdfc07dceed netserver and netonnectedclient splited to different files
displacer
parents:
diff changeset
    76
      throw ShouldDisconnectException();
6cdfc07dceed netserver and netonnectedclient splited to different files
displacer
parents:
diff changeset
    77
    }
6cdfc07dceed netserver and netonnectedclient splited to different files
displacer
parents:
diff changeset
    78
6cdfc07dceed netserver and netonnectedclient splited to different files
displacer
parents:
diff changeset
    79
    client_nick=lst[1];
6cdfc07dceed netserver and netonnectedclient splited to different files
displacer
parents:
diff changeset
    80
    RawSendNet(QString("CONNECTED"));
465
07eca0a2546c chatWidget with nicks ready
displacer
parents: 461
diff changeset
    81
    if(m_hwserver->isChiefClient(this)) {
07eca0a2546c chatWidget with nicks ready
displacer
parents: 461
diff changeset
    82
      RawSendNet(QString("CONFIGASKED"));
07eca0a2546c chatWidget with nicks ready
displacer
parents: 461
diff changeset
    83
    }
420
6cdfc07dceed netserver and netonnectedclient splited to different files
displacer
parents:
diff changeset
    84
    else {
6cdfc07dceed netserver and netonnectedclient splited to different files
displacer
parents:
diff changeset
    85
      RawSendNet(QString("SLAVE"));
6cdfc07dceed netserver and netonnectedclient splited to different files
displacer
parents:
diff changeset
    86
      // send teams
6cdfc07dceed netserver and netonnectedclient splited to different files
displacer
parents:
diff changeset
    87
      QList<QStringList> team_conf=m_hwserver->getTeamsConfig();
6cdfc07dceed netserver and netonnectedclient splited to different files
displacer
parents:
diff changeset
    88
      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
    89
	    RawSendNet(QString("ADDTEAM:")+delimeter+tmit->join(QString(delimeter)));
420
6cdfc07dceed netserver and netonnectedclient splited to different files
displacer
parents:
diff changeset
    90
      }
6cdfc07dceed netserver and netonnectedclient splited to different files
displacer
parents:
diff changeset
    91
      // send config
6cdfc07dceed netserver and netonnectedclient splited to different files
displacer
parents:
diff changeset
    92
      QMap<QString, QStringList> conf=m_hwserver->getGameCfg();
6cdfc07dceed netserver and netonnectedclient splited to different files
displacer
parents:
diff changeset
    93
      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
    94
	    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
    95
      }
6cdfc07dceed netserver and netonnectedclient splited to different files
displacer
parents:
diff changeset
    96
    }
465
07eca0a2546c chatWidget with nicks ready
displacer
parents: 461
diff changeset
    97
    m_hwserver->sendNicks(this);
461
105af110b0e6 chatWidget with layout
displacer
parents: 455
diff changeset
    98
    m_hwserver->sendOthers(this, QString("JOINED")+delimeter+client_nick);
420
6cdfc07dceed netserver and netonnectedclient splited to different files
displacer
parents:
diff changeset
    99
    return;
6cdfc07dceed netserver and netonnectedclient splited to different files
displacer
parents:
diff changeset
   100
  }
569
4e41c9e9e4d1 Highlight some bad behavior of network server/clients
unc0rr
parents: 468
diff changeset
   101
573
e0cf483e68d6 - Highlight more undefined behavior of net protocol
unc0rr
parents: 571
diff changeset
   102
  if(client_nick=="")
e0cf483e68d6 - Highlight more undefined behavior of net protocol
unc0rr
parents: 571
diff changeset
   103
  {
574
1cafd9eb1a21 - Update copyright header
unc0rr
parents: 573
diff changeset
   104
  	qWarning(QString("Net server: Message from unnamed client: '%1'").arg(msg).toAscii().data());
573
e0cf483e68d6 - Highlight more undefined behavior of net protocol
unc0rr
parents: 571
diff changeset
   105
  	return;
e0cf483e68d6 - Highlight more undefined behavior of net protocol
unc0rr
parents: 571
diff changeset
   106
  }
420
6cdfc07dceed netserver and netonnectedclient splited to different files
displacer
parents:
diff changeset
   107
6cdfc07dceed netserver and netonnectedclient splited to different files
displacer
parents:
diff changeset
   108
  if (lst[0]=="START:") {
6cdfc07dceed netserver and netonnectedclient splited to different files
displacer
parents:
diff changeset
   109
    readyToStart=true;
6cdfc07dceed netserver and netonnectedclient splited to different files
displacer
parents:
diff changeset
   110
    if(m_hwserver->shouldStart(this)) {
6cdfc07dceed netserver and netonnectedclient splited to different files
displacer
parents:
diff changeset
   111
      // start
6cdfc07dceed netserver and netonnectedclient splited to different files
displacer
parents:
diff changeset
   112
      m_hwserver->sendAll("RUNGAME");
6cdfc07dceed netserver and netonnectedclient splited to different files
displacer
parents:
diff changeset
   113
      m_hwserver->resetStart();
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
    return;
6cdfc07dceed netserver and netonnectedclient splited to different files
displacer
parents:
diff changeset
   116
  }
6cdfc07dceed netserver and netonnectedclient splited to different files
displacer
parents:
diff changeset
   117
455
925891c52e40 hedgehogs num bugfix for netgame
displacer
parents: 443
diff changeset
   118
  if(lst[0]=="HHNUM") {
571
a6cea9fbbc59 hedgehogs num bug fixed
displacer
parents: 570
diff changeset
   119
    if (lst.size()<4) {
574
1cafd9eb1a21 - Update copyright header
unc0rr
parents: 573
diff changeset
   120
      qWarning((QString("Net server: Bad 'HHNUM' message: ")+msg+" size="+QString("%1").arg(lst.size())).toAscii().data());
571
a6cea9fbbc59 hedgehogs num bug fixed
displacer
parents: 570
diff changeset
   121
      return;
a6cea9fbbc59 hedgehogs num bug fixed
displacer
parents: 570
diff changeset
   122
    }
a6cea9fbbc59 hedgehogs num bug fixed
displacer
parents: 570
diff changeset
   123
    if(!m_hwserver->isChiefClient(this))
569
4e41c9e9e4d1 Highlight some bad behavior of network server/clients
unc0rr
parents: 468
diff changeset
   124
    {
571
a6cea9fbbc59 hedgehogs num bug fixed
displacer
parents: 570
diff changeset
   125
      return; // permission denied
a6cea9fbbc59 hedgehogs num bug fixed
displacer
parents: 570
diff changeset
   126
    }
455
925891c52e40 hedgehogs num bugfix for netgame
displacer
parents: 443
diff changeset
   127
    const QString confstr=lst[0]+"+"+lst[1]+"+"+lst[2];
925891c52e40 hedgehogs num bugfix for netgame
displacer
parents: 443
diff changeset
   128
    QMap<QString, QStringList>::iterator it=m_hwserver->m_gameCfg.find(confstr);
925891c52e40 hedgehogs num bugfix for netgame
displacer
parents: 443
diff changeset
   129
    int oldTeamHHNum = it==m_hwserver->m_gameCfg.end() ? 0 : it.value()[0].toUInt();
925891c52e40 hedgehogs num bugfix for netgame
displacer
parents: 443
diff changeset
   130
    int newTeamHHNum = lst[3].toUInt();
925891c52e40 hedgehogs num bugfix for netgame
displacer
parents: 443
diff changeset
   131
    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
   132
qDebug() << "HHNUM hhnum = " << m_hwserver->hhnum;
455
925891c52e40 hedgehogs num bugfix for netgame
displacer
parents: 443
diff changeset
   133
    // create CONFIG_PARAM to save HHNUM at server from lst
925891c52e40 hedgehogs num bugfix for netgame
displacer
parents: 443
diff changeset
   134
    lst=QStringList("CONFIG_PARAM") << confstr << lst[3];
571
a6cea9fbbc59 hedgehogs num bug fixed
displacer
parents: 570
diff changeset
   135
    m_hwserver->sendOthers(this, lst.join(QString(delimeter)));
747
c7f67e90c3ee delimiter changed
displacer
parents: 746
diff changeset
   136
    m_hwserver->m_gameCfg[lst[1]]=lst.mid(2);
c7f67e90c3ee delimiter changed
displacer
parents: 746
diff changeset
   137
    return;
455
925891c52e40 hedgehogs num bugfix for netgame
displacer
parents: 443
diff changeset
   138
  }
925891c52e40 hedgehogs num bugfix for netgame
displacer
parents: 443
diff changeset
   139
420
6cdfc07dceed netserver and netonnectedclient splited to different files
displacer
parents:
diff changeset
   140
  if(lst[0]=="CONFIG_PARAM") {
571
a6cea9fbbc59 hedgehogs num bug fixed
displacer
parents: 570
diff changeset
   141
    if (lst.size()<3) {
574
1cafd9eb1a21 - Update copyright header
unc0rr
parents: 573
diff changeset
   142
      qWarning((QString("Net server: Bad 'CONFIG_PARAM' message: ")+msg).toAscii().data());
571
a6cea9fbbc59 hedgehogs num bug fixed
displacer
parents: 570
diff changeset
   143
      return;
a6cea9fbbc59 hedgehogs num bug fixed
displacer
parents: 570
diff changeset
   144
    }
573
e0cf483e68d6 - Highlight more undefined behavior of net protocol
unc0rr
parents: 571
diff changeset
   145
571
a6cea9fbbc59 hedgehogs num bug fixed
displacer
parents: 570
diff changeset
   146
    if(!m_hwserver->isChiefClient(this))
a6cea9fbbc59 hedgehogs num bug fixed
displacer
parents: 570
diff changeset
   147
    {
a6cea9fbbc59 hedgehogs num bug fixed
displacer
parents: 570
diff changeset
   148
      return; // permission denied
a6cea9fbbc59 hedgehogs num bug fixed
displacer
parents: 570
diff changeset
   149
    }
420
6cdfc07dceed netserver and netonnectedclient splited to different files
displacer
parents:
diff changeset
   150
    else m_hwserver->m_gameCfg[lst[1]]=lst.mid(2);
6cdfc07dceed netserver and netonnectedclient splited to different files
displacer
parents:
diff changeset
   151
  }
6cdfc07dceed netserver and netonnectedclient splited to different files
displacer
parents:
diff changeset
   152
6cdfc07dceed netserver and netonnectedclient splited to different files
displacer
parents:
diff changeset
   153
  if(lst[0]=="ADDTEAM:") {
569
4e41c9e9e4d1 Highlight some bad behavior of network server/clients
unc0rr
parents: 468
diff changeset
   154
    if(lst.size() < 14)
4e41c9e9e4d1 Highlight some bad behavior of network server/clients
unc0rr
parents: 468
diff changeset
   155
    {
574
1cafd9eb1a21 - Update copyright header
unc0rr
parents: 573
diff changeset
   156
      qWarning("Net server: Bad 'ADDTEAM' message");
569
4e41c9e9e4d1 Highlight some bad behavior of network server/clients
unc0rr
parents: 468
diff changeset
   157
	  return;
4e41c9e9e4d1 Highlight some bad behavior of network server/clients
unc0rr
parents: 468
diff changeset
   158
    }
420
6cdfc07dceed netserver and netonnectedclient splited to different files
displacer
parents:
diff changeset
   159
    lst.pop_front();
569
4e41c9e9e4d1 Highlight some bad behavior of network server/clients
unc0rr
parents: 468
diff changeset
   160
420
6cdfc07dceed netserver and netonnectedclient splited to different files
displacer
parents:
diff changeset
   161
    // add team ID
6cdfc07dceed netserver and netonnectedclient splited to different files
displacer
parents:
diff changeset
   162
    static unsigned int netTeamID=0;
6cdfc07dceed netserver and netonnectedclient splited to different files
displacer
parents:
diff changeset
   163
    lst.insert(1, QString::number(++netTeamID));
6cdfc07dceed netserver and netonnectedclient splited to different files
displacer
parents:
diff changeset
   164
6cdfc07dceed netserver and netonnectedclient splited to different files
displacer
parents:
diff changeset
   165
    // hedgehogs num count
6cdfc07dceed netserver and netonnectedclient splited to different files
displacer
parents:
diff changeset
   166
    int maxAdd=18-m_hwserver->hhnum;
569
4e41c9e9e4d1 Highlight some bad behavior of network server/clients
unc0rr
parents: 468
diff changeset
   167
    if (maxAdd<=0)
4e41c9e9e4d1 Highlight some bad behavior of network server/clients
unc0rr
parents: 468
diff changeset
   168
    {
574
1cafd9eb1a21 - Update copyright header
unc0rr
parents: 573
diff changeset
   169
	  qWarning("Net server: 'ADDTEAM' message: rejecting");
569
4e41c9e9e4d1 Highlight some bad behavior of network server/clients
unc0rr
parents: 468
diff changeset
   170
	  return; // reject command
4e41c9e9e4d1 Highlight some bad behavior of network server/clients
unc0rr
parents: 468
diff changeset
   171
    }
420
6cdfc07dceed netserver and netonnectedclient splited to different files
displacer
parents:
diff changeset
   172
    int toAdd=maxAdd<4 ? maxAdd : 4;
6cdfc07dceed netserver and netonnectedclient splited to different files
displacer
parents:
diff changeset
   173
    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
   174
qDebug() << "to add = " << toAdd << "m_hwserver->hhnum = " << m_hwserver->hhnum;
420
6cdfc07dceed netserver and netonnectedclient splited to different files
displacer
parents:
diff changeset
   175
    // hedgehogs num config
6cdfc07dceed netserver and netonnectedclient splited to different files
displacer
parents:
diff changeset
   176
    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
   177
      .arg(netTeamID)\
6cdfc07dceed netserver and netonnectedclient splited to different files
displacer
parents:
diff changeset
   178
      .arg(toAdd);
569
4e41c9e9e4d1 Highlight some bad behavior of network server/clients
unc0rr
parents: 468
diff changeset
   179
420
6cdfc07dceed netserver and netonnectedclient splited to different files
displacer
parents:
diff changeset
   180
    // creating color config for new team
6cdfc07dceed netserver and netonnectedclient splited to different files
displacer
parents:
diff changeset
   181
    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
   182
      .arg(netTeamID)\
6cdfc07dceed netserver and netonnectedclient splited to different files
displacer
parents:
diff changeset
   183
      .arg(lst.takeAt(2));
6cdfc07dceed netserver and netonnectedclient splited to different files
displacer
parents:
diff changeset
   184
6cdfc07dceed netserver and netonnectedclient splited to different files
displacer
parents:
diff changeset
   185
    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
   186
    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
   187
    m_teamsCfg.push_back(lst);
6cdfc07dceed netserver and netonnectedclient splited to different files
displacer
parents:
diff changeset
   188
6cdfc07dceed netserver and netonnectedclient splited to different files
displacer
parents:
diff changeset
   189
    m_hwserver->sendOthers(this, QString("ADDTEAM:")+delimeter+lst.join(QString(delimeter)));
6cdfc07dceed netserver and netonnectedclient splited to different files
displacer
parents:
diff changeset
   190
    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
   191
    m_hwserver->sendAll(colorCfg);
6cdfc07dceed netserver and netonnectedclient splited to different files
displacer
parents:
diff changeset
   192
    m_hwserver->sendAll(hhnumCfg);
6cdfc07dceed netserver and netonnectedclient splited to different files
displacer
parents:
diff changeset
   193
    return;
6cdfc07dceed netserver and netonnectedclient splited to different files
displacer
parents:
diff changeset
   194
  }
6cdfc07dceed netserver and netonnectedclient splited to different files
displacer
parents:
diff changeset
   195
6cdfc07dceed netserver and netonnectedclient splited to different files
displacer
parents:
diff changeset
   196
  if(lst[0]=="REMOVETEAM:") {
569
4e41c9e9e4d1 Highlight some bad behavior of network server/clients
unc0rr
parents: 468
diff changeset
   197
    if(lst.size() < 2)
4e41c9e9e4d1 Highlight some bad behavior of network server/clients
unc0rr
parents: 468
diff changeset
   198
    {
574
1cafd9eb1a21 - Update copyright header
unc0rr
parents: 573
diff changeset
   199
      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
   200
      return;
569
4e41c9e9e4d1 Highlight some bad behavior of network server/clients
unc0rr
parents: 468
diff changeset
   201
    }
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
    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
   204
    {
420
6cdfc07dceed netserver and netonnectedclient splited to different files
displacer
parents:
diff changeset
   205
      QStringList hhTmpList=it.key().split('+');
569
4e41c9e9e4d1 Highlight some bad behavior of network server/clients
unc0rr
parents: 468
diff changeset
   206
      if(hhTmpList[0] == "HHNUM")
4e41c9e9e4d1 Highlight some bad behavior of network server/clients
unc0rr
parents: 468
diff changeset
   207
      {
4e41c9e9e4d1 Highlight some bad behavior of network server/clients
unc0rr
parents: 468
diff changeset
   208
        if(hhTmpList[1]==lst[1])
4e41c9e9e4d1 Highlight some bad behavior of network server/clients
unc0rr
parents: 468
diff changeset
   209
        {
4e41c9e9e4d1 Highlight some bad behavior of network server/clients
unc0rr
parents: 468
diff changeset
   210
		  m_hwserver->hhnum-=it.value()[0].toUInt();
1078
8f891269392f Add a few debug message which show the problem with total hedgehogs number counting
unc0rr
parents: 1066
diff changeset
   211
qDebug() << "REMOVETEAM hhnum = " << m_hwserver->hhnum;
569
4e41c9e9e4d1 Highlight some bad behavior of network server/clients
unc0rr
parents: 468
diff changeset
   212
		  break;
4e41c9e9e4d1 Highlight some bad behavior of network server/clients
unc0rr
parents: 468
diff changeset
   213
        }
420
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
6cdfc07dceed netserver and netonnectedclient splited to different files
displacer
parents:
diff changeset
   217
    unsigned int netID=removeTeam(lst[1]);
6cdfc07dceed netserver and netonnectedclient splited to different files
displacer
parents:
diff changeset
   218
    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
   219
    return;
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
6cdfc07dceed netserver and netonnectedclient splited to different files
displacer
parents:
diff changeset
   222
  m_hwserver->sendOthers(this, msg);
6cdfc07dceed netserver and netonnectedclient splited to different files
displacer
parents:
diff changeset
   223
}
6cdfc07dceed netserver and netonnectedclient splited to different files
displacer
parents:
diff changeset
   224
6cdfc07dceed netserver and netonnectedclient splited to different files
displacer
parents:
diff changeset
   225
unsigned int HWConnectedClient::removeTeam(const QString& tname)
6cdfc07dceed netserver and netonnectedclient splited to different files
displacer
parents:
diff changeset
   226
{
884
99cc72c8a812 - Some debug info
unc0rr
parents: 883
diff changeset
   227
	unsigned int netID=0;
99cc72c8a812 - Some debug info
unc0rr
parents: 883
diff changeset
   228
	for(QList<QStringList>::iterator it=m_teamsCfg.begin(); it!=m_teamsCfg.end(); ++it) {
99cc72c8a812 - Some debug info
unc0rr
parents: 883
diff changeset
   229
		if((*it)[0]==tname) {
99cc72c8a812 - Some debug info
unc0rr
parents: 883
diff changeset
   230
			netID=(*it)[1].toUInt();
99cc72c8a812 - Some debug info
unc0rr
parents: 883
diff changeset
   231
			m_teamsCfg.erase(it);
99cc72c8a812 - Some debug info
unc0rr
parents: 883
diff changeset
   232
			break;
99cc72c8a812 - Some debug info
unc0rr
parents: 883
diff changeset
   233
		}
99cc72c8a812 - Some debug info
unc0rr
parents: 883
diff changeset
   234
	}
99cc72c8a812 - Some debug info
unc0rr
parents: 883
diff changeset
   235
	if (netID == 0)
99cc72c8a812 - Some debug info
unc0rr
parents: 883
diff changeset
   236
		qDebug() << QString("removeTeam: team '%1' not found").arg(tname);
99cc72c8a812 - Some debug info
unc0rr
parents: 883
diff changeset
   237
99cc72c8a812 - Some debug info
unc0rr
parents: 883
diff changeset
   238
	return netID;
420
6cdfc07dceed netserver and netonnectedclient splited to different files
displacer
parents:
diff changeset
   239
}
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
QList<QStringList> HWConnectedClient::getTeamNames() const
6cdfc07dceed netserver and netonnectedclient splited to different files
displacer
parents:
diff changeset
   242
{
6cdfc07dceed netserver and netonnectedclient splited to different files
displacer
parents:
diff changeset
   243
  return m_teamsCfg;
6cdfc07dceed netserver and netonnectedclient splited to different files
displacer
parents:
diff changeset
   244
}
6cdfc07dceed netserver and netonnectedclient splited to different files
displacer
parents:
diff changeset
   245
6cdfc07dceed netserver and netonnectedclient splited to different files
displacer
parents:
diff changeset
   246
void HWConnectedClient::RawSendNet(const QString & str)
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
  RawSendNet(str.toUtf8());
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
6cdfc07dceed netserver and netonnectedclient splited to different files
displacer
parents:
diff changeset
   251
void HWConnectedClient::RawSendNet(const QByteArray & buf)
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
  m_client->write(buf);
6cdfc07dceed netserver and netonnectedclient splited to different files
displacer
parents:
diff changeset
   254
  m_client->write("\n", 1);
6cdfc07dceed netserver and netonnectedclient splited to different files
displacer
parents:
diff changeset
   255
}
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
QString HWConnectedClient::getClientNick() const
6cdfc07dceed netserver and netonnectedclient splited to different files
displacer
parents:
diff changeset
   258
{
6cdfc07dceed netserver and netonnectedclient splited to different files
displacer
parents:
diff changeset
   259
  return client_nick;
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
bool HWConnectedClient::isReady() 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 readyToStart;
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
QString HWConnectedClient::getHedgehogsDescription() const
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
  return QString();//pclent_team->TeamGameConfig(65535, 4, 100, true).join((QString)delimeter);
6cdfc07dceed netserver and netonnectedclient splited to different files
displacer
parents:
diff changeset
   270
}