author | displacer |
Sun, 21 Jan 2007 19:53:25 +0000 | |
changeset 352 | 4665bfe25470 |
parent 347 | 6521e1b2cd40 |
child 354 | 60e4af0a4375 |
permissions | -rw-r--r-- |
315 | 1 |
/* |
2 |
* Hedgewars, a worms-like game |
|
3 |
* Copyright (c) 2006 Igor Ulyanov <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 _NETSERVER_INCLUDED |
|
20 |
#define _NETSERVER_INCLUDED |
|
21 |
||
22 |
#include <QObject> |
|
23 |
#include <QList> |
|
335 | 24 |
#include <QMap> |
315 | 25 |
|
26 |
#include "team.h" |
|
27 |
||
28 |
class HWNetServer; |
|
29 |
class QTcpSocket; |
|
30 |
class QTcpServer; |
|
31 |
||
32 |
class HWConnectedClient : public QObject |
|
33 |
{ |
|
34 |
Q_OBJECT |
|
35 |
||
317 | 36 |
friend class HWNetServer; |
37 |
||
38 |
private: |
|
315 | 39 |
HWConnectedClient(HWNetServer* hwserver, QTcpSocket* client); |
40 |
~HWConnectedClient(); |
|
41 |
QString getClientNick() const; |
|
42 |
||
338
d1e75dcd285f
multiple teams now available per host (still alpha)
displacer
parents:
335
diff
changeset
|
43 |
QList<QStringList> getTeamNames() const; |
315 | 44 |
class NoTeamNameException{}; |
45 |
bool isReady() const; |
|
46 |
||
47 |
QString getHedgehogsDescription() const; |
|
48 |
||
49 |
bool readyToStart; |
|
338
d1e75dcd285f
multiple teams now available per host (still alpha)
displacer
parents:
335
diff
changeset
|
50 |
QMap<QString, QString> m_gameCfg; // config_param - value |
d1e75dcd285f
multiple teams now available per host (still alpha)
displacer
parents:
335
diff
changeset
|
51 |
QList<QStringList> m_teamsCfg; // TeamName - hhs |
315 | 52 |
class ShouldDisconnectException {}; |
326 | 53 |
|
315 | 54 |
QString client_nick; |
55 |
void ParseLine(const QByteArray & line); |
|
352 | 56 |
unsigned int removeTeam(const QString& tname); // returns netID |
315 | 57 |
|
58 |
HWNetServer* m_hwserver; |
|
59 |
QTcpSocket* m_client; |
|
60 |
||
61 |
void RawSendNet(const QString & buf); |
|
62 |
void RawSendNet(const QByteArray & buf); |
|
63 |
||
64 |
//QByteArray readbuffer; |
|
65 |
||
66 |
signals: |
|
67 |
void HWClientDisconnected(HWConnectedClient* client); |
|
68 |
||
69 |
private slots: |
|
70 |
void ClientRead(); |
|
71 |
void ClientDisconnect(); |
|
72 |
}; |
|
73 |
||
74 |
class HWNetServer : public QObject |
|
75 |
{ |
|
76 |
Q_OBJECT |
|
77 |
||
78 |
public: |
|
79 |
void StartServer(); |
|
80 |
void StopServer(); |
|
326 | 81 |
bool isChiefClient(HWConnectedClient* cl) const; |
335 | 82 |
QMap<QString, QString> getGameCfg() const; |
319 | 83 |
void sendAll(QString gameCfg); |
84 |
void sendOthers(HWConnectedClient* this_cl, QString gameCfg); |
|
315 | 85 |
bool haveNick(const QString& nick) const; |
86 |
QString getRunningHostName() const; |
|
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 | 89 |
void teamChanged(); |
90 |
bool shouldStart(HWConnectedClient* client); |
|
91 |
QString prepareConfig(QStringList lst); |
|
92 |
||
93 |
private: |
|
334 | 94 |
HWConnectedClient* getChiefClient() const; |
315 | 95 |
static const quint16 ds_port; |
96 |
QTcpServer* IPCServer; |
|
97 |
QList<HWConnectedClient*> connclients; |
|
98 |
||
99 |
private slots: |
|
100 |
void NewConnection(); |
|
101 |
void ClientDisconnect(HWConnectedClient* client); |
|
102 |
}; |
|
103 |
||
104 |
#endif // _NETSERVER_INCLUDED |