QTfrontend/newnetclient.h
author unc0rr
Sun, 14 Jan 2007 21:51:17 +0000
changeset 337 a46abb65eb0c
parent 334 85eacbd9827f
child 338 d1e75dcd285f
permissions -rw-r--r--
- Fix not debug build - Allow multiple debug engines running simultaneously (there were problems with debug.txt)
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 Ulyanov Igor <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 _NEW_NETCLIENT_INCLUDED
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    20
#define _NEW_NETCLIENT_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 <QString>
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    24
#include <QTcpSocket>
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 GameUIConfig;
334
85eacbd9827f protocol changes
displacer
parents: 329
diff changeset
    29
class GameCFGWidget;
315
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    30
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    31
extern char delimeter;
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    32
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    33
class HWNewNet : public QObject
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    34
{
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    35
  Q_OBJECT
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    36
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    37
 public:
334
85eacbd9827f protocol changes
displacer
parents: 329
diff changeset
    38
  HWNewNet(GameUIConfig * config, GameCFGWidget* pGameCFGWidget);
315
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    39
  void Connect(const QString & hostName, quint16 port, const QString & nick);
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    40
  void Disconnect();
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    41
  void JoinGame(const QString & game);
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    42
  void StartGame();
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    43
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    44
 private:
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    45
  GameUIConfig* config;
334
85eacbd9827f protocol changes
displacer
parents: 329
diff changeset
    46
  GameCFGWidget* m_pGameCFGWidget;
315
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    47
334
85eacbd9827f protocol changes
displacer
parents: 329
diff changeset
    48
  bool isChief;
315
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    49
  QString mynick;
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    50
  QTcpSocket NetSocket;
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    51
  QString seed;
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    52
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    53
  void ConfigAsked();
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    54
  void RunGame();
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    55
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    56
  template <typename T>
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    57
  void SendCfgStrNet(T a) {
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    58
    QByteArray strmsg;
328
95625db21bf8 Oops, I should be more careful
unc0rr
parents: 315
diff changeset
    59
    strmsg.append(a);
315
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    60
    quint8 sz = strmsg.size();
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    61
    QByteArray enginemsg = QByteArray((char *)&sz, 1) + strmsg;
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    62
    QString _msg = delimeter + QString(enginemsg.toBase64());
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    63
    RawSendNet(_msg);
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    64
  }
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    65
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    66
  template <typename T>
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    67
  void SendCfgStrLoc(T a) {
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    68
    QByteArray strmsg;
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    69
    strmsg.append(QString(a).toUtf8());
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    70
    quint8 sz = strmsg.size();
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    71
    QByteArray enginemsg = QByteArray((char *)&sz, 1) + strmsg;
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    72
    emit FromNet(enginemsg);
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    73
  }
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    74
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    75
  void RawSendNet(const QString & buf);
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    76
  void RawSendNet(const QByteArray & buf);
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    77
  void ParseLine(const QByteArray & line);
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    78
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    79
 signals:
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    80
  void Connected();
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    81
  void Disconnected();
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    82
  void AddGame(const QString & chan);
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    83
  void EnteredGame();
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    84
  void FromNet(const QByteArray & buf);
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    85
  void LocalCFG(const QString & team);
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    86
  void ChangeInTeams(const QStringList & teams);
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    87
329
4c3aad46baa5 Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents: 328
diff changeset
    88
  void seedChanged(const QString & seed);
4c3aad46baa5 Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents: 328
diff changeset
    89
  void mapChanged(const QString & map);
4c3aad46baa5 Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents: 328
diff changeset
    90
  void themeChanged(const QString & theme);
4c3aad46baa5 Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents: 328
diff changeset
    91
  void initHealthChanged(quint32 health);
4c3aad46baa5 Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents: 328
diff changeset
    92
  void turnTimeChanged(quint32 time);
4c3aad46baa5 Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents: 328
diff changeset
    93
  void fortsModeChanged(bool value);
4c3aad46baa5 Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents: 328
diff changeset
    94
315
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    95
 public slots:
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    96
  void SendNet(const QByteArray & buf);
328
95625db21bf8 Oops, I should be more careful
unc0rr
parents: 315
diff changeset
    97
  void AddTeam(const HWTeam & team);
329
4c3aad46baa5 Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents: 328
diff changeset
    98
  void onSeedChanged(const QString & seed);
4c3aad46baa5 Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents: 328
diff changeset
    99
  void onMapChanged(const QString & map);
4c3aad46baa5 Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents: 328
diff changeset
   100
  void onThemeChanged(const QString & theme);
4c3aad46baa5 Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents: 328
diff changeset
   101
  void onInitHealthChanged(quint32 health);
4c3aad46baa5 Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents: 328
diff changeset
   102
  void onTurnTimeChanged(quint32 time);
4c3aad46baa5 Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents: 328
diff changeset
   103
  void onFortsModeChanged(bool value);
315
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   104
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   105
 private slots:
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   106
  void ClientRead();
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   107
  void OnConnect();
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   108
  void OnDisconnect();
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   109
  //void Perform();
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   110
  void displayError(QAbstractSocket::SocketError socketError);
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   111
  //void FlushNetBuf();
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   112
};
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   113
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   114
#endif // _NEW_NETCLIENT_INCLUDED