• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • libtdegames
 

libtdegames

  • libtdegames
  • kgame
kmessageserver.h
1 /*
2  This file is part of the TDE games library
3  Copyright (C) 2001 Burkhard Lehner (Burkhard.Lehner@gmx.de)
4 
5  This library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Library General Public
7  License version 2 as published by the Free Software Foundation.
8 
9  This library is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  Library General Public License for more details.
13 
14  You should have received a copy of the GNU Library General Public License
15  along with this library; see the file COPYING.LIB. If not, write to
16  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  Boston, MA 02110-1301, USA.
18 */
19 
20 #ifndef __KMESSAGESERVER_H__
21 #define __KMESSAGESERVER_H__
22 
23 #include <tqobject.h>
24 #include <tqserversocket.h>
25 #include <tqstring.h>
26 #include <tqvaluelist.h>
27 
28 class KMessageIO;
29 class KMessageServerPrivate;
30 
175 class KMessageServer : public TQObject
176 {
177  TQ_OBJECT
178 
179 
180 public:
184  enum {
185  REQ_BROADCAST = 1,
186  REQ_FORWARD,
187  REQ_CLIENT_ID,
188  REQ_ADMIN_ID,
189  REQ_ADMIN_CHANGE,
190  REQ_REMOVE_CLIENT,
191  REQ_MAX_NUM_CLIENTS,
192  REQ_CLIENT_LIST,
193  REQ_MAX_REQ = 0xffff };
194 
198  enum {
199  MSG_BROADCAST = 101,
200  MSG_FORWARD,
201  ANS_CLIENT_ID,
202  ANS_ADMIN_ID,
203  ANS_CLIENT_LIST,
204  EVNT_CLIENT_CONNECTED,
205  EVNT_CLIENT_DISCONNECTED,
206  EVNT_MAX_EVNT = 0xffff
207  };
208 
212  KMessageServer(TQ_UINT16 cookie = 42, TQObject* parent = 0);
213 
214  ~KMessageServer();
215 
219  virtual void Debug();
220 
221 //---------------------------------- TCP/IP server stuff
222 
230  bool initNetwork (TQ_UINT16 port = 0);
231 
238  TQ_UINT16 serverPort () const;
239 
245  void stopNetwork();
246 
251  bool isOfferingConnections() const;
252 
253 //---------------------------------- adding / removing clients
254 
255 public slots:
269  void addClient (KMessageIO *);
270 
282  void removeClient (KMessageIO *io, bool broken);
283 
287  void deleteClients();
288 
289 private slots:
296  void removeBrokenClient ();
297 
298 public:
310  void setMaxClients(int maxnumber);
311 
317  int maxClients() const;
318 
324  int clientCount() const;
325 
329  TQValueList <TQ_UINT32> clientIDs() const;
330 
336  KMessageIO *findClient (TQ_UINT32 no) const;
337 
344  TQ_UINT32 adminID() const;
345 
351  void setAdmin (TQ_UINT32 adminID);
352 
353 
354 //------------------------------ ID stuff
355 
356  /*
357  * The unique ID of this game
358  *
359  * @return int id
360  **/
361 // int gameId() const;
362 
363  /*
364  * Application cookie. this idendifies the game application. It
365  * help to distinguish between e.g. KPoker and KWin4
366  *
367  * @return the application cookie
368  **/
369 // int cookie() const;
370 
371 //------------------------------ Message stuff
372 
373 public:
379  virtual void broadcastMessage (const TQByteArray &msg);
380 
389  virtual void sendMessage (TQ_UINT32 id, const TQByteArray &msg);
390 
398  virtual void sendMessage (const TQValueList <TQ_UINT32> &ids, const TQByteArray &msg);
399 
400 protected slots:
410  virtual void getReceivedMessage (const TQByteArray &msg);
411 
420  virtual void processOneMessage ();
421 
422 //---------------------------- Signals
423 
424 signals:
429  void clientConnected (KMessageIO *client);
430 
438  void connectionLost (KMessageIO *client);
439 
452  void messageReceived (const TQByteArray &data, TQ_UINT32 clientID, bool &unknown);
453 
454 protected:
460  TQ_UINT32 uniqueClientNumber() const;
461 
462 private:
463  KMessageServerPrivate* d;
464 };
465 
466 
477 class KMessageServerSocket : public TQServerSocket
478 {
479  TQ_OBJECT
480 
481 
482 public:
483  KMessageServerSocket (TQ_UINT16 port, TQObject *parent = 0);
484  ~KMessageServerSocket ();
485 
486  void newConnection (int socket);
487 
488 signals:
489  void newClientConnected (KMessageIO *client);
490 };
491 
492 
493 
494 #endif
KMessageServer::uniqueClientNumber
TQ_UINT32 uniqueClientNumber() const
Definition: kmessageserver.cpp:335
KMessageServer::findClient
KMessageIO * findClient(TQ_UINT32 no) const
Find the KMessageIO object to the given client number.
Definition: kmessageserver.cpp:291
KMessageServer::serverPort
TQ_UINT16 serverPort() const
Returns the TCP/IP port number we are listening to for incoming connections.
Definition: kmessageserver.cpp:146
KMessageServer::clientCount
int clientCount() const
returns the current number of connected clients.
Definition: kmessageserver.cpp:278
KMessageServer::Debug
virtual void Debug()
Gives debug output of the game status.
Definition: kmessageserver.cpp:503
KMessageServer::removeClient
void removeClient(KMessageIO *io, bool broken)
Removes the KMessageIO object from the client list and deletes it.
Definition: kmessageserver.cpp:223
KMessageServerSocket
Internal class of KMessageServer.
Definition: kmessageserver.h:477
KMessageServer::addClient
void addClient(KMessageIO *)
Adds a new KMessageIO object to the communication server.
Definition: kmessageserver.cpp:170
KMessageServer::clientConnected
void clientConnected(KMessageIO *client)
A new client connected to the game.
KMessageServer::deleteClients
void deleteClients()
Deletes all connections to the clients.
Definition: kmessageserver.cpp:247
KMessageServer::adminID
TQ_UINT32 adminID() const
Returns the clientID of the admin, if there is a admin, 0 otherwise.
Definition: kmessageserver.cpp:306
KMessageServer::KMessageServer
KMessageServer(TQ_UINT16 cookie=42, TQObject *parent=0)
Create a KGameNetwork object.
Definition: kmessageserver.cpp:89
KMessageServer::messageReceived
void messageReceived(const TQByteArray &data, TQ_UINT32 clientID, bool &unknown)
This signal is always emitted when a message from a client is received.
KMessageIO
This abstract base class represents one end of a message connections between two clients.
Definition: kmessageio.h:56
KMessageServer::initNetwork
bool initNetwork(TQ_UINT16 port=0)
Starts the Communication server to listen for incoming TCP/IP connections.
Definition: kmessageserver.cpp:118
KMessageServer
A server for message sending and broadcasting, using TCP/IP connections.
Definition: kmessageserver.h:175
KMessageServer::setAdmin
void setAdmin(TQ_UINT32 adminID)
Sets the admin to a new client with the given ID.
Definition: kmessageserver.cpp:311
KMessageServer::getReceivedMessage
virtual void getReceivedMessage(const TQByteArray &msg)
This slot receives all the messages from the KMessageIO::received signals.
Definition: kmessageserver.cpp:361
KMessageServer::processOneMessage
virtual void processOneMessage()
This slot is called whenever there are elements in the message queue.
Definition: kmessageserver.cpp:382
KMessageServer::sendMessage
virtual void sendMessage(TQ_UINT32 id, const TQByteArray &msg)
Sends a message to a single client with the given ID.
Definition: kmessageserver.cpp:348
KMessageServer::clientIDs
TQValueList< TQ_UINT32 > clientIDs() const
returns a list of the unique IDs of all clients.
Definition: kmessageserver.cpp:283
KMessageServer::broadcastMessage
virtual void broadcastMessage(const TQByteArray &msg)
Sends a message to all connected clients.
Definition: kmessageserver.cpp:342
KMessageServer::isOfferingConnections
bool isOfferingConnections() const
Are we still offer offering server connections?
Definition: kmessageserver.cpp:163
KMessageServer::maxClients
int maxClients() const
returns the maximum number of clients
Definition: kmessageserver.cpp:273
KMessageServer::connectionLost
void connectionLost(KMessageIO *client)
A network connection got broken.
KMessageServer::setMaxClients
void setMaxClients(int maxnumber)
sets the maximum number of clients which can connect.
Definition: kmessageserver.cpp:268
KMessageServer::stopNetwork
void stopNetwork()
Stops listening for connections.
Definition: kmessageserver.cpp:154

libtdegames

Skip menu "libtdegames"
  • Main Page
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

libtdegames

Skip menu "libtdegames"
  • libtdegames
Generated for libtdegames by doxygen 1.8.13
This website is maintained by Timothy Pearson.