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 <qstring.h>
00027 #include <qobject.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 QObject
00047 {
00048 Q_OBJECT
00049
00050 public:
00054 KGameNetwork(int cookie=42,QObject* parent=0);
00055 virtual ~KGameNetwork();
00056
00060 virtual void Debug();
00061
00066 bool isNetwork() const;
00067
00080 bool isMaster() const;
00081
00092 bool isAdmin() const;
00093
00099 Q_UINT32 gameId() const;
00100
00111 bool offerConnections (Q_UINT16 port);
00112
00123 void setDiscoveryInfo(const QString& type, const QString& name=QString::null);
00124
00133 bool connectToServer(const QString& host, Q_UINT16 port);
00134
00141 Q_UINT16 port() const;
00142
00149 QString hostName() const;
00150
00155 bool stopServerConnection();
00156
00167 void setMaxClients(int max);
00168
00169
00170
00171
00191
00192 bool sendSystemMessage(const QByteArray& buffer, int msgid, Q_UINT32 receiver=0, Q_UINT32 sender=0);
00193
00197 bool sendSystemMessage(int data, int msgid, Q_UINT32 receiver=0, Q_UINT32 sender=0);
00198
00202 bool sendSystemMessage(const QDataStream &msg, int msgid, Q_UINT32 receiver=0, Q_UINT32 sender=0);
00203
00207 bool sendSystemMessage(const QString& msg, int msgid, Q_UINT32 receiver=0, Q_UINT32 sender=0);
00208
00220 void sendError(int error, const QByteArray& message, Q_UINT32 receiver=0, Q_UINT32 sender=0);
00221
00226 bool isOfferingConnections() const;
00227
00233 int cookie() const;
00234
00267
00268 bool sendMessage(const QByteArray& buffer, int msgid, Q_UINT32 receiver=0, Q_UINT32 sender=0);
00269
00273 bool sendMessage(const QDataStream &msg, int msgid, Q_UINT32 receiver=0, Q_UINT32 sender=0);
00274
00278 bool sendMessage(const QString& msg, int msgid, Q_UINT32 receiver=0, Q_UINT32 sender=0);
00279
00283 bool sendMessage(int data, int msgid, Q_UINT32 receiver=0, Q_UINT32 sender=0);
00284
00285
00290 virtual void networkTransmission(QDataStream&, int, Q_UINT32, Q_UINT32, Q_UINT32 clientID) = 0;
00291
00292
00296 void disconnect();
00297
00298
00307 void electAdmin(Q_UINT32 clientID);
00308
00317 KMessageClient* messageClient() const;
00318
00327 KMessageServer* messageServer() const;
00328
00335 virtual void lock();
00336
00340 virtual void unlock();
00341
00342 signals:
00348 void signalNetworkErrorMessage(int error, QString text);
00349
00354 void signalConnectionBroken();
00355
00365 void signalClientConnected(Q_UINT32 clientID);
00366
00378 void signalClientDisconnected(Q_UINT32 clientID, bool broken);
00379
00385 void signalAdminStatusChanged(bool isAdmin);
00386
00387 protected:
00394 void setMaster();
00395
00396 protected slots:
00404 void receiveNetworkTransmission(const QByteArray& a, Q_UINT32 clientID);
00405
00410 void slotAdminStatusChanged(bool isAdmin);
00411
00416 void aboutToLoseConnection(Q_UINT32 id);
00417
00422 void slotResetConnection();
00423
00424
00425 private:
00426 void tryPublish();
00427 void tryStopPublishing();
00428 KGameNetworkPrivate* d;
00429 };
00430
00431 #endif