libkdegames Library API Documentation

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., 59 Temple Place - Suite 330,
00018     Boston, MA 02111-1307, USA.
00019 */
00020 /*
00021     $Id: kgamenetwork.h 377450 2005-01-11 12:51:23Z mlaurent $
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 
00113     void setDiscoveryInfo(const QString& type, const QString& name=QString::null);
00114     
00123     bool connectToServer(const QString& host, Q_UINT16 port);
00124 
00131     Q_UINT16 port() const;
00132 
00139     QString hostName() const;
00140 
00145     bool stopServerConnection();
00146 
00157     void setMaxClients(int max);
00158 
00159     //AB: is this now internal only? Can we make it protected (maybe with
00160     //friends)? sendSystemMessage AND sendMessage is very confusing to the
00161     //user.
00181     // AB: TODO: doc on how "receiver" and "sender" should be created!
00182     bool sendSystemMessage(const QByteArray& buffer, int msgid, Q_UINT32 receiver=0, Q_UINT32 sender=0);
00183 
00187     bool sendSystemMessage(int data, int msgid, Q_UINT32 receiver=0, Q_UINT32 sender=0);
00188 
00192     bool sendSystemMessage(const QDataStream &msg, int msgid, Q_UINT32 receiver=0, Q_UINT32 sender=0);
00193 
00197     bool sendSystemMessage(const QString& msg, int msgid, Q_UINT32 receiver=0, Q_UINT32 sender=0);
00198 
00210     void sendError(int error, const QByteArray& message, Q_UINT32 receiver=0, Q_UINT32 sender=0);
00211 
00216     bool isOfferingConnections() const;
00217 
00223     int cookie() const;
00224 
00257     // AB: TODO: doc on how "receiver" and "sender" should be created!
00258     bool sendMessage(const QByteArray& buffer, int msgid, Q_UINT32 receiver=0, Q_UINT32 sender=0);
00259 
00263     bool sendMessage(const QDataStream &msg, int msgid, Q_UINT32 receiver=0, Q_UINT32 sender=0);
00264 
00268     bool sendMessage(const QString& msg, int msgid, Q_UINT32 receiver=0, Q_UINT32 sender=0);
00269 
00273     bool sendMessage(int data, int msgid, Q_UINT32 receiver=0, Q_UINT32 sender=0);
00274 
00275 
00280     virtual void networkTransmission(QDataStream&, int, Q_UINT32, Q_UINT32, Q_UINT32 clientID) = 0;
00281 
00282 
00286     void disconnect();
00287 
00288 
00297     void electAdmin(Q_UINT32 clientID);
00298 
00307     KMessageClient* messageClient() const;
00308 
00317     KMessageServer* messageServer() const;
00318 
00325     virtual void lock();
00326 
00330     virtual void unlock();
00331 
00332 signals:
00338     void signalNetworkErrorMessage(int error, QString text);
00339 
00344     void signalConnectionBroken();
00345 
00355     void signalClientConnected(Q_UINT32 clientID);
00356 
00368     void signalClientDisconnected(Q_UINT32 clientID, bool broken);
00369 
00375     void signalAdminStatusChanged(bool isAdmin);
00376 
00377 protected:
00384     void setMaster();
00385 
00386 protected slots:
00394     void receiveNetworkTransmission(const QByteArray& a, Q_UINT32 clientID);
00395 
00400     void slotAdminStatusChanged(bool isAdmin);
00401 
00406      void aboutToLoseConnection(Q_UINT32 id);
00407 
00412      void slotResetConnection();
00413 
00414 
00415 private:
00416      void tryPublish();
00417      void tryStopPublishing();
00418      KGameNetworkPrivate* d;
00419 };
00420 
00421 #endif
KDE Logo
This file is part of the documentation for libkdegames Library Version 3.4.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Mon Sep 12 05:17:50 2005 by doxygen 1.4.4 written by Dimitri van Heesch, © 1997-2003