QTfrontend/netconnectedclient.h
author unc0rr
Sat, 26 Apr 2008 18:21:03 +0000
changeset 877 ebb801acd8b9
parent 420 6cdfc07dceed
child 1066 1f1b3686a2b0
permissions -rw-r--r--
Try new approach for netserver
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
420
6cdfc07dceed netserver and netonnectedclient splited to different files
displacer
parents:
diff changeset
     1
/*
6cdfc07dceed netserver and netonnectedclient splited to different files
displacer
parents:
diff changeset
     2
 * Hedgewars, a worms-like game
6cdfc07dceed netserver and netonnectedclient splited to different files
displacer
parents:
diff changeset
     3
 * Copyright (c) 2006 Igor Ulyanov <iulyanov@gmail.com>
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
#ifndef _HET_CONNECTEDCLIENT_INCLUDED
6cdfc07dceed netserver and netonnectedclient splited to different files
displacer
parents:
diff changeset
    20
#define _HET_CONNECTEDCLIENT_INCLUDED
6cdfc07dceed netserver and netonnectedclient splited to different files
displacer
parents:
diff changeset
    21
6cdfc07dceed netserver and netonnectedclient splited to different files
displacer
parents:
diff changeset
    22
#include <QObject>
6cdfc07dceed netserver and netonnectedclient splited to different files
displacer
parents:
diff changeset
    23
#include <QList>
6cdfc07dceed netserver and netonnectedclient splited to different files
displacer
parents:
diff changeset
    24
#include <QMap>
6cdfc07dceed netserver and netonnectedclient splited to different files
displacer
parents:
diff changeset
    25
6cdfc07dceed netserver and netonnectedclient splited to different files
displacer
parents:
diff changeset
    26
class HWNetServer;
6cdfc07dceed netserver and netonnectedclient splited to different files
displacer
parents:
diff changeset
    27
class QTcpSocket;
6cdfc07dceed netserver and netonnectedclient splited to different files
displacer
parents:
diff changeset
    28
class QTcpServer;
6cdfc07dceed netserver and netonnectedclient splited to different files
displacer
parents:
diff changeset
    29
6cdfc07dceed netserver and netonnectedclient splited to different files
displacer
parents:
diff changeset
    30
class HWConnectedClient : public QObject
6cdfc07dceed netserver and netonnectedclient splited to different files
displacer
parents:
diff changeset
    31
{
6cdfc07dceed netserver and netonnectedclient splited to different files
displacer
parents:
diff changeset
    32
  Q_OBJECT
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
 friend class HWNetServer;
6cdfc07dceed netserver and netonnectedclient splited to different files
displacer
parents:
diff changeset
    35
6cdfc07dceed netserver and netonnectedclient splited to different files
displacer
parents:
diff changeset
    36
 private:
6cdfc07dceed netserver and netonnectedclient splited to different files
displacer
parents:
diff changeset
    37
  HWConnectedClient(HWNetServer* hwserver, QTcpSocket* client);
6cdfc07dceed netserver and netonnectedclient splited to different files
displacer
parents:
diff changeset
    38
  ~HWConnectedClient();
6cdfc07dceed netserver and netonnectedclient splited to different files
displacer
parents:
diff changeset
    39
  QString getClientNick() const;
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
  QList<QStringList> getTeamNames() const;
6cdfc07dceed netserver and netonnectedclient splited to different files
displacer
parents:
diff changeset
    42
  class NoTeamNameException{};
6cdfc07dceed netserver and netonnectedclient splited to different files
displacer
parents:
diff changeset
    43
  bool isReady() const;
6cdfc07dceed netserver and netonnectedclient splited to different files
displacer
parents:
diff changeset
    44
6cdfc07dceed netserver and netonnectedclient splited to different files
displacer
parents:
diff changeset
    45
  QString getHedgehogsDescription() const;
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
  bool readyToStart;
6cdfc07dceed netserver and netonnectedclient splited to different files
displacer
parents:
diff changeset
    48
  QList<QStringList> m_teamsCfg; // TeamName - hhs
6cdfc07dceed netserver and netonnectedclient splited to different files
displacer
parents:
diff changeset
    49
  class ShouldDisconnectException {};
6cdfc07dceed netserver and netonnectedclient splited to different files
displacer
parents:
diff changeset
    50
6cdfc07dceed netserver and netonnectedclient splited to different files
displacer
parents:
diff changeset
    51
  QString client_nick;
6cdfc07dceed netserver and netonnectedclient splited to different files
displacer
parents:
diff changeset
    52
  void ParseLine(const QByteArray & line);
6cdfc07dceed netserver and netonnectedclient splited to different files
displacer
parents:
diff changeset
    53
  unsigned int removeTeam(const QString& tname); // returns netID
6cdfc07dceed netserver and netonnectedclient splited to different files
displacer
parents:
diff changeset
    54
6cdfc07dceed netserver and netonnectedclient splited to different files
displacer
parents:
diff changeset
    55
  HWNetServer* m_hwserver;
6cdfc07dceed netserver and netonnectedclient splited to different files
displacer
parents:
diff changeset
    56
  QTcpSocket* m_client;
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 RawSendNet(const QString & buf);
6cdfc07dceed netserver and netonnectedclient splited to different files
displacer
parents:
diff changeset
    59
  void RawSendNet(const QByteArray & buf);
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
  //QByteArray readbuffer;
6cdfc07dceed netserver and netonnectedclient splited to different files
displacer
parents:
diff changeset
    62
6cdfc07dceed netserver and netonnectedclient splited to different files
displacer
parents:
diff changeset
    63
 signals:
6cdfc07dceed netserver and netonnectedclient splited to different files
displacer
parents:
diff changeset
    64
  void HWClientDisconnected(HWConnectedClient* client);
6cdfc07dceed netserver and netonnectedclient splited to different files
displacer
parents:
diff changeset
    65
6cdfc07dceed netserver and netonnectedclient splited to different files
displacer
parents:
diff changeset
    66
 private slots:
6cdfc07dceed netserver and netonnectedclient splited to different files
displacer
parents:
diff changeset
    67
  void ClientRead();
6cdfc07dceed netserver and netonnectedclient splited to different files
displacer
parents:
diff changeset
    68
  void ClientDisconnect();
6cdfc07dceed netserver and netonnectedclient splited to different files
displacer
parents:
diff changeset
    69
};
6cdfc07dceed netserver and netonnectedclient splited to different files
displacer
parents:
diff changeset
    70
6cdfc07dceed netserver and netonnectedclient splited to different files
displacer
parents:
diff changeset
    71
#endif // _HET_CONNECTEDCLIENT_INCLUDED