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

libtdegames

Signals | Public Member Functions | Protected Slots | Protected Member Functions | List of all members
KGameNetwork Class Referenceabstract

#include <kgamenetwork.h>

Inheritance diagram for KGameNetwork:
KGame

Signals

void signalNetworkErrorMessage (int error, TQString text)
 
void signalConnectionBroken ()
 
void signalClientConnected (TQ_UINT32 clientID)
 
void signalClientDisconnected (TQ_UINT32 clientID, bool broken)
 
void signalAdminStatusChanged (bool isAdmin)
 

Public Member Functions

 KGameNetwork (int cookie=42, TQObject *parent=0)
 
virtual void Debug ()
 
bool isNetwork () const
 
bool isMaster () const
 
bool isAdmin () const
 
TQ_UINT32 gameId () const
 
bool offerConnections (TQ_UINT16 port)
 
void setDiscoveryInfo (const TQString &type, const TQString &name=TQString())
 
bool connectToServer (const TQString &host, TQ_UINT16 port)
 
TQ_UINT16 port () const
 
TQString hostName () const
 
bool stopServerConnection ()
 
void setMaxClients (int max)
 
bool sendSystemMessage (const TQByteArray &buffer, int msgid, TQ_UINT32 receiver=0, TQ_UINT32 sender=0)
 
bool sendSystemMessage (int data, int msgid, TQ_UINT32 receiver=0, TQ_UINT32 sender=0)
 
bool sendSystemMessage (const TQDataStream &msg, int msgid, TQ_UINT32 receiver=0, TQ_UINT32 sender=0)
 
bool sendSystemMessage (const TQString &msg, int msgid, TQ_UINT32 receiver=0, TQ_UINT32 sender=0)
 
void sendError (int error, const TQByteArray &message, TQ_UINT32 receiver=0, TQ_UINT32 sender=0)
 
bool isOfferingConnections () const
 
int cookie () const
 
bool sendMessage (const TQByteArray &buffer, int msgid, TQ_UINT32 receiver=0, TQ_UINT32 sender=0)
 
bool sendMessage (const TQDataStream &msg, int msgid, TQ_UINT32 receiver=0, TQ_UINT32 sender=0)
 
bool sendMessage (const TQString &msg, int msgid, TQ_UINT32 receiver=0, TQ_UINT32 sender=0)
 
bool sendMessage (int data, int msgid, TQ_UINT32 receiver=0, TQ_UINT32 sender=0)
 
virtual void networkTransmission (TQDataStream &, int, TQ_UINT32, TQ_UINT32, TQ_UINT32 clientID)=0
 
void disconnect ()
 
void electAdmin (TQ_UINT32 clientID)
 
KMessageClient * messageClient () const
 
KMessageServer * messageServer () const
 
virtual void lock ()
 
virtual void unlock ()
 

Protected Slots

void receiveNetworkTransmission (const TQByteArray &a, TQ_UINT32 clientID)
 
void slotAdminStatusChanged (bool isAdmin)
 
void aboutToLoseConnection (TQ_UINT32 id)
 
void slotResetConnection ()
 

Protected Member Functions

void setMaster ()
 

Detailed Description

The KGameNetwork class is the KGame class with network support.

All other features are the same but they are now network transparent. It is not used directly but only via a KGame object. So you do not really have to bother with this object.

The main KDE game object

Author
Martin Heni marti.nosp@m.n@he.nosp@m.ni-on.nosp@m.line.nosp@m..de
Version
$Id$

Definition at line 46 of file kgamenetwork.h.

Constructor & Destructor Documentation

◆ KGameNetwork()

KGameNetwork::KGameNetwork ( int  cookie = 42,
TQObject *  parent = 0 
)

Create a KGameNetwork object.

Definition at line 62 of file kgamenetwork.cpp.

◆ ~KGameNetwork()

KGameNetwork::~KGameNetwork ( )
virtual

Definition at line 74 of file kgamenetwork.cpp.

Member Function Documentation

◆ aboutToLoseConnection

void KGameNetwork::aboutToLoseConnection ( TQ_UINT32  id)
protectedslot

Called when the network connection is about to terminate.

Is used to store the network parameter like the game id

Definition at line 323 of file kgamenetwork.cpp.

◆ connectToServer()

bool KGameNetwork::connectToServer ( const TQString &  host,
TQ_UINT16  port 
)

Inits a network game as a network CLIENT.

Parameters
hostthe host to which we want to connect
portthe port we want to connect to
Returns
true if connected

}

Definition at line 204 of file kgamenetwork.cpp.

◆ cookie()

int KGameNetwork::cookie ( ) const

