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$ 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 TQ_OBJECT 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 //AB: is this now internal only? Can we make it protected (maybe with 00171 //friends)? sendSystemMessage AND sendMessage is very confusing to the 00172 //user. 00192 // AB: TODO: doc on how "receiver" and "sender" should be created! 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 // AB: TODO: doc on how "receiver" and "sender" should be created! 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