author | unc0rr |
Sun, 11 Feb 2007 15:33:19 +0000 | |
changeset 433 | 9f8f22094c0e |
parent 431 | 79ac59673df3 |
child 448 | e968e19a464c |
permissions | -rw-r--r-- |
315 | 1 |
/* |
2 |
* Hedgewars, a worms-like game |
|
3 |
* Copyright (c) 2006 Ulyanov Igor <iulyanov@gmail.com> |
|
4 |
* |
|
5 |
* This program is free software; you can redistribute it and/or modify |
|
6 |
* it under the terms of the GNU General Public License as published by |
|
7 |
* the Free Software Foundation; version 2 of the License |
|
8 |
* |
|
9 |
* This program is distributed in the hope that it will be useful, |
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 |
* GNU General Public License for more details. |
|
13 |
* |
|
14 |
* You should have received a copy of the GNU General Public License |
|
15 |
* along with this program; if not, write to the Free Software |
|
16 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
|
17 |
*/ |
|
18 |
||
19 |
#ifndef _NEW_NETCLIENT_INCLUDED |
|
20 |
#define _NEW_NETCLIENT_INCLUDED |
|
21 |
||
22 |
#include <QObject> |
|
23 |
#include <QString> |
|
24 |
#include <QTcpSocket> |
|
354
60e4af0a4375
network to local teams map, addteams from server before team config bug, fixed some segfaults
displacer
parents:
352
diff
changeset
|
25 |
#include <QMap> |
315 | 26 |
|
27 |
#include "team.h" |
|
28 |
||
29 |
class GameUIConfig; |
|
334 | 30 |
class GameCFGWidget; |
339
7535ab6c3820
Run game message added, team and config info provided for net game
displacer
parents:
338
diff
changeset
|
31 |
class TeamSelWidget; |
315 | 32 |
|
33 |
extern char delimeter; |
|
34 |
||
35 |
class HWNewNet : public QObject |
|
36 |
{ |
|
37 |
Q_OBJECT |
|
38 |
||
39 |
public: |
|
339
7535ab6c3820
Run game message added, team and config info provided for net game
displacer
parents:
338
diff
changeset
|
40 |
HWNewNet(GameUIConfig * config, GameCFGWidget* pGameCFGWidget, TeamSelWidget* pTeamSelWidget); |
315 | 41 |
void Connect(const QString & hostName, quint16 port, const QString & nick); |
42 |
void Disconnect(); |
|
43 |
void JoinGame(const QString & game); |
|
44 |
void StartGame(); |
|
45 |
||
46 |
private: |
|
47 |
GameUIConfig* config; |
|
334 | 48 |
GameCFGWidget* m_pGameCFGWidget; |
339
7535ab6c3820
Run game message added, team and config info provided for net game
displacer
parents:
338
diff
changeset
|
49 |
TeamSelWidget* m_pTeamSelWidget; |
315 | 50 |
|
334 | 51 |
bool isChief; |
315 | 52 |
QString mynick; |
53 |
QTcpSocket NetSocket; |
|
54 |
QString seed; |
|
383 | 55 |
bool m_game_connected; |
315 | 56 |
|
354
60e4af0a4375
network to local teams map, addteams from server before team config bug, fixed some segfaults
displacer
parents:
352
diff
changeset
|
57 |
QMap<unsigned int, QString> m_networkToLocalteams; // key is netID, value is local team name |
60e4af0a4375
network to local teams map, addteams from server before team config bug, fixed some segfaults
displacer
parents:
352
diff
changeset
|
58 |
|
315 | 59 |
void ConfigAsked(); |
60 |
void RunGame(); |
|
61 |
||
62 |
template <typename T> |
|
63 |
void SendCfgStrNet(T a) { |
|
64 |
QByteArray strmsg; |
|
328 | 65 |
strmsg.append(a); |
315 | 66 |
quint8 sz = strmsg.size(); |
67 |
QByteArray enginemsg = QByteArray((char *)&sz, 1) + strmsg; |
|
68 |
QString _msg = delimeter + QString(enginemsg.toBase64()); |
|
69 |
RawSendNet(_msg); |
|
70 |
} |
|
71 |
||
72 |
template <typename T> |
|
73 |
void SendCfgStrLoc(T a) { |
|
74 |
QByteArray strmsg; |
|
75 |
strmsg.append(QString(a).toUtf8()); |
|
76 |
quint8 sz = strmsg.size(); |
|
77 |
QByteArray enginemsg = QByteArray((char *)&sz, 1) + strmsg; |
|
78 |
emit FromNet(enginemsg); |
|
79 |
} |
|
80 |
||
81 |
void RawSendNet(const QString & buf); |
|
82 |
void RawSendNet(const QByteArray & buf); |
|
83 |
void ParseLine(const QByteArray & line); |
|
84 |
||
85 |
signals: |
|
86 |
void Connected(); |
|
87 |
void Disconnected(); |
|
88 |
void AddGame(const QString & chan); |
|
89 |
void EnteredGame(); |
|
90 |
void FromNet(const QByteArray & buf); |
|
339
7535ab6c3820
Run game message added, team and config info provided for net game
displacer
parents:
338
diff
changeset
|
91 |
void AddNetTeam(const HWTeam&); |
315 | 92 |
|
329
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 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
|
94 |
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
|
95 |
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
|
96 |
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
|
97 |
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
|
98 |
void fortsModeChanged(bool value); |
352 | 99 |
void hhnumChanged(const HWTeam&); |
372 | 100 |
void teamColorChanged(const HWTeam&); |
329
4c3aad46baa5
Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents:
328
diff
changeset
|
101 |
|
315 | 102 |
public slots: |
103 |
void SendNet(const QByteArray & buf); |
|
328 | 104 |
void AddTeam(const HWTeam & team); |
347 | 105 |
void RemoveTeam(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
|
106 |
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
|
107 |
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
|
108 |
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
|
109 |
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
|
110 |
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
|
111 |
void onFortsModeChanged(bool value); |
352 | 112 |
void onHedgehogsNumChanged(const HWTeam& team); |
372 | 113 |
void onTeamColorChanged(const HWTeam& team); |
315 | 114 |
|
115 |
private slots: |
|
116 |
void ClientRead(); |
|
117 |
void OnConnect(); |
|
118 |
void OnDisconnect(); |
|
119 |
//void Perform(); |
|
120 |
void displayError(QAbstractSocket::SocketError socketError); |
|
431 | 121 |
void ShowErrorMessage(const QString &); |
315 | 122 |
//void FlushNetBuf(); |
123 |
}; |
|
124 |
||
125 |
#endif // _NEW_NETCLIENT_INCLUDED |