Application cookie.

this idendifies the game application. It help to distinguish between e.g. KPoker and KWin4

Returns
the application cookie

Definition at line 98 of file kgamenetwork.cpp.

◆ Debug()

void KGameNetwork::Debug ( )
virtual

Gives debug output of the game status.

Reimplemented in KGame.

Definition at line 505 of file kgamenetwork.cpp.

◆ disconnect()

void KGameNetwork::disconnect ( )

Disconnect the current connection and establish a new local one.

Definition at line 273 of file kgamenetwork.cpp.

◆ electAdmin()

void KGameNetwork::electAdmin ( TQ_UINT32  clientID)

If you are the ADMIN of the game you can give the ADMIN status away to another client.

Use this e.g. if you want to quit the game or if you want another client to administrate the game (note that disconnect calls this automatically).

Parameters
clientIDthe ID of the new ADMIN (note: this is the _client_ID which has nothing to do with the player IDs. See KMessageServer)

Definition at line 335 of file kgamenetwork.cpp.

◆ gameId()

TQ_UINT32 KGameNetwork::gameId ( ) const

The unique ID of this game.

Returns
int id

Definition at line 86 of file kgamenetwork.cpp.

◆ hostName()

TQString KGameNetwork::hostName ( ) const
Since
3.2
Returns
The name of the host that we are currently connected to is isNetwork is true and we are not the MASTER, i.e. if connectToServer was called. Otherwise this will return "localhost".

Definition at line 254 of file kgamenetwork.cpp.

◆ isAdmin()

bool KGameNetwork::isAdmin ( ) const

The admin of a game is the one who initializes newly connected clients using negotiateNetworkGame and is allowed to configure the game.

E.g. only the admin is allowed to use KGame::setMaxPlayers.

If one KGame object in the game is MASTER then this client is the admin as well. isMaster and isAdmin differ only if the KMessageServer is running in an own process.

Returns
Whether this client (KGame object) is the admin

Definition at line 104 of file kgamenetwork.cpp.

◆ isMaster()

bool KGameNetwork::isMaster ( ) const

Is this the game MASTER (i.e.

has started theKMessageServer). A game has always exactly one MASTER. This is either a KGame object (i.e. a Client) or an own MessageServer-process. A KGame object that has the MASTER status is always admin.

You probably don't want to use this. It is a mostly internal method which will probably become protected. Better use isAdmin

See also
isAdmin
Returns
Whether this client has started the KMessageServer

Definition at line 101 of file kgamenetwork.cpp.

◆ isNetwork()

bool KGameNetwork::isNetwork ( ) const
Returns
true if this is a network game - i.e. you are either MASTER or connected to a remote MASTER.

Definition at line 83 of file kgamenetwork.cpp.

◆ isOfferingConnections()

bool KGameNetwork::isOfferingConnections ( ) const

Are we still offer offering server connections - only for game MASTER.

Returns
true/false

Definition at line 270 of file kgamenetwork.cpp.

◆ lock()

void KGameNetwork::lock ( )
virtual

You should call this before doing thigs like, e.g.

tqApp->processEvents(). Don't forget to call unlock once you are done!

See also
KMessageClient::lock

Definition at line 361 of file kgamenetwork.cpp.

◆ messageClient()

KMessageClient * KGameNetwork::messageClient ( ) const

Don't use this unless you really know what youre doing! You might experience some strange behaviour if you send your messages directly through the KMessageClient!

Returns
a pointer to the KMessageClient used internally to send the messages. You should rather use one of the send functions!

Definition at line 107 of file kgamenetwork.cpp.

◆ messageServer()

KMessageServer * KGameNetwork::messageServer ( ) const

Don't use this unless you really know what you are doing! You might experience some strange behaviour if you use the message server directly!

Returns
a pointer to the message server if this is the MASTER KGame object. Note that it might be possible that no KGame object contains the KMessageServer at all! It might even run stand alone!

Definition at line 110 of file kgamenetwork.cpp.

◆ networkTransmission()

virtual void KGameNetwork::networkTransmission ( TQDataStream &  ,
int  ,
TQ_UINT32  ,
TQ_UINT32  ,
TQ_UINT32  clientID 
)
pure virtual

Called by ReceiveNetworkTransmission().

Will be overwritten by KGame and handle the incoming message.

Implemented in KGame.

◆ offerConnections()

bool KGameNetwork::offerConnections ( TQ_UINT16  port)

Inits a network game as network MASTER.

Note that if the KMessageServer is not yet started it will be started here (see setMaster). Any existing connection will be disconnected.

If you already offer connections the port is changed.

Parameters
portThe port on which the service is offered
Returns
true if it worked

