• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • libkdegames
 

libkdegames

  • libkdegames
  • kgame
kmessageserver.h
1 /*
2  This file is part of the KDE games library
3  Copyright (C) 2001 Burkhard Lehner (Burkhard.Lehner@gmx.de)
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 <tqobject.h>
24 #include <tqserversocket.h>
25 #include <tqstring.h>
26 #include <tqvaluelist.h>
27 
28 class KMessageIO;
29 class KMessageServerPrivate;
30 
175 class KMessageServer : public TQObject
176 {
177  Q_OBJECT
178  TQ_OBJECT
179 
180 public:
184  enum {
185  RETQ_BROADCAST = 1,
186  RETQ_FORWARD,
187  RETQ_CLIENT_ID,
188  RETQ_ADMIN_ID,
189  RETQ_ADMIN_CHANGE,
190  RETQ_REMOVE_CLIENT,
191  RETQ_MAX_NUM_CLIENTS,
192  RETQ_CLIENT_LIST,
193  RETQ_MAX_REQ = 0xffff };
194 
198  enum {
199  MSG_BROADCAST = 101,
200  MSG_FORWARD,
201  ANS_CLIENT_ID,
202  ANS_ADMIN_ID,
203  ANS_CLIENT_LIST,
204  EVNT_CLIENT_CONNECTED,
205  EVNT_CLIENT_DISCONNECTED,
206  EVNT_MAX_EVNT = 0xffff
207  };
208 
212  KMessageServer(TQ_UINT16 cookie = 42, TQObject* parent = 0);
213 
214  ~KMessageServer();
215 
219  virtual void Debug();
220 
221 //---------------------------------- TCP/IP server stuff
222 
230  bool initNetwork (TQ_UINT16 port = 0);
231 
238  TQ_UINT16 serverPort () const;
239 
245  void stopNetwork();
246 
251  bool isOfferingConnections() const;
252 
253 //---------------------------------- adding / removing clients
254 
255 public slots:
269  void addClient (KMessageIO *);
270 
282  void removeClient (KMessageIO *io, bool broken);
283 
287  void deleteClients();
288 
289 private slots:
296  void removeBrokenClient ();
297 
298 public:
310  void setMaxClients(int maxnumber);
311 
317  int maxClients() const;
318 
324  int clientCount() const;
325 
329  TQValueList <TQ_UINT32> clientIDs() const;
330 
336  KMessageIO *findClient (TQ_UINT32 no) const;
337 
344  TQ_UINT32 adminID() const;
345 
351  void setAdmin (TQ_UINT32 adminID);
352 
353 
354 //------------------------------ ID stuff
355 
356  /*
357  * The unique ID of this game
358  *
359  * @return int id
360  **/
361 // int gameId() const;
362 
363  /*
364  * Application cookie. this idendifies the game application. It
365  * help to distinguish between e.g. KPoker and KWin4
366  *
367  * @return the application cookie
368  **/
369 // int cookie() const;
370 
371 //------------------------------ Message stuff
372 
373 public:
379  virtual void broadcastMessage (const TQByteArray &msg);
380 
389  virtual void sendMessage (TQ_UINT32 id, const TQByteArray &msg);
390 
398  virtual void sendMessage (const TQValueList <TQ_UINT32> &ids, const TQByteArray &msg);
399 
400 protected slots:
410  virtual void getReceivedMessage (const TQByteArray &msg);
411 
420  virtual void processOneMessage ();
421 
422 //---------------------------- Signals
423 
424 signals:
429  void clientConnected (KMessageIO *client);
430 
438  void connectionLost (KMessageIO *client);
439 
452  void messageReceived (const TQByteArray &data, TQ_UINT32 clientID, bool &unknown);
453 
454 protected:
460  TQ_UINT32 uniqueClientNumber() const;
461 
462 private:
463  KMessageServerPrivate* d;
464 };
465 
466 
477 class KMessageServerSocket : public TQServerSocket
478 {
479  Q_OBJECT
480  TQ_OBJECT
481 
482 public:
483  KMessageServerSocket (TQ_UINT16 port, TQObject *parent = 0);
484  ~KMessageServerSocket ();
485 
486  void newConnection (int socket);
487 
488 signals:
489  void newClientConnected (KMessageIO *client);
490 };
491 
492 
493 
494 #endif

libkdegames

Skip menu "libkdegames"
  • Main Page
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

libkdegames

Skip menu "libkdegames"
  • libkdegames
Generated for libkdegames by doxygen 1.8.1.2
This website is maintained by Timothy Pearson.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. |