QTfrontend/netserver.h
author unc0rr
Fri, 26 Jan 2007 22:36:21 +0000
changeset 369 2aed85310727
parent 354 60e4af0a4375
child 388 dcf5335940bd
permissions -rw-r--r--
AI compiles, but doesn't work
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;
354
60e4af0a4375 network to local teams map, addteams from server before team config bug, fixed some segfaults
displacer
parents: 352
diff changeset
    50
  QMap<QString, QStringList> m_gameCfg; // config_param - value
338
d1e75dcd285f multiple teams now available per host (still alpha)
displacer
parents: 335
diff changeset
    51
  QList<QStringList> m_teamsCfg; // TeamName - hhs
315
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    52
  class ShouldDisconnectException {};
326
c6718bfdd642 Small fixes
unc0rr
parents: 319
diff changeset
    53
315
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    54
  QString client_nick;
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    55
  void ParseLine(const QByteArray & line);
352
4665bfe25470 first buggy hedgehogs num net change
displacer
parents: 347
diff changeset
    56
  unsigned int removeTeam(const QString& tname); // returns netID
315
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    57
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    58
  HWNetServer* m_hwserver;
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    59
  QTcpSocket* m_client;
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    60
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    61
  void RawSendNet(const QString & buf);
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    62
  void RawSendNet(const QByteArray & buf);
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    63
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    64
  //QByteArray readbuffer;
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    65
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    66
 signals:
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    67
  void HWClientDisconnected(HWConnectedClient* client);
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    68
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    69
 private slots:
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    70
  void ClientRead();
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    71
  void ClientDisconnect();
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    72
};
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    73
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    74
class HWNetServer : public QObject
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    75
{
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    76
  Q_OBJECT
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    77
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    78
 public:
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    79
  void StartServer();
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    80
  void StopServer();
326
c6718bfdd642 Small fixes
unc0rr
parents: 319
diff changeset
    81
  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
    82
  QMap<QString, QStringList> getGameCfg() const;
319
7f3bd9e31f18 some changes
displacer
parents: 317
diff changeset
    83
  void sendAll(QString gameCfg);
7f3bd9e31f18 some changes
displacer
parents: 317
diff changeset
    84
  void sendOthers(HWConnectedClient* this_cl, QString gameCfg);
315
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    85
  bool haveNick(const QString& nick) const;
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    86
  QString getRunningHostName() const;
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    87
  quint16 getRunningPort() const;
338
d1e75dcd285f multiple teams now available per host (still alpha)
displacer
parents: 335
diff changeset
    88
  QList<QStringList> getTeamsConfig() const;
315
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    89
  void teamChanged();
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    90
  bool shouldStart(HWConnectedClient* client);
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    91
  QString prepareConfig(QStringList lst);
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    92
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    93
 private:
334
85eacbd9827f protocol changes
displacer
parents: 326
diff changeset
    94
  HWConnectedClient* getChiefClient() const;
315
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    95
  static const quint16 ds_port;
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    96
  QTcpServer* IPCServer;
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    97
  QList<HWConnectedClient*> connclients;
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    98
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    99
 private slots:
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   100
  void NewConnection();
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   101
  void ClientDisconnect(HWConnectedClient* client);
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   102
};
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   103
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   104
#endif // _NETSERVER_INCLUDED