QTfrontend/netserver.h
author unc0rr
Sun, 14 Jan 2007 11:58:08 +0000
changeset 325 17c860483407
parent 319 7f3bd9e31f18
child 326 c6718bfdd642
permissions -rw-r--r--
New signals and slot for GameCFGWidget
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
317
e95340dbfc1d start all clients
displacer
parents: 315
diff changeset
    35
 friend class HWNetServer;
e95340dbfc1d start all clients
displacer
parents: 315
diff changeset
    36
e95340dbfc1d start all clients
displacer
parents: 315
diff changeset
    37
 private:
315
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    38
  HWConnectedClient(HWNetServer* hwserver, QTcpSocket* client);
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    39
  ~HWConnectedClient();
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    40
  QString getClientNick() const;
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    41
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    42
  class NoTeamNameException{};
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    43
  QString getTeamName() const;
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    44
  void teamChangedNotify();
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    45
  bool isReady() const;
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    46
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    47
  QString getHedgehogsDescription() const;
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    48
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    49
  bool readyToStart;
317
e95340dbfc1d start all clients
displacer
parents: 315
diff changeset
    50
  QStringList gameCfg;
315
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    51
  class ShouldDisconnectException {};
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    52
  
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    53
  QString client_nick;
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    54
  void ParseLine(const QByteArray & line);
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    55
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    56
  HWNetServer* m_hwserver;
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    57
  QTcpSocket* m_client;
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    58
  HWTeam* pclent_team;
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    59
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    60
  void RawSendNet(const QString & buf);
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    61
  void RawSendNet(const QByteArray & buf);
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    62
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    63
  //QByteArray readbuffer;
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    64
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    65
 signals:
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    66
  void HWClientDisconnected(HWConnectedClient* client);
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    67
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    68
 private slots:
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    69
  void ClientRead();
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    70
  void ClientDisconnect();
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    71
};
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    72
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    73
class HWNetServer : public QObject
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    74
{
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    75
  Q_OBJECT
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    76
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    77
 public:
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    78
  void StartServer();
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    79
  void StopServer();
317
e95340dbfc1d start all clients
displacer
parents: 315
diff changeset
    80
  bool isCheefClient(HWConnectedClient* cl) const;
319
7f3bd9e31f18 some changes
displacer
parents: 317
diff changeset
    81
  void sendAll(QString gameCfg);
7f3bd9e31f18 some changes
displacer
parents: 317
diff changeset
    82
  void sendOthers(HWConnectedClient* this_cl, QString gameCfg);
315
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    83
  bool haveNick(const QString& nick) const;
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    84
  QString getRunningHostName() const;
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    85
  quint16 getRunningPort() const;
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    86
  QStringList getTeams() const;
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    87
  void teamChanged();
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    88
  bool shouldStart(HWConnectedClient* client);
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    89
  QString prepareConfig(QStringList lst);
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    90
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    91
 private:
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    92
  static const quint16 ds_port;
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    93
  QTcpServer* IPCServer;
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    94
  QList<HWConnectedClient*> connclients;
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    95
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    96
 private slots:
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    97
  void NewConnection();
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    98
  void ClientDisconnect(HWConnectedClient* client);
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    99
};
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   100
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   101
#endif // _NETSERVER_INCLUDED