Definition at line 174 of file kgamenetwork.cpp.

◆ port()

TQ_UINT16 KGameNetwork::port ( ) const
Since
3.2
Returns
The port we are listening to if offerConnections was called or the port we are connected to if connectToServer was called. Otherwise 0.

Definition at line 242 of file kgamenetwork.cpp.

◆ receiveNetworkTransmission

void KGameNetwork::receiveNetworkTransmission ( const TQByteArray &  a,
TQ_UINT32  clientID 
)
protectedslot

Called by KMessageClient::broadcastReceived() and will check if the message format is valid.

If it is not, it will generate an error (see signalNetworkVersionError and signalNetworkErorrMessage). If it is valid, the pure virtual method networkTransmission() is called. (This one is overwritten in KGame.)

Definition at line 461 of file kgamenetwork.cpp.

◆ sendError()

void KGameNetwork::sendError ( int  error,
const TQByteArray &  message,
TQ_UINT32  receiver = 0,
TQ_UINT32  sender = 0 
)

Sends a network message.

Parameters
errorThe error code
messageThe error message - use KGameError
receiverthe KGame / KPlayer this message is for. 0 For all
senderThe KGame / KPlayer this message is from (i.e. you). You probably want to leave this 0, then KGameNetwork will create the correct value for you. You might want to use this if you send a message from a specific player.

Definition at line 450 of file kgamenetwork.cpp.

◆ sendMessage() [1/4]

bool KGameNetwork::sendMessage ( const TQByteArray &  buffer,
int  msgid,
TQ_UINT32  receiver = 0,
TQ_UINT32  sender = 0 
)

Send a network message msg with a given message ID msgid to all clients.

You want to use this to send a message to the clients.

Note that a message is always sent to ALL clients! This is necessary so that all clients always have the same data and can easily be changed from network to non-network without restarting the game. If you want a specific KGame / KPlayer to react to the message use the receiver and sender parameters. See KGameMessage::calsMessageId

SendMessage differs from sendSystemMessage only by the msgid parameter. sendSystemMessage is thought as a KGame only mehtod while sendMessage is for public use. The msgid parameter will be +=KGameMessage::IdUser and in KGame::signalNetworkData msgid will be -= KGameMessage::IdUser again, so that one can easily distinguish between system and user messages.

Use sendSystemMessage to comunicate with KGame (e.g. by adding a player) and sendMessage for your own user message.

Note: a player should send messages through a KGameIO!

Parameters
bufferthe message which will be send. See messages.txt for contents
msgidan id for this message. See KGameMessage::GameMessageIds
receiverthe KGame / KPlayer this message is for.
senderThe KGame / KPlayer this message is from (i.e. you). You probably want to leave this 0, then KGameNetwork will create the correct value for you. You might want to use this if you send a message from a specific player.
Returns
true if worked

Definition at line 447 of file kgamenetwork.cpp.

◆ sendMessage() [2/4]

bool KGameNetwork::sendMessage ( const TQDataStream &  msg,
int  msgid,
TQ_UINT32  receiver = 0,
TQ_UINT32  sender = 0 
)

This is an overloaded member function, provided for convenience.

Definition at line 444 of file kgamenetwork.cpp.

◆ sendMessage() [3/4]

bool KGameNetwork::sendMessage ( const TQString &  msg,
int  msgid,
TQ_UINT32  receiver = 0,
TQ_UINT32  sender = 0 
)

This is an overloaded member function, provided for convenience.

Definition at line 441 of file kgamenetwork.cpp.

◆ sendMessage() [4/4]

bool KGameNetwork::sendMessage ( int  data,
int  msgid,
TQ_UINT32  receiver = 0,
TQ_UINT32  sender = 0 
)

This is an overloaded member function, provided for convenience.

Definition at line 438 of file kgamenetwork.cpp.

◆ sendSystemMessage() [1/4]

bool KGameNetwork::sendSystemMessage ( const TQByteArray &  buffer,
int  msgid,
TQ_UINT32  receiver = 0,
TQ_UINT32  sender = 0 
)

Sends a network message msg with a given msg id msgid to all clients.

Use this to communicate with KGame (e.g. to add a player ot to configure the game - usually not necessary).

For your own messages use sendMessage instead! This is mostly internal!

Parameters
bufferthe message which will be send. See messages.txt for contents
msgidan id for this message. See KGameMessage::GameMessageIds
receiverthe KGame / KPlayer this message is for.
senderThe KGame / KPlayer this message is from (i.e. you). You probably want to leave this 0, then KGameNetwork will create the correct value for you. You might want to use this if you send a message from a specific player.
Returns
true if worked

