KDEGames

kmessageserver.h
1 /*
2  This file is part of the KDE games library
3  Copyright (C) 2001 Burkhard Lehner ([email protected])
4 
5  This library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Library General Public
7  License version 2 as published by the Free Software Foundation.
8 
9  This library 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 GNU
12  Library General Public License for more details.
13 
14  You should have received a copy of the GNU Library General Public License
15  along with this library; see the file COPYING.LIB. If not, write to
16  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  Boston, MA 02110-1301, USA.
18 */
19 
20 #ifndef __KMESSAGESERVER_H__
21 #define __KMESSAGESERVER_H__
22 
23 #include <QObject>
24 #include <QString>
25 #include "libkdegamesprivate_export.h"
26 
27 class KMessageIO;
28 class KMessageServerPrivate;
29 
175 class KDEGAMESPRIVATE_EXPORT KMessageServer : public QObject
176 {
177  Q_OBJECT
178 
179 public:
183  enum {
184  REQ_BROADCAST = 1,
185  REQ_FORWARD,
186  REQ_CLIENT_ID,
187  REQ_ADMIN_ID,
188  REQ_ADMIN_CHANGE,
189  REQ_REMOVE_CLIENT,
190  REQ_MAX_NUM_CLIENTS,
191  REQ_CLIENT_LIST,
192  REQ_MAX_REQ = 0xffff };
193 
197  enum {
198  MSG_BROADCAST = 101,
199  MSG_FORWARD,
200  ANS_CLIENT_ID,
201  ANS_ADMIN_ID,
202  ANS_CLIENT_LIST,
203  EVNT_CLIENT_CONNECTED,
204  EVNT_CLIENT_DISCONNECTED,
205  EVNT_MAX_EVNT = 0xffff
206  };
207 
211  explicit KMessageServer(quint16 cookie = 42, QObject* parent = nullptr);
212 
213  ~KMessageServer();
214 
218  virtual void Debug();
219 
220 //---------------------------------- TCP/IP server stuff
221 
229  bool initNetwork (quint16 port = 0);
230 
237  quint16 serverPort () const;
238 
244  void stopNetwork();
245 
250  bool isOfferingConnections() const;
251 
252 //---------------------------------- adding / removing clients
253 
254 public Q_SLOTS:
268  void addClient (KMessageIO *);
269 
281  void removeClient (KMessageIO *io, bool broken);
282 
286  void deleteClients();
287 
288 private Q_SLOTS:
295  void removeBrokenClient ();
296 
297 public:
309  void setMaxClients(int maxnumber);
310 
316  int maxClients() const;
317 
323  int clientCount() const;
324 
328  QList <quint32> clientIDs() const;
329 
335  KMessageIO *findClient (quint32 no) const;
336 
343  quint32 adminID() const;
344 
350  void setAdmin (quint32 adminID);
351 
352 
353 //------------------------------ ID stuff
354 
355  /*
356  * The unique ID of this game
357  *
358  * @return int id
359  **/
360 // int gameId() const;
361 
362  /*
363  * Application cookie. this identifies the game application. It
364  * help to distinguish between e.g. KPoker and KWin4
365  *
366  * @return the application cookie
367  **/
368 // int cookie() const;
369 
370 //------------------------------ Message stuff
371 
372 public:
378  virtual void broadcastMessage (const QByteArray &msg);
379 
388  virtual void sendMessage (quint32 id, const QByteArray &msg);
389 
397  virtual void sendMessage (const QList <quint32> &ids, const QByteArray &msg);
398 
399 protected Q_SLOTS:
409  virtual void getReceivedMessage (const QByteArray &msg);
410 
419  virtual void processOneMessage ();
420 
421 //---------------------------- Signals
422 
423 Q_SIGNALS:
428  void clientConnected (KMessageIO *client);
429 
437  void connectionLost (KMessageIO *client);
438 
451  void messageReceived (const QByteArray &data, quint32 clientID, bool &unknown);
452 
453 protected:
459  quint32 uniqueClientNumber() const;
460 
461 private:
462  KMessageServerPrivate* d;
463 };
464 
465 
466 #endif
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.
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Thu Nov 26 2020 22:36:18 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.