author | displacer |
Thu, 08 Feb 2007 20:03:03 +0000 | |
changeset 417 | bc7fea9abd9c |
parent 404 | 64a62b679b04 |
child 420 | 6cdfc07dceed |
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 |
QList<QStringList> m_teamsCfg; // TeamName - hhs |
315 | 51 |
class ShouldDisconnectException {}; |
326 | 52 |
|
315 | 53 |
QString client_nick; |
54 |
void ParseLine(const QByteArray & line); |
|
352 | 55 |
unsigned int removeTeam(const QString& tname); // returns netID |
315 | 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; |
354
60e4af0a4375
network to local teams map, addteams from server before team config bug, fixed some segfaults
displacer
parents:
352
diff
changeset
|
81 |
QMap<QString, QStringList> 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); |
|
388 | 91 |
void resetStart(); |
315 | 92 |
|
404 | 93 |
QMap<QString, QStringList> m_gameCfg; // config_param - value |
399 | 94 |
int hhnum; |
95 |
||
315 | 96 |
private: |
334 | 97 |
HWConnectedClient* getChiefClient() const; |
315 | 98 |
static const quint16 ds_port; |
99 |
QTcpServer* IPCServer; |
|
100 |
QList<HWConnectedClient*> connclients; |
|
101 |
||
102 |
private slots: |
|
103 |
void NewConnection(); |
|
104 |
void ClientDisconnect(HWConnectedClient* client); |
|
105 |
}; |
|
106 |
||
107 |
#endif // _NETSERVER_INCLUDED |