• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

libkdegames/kgame

kmessageserver.h

Go to the documentation of this file.
00001 /*
00002     This file is part of the KDE games library
00003     Copyright (C) 2001 Burkhard Lehner (Burkhard.Lehner@gmx.de)
00004 
00005     This library is free software; you can redistribute it and/or
00006     modify it under the terms of the GNU Library General Public
00007     License version 2 as published by the Free Software Foundation.
00008 
00009     This library is distributed in the hope that it will be useful,
00010     but WITHOUT ANY WARRANTY; without even the implied warranty of
00011     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012     Library General Public License for more details.
00013 
00014     You should have received a copy of the GNU Library General Public License
00015     along with this library; see the file COPYING.LIB.  If not, write to
00016     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017     Boston, MA 02110-1301, USA.
00018 */
00019 
00020 #ifndef __KMESSAGESERVER_H__
00021 #define __KMESSAGESERVER_H__
00022 
00023 #include <QtCore/QObject>
00024 #include <QtCore/QString>
00025 
00026 class KMessageIO;
00027 class KMessageServerPrivate;
00028 
00174 class KMessageServer : public QObject
00175 {
00176   Q_OBJECT
00177 
00178 public:
00182     enum { 
00183             REQ_BROADCAST = 1, 
00184             REQ_FORWARD,
00185             REQ_CLIENT_ID,
00186             REQ_ADMIN_ID,
00187             REQ_ADMIN_CHANGE,
00188             REQ_REMOVE_CLIENT,
00189             REQ_MAX_NUM_CLIENTS,
00190             REQ_CLIENT_LIST,
00191             REQ_MAX_REQ = 0xffff };
00192 
00196     enum {
00197             MSG_BROADCAST = 101, 
00198             MSG_FORWARD, 
00199             ANS_CLIENT_ID, 
00200             ANS_ADMIN_ID, 
00201             ANS_CLIENT_LIST,
00202             EVNT_CLIENT_CONNECTED, 
00203             EVNT_CLIENT_DISCONNECTED,
00204             EVNT_MAX_EVNT = 0xffff
00205     };
00206 
00210     explicit KMessageServer(quint16 cookie = 42, QObject* parent = 0);
00211 
00212     ~KMessageServer();
00213 
00217     virtual void Debug();
00218 
00219 //---------------------------------- TCP/IP server stuff
00220 
00228     bool initNetwork (quint16 port = 0);
00229 
00236     quint16 serverPort () const;
00237 
00243     void stopNetwork();
00244 
00249     bool isOfferingConnections() const;
00250 
00251 //---------------------------------- adding / removing clients
00252 
00253 public Q_SLOTS:
00267     void addClient (KMessageIO *);
00268 
00280     void removeClient (KMessageIO *io, bool broken);
00281 
00285     void deleteClients();
00286 
00287 private Q_SLOTS:
00294     void removeBrokenClient ();
00295 
00296 public:
00308     void setMaxClients(int maxnumber);
00309 
00315     int maxClients() const;
00316 
00322     int clientCount() const;
00323 
00327     QList <quint32> clientIDs() const;
00328 
00334     KMessageIO *findClient (quint32 no) const;
00335 
00342     quint32 adminID() const;
00343 
00349     void setAdmin (quint32 adminID);
00350 
00351 
00352 //------------------------------ ID stuff
00353 
00354     /*
00355      * The unique ID of this game
00356      *
00357      * @return int id
00358      **/
00359 //    int gameId() const;
00360 
00361     /*
00362      * Application cookie. this idendifies the game application. It
00363      * help to distinguish between e.g. KPoker and KWin4
00364      *
00365      * @return the application cookie
00366      **/
00367 //    int cookie() const;
00368 
00369 //------------------------------ Message stuff
00370 
00371 public:
00377     virtual void broadcastMessage (const QByteArray &msg);
00378 
00387     virtual void sendMessage (quint32 id, const QByteArray &msg);
00388 
00396     virtual void sendMessage (const QList <quint32> &ids, const QByteArray &msg);
00397 
00398 protected Q_SLOTS:
00408     virtual void getReceivedMessage (const QByteArray &msg);
00409 
00418     virtual void processOneMessage ();
00419 
00420 //---------------------------- Signals
00421 
00422 Q_SIGNALS:
00427     void clientConnected (KMessageIO *client);
00428 
00436     void connectionLost (KMessageIO *client);
00437 
00450     void messageReceived (const QByteArray &data, quint32 clientID, bool &unknown);
00451 
00452 protected:
00458     quint32 uniqueClientNumber() const;
00459 
00460 private:
00461     KMessageServerPrivate* d;
00462 };
00463 
00464 
00465 #endif

libkdegames/kgame

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

API Reference

Skip menu "API Reference"
  • kblackbox
  • kgoldrunner
  • kmahjongg
  • ksquares
  • libkdegames
  •   highscore
  •   kgame
  •   kggzgames
  •   kggzmod
  •   kggznet
  • libkmahjongg
Generated for API Reference by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal