KDEGames
kgamenetwork.cpp
56 qCDebug(GAMES_PRIVATE_KGAME) << "this=" << this << ", cookie=" << cookie() << "sizeof(this)=" << sizeof(KGameNetwork);
119 connect(d->mMessageClient, &KMessageClient::broadcastReceived, this, &KGameNetwork::receiveNetworkTransmission);
120 connect(d->mMessageClient, &KMessageClient::connectionBroken, this, &KGameNetwork::signalConnectionBroken);
121 connect(d->mMessageClient, &KMessageClient::aboutToDisconnect, this, &KGameNetwork::aboutToLoseConnection);
122 connect(d->mMessageClient, &KMessageClient::connectionBroken, this, &KGameNetwork::slotResetConnection);
124 connect(d->mMessageClient, &KMessageClient::adminStatusChanged, this, &KGameNetwork::slotAdminStatusChanged);
125 connect(d->mMessageClient, &KMessageClient::eventClientConnected, this, &KGameNetwork::signalClientConnected);
126 connect(d->mMessageClient, &KMessageClient::eventClientDisconnected, this, &KGameNetwork::signalClientDisconnected);
129 connect(d->mMessageClient, &KMessageClient::forwardReceived, d->mMessageClient, &KMessageClient::broadcastReceived);
224 qCWarning(GAMES_PRIVATE_KGAME) << "we are server but we are trying to connect to another server! "
235 Q_EMIT signalAdminStatusChanged(false); // as we delete the connection above isAdmin() is always false now!
383 bool KGameNetwork::sendSystemMessage(const QString &msg, int msgid, quint32 receiver, quint32 sender)
391 bool KGameNetwork::sendSystemMessage(const QDataStream &msg, int msgid, quint32 receiver, quint32 sender)
396 bool KGameNetwork::sendSystemMessage(const QByteArray &data, int msgid, quint32 receiver, quint32 sender)
445 bool KGameNetwork::sendMessage(const QDataStream &msg, int msgid, quint32 receiver, quint32 sender)
450 bool KGameNetwork::sendMessage(const QByteArray &msg, int msgid, quint32 receiver, quint32 sender)
455 void KGameNetwork::sendError(int error, const QByteArray &message, quint32 receiver, quint32 sender)
465 void KGameNetwork::receiveNetworkTransmission(const QByteArray &receiveBuffer, quint32 clientID)
472 // qCDebug(GAMES_PRIVATE_KGAME) << "id=" << msgid << "sender=" << sender << "recv=" << receiver;
479 qCDebug(GAMES_PRIVATE_KGAME) << "Message not meant for us " << gameId() << "!=" << receiver << "rawid=" << KGameMessage::rawGameId(receiver);
static bool isPlayer(quint32 id)
Checks whether a message receiver/sender is a player.
Definition: kgamemessage.cpp:34
void slotResetConnection()
Called when the network connection is terminated.
Definition: kgamenetwork.cpp:327
void signalAdminStatusChanged(bool isAdmin)
This client gets or loses the admin status.
bool stopServerConnection()
Stops offering server connections - only for game MASTER.
Definition: kgamenetwork.cpp:262
Definition: kmessageio.h:49
KMessageClient * messageClient() const
Don't use this unless you really know what you're doing! You might experience some strange behaviour ...
Definition: kgamenetwork.cpp:99
WriteOnly
void forwardReceived(const QByteArray &msg, quint32 senderID, const QList< quint32 > &receivers)
This signal is emitted when the client receives a forward message from the KMessageServer,...
int size() const const
Q_EMITQ_EMIT
static int rawPlayerId(quint32 playerid)
Returns the raw playerid, that is, a id which does not contain the game number encoded in it.
Definition: kgamemessage.cpp:24
KMessageServer * messageServer() const
Don't use this unless you really know what you are doing! You might experience some strange behaviour...
Definition: kgamenetwork.cpp:104
void connectionBroken()
This signal is emitted when the connection to the KMessageServer is broken.
bool sendMessage(const QByteArray &buffer, int msgid, quint32 receiver=0, quint32 sender=0)
Send a network message msg with a given message ID msgid to all clients.
Definition: kgamenetwork.cpp:450
QIODevice * device() const const
QObject * sender() const const
void signalConnectionBroken()
Our connection to the KMessageServer has broken.
void aboutToLoseConnection(quint32 id)
Called when the network connection is about to terminate.
Definition: kgamenetwork.cpp:321
QByteArray toLatin1() const const
void electAdmin(quint32 clientID)
If you are the ADMIN of the game you can give the ADMIN status away to another client.
Definition: kgamenetwork.cpp:333
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
void sendError(int error, const QByteArray &message, quint32 receiver=0, quint32 sender=0)
Sends a network message.
Definition: kgamenetwork.cpp:455
static void extractHeader(QDataStream &msg, quint32 &sender, quint32 &receiver, int &msgid)
Retrieves the information like cookie,sender,receiver,...
Definition: kgamemessage.cpp:53
void eventClientDisconnected(quint32 clientID, bool broken)
This signal is emitted when the server has lost the connection to one of the clients (This could be b...
void unlock()
Deliver every message that was delayed by lock() and actually deliver all messages that get received ...
Definition: kmessageclient.cpp:321
KGameNetwork(int cookie=42, QObject *parent=nullptr)
Create a KGameNetwork object.
Definition: kgamenetwork.cpp:46
Definition: kmessageio.h:169
int writeRawData(const char *s, int len)
bool connectToServer(const QString &host, quint16 port)
Inits a network game as a network CLIENT.
Definition: kgamenetwork.cpp:198
virtual void lock()
You should call this before doing thigs like, e.g.
Definition: kgamenetwork.cpp:359
void adminStatusChanged(bool isAdmin)
This signal is emitted when this client becomes the admin client or when it loses the admin client st...
void signalNetworkErrorMessage(int error, const QString &text)
A network error occurred.
void disconnect()
Disconnect the current connection and establish a new local one.
Definition: kgamenetwork.cpp:278
ScriptableExtension * host() const
bool sendSystemMessage(const QByteArray &buffer, int msgid, quint32 receiver=0, quint32 sender=0)
Sends a network message msg with a given msg id msgid to all clients.
Definition: kgamenetwork.cpp:396
void lock()
Once this function is called no message will be received anymore.
Definition: kmessageclient.cpp:316
void signalClientDisconnected(quint32 clientID, bool broken)
This signal is emitted whenever the KMessageServer sends us a message that a connection to a client w...
bool isAdmin() const
The admin of a game is the one who initializes newly connected clients using negotiateNetworkGame and...
Definition: kgamenetwork.cpp:94
QList::iterator begin()
int size() const const
QChar * data()
void slotAdminStatusChanged(bool isAdmin)
This KGame object receives or loses the admin status.
Definition: kgamenetwork.cpp:495
bool offerConnections(quint16 port)
Inits a network game as network MASTER.
Definition: kgamenetwork.cpp:168
void setMaxClients(int max)
Changes the maximal connection number of the KMessageServer to max.
Definition: kgamenetwork.cpp:346
void eventClientConnected(quint32 clientID)
This signal is emitted when another client has connected to the server.
A server for message sending and broadcasting, using TCP/IP connections.
Definition: kmessageserver.h:166
virtual void networkTransmission(QDataStream &, int, quint32, quint32, quint32 clientID)=0
Called by ReceiveNetworkTransmission().
QList::iterator end()
static void createHeader(QDataStream &msg, quint32 sender, quint32 receiver, int msgid)
Creates a message header given cookie,sender,receiver,...
Definition: kgamemessage.cpp:48
void aboutToDisconnect(quint32 id)
This signal is emitted right before the client disconnects.
static quint32 rawGameId(quint32 playerid)
Returns the raw game id, that is, the game id the player belongs to.
Definition: kgamemessage.cpp:29
void signalClientConnected(quint32 clientID)
This signal is emitted whenever the KMessageServer sends us a message that a new client connected.
void receiveNetworkTransmission(const QByteArray &a, quint32 clientID)
Called by KMessageClient::broadcastReceived() and will check if the message format is valid.
Definition: kgamenetwork.cpp:465
QString message
void broadcastReceived(const QByteArray &msg, quint32 senderID)
This signal is emitted when the client receives a broadcast message from the KMessageServer,...
char * data()
bool isOfferingConnections() const
Are we still offer offering server connections - only for game MASTER.
Definition: kgamenetwork.cpp:273
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon Sep 25 2023 03:46:46 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon Sep 25 2023 03:46:46 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.