libtdegames
kgamenetwork.h
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef __KGAMENETWORK_H_
00024 #define __KGAMENETWORK_H_
00025
00026 #include <tqstring.h>
00027 #include <tqobject.h>
00028 #include <kdemacros.h>
00029 class KGameIO;
00030 class KMessageClient;
00031 class KMessageServer;
00032
00033 class KGameNetworkPrivate;
00034
00046 class KDE_EXPORT KGameNetwork : public TQObject
00047 {
00048 Q_OBJECT
00049
00050
00051 public:
00055 KGameNetwork(int cookie=42,TQObject* parent=0);
00056 virtual ~KGameNetwork();
00057
00061 virtual void Debug();
00062
00067 bool isNetwork() const;
00068
00081 bool isMaster() const;
00082
00093 bool isAdmin() const;
00094
00100 TQ_UINT32 gameId() const;
00101
00112 bool offerConnections (TQ_UINT16 port);
00113
00124 void setDiscoveryInfo(const TQString& type, const TQString& name=TQString());
00125
00134 bool connectToServer(const TQString& host, TQ_UINT16 port);
00135
00142 TQ_UINT16 port() const;
00143
00150 TQString hostName() const;
00151
00156 bool stopServerConnection();
00157
00168 void setMaxClients(int max);
00169
00170
00171
00172
00192
00193 bool sendSystemMessage(const TQByteArray& buffer, int msgid, TQ_UINT32 receiver=0, TQ_UINT32 sender=0);
00194
00198 bool sendSystemMessage(int data, int msgid, TQ_UINT32 receiver=0, TQ_UINT32 sender=0);
00199
00203 bool sendSystemMessage(const TQDataStream &msg, int msgid, TQ_UINT32 receiver=0, TQ_UINT32 sender=0);
00204
00208 bool sendSystemMessage(const TQString& msg, int msgid, TQ_UINT32 receiver=0, TQ_UINT32 sender=0);
00209
00221 void sendError(int error, const TQByteArray& message, TQ_UINT32 receiver=0, TQ_UINT32 sender=0);
00222
00227 bool isOfferingConnections() const;
00228
00234 int cookie() const;
00235
00268
00269 bool sendMessage(const TQByteArray& buffer, int msgid, TQ_UINT32 receiver=0, TQ_UINT32 sender=0);
00270
00274 bool sendMessage(const TQDataStream &msg, int msgid, TQ_UINT32 receiver=0, TQ_UINT32 sender=0);
00275
00279 bool sendMessage(const TQString& msg, int msgid, TQ_UINT32 receiver=0, TQ_UINT32 sender=0);
00280
00284 bool sendMessage(int data, int msgid, TQ_UINT32 receiver=0, TQ_UINT32 sender=0);
00285
00286
00291 virtual void networkTransmission(TQDataStream&, int, TQ_UINT32, TQ_UINT32, TQ_UINT32 clientID) = 0;
00292
00293
00297 void disconnect();
00298
00299
00308 void electAdmin(TQ_UINT32 clientID);
00309
00318 KMessageClient* messageClient() const;
00319
00328 KMessageServer* messageServer() const;
00329
00336 virtual void lock();
00337
00341 virtual void unlock();
00342
00343 signals:
00349 void signalNetworkErrorMessage(int error, TQString text);
00350
00355 void signalConnectionBroken();
00356
00366 void signalClientConnected(TQ_UINT32 clientID);
00367
00379 void signalClientDisconnected(TQ_UINT32 clientID, bool broken);
00380
00386 void signalAdminStatusChanged(bool isAdmin);
00387
00388 protected:
00395 void setMaster();
00396
00397 protected slots:
00405 void receiveNetworkTransmission(const TQByteArray& a, TQ_UINT32 clientID);
00406
00411 void slotAdminStatusChanged(bool isAdmin);
00412
00417 void aboutToLoseConnection(TQ_UINT32 id);
00418
00423 void slotResetConnection();
00424
00425
00426 private:
00427 void tryPublish();
00428 void tryStopPublishing();
00429 KGameNetworkPrivate* d;
00430 };
00431
00432 #endif