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 |
|
|
43 |
class NoTeamNameException{};
|
|
44 |
QString getTeamName() const;
|
|
45 |
void teamChangedNotify();
|
|
46 |
bool isReady() const;
|
|
47 |
|
|
48 |
QString getHedgehogsDescription() const;
|
|
49 |
|
|
50 |
bool readyToStart;
|
334
|
51 |
QMap<QString, QString> m_gameCfg;
|
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 |
HWTeam* pclent_team;
|
|
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;
|
|
88 |
QStringList getTeams() const;
|
|
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
|