libkdegames Library API Documentation

kmessageserver.h

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., 59 Temple Place - Suite 330, 00017 Boston, MA 02111-1307, USA. 00018 */ 00019 00020 #ifndef __KMESSAGESERVER_H__ 00021 #define __KMESSAGESERVER_H__ 00022 00023 #include <qobject.h> 00024 #include <qserversocket.h> 00025 #include <qstring.h> 00026 #include <qvaluelist.h> 00027 00028 class KMessageIO; 00029 class KMessageServerPrivate; 00030 00175 class KMessageServer : public QObject 00176 { 00177 Q_OBJECT 00178 00179 public: 00183 enum { 00184 REQ_BROADCAST = 1, 00185 REQ_FORWARD, 00186 REQ_CLIENT_ID, 00187 REQ_ADMIN_ID, 00188 REQ_ADMIN_CHANGE, 00189 REQ_REMOVE_CLIENT, 00190 REQ_MAX_NUM_CLIENTS, 00191 REQ_CLIENT_LIST, 00192 REQ_MAX_REQ = 0xffff }; 00193 00197 enum { 00198 MSG_BROADCAST = 101, 00199 MSG_FORWARD, 00200 ANS_CLIENT_ID, 00201 ANS_ADMIN_ID, 00202 ANS_CLIENT_LIST, 00203 EVNT_CLIENT_CONNECTED, 00204 EVNT_CLIENT_DISCONNECTED, 00205 EVNT_MAX_EVNT = 0xffff 00206 }; 00207 00211 KMessageServer(Q_UINT16 cookie = 42, QObject* parent = 0); 00212 00213 ~KMessageServer(); 00214 00218 virtual void Debug(); 00219 00220 //---------------------------------- TCP/IP server stuff 00221 00229 bool initNetwork (Q_UINT16 port = 0); 00230 00237 Q_UINT16 serverPort () const; 00238 00244 void stopNetwork(); 00245 00250 bool isOfferingConnections() const; 00251 00252 //---------------------------------- adding / removing clients 00253 00254 public slots: 00268 void addClient (KMessageIO *); 00269 00281 void removeClient (KMessageIO *io, bool broken); 00282 00286 void deleteClients(); 00287 00288 private slots: 00295 void removeBrokenClient (); 00296 00297 public: 00309 void setMaxClients(int maxnumber); 00310 00316 int maxClients() const; 00317 00323 int clientCount() const; 00324 00328 QValueList <Q_UINT32> clientIDs() const; 00329 00335 KMessageIO *findClient (Q_UINT32 no) const; 00336 00343 Q_UINT32 adminID() const; 00344 00350 void setAdmin (Q_UINT32 adminID); 00351 00352 00353 //------------------------------ ID stuff 00354 00355 /* 00356 * The unique ID of this game 00357 * 00358 * @return int id 00359 **/ 00360 // int gameId() const; 00361 00362 /* 00363 * Application cookie. this idendifies the game application. It 00364 * help to distinguish between e.g. KPoker and KWin4 00365 * 00366 * @return the application cookie 00367 **/ 00368 // int cookie() const; 00369 00370 //------------------------------ Message stuff 00371 00372 public: 00378 virtual void broadcastMessage (const QByteArray &msg); 00379 00388 virtual void sendMessage (Q_UINT32 id, const QByteArray &msg); 00389 00397 virtual void sendMessage (const QValueList <Q_UINT32> &ids, const QByteArray &msg); 00398 00399 protected slots: 00409 virtual void getReceivedMessage (const QByteArray &msg); 00410 00419 virtual void processOneMessage (); 00420 00421 //---------------------------- Signals 00422 00423 signals: 00428 void clientConnected (KMessageIO *client); 00429 00437 void connectionLost (KMessageIO *client); 00438 00451 void messageReceived (const QByteArray &data, Q_UINT32 clientID, bool &unknown); 00452 00453 protected: 00459 Q_UINT32 uniqueClientNumber() const; 00460 00461 private: 00462 KMessageServerPrivate* d; 00463 }; 00464 00465 00476 class KMessageServerSocket : public QServerSocket 00477 { 00478 Q_OBJECT 00479 00480 public: 00481 KMessageServerSocket (Q_UINT16 port, QObject *parent = 0); 00482 ~KMessageServerSocket (); 00483 00484 void newConnection (int socket); 00485 00486 signals: 00487 void newClientConnected (KMessageIO *client); 00488 }; 00489 00490 00491 00492 #endif
KDE Logo
This file is part of the documentation for libkdegames Library Version 3.2.3.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Tue Sep 21 12:08:03 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003