QTfrontend/netserver.h
author displacer
Wed, 10 Jan 2007 23:24:55 +0000
changeset 315 73003488240b
child 317 e95340dbfc1d
permissions -rw-r--r--
client/server net pre-alpha
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 Igor Ulyanov <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
#ifndef _NETSERVER_INCLUDED
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    20
#define _NETSERVER_INCLUDED
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    21
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    22
#include <QObject>
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    23
#include <QList>
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    24
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    25
#include "team.h"
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    26
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    27
class HWNetServer;
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    28
class QTcpSocket;
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    29
class QTcpServer;
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    30
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    31
class HWConnectedClient : public QObject
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    32
{
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    33
  Q_OBJECT
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    34
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    35
 public:
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    36
  HWConnectedClient(HWNetServer* hwserver, QTcpSocket* client);
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    37
  ~HWConnectedClient();
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    38
  QString getClientNick() const;
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    39
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    40
  class NoTeamNameException{};
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    41
  QString getTeamName() const;
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    42
  void teamChangedNotify();
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    43
  bool isReady() const;
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    44
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    45
  QString getHedgehogsDescription() const;
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    46
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    47
 private:
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    48
  bool readyToStart;
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    49
  class ShouldDisconnectException {};
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    50
  
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    51
  QString client_nick;
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    52
  void ParseLine(const QByteArray & line);
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    53
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    54
  HWNetServer* m_hwserver;
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    55
  QTcpSocket* m_client;
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    56
  HWTeam* pclent_team;
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    57
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    58
  void RawSendNet(const QString & buf);
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    59
  void RawSendNet(const QByteArray & buf);
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    60
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    61
  //QByteArray readbuffer;
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    62
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    63
 signals:
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    64
  void HWClientDisconnected(HWConnectedClient* client);
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    65
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    66
 private slots:
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    67
  void ClientRead();
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    68
  void ClientDisconnect();
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
class HWNetServer : public QObject
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    72
{
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    73
  Q_OBJECT
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    74
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    75
 public:
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    76
  void StartServer();
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    77
  void StopServer();
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    78
  bool haveNick(const QString& nick) const;
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    79
  QString getRunningHostName() const;
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    80
  quint16 getRunningPort() const;
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    81
  QStringList getTeams() const;
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    82
  void teamChanged();
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    83
  bool shouldStart(HWConnectedClient* client);
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    84
  QString prepareConfig(QStringList lst);
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    85
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    86
 private:
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    87
  static const quint16 ds_port;
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    88
  QTcpServer* IPCServer;
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    89
  QList<HWConnectedClient*> connclients;
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    90
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    91
 private slots:
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    92
  void NewConnection();
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    93
  void ClientDisconnect(HWConnectedClient* client);
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    94
};
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    95
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    96
#endif // _NETSERVER_INCLUDED