QTfrontend/netserver.cpp
author unc0rr
Sun, 14 Jan 2007 13:10:29 +0000
changeset 326 c6718bfdd642
parent 319 7f3bd9e31f18
child 332 10080f681118
permissions -rw-r--r--
Small fixes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
315
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
     1
/*
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
     2
 * Hedgewars, a worms-like game
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
     3
 * Copyright (c) 2006 Ulyanov Igor <iulyanov@gmail.com>
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
     4
 *
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
     6
 * it under the terms of the GNU General Public License as published by
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
     7
 * the Free Software Foundation; version 2 of the License
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
     8
 *
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    12
 * GNU General Public License for more details.
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    13
 *
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    14
 * You should have received a copy of the GNU General Public License
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    15
 * along with this program; if not, write to the Free Software
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    16
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    17
 */
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    18
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    19
#include "netserver.h"
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    20
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    21
#include <QTcpServer>
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    22
#include <QTcpSocket>
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    23
#include <QMessageBox>
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    24
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    25
#include <algorithm>
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    26
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    27
#include <QDebug>
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    28
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    29
const quint16 HWNetServer::ds_port=46631;
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    30
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    31
extern char delimeter;
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    32
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    33
void HWNetServer::StartServer()
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    34
{
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    35
  IPCServer = new QTcpServer(this);
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    36
  if (!IPCServer->listen(QHostAddress::LocalHost, ds_port)) {
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    37
    QMessageBox::critical(0, tr("Error"),
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    38
			  tr("Unable to start the server: %1.")
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    39
			  .arg(IPCServer->errorString()));
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    40
  }
326
c6718bfdd642 Small fixes
unc0rr
parents: 319
diff changeset
    41
315
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    42
  connect(IPCServer, SIGNAL(newConnection()), this, SLOT(NewConnection()));
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    43
}
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    44
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    45
void HWNetServer::StopServer()
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    46
{
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    47
  IPCServer->close();
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    48
}
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    49
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    50
void HWNetServer::NewConnection()
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    51
{
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    52
  QTcpSocket* client = IPCServer->nextPendingConnection();
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    53
  if(!client) return;
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    54
  connclients.push_back(new HWConnectedClient(this, client));
326
c6718bfdd642 Small fixes
unc0rr
parents: 319
diff changeset
    55
  connect(connclients.back(), SIGNAL(HWClientDisconnected(HWConnectedClient*)),
315
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    56
	  this, SLOT(ClientDisconnect(HWConnectedClient*)));
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    57
}
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    58
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    59
void HWNetServer::ClientDisconnect(HWConnectedClient* client)
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    60
{
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    61
  QList<HWConnectedClient*>::iterator it=std::find(connclients.begin(), connclients.end(), client);
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    62
  connclients.erase(it);
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    63
  teamChanged();
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    64
}
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    65
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    66
QString HWNetServer::getRunningHostName() const
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    67
{
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    68
  return IPCServer->serverAddress().toString();
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    69
}
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    70
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    71
quint16 HWNetServer::getRunningPort() const
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    72
{
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    73
  return ds_port;
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    74
}
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    75
326
c6718bfdd642 Small fixes
unc0rr
parents: 319
diff changeset
    76
bool HWNetServer::isChiefClient(HWConnectedClient* cl) const
317
e95340dbfc1d start all clients
displacer
parents: 315
diff changeset
    77
{
e95340dbfc1d start all clients
displacer
parents: 315
diff changeset
    78
  for(QList<HWConnectedClient*>::const_iterator it=connclients.begin(); it!=connclients.end(); ++it) {
e95340dbfc1d start all clients
displacer
parents: 315
diff changeset
    79
    if((*it)->getClientNick()!="" && *it==cl)  return true;
e95340dbfc1d start all clients
displacer
parents: 315
diff changeset
    80
  }
e95340dbfc1d start all clients
displacer
parents: 315
diff changeset
    81
  return false;
e95340dbfc1d start all clients
displacer
parents: 315
diff changeset
    82
}
e95340dbfc1d start all clients
displacer
parents: 315
diff changeset
    83
