author | displacer |
Sun, 14 Jan 2007 23:13:24 +0000 | |
changeset 338 | d1e75dcd285f |
parent 335 | 751348947fce |
child 347 | 6521e1b2cd40 |
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); |
|
56 |
||
57 |
HWNetServer* m_hwserver; |
|
58 |
QTcpSocket* m_client; |
|
59 |
||
60 |
void RawSendNet(const QString & buf); |
|
61 |
void RawSendNet(const QByteArray & buf); |
|
62 |
||
63 |
//QByteArray readbuffer; |
|
64 |
||
65 |
signals: |
|
66 |
void HWClientDisconnected(HWConnectedClient* client); |
|
67 |
||
68 |
private slots: |
|
69 |
void ClientRead(); |
|
70 |
void ClientDisconnect(); |
|
71 |
}; |
|
72 |
||
73 |
class HWNetServer : public QObject |
|
74 |
{ |
|
75 |
Q_OBJECT |
|
76 |
||
77 |
public: |
|
78 |
void StartServer(); |
|
79 |
void StopServer(); |
|
326 | 80 |
bool isChiefClient(HWConnectedClient* cl) const; |
335 | 81 |
QMap<QString, QString> getGameCfg() const; |
319 | 82 |
void sendAll(QString gameCfg); |
83 |
void sendOthers(HWConnectedClient* this_cl, QString gameCfg); |
|
315 | 84 |
bool haveNick(const QString& nick) const; |
85 |
QString getRunningHostName() const; |
|
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 | 88 |
void teamChanged(); |
89 |
bool shouldStart(HWConnectedClient* client); |
|
90 |
QString prepareConfig(QStringList lst); |
|
91 |
||
92 |
private: |
|
334 | 93 |
HWConnectedClient* getChiefClient() const; |
315 | 94 |
static const quint16 ds_port; |
95 |
QTcpServer* IPCServer; |
|
96 |
QList<HWConnectedClient*> connclients; |
|
97 |
||
98 |
private slots: |
|
99 |
void NewConnection(); |
|
100 |
void ClientDisconnect(HWConnectedClient* client); |
|
101 |
}; |
|
102 |
||
103 |
#endif // _NETSERVER_INCLUDED |