libkdegames/kgame
kmessageserver.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
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
00220
00228 bool initNetwork (quint16 port = 0);
00229
00236 quint16 serverPort () const;
00237
00243 void stopNetwork();
00244
00249 bool isOfferingConnections() const;
00250
00251
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
00353
00354
00355
00356
00357
00358
00359
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369
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
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