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>
|
|
24 |
|
|
25 |
#include "team.h"
|
|
26 |
|
|
27 |
class HWNetServer;
|
|
28 |
class QTcpSocket;
|
|
29 |
class QTcpServer;
|
|
30 |
|
|
31 |
class HWConnectedClient : public QObject
|
|
32 |
{
|
|
33 |
Q_OBJECT
|
|
34 |
|
317
|
35 |
friend class HWNetServer;
|
|
36 |
|
|
37 |
private:
|
315
|
38 |
HWConnectedClient(HWNetServer* hwserver, QTcpSocket* client);
|
|
39 |
~HWConnectedClient();
|
|
40 |
QString getClientNick() const;
|
|
41 |
|
|
42 |
class NoTeamNameException{};
|
|
43 |
QString getTeamName() const;
|
|
44 |
void teamChangedNotify();
|
|
45 |
bool isReady() const;
|
|
46 |
|
|
47 |
QString getHedgehogsDescription() const;
|
|
48 |
|
|
49 |
bool readyToStart;
|
334
|
50 |
QMap<QString, QString> m_gameCfg;
|
315
|
51 |
class ShouldDisconnectException {};
|
326
|
52 |
|
315
|
53 |
QString client_nick;
|
|
54 |
void ParseLine(const QByteArray & line);
|
|
55 |
|
|
56 |
HWNetServer* m_hwserver;
|
|
57 |
QTcpSocket* m_client;
|
|
58 |
HWTeam* pclent_team;
|
|
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;
|
334
|
81 |
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;
|
|
87 |
QStringList getTeams() const;
|
|
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
|