author | displacer |
Sun, 04 Feb 2007 21:30:23 +0000 | |
changeset 390 | dca6bd77d71d |
parent 388 | dcf5335940bd |
child 399 | c7da1bd32b4e |
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; |
|
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 | 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; |
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 | 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); |
|
388 | 92 |
void resetStart(); |
315 | 93 |
|
94 |
private: |
|
334 | 95 |
HWConnectedClient* getChiefClient() const; |
315 | 96 |
static const quint16 ds_port; |
97 |
QTcpServer* IPCServer; |
|
98 |
QList<HWConnectedClient*> connclients; |
|
99 |
||
100 |
private slots: |
|
101 |
void NewConnection(); |
|
102 |
void ClientDisconnect(HWConnectedClient* client); |
|
103 |
}; |
|
104 |
||
105 |
#endif // _NETSERVER_INCLUDED |