KGameNetwork Class Reference
The KGameNetwork class is the KGame class with network support. The main KDE game object. More...
#include <kgamenetwork.h>
Inheritance diagram for KGameNetwork:

Signals | |
void | signalNetworkErrorMessage (int error, QString text) |
void | signalConnectionBroken () |
void | signalClientConnected (Q_UINT32 clientID) |
void | signalClientDisconnected (Q_UINT32 clientID, bool broken) |
void | signalAdminStatusChanged (bool isAdmin) |
Public Member Functions | |
KGameNetwork (int cookie=42, QObject *parent=0) | |
virtual void | Debug () |
bool | isNetwork () const |
bool | isMaster () const |
bool | isAdmin () const |
Q_UINT32 | gameId () const |
bool | offerConnections (Q_UINT16 port) |
bool | connectToServer (const QString &host, Q_UINT16 port) |
Q_UINT16 | port () const |
QString | hostName () const |
bool | stopServerConnection () |
void | setMaxClients (int max) |
bool | sendSystemMessage (const QByteArray &buffer, int msgid, Q_UINT32 receiver=0, Q_UINT32 sender=0) |
bool | sendSystemMessage (int data, int msgid, Q_UINT32 receiver=0, Q_UINT32 sender=0) |
bool | sendSystemMessage (const QDataStream &msg, int msgid, Q_UINT32 receiver=0, Q_UINT32 sender=0) |
bool | sendSystemMessage (const QString &msg, int msgid, Q_UINT32 receiver=0, Q_UINT32 sender=0) |
void | sendError (int error, const QByteArray &message, Q_UINT32 receiver=0, Q_UINT32 sender=0) |
bool | isOfferingConnections () const |
int | cookie () const |
bool | sendMessage (const QByteArray &buffer, int msgid, Q_UINT32 receiver=0, Q_UINT32 sender=0) |
bool | sendMessage (const QDataStream &msg, int msgid, Q_UINT32 receiver=0, Q_UINT32 sender=0) |
bool | sendMessage (const QString &msg, int msgid, Q_UINT32 receiver=0, Q_UINT32 sender=0) |
bool | sendMessage (int data, int msgid, Q_UINT32 receiver=0, Q_UINT32 sender=0) |
virtual void | networkTransmission (QDataStream &, int, Q_UINT32, Q_UINT32, Q_UINT32 clientID)=0 |
void | disconnect () |
void | electAdmin (Q_UINT32 clientID) |
KMessageClient * | messageClient () const |
KMessageServer * | messageServer () const |
virtual void | lock () |
virtual void | unlock () |
Protected Slots | |
void | receiveNetworkTransmission (const QByteArray &a, Q_UINT32 clientID) |
void | slotAdminStatusChanged (bool isAdmin) |
void | aboutToLoseConnection (Q_UINT32 id) |
void | slotResetConnection () |
Protected Member Functions | |
void | setMaster () |
Detailed Description
The KGameNetwork class is the KGame class with network support. The main KDE game object.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.
- Author:
- Martin Heni <martin@heni-online.de>
- Version:
- Id
- kgamenetwork.h,v 1.29 2003/10/12 13:32:56 bhards Exp
Definition at line 46 of file kgamenetwork.h.
Constructor & Destructor Documentation
|
Create a KGameNetwork object. Definition at line 57 of file kgamenetwork.cpp. References cookie(). |
Member Function Documentation
|
Gives debug output of the game status.
Reimplemented in KGame. Definition at line 472 of file kgamenetwork.cpp. References gameId(), isAdmin(), and isMaster(). Referenced by KGame::Debug(). |
|
References isOfferingConnections(). Referenced by port(). |
|
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
Referenced by Debug(), and offerConnections(). |
|
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.
Referenced by Debug(), electAdmin(), KGame::negotiateNetworkGame(), setMaxClients(), KGame::setMaxPlayers(), KGame::setMinPlayers(), KGame::slotClientConnected(), KGame::systemActivatePlayer(), and KGame::systemInactivatePlayer(). |
|
The unique ID of this game.
Referenced by Debug(), disconnect(), KPlayer::networkTransmission(), KGame::networkTransmission(), receiveNetworkTransmission(), sendSystemMessage(), and KGame::slotServerDisconnected(). |
|
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.
References isMaster(). |
|
Inits a network game as a network CLIENT.
References signalAdminStatusChanged(), and stopServerConnection(). |
|
References isNetwork(), and isOfferingConnections(). |
|
|
|
Stops offering server connections - only for game MASTER.
Referenced by connectToServer(), and disconnect(). |
|
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!
References isAdmin(). |
|
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!
References gameId(). Referenced by KGame::activatePlayer(), KGame::addPlayer(), KPlayer::forwardMessage(), KGame::inactivatePlayer(), KGame::negotiateNetworkGame(), KGame::networkTransmission(), KGame::playerDeleted(), sendError(), sendMessage(), KGame::sendPlayerInput(), KGame::sendPlayerProperty(), KGame::sendProperty(), sendSystemMessage(), and KGame::syncRandom(). |
|
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 344 of file kgamenetwork.cpp. References sendSystemMessage(). |
|
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 360 of file kgamenetwork.cpp. References sendSystemMessage(). |
|
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 352 of file kgamenetwork.cpp. References sendSystemMessage(). |
|
Sends a network message.
References sendSystemMessage(). Referenced by KGame::networkTransmission(). |
|
Are we still offer offering server connections - only for game MASTER.
Referenced by isNetwork(), and port(). |
|
Application cookie. this idendifies the game application. It help to distinguish between e.g. KPoker and KWin4
Referenced by KGameNetwork(), KGame::loadgame(), KGame::negotiateNetworkGame(), KGame::networkTransmission(), and KGame::savegame(). |
|
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!
References sendSystemMessage(). Referenced by KGame::sendGroupMessage(). |
|
This is an overloaded member function, provided for convenience. Definition at line 411 of file kgamenetwork.cpp. References sendSystemMessage(). |
|
This is an overloaded member function, provided for convenience. Definition at line 408 of file kgamenetwork.cpp. References sendSystemMessage(). |
|
This is an overloaded member function, provided for convenience. Definition at line 405 of file kgamenetwork.cpp. References sendSystemMessage(). |
|
Called by ReceiveNetworkTransmission(). Will be overwritten by KGame and handle the incoming message. Implemented in KGame.
Referenced by receiveNetworkTransmission(). |
|
Disconnect the current connection and establish a new local one. Definition at line 240 of file kgamenetwork.cpp. References gameId(), KMessageIO::rtti(), and stopServerConnection(). Referenced by KGame::networkTransmission(). |
|
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).
References isAdmin(). |
|
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!
|
|
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!
|
|
You should call this before doing thigs like, e.g. qApp->processEvents(). Don't forget to call unlock once you are done!
References KMessageClient::lock(), and messageClient(). |
|
References messageClient(), and KMessageClient::unlock(). |
|
A network error occurred.
Referenced by receiveNetworkTransmission(). |
|
Our connection to the KMessageServer has broken. See KMessageClient::connectionBroken Referenced by KGame::KGame(). |
|
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)
Referenced by KGame::KGame(). |
|
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.
Referenced by KGame::KGame(). |
|
This client gets or loses the admin status.
Referenced by connectToServer(), and slotAdminStatusChanged(). |
|
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 428 of file kgamenetwork.cpp. References gameId(), networkTransmission(), and signalNetworkErrorMessage(). |
|
This KGame object receives or loses the admin status.
References signalAdminStatusChanged(). |
|
Called when the network connection is about to terminate. Is used to store the network parameter like the game id Definition at line 290 of file kgamenetwork.cpp. |
|
Called when the network connection is terminated. Used to clean up the disconnect parameter Definition at line 296 of file kgamenetwork.cpp. |
The documentation for this class was generated from the following files: