QTfrontend/netserver.h
author displacer
Tue, 06 Feb 2007 23:18:28 +0000
changeset 404 64a62b679b04
parent 399 c7da1bd32b4e
child 420 6cdfc07dceed
permissions -rw-r--r--
final bugfixes :)
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>
335
751348947fce CONFIG_PARAM for storing config
displacer
parents: 334
diff changeset
    24
#include <QMap>
315
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    25
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    26
#include "team.h"
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    27
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    28
class HWNetServer;
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    29
class QTcpSocket;
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    30
class QTcpServer;
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    31
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    32
class HWConnectedClient : public QObject
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    33
{
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    34
  Q_OBJECT
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    35
317
e95340dbfc1d start all clients
displacer
parents: 315
diff changeset
    36
 friend class HWNetServer;
e95340dbfc1d start all clients
displacer
parents: 315
diff changeset
    37
e95340dbfc1d start all clients
displacer
parents: 315
diff changeset
    38
 private:
315
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    39
  HWConnectedClient(HWNetServer* hwserver, QTcpSocket* client);
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    40
  ~HWConnectedClient();
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    41
  QString getClientNick() const;
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    42
338
d1e75dcd285f multiple teams now available per host (still alpha)
displacer
parents: 335
diff changeset
    43
  QList<QStringList> getTeamNames() const;
315
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    44
  class NoTeamNameException{};
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;
338
d1e75dcd285f multiple teams now available per host (still alpha)
displacer
parents: 335
diff changeset
    50
  QList<QStringList> m_teamsCfg; // TeamName - hhs
315
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    51
  class ShouldDisconnectException {};
326
c6718bfdd642 Small fixes
unc0rr
parents: 319
diff changeset
    52
315
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);
352
4665bfe25470 first buggy hedgehogs num net change
displacer
parents: 347
diff changeset
    55
  unsigned int removeTeam(const QString& tname); // returns netID
315
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    56
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    57
  HWNetServer* m_hwserver;
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    58
  QTcpSocket* m_client;
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();
326
c6718bfdd642 Small fixes
unc0rr
parents: 319
diff changeset
    80
  bool isChiefClient(HWConnectedClient* cl) const;
354
60e4af0a4375 network to local teams map, addteams from server before team config bug, fixed some segfaults
displacer
parents: 352
diff changeset
    81
  QMap<QString, QStringList> getGameCfg() const;
319
7f3bd9e31f18 some changes
displacer
parents: 317
diff changeset
    82
  void sendAll(QString gameCfg);
7f3bd9e31f18 some changes
displacer
parents: 317
diff changeset
    83
  void sendOthers(HWConnectedClient* this_cl, QString gameCfg);
315
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    84
  bool haveNick(const QString& nick) const;
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    85
  QString getRunningHostName() const;
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    86
  quint16 getRunningPort() const;
338
d1e75dcd285f multiple teams now available per host (still alpha)
displacer
parents: 335
diff changeset
    87
  QList<QStringList> getTeamsConfig() const;
315
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    88
  void teamChanged();
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    89
  bool shouldStart(HWConnectedClient* client);
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    90
  QString prepareConfig(QStringList lst);
388
dcf5335940bd repeated start now allowed
displacer
parents: 354
diff changeset
    91
  void resetStart();
315
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    92
404
64a62b679b04 final bugfixes :)
displacer
parents: 399
diff changeset
    93
  QMap<QString, QStringList> m_gameCfg; // config_param - value
399
c7da1bd32b4e more correct network hhnum
displacer
parents: 388
diff changeset
    94
  int hhnum;
c7da1bd32b4e more correct network hhnum
displacer
parents: 388
diff changeset
    95
315
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    96
 private:
334
85eacbd9827f protocol changes
displacer
parents: 326
diff changeset
    97
  HWConnectedClient* getChiefClient() const;
315
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    98
  static const quint16 ds_port;
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    99
  QTcpServer* IPCServer;
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   100
  QList<HWConnectedClient*> connclients;
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   101
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   102
 private slots:
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   103
  void NewConnection();
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   104
  void ClientDisconnect(HWConnectedClient* client);
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   105
};
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   106
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   107
#endif // _NETSERVER_INCLUDED