Definition at line 396 of file kgamenetwork.cpp.

◆ sendSystemMessage() [2/4]

bool KGameNetwork::sendSystemMessage ( const TQDataStream &  msg,
int  msgid,
TQ_UINT32  receiver = 0,
TQ_UINT32  sender = 0 
)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 393 of file kgamenetwork.cpp.

◆ sendSystemMessage() [3/4]

bool KGameNetwork::sendSystemMessage ( const TQString &  msg,
int  msgid,
TQ_UINT32  receiver = 0,
TQ_UINT32  sender = 0 
)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 385 of file kgamenetwork.cpp.

◆ sendSystemMessage() [4/4]

bool KGameNetwork::sendSystemMessage ( int  data,
int  msgid,
TQ_UINT32  receiver = 0,
TQ_UINT32  sender = 0 
)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 377 of file kgamenetwork.cpp.

◆ setDiscoveryInfo()

void KGameNetwork::setDiscoveryInfo ( const TQString &  type,
const TQString &  name = TQString() 
)

Announces game MASTER on network using DNS-SD.

Clients then can discover it using DNSSD::ServiceBrowser (or KGameConnectWidget) instead of manually entering IP address.

Parameters
typeservice type (something like _twin4._tcp). It should be unique for application.
namegame name that will be displayed by clients. If not set hostname will be used. In case of name conflict -2, -3 and so on will be added to name.
Since
3.4

Definition at line 150 of file kgamenetwork.cpp.

◆ setMaster()

void KGameNetwork::setMaster ( )
protected

Definition at line 114 of file kgamenetwork.cpp.

◆ setMaxClients()

void KGameNetwork::setMaxClients ( int  max)

Changes the maximal connection number of the KMessageServer to max.

-1 Means infinite connections are possible. Note that existing connections are not affected, so even if you set this to 0 in a running game no client is being disconnected. You can call this only if you are the ADMIN!

See also
KMessageServer::setMaxClients
Parameters
maxThe maximal number of connections possible.

Definition at line 348 of file kgamenetwork.cpp.

◆ signalAdminStatusChanged

void KGameNetwork::signalAdminStatusChanged ( bool  isAdmin)
signal

This client gets or loses the admin status.

See also
KMessageClient::adminStatusChanged
Parameters
isAdminTrue if this client gets the ADMIN status otherwise false

◆ signalClientConnected

void KGameNetwork::signalClientConnected ( TQ_UINT32  clientID)
signal

This signal is emitted whenever the KMessageServer sends us a message that a new client connected.

KGame uses this to call KGame::negotiateNetworkGame for the newly connected client if we are admin (see isAdmin)

See also
KMessageClient::eventClientConnected
Parameters
clientIDthe ID of the newly connected client

◆ signalClientDisconnected

void KGameNetwork::signalClientDisconnected ( TQ_UINT32  clientID,
bool  broken 
)
signal

This signal is emitted whenever the KMessageServer sends us a message that a connection to a client was detached.

The second parameter can be used to distinguish between network errors or removing on purpose.

See also
KMessageClient::eventClientDisconnected
Parameters
clientIDthe client that has disconnected
brokentrue if the connection was lost because of a network error, false if the connection was closed by the message server admin.

◆ signalConnectionBroken

void KGameNetwork::signalConnectionBroken ( )
signal

Our connection to the KMessageServer has broken.

See KMessageClient::connectionBroken

◆ signalNetworkErrorMessage

void KGameNetwork::signalNetworkErrorMessage ( int  error,
TQString  text 
)
signal

A network error occurred.

Parameters
errorthe error code
textthe error text

◆ slotAdminStatusChanged

void KGameNetwork::slotAdminStatusChanged ( bool  isAdmin)
protectedslot

This KGame object receives or loses the admin status.

Parameters
isAdminWhether we are admin or not

Definition at line 498 of file kgamenetwork.cpp.

◆ slotResetConnection

void KGameNetwork::slotResetConnection ( )
protectedslot

Called when the network connection is terminated.

Used to clean up the disconnect parameter

Definition at line 329 of file kgamenetwork.cpp.

◆ stopServerConnection()

bool KGameNetwork::stopServerConnection ( )

Stops offering server connections - only for game MASTER.

Returns
true

Definition at line 259 of file kgamenetwork.cpp.

◆ unlock()

void KGameNetwork::unlock ( )
virtual
See also
KMessageClient::unlock

Definition at line 368 of file kgamenetwork.cpp.


The documentation for this class was generated from the following files:
  • kgamenetwork.h
  • kgamenetwork.cpp

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.9.4
This website is maintained by Timothy Pearson.