315
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    84
bool HWNetServer::haveNick(const QString& nick) const
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    85
{
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    86
  for(QList<HWConnectedClient*>::const_iterator it=connclients.begin(); it!=connclients.end(); ++it) {
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    87
    if((*it)->getClientNick()==nick) {
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    88
      return true;
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    89
    }
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    90
  }
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    91
  return false;
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    92
}
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    93
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    94
QStringList HWNetServer::getTeams() const
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    95
{
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    96
  QStringList lst;
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    97
  for(QList<HWConnectedClient*>::const_iterator it=connclients.begin(); it!=connclients.end(); ++it) {
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    98
    try {
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    99
      lst.push_back((*it)->getTeamName());
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   100
    } catch(HWConnectedClient::NoTeamNameException& e) {
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   101
    }
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   102
  }
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   103
  return lst;
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   104
}
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   105
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   106
void HWNetServer::teamChanged()
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   107
{
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   108
  for(QList<HWConnectedClient*>::const_iterator it=connclients.begin(); it!=connclients.end(); ++it) {
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   109
    (*it)->teamChangedNotify();
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   110
  }
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   111
}
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   112
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   113
bool HWNetServer::shouldStart(HWConnectedClient* client)
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   114
{
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   115
  QList<HWConnectedClient*>::iterator it=std::find(connclients.begin(), connclients.end(), client);
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   116
  if(it==connclients.end() || *it!=client) return false;
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   117
  for(it=connclients.begin(); it!=connclients.end(); ++it) {
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   118
    if(!(*it)->isReady()) return false;
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   119
  }
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   120
  return true;
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   121
}
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   122
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   123
QString HWNetServer::prepareConfig(QStringList lst)
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   124
{
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   125
  QString msg=lst.join((QString)delimeter)+delimeter;
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   126
  for(QList<HWConnectedClient*>::iterator it=connclients.begin(); it!=connclients.end(); ++it) {
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   127
    if(!(*it)->isReady()) continue;
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   128
    msg+=(*it)->getHedgehogsDescription()+delimeter;
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   129
  }
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   130
  qDebug() << msg;
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   131
  return msg;
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   132
}
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   133
319
7f3bd9e31f18 some changes
displacer
parents: 317
diff changeset
   134
void HWNetServer::sendAll(QString gameCfg)
317
e95340dbfc1d start all clients
displacer
parents: 315
diff changeset
   135
{
e95340dbfc1d start all clients
displacer
parents: 315
diff changeset
   136
  for(QList<HWConnectedClient*>::iterator it=connclients.begin(); it!=connclients.end(); ++it) {
e95340dbfc1d start all clients
displacer
parents: 315
diff changeset
   137
    (*it)->RawSendNet(gameCfg);
e95340dbfc1d start all clients
displacer
parents: 315
diff changeset
   138
  }
e95340dbfc1d start all clients
displacer
parents: 315
diff changeset
   139
}
e95340dbfc1d start all clients
displacer
parents: 315
diff changeset
   140
319
7f3bd9e31f18 some changes
displacer
parents: 317
diff changeset
   141
void HWNetServer::sendOthers(HWConnectedClient* this_cl, QString gameCfg)
7f3bd9e31f18 some changes
displacer
parents: 317
diff changeset
   142
{
7f3bd9e31f18 some changes
displacer
parents: 317
diff changeset
   143
  for(QList<HWConnectedClient*>::iterator it=connclients.begin(); it!=connclients.end(); ++it) {
7f3bd9e31f18 some changes
displacer
parents: 317
diff changeset
   144
    if(*it==this_cl) continue;
7f3bd9e31f18 some changes
displacer
parents: 317
diff changeset
   145
    (*it)->RawSendNet(gameCfg);
7f3bd9e31f18 some changes
displacer
parents: 317
diff changeset
   146
  }
7f3bd9e31f18 some changes
displacer
parents: 317
diff changeset
   147
}
7f3bd9e31f18 some changes
displacer
parents: 317
diff changeset
   148
315
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   149
HWConnectedClient::HWConnectedClient(HWNetServer* hwserver, QTcpSocket* client) :
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   150
  readyToStart(false),
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   151
  m_hwserver(hwserver),
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   152
  m_client(client),
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   153
  pclent_team(0)
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   154
{
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   155
  connect(client, SIGNAL(disconnected()), this, SLOT(ClientDisconnect()));
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   156
  connect(client, SIGNAL(readyRead()), this, SLOT(ClientRead()));
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   157
}
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   158
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   159
HWConnectedClient::~HWConnectedClient()
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   160
{
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   161
  if(pclent_team) delete pclent_team;
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   162
}
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   163
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   164
void HWConnectedClient::ClientDisconnect()
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   165
{
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   166
  emit(HWClientDisconnected(this));
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   167
}
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   168
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   169
void HWConnectedClient::ClientRead()
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   170
{
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   171
  try {
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   172
    while (m_client->canReadLine()) {
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   173
      ParseLine(m_client->readLine().trimmed());
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   174
    }
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   175
  } catch(ShouldDisconnectException& e) {
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   176
    m_client->close();
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   177
  }
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   178
}
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   179
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   180
void HWConnectedClient::ParseLine(const QByteArray & line)
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   181
{
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   182
  QString msg = QString::fromUtf8 (line.data(), line.size());
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   183
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   184
  qDebug() << "line " << msg << " received";
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   185
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   186
  QStringList lst = msg.split(delimeter);
319
7f3bd9e31f18 some changes
displacer
parents: 317
diff changeset
   187
  if(!lst.size()) return;
315
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   188
  if (lst[0] == "NICK") {
319
7f3bd9e31f18 some changes
displacer
parents: 317
diff changeset
   189
    if(lst.size()<2) return;
315
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   190
    if(m_hwserver->haveNick(lst[1])) {
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   191
      RawSendNet(QString("ERRONEUSNICKNAME"));
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   192
      throw ShouldDisconnectException();
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   193
    }
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   194
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   195
    client_nick=lst[1];
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   196
    qDebug() << "send connected";
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   197
    RawSendNet(QString("CONNECTED"));
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   198
    m_hwserver->teamChanged();
326
c6718bfdd642 Small fixes
unc0rr
parents: 319
diff changeset
   199
    if(m_hwserver->isChiefClient(this)) RawSendNet(QString("CONFIGASKED"));
315
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   200
    return;
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   201
  }
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   202
  if(client_nick=="") return;
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   203
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   204
  if (lst[0]=="START:") {
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   205
    readyToStart=true;
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   206
    if(m_hwserver->shouldStart(this)) {
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   207
      // start
319
7f3bd9e31f18 some changes
displacer
parents: 317
diff changeset
   208
      m_hwserver->sendAll(QString("CONFIGURED")+delimeter+m_hwserver->prepareConfig(gameCfg)+delimeter+"!"+delimeter);
315
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   209
    }
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   210
    return;
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   211
  }
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   212
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   213
  if(lst[0]=="CONFIGANSWER") {
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   214
    lst.pop_front();
317
e95340dbfc1d start all clients
displacer
parents: 315
diff changeset
   215
    gameCfg=lst;
315
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   216
    return;
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   217
  }
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   218
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   219
  if(lst[0]=="ADDTEAM:") {
319
7f3bd9e31f18 some changes
displacer
parents: 317
diff changeset
   220
    if(lst.size()<10) return;
315
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   221
    lst.pop_front();
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   222
    if(pclent_team) delete pclent_team;
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   223
    pclent_team=new HWTeam(lst);
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   224
    m_hwserver->teamChanged();
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   225
    return;
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   226
  }
326
c6718bfdd642 Small fixes
unc0rr
parents: 319
diff changeset
   227
319
7f3bd9e31f18 some changes
displacer
parents: 317
diff changeset
   228
  m_hwserver->sendOthers(this, msg);
315
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   229
}
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   230
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   231
void HWConnectedClient::teamChangedNotify()
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   232
{
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   233
  QString teams;
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   234
  QStringList lst=m_hwserver->getTeams();
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   235
  for(int i=0; i<lst.size(); i++) {
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   236
    teams+=delimeter+lst[i];
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   237
  }
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   238
  RawSendNet(QString("TEAMCHANGED")+teams);
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   239
}
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   240
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   241
void HWConnectedClient::RawSendNet(const QString & str)
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   242
{
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   243
  RawSendNet(str.toUtf8());
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   244
}
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   245
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   246
void HWConnectedClient::RawSendNet(const QByteArray & buf)
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   247
{
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   248
  m_client->write(buf);
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   249
  m_client->write("\n", 1);
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   250
}
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   251
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   252
QString HWConnectedClient::getClientNick() const
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   253
{
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   254
  return client_nick;
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   255
}
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   256
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   257
QString HWConnectedClient::getTeamName() const
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   258
{
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   259
  if(!pclent_team) throw NoTeamNameException();
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   260
  return pclent_team->TeamName;
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   261
}
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   262
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   263
bool HWConnectedClient::isReady() const
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   264
{
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   265
  return readyToStart;
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   266
}
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   267
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   268
QString HWConnectedClient::getHedgehogsDescription() const
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   269
{
319
7f3bd9e31f18 some changes
displacer
parents: 317
diff changeset
   270
  return pclent_team->TeamGameConfig(65535, 4, 100, true).join((QString)delimeter);
315
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   271
}