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 |
|
|
35 |
public:
|
|
36 |
HWConnectedClient(HWNetServer* hwserver, QTcpSocket* client);
|
|
37 |
~HWConnectedClient();
|
|
38 |
QString getClientNick() const;
|
|
39 |
|
|
40 |
class NoTeamNameException{};
|
|
41 |
QString getTeamName() const;
|
|
42 |
void teamChangedNotify();
|
|
43 |
bool isReady() const;
|
|
44 |
|
|
45 |
QString getHedgehogsDescription() const;
|
|
46 |
|
|
47 |
private:
|
|
48 |
bool readyToStart;
|
|
49 |
class ShouldDisconnectException {};
|
|
50 |
|
|
51 |
QString client_nick;
|
|
52 |
void ParseLine(const QByteArray & line);
|
|
53 |
|
|
54 |
HWNetServer* m_hwserver;
|
|
55 |
QTcpSocket* m_client;
|
|
56 |
HWTeam* pclent_team;
|
|
57 |
|
|
58 |
void RawSendNet(const QString & buf);
|
|
59 |
void RawSendNet(const QByteArray & buf);
|
|
60 |
|
|
61 |
//QByteArray readbuffer;
|
|
62 |
|
|
63 |
signals:
|
|
64 |
void HWClientDisconnected(HWConnectedClient* client);
|
|
65 |
|
|
66 |
private slots:
|
|
67 |
void ClientRead();
|
|
68 |
void ClientDisconnect();
|
|
69 |
};
|
|
70 |
|
|
71 |
class HWNetServer : public QObject
|
|
72 |
{
|
|
73 |
Q_OBJECT
|
|
74 |
|
|
75 |
public:
|
|
76 |
void StartServer();
|
|
77 |
void StopServer();
|
|
78 |
bool haveNick(const QString& nick) const;
|
|
79 |
QString getRunningHostName() const;
|
|
80 |
quint16 getRunningPort() const;
|
|
81 |
QStringList getTeams() const;
|
|
82 |
void teamChanged();
|
|
83 |
bool shouldStart(HWConnectedClient* client);
|
|
84 |
QString prepareConfig(QStringList lst);
|
|
85 |
|
|
86 |
private:
|
|
87 |
static const quint16 ds_port;
|
|
88 |
QTcpServer* IPCServer;
|
|
89 |
QList<HWConnectedClient*> connclients;
|
|
90 |
|
|
91 |
private slots:
|
|
92 |
void NewConnection();
|
|
93 |
void ClientDisconnect(HWConnectedClient* client);
|
|
94 |
};
|
|
95 |
|
|
96 |
#endif // _NETSERVER_INCLUDED
|