kgamenetwork.h

00001 /*
00002     This file is part of the KDE games library
00003     Copyright (C) 2001 Martin Heni (martin@heni-online.de)
00004     Copyright (C) 2001 Andreas Beckermann (b_mann@gmx.de)
00005 
00006     This library is free software; you can redistribute it and/or
00007     modify it under the terms of the GNU Library General Public
00008     License version 2 as published by the Free Software Foundation.
00009 
00010     This library is distributed in the hope that it will be useful,
00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013     Library General Public License for more details.
00014 
00015     You should have received a copy of the GNU Library General Public License
00016     along with this library; see the file COPYING.LIB.  If not, write to
00017     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00018     Boston, MA 02110-1301, USA.
00019 */
00020 /*
00021     $Id: kgamenetwork.h 465369 2005-09-29 14:33:08Z mueller $
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     //AB: is this now internal only? Can we make it protected (maybe with
00170     //friends)? sendSystemMessage AND sendMessage is very confusing to the
00171     //user.
00191     // AB: TODO: doc on how "receiver" and "sender" should be created!
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     // AB: TODO: doc on how "receiver" and "sender" should be created!
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
KDE Home | KDE Accessibility Home | Description of Access Keys