KDEGames

kgamenetwork.h
1 /*
2  This file is part of the KDE games library
3  Copyright (C) 2001 Martin Heni (kde at heni-online.de)
4  Copyright (C) 2001 Andreas Beckermann ([email protected])
5 
6  This library is free software; you can redistribute it and/or
7  modify it under the terms of the GNU Library General Public
8  License version 2 as published by the Free Software Foundation.
9 
10  This library is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Library General Public License for more details.
14 
15  You should have received a copy of the GNU Library General Public License
16  along with this library; see the file COPYING.LIB. If not, write to
17  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18  Boston, MA 02110-1301, USA.
19 */
20 
21 #ifndef __KGAMENETWORK_H_
22 #define __KGAMENETWORK_H_
23 
24 #include <QString>
25 #include <QObject>
26 #include "libkdegamesprivate_export.h"
27 
28 class KGameIO;
29 class KMessageIO;
30 class KMessageClient;
31 class KMessageServer;
32 
33 class KGameNetworkPrivate;
34 
46 class KDEGAMESPRIVATE_EXPORT KGameNetwork : public QObject
47 {
48  Q_OBJECT
49 
50 public:
54  explicit KGameNetwork(int cookie=42,QObject* parent=nullptr);
55  virtual ~KGameNetwork();
56 
60  virtual void Debug();
61 
66  bool isNetwork() const;
67 
80  bool isMaster() const;
81 
92  bool isAdmin() const;
93 
99  quint32 gameId() const;
100 
111  bool offerConnections (quint16 port);
112 
113  void setDiscoveryInfo(const QString& type, const QString& name=QString());
114 
123  bool connectToServer(const QString& host, quint16 port);
124  bool connectToServer(KMessageIO *connection);
125 
131  quint16 port() const;
132 
138  QString hostName() const;
139 
144  bool stopServerConnection();
145 
156  void setMaxClients(int max);
157 
158  //AB: is this now internal only? Can we make it protected (maybe with
159  //friends)? sendSystemMessage AND sendMessage is very confusing to the
160  //user.
180  // AB: TODO: doc on how "receiver" and "sender" should be created!
181  bool sendSystemMessage(const QByteArray& buffer, int msgid, quint32 receiver=0, quint32 sender=0);
182 
186  bool sendSystemMessage(int data, int msgid, quint32 receiver=0, quint32 sender=0);
187 
191  bool sendSystemMessage(const QDataStream &msg, int msgid, quint32 receiver=0, quint32 sender=0);
192 
196  bool sendSystemMessage(const QString& msg, int msgid, quint32 receiver=0, quint32 sender=0);
197 
209  void sendError(int error, const QByteArray& message, quint32 receiver=0, quint32 sender=0);
210 
215  bool isOfferingConnections() const;
216 
222  int cookie() const;
223 
256  // AB: TODO: doc on how "receiver" and "sender" should be created!
257  bool sendMessage(const QByteArray& buffer, int msgid, quint32 receiver=0, quint32 sender=0);
258 
262  bool sendMessage(const QDataStream &msg, int msgid, quint32 receiver=0, quint32 sender=0);
263 
267  bool sendMessage(const QString& msg, int msgid, quint32 receiver=0, quint32 sender=0);
268 
272  bool sendMessage(int data, int msgid, quint32 receiver=0, quint32 sender=0);
273 
274 
279  virtual void networkTransmission(QDataStream&, int, quint32, quint32, quint32 clientID) = 0;
280 
281 
285  void disconnect();
286 
287 
296  void electAdmin(quint32 clientID);
297 
306  KMessageClient* messageClient() const;
307 
316  KMessageServer* messageServer() const;
317 
324  virtual void lock();
325 
329  virtual void unlock();
330 
331 Q_SIGNALS:
337  void signalNetworkErrorMessage(int error, const QString &text);
338 
343  void signalConnectionBroken();
344 
354  void signalClientConnected(quint32 clientID);
355 
367  void signalClientDisconnected(quint32 clientID, bool broken);
368 
374  void signalAdminStatusChanged(bool isAdmin);
375 
376 protected:
383  void setMaster();
384 
385 protected Q_SLOTS:
393  void receiveNetworkTransmission(const QByteArray& a, quint32 clientID);
394 
399  void slotAdminStatusChanged(bool isAdmin);
400 
405  void aboutToLoseConnection(quint32 id);
406 
411  void slotResetConnection();
412 
413 
414 private:
415  void tryPublish();
416  void tryStopPublishing();
417  KGameNetworkPrivate* const d;
418 };
419 
420 #endif
bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *method)
A client to connect to a KMessageServer.
This abstract base class represents one end of a message connections between two clients.
Definition: kmessageio.h:62
A server for message sending and broadcasting, using TCP/IP connections.
The KGameNetwork class is the KGame class with network support.
Definition: kgamenetwork.h:46
Base class for IO devices for games.
Definition: kgameio.h:65
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Nov 30 2020 22:37:54 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.