KDEGames
kgamenetwork.cpp
51 qCDebug(KDEGAMESPRIVATE_KGAME_LOG) << "this=" << this << ", cookie=" << cookie() << "sizeof(this)=" << sizeof(KGameNetwork);
114 connect(d->mMessageClient, &KMessageClient::broadcastReceived, this, &KGameNetwork::receiveNetworkTransmission);
115 connect(d->mMessageClient, &KMessageClient::connectionBroken, this, &KGameNetwork::signalConnectionBroken);
116 connect(d->mMessageClient, &KMessageClient::aboutToDisconnect, this, &KGameNetwork::aboutToLoseConnection);
117 connect(d->mMessageClient, &KMessageClient::connectionBroken, this, &KGameNetwork::slotResetConnection);
119 connect(d->mMessageClient, &KMessageClient::adminStatusChanged, this, &KGameNetwork::slotAdminStatusChanged);
120 connect(d->mMessageClient, &KMessageClient::eventClientConnected, this, &KGameNetwork::signalClientConnected);
121 connect(d->mMessageClient, &KMessageClient::eventClientDisconnected, this, &KGameNetwork::signalClientDisconnected);
124 connect(d->mMessageClient, &KMessageClient::forwardReceived, d->mMessageClient, &KMessageClient::broadcastReceived);
219 qCWarning(KDEGAMESPRIVATE_KGAME_LOG) << "we are server but we are trying to connect to another server! "
230 Q_EMIT signalAdminStatusChanged(false); // as we delete the connection above isAdmin() is always false now!
296 qCDebug(KDEGAMESPRIVATE_KGAME_LOG) << "+++++++++++++++++++++++++++++++++++++++++++++++++++++++";
377bool KGameNetwork::sendSystemMessage(const QString &msg, int msgid, quint32 receiver, quint32 sender)
385bool KGameNetwork::sendSystemMessage(const QDataStream &msg, int msgid, quint32 receiver, quint32 sender)
390bool KGameNetwork::sendSystemMessage(const QByteArray &data, int msgid, quint32 receiver, quint32 sender)
439bool KGameNetwork::sendMessage(const QDataStream &msg, int msgid, quint32 receiver, quint32 sender)
444bool KGameNetwork::sendMessage(const QByteArray &msg, int msgid, quint32 receiver, quint32 sender)
449void KGameNetwork::sendError(int error, const QByteArray &message, quint32 receiver, quint32 sender)
466 // qCDebug(KDEGAMESPRIVATE_KGAME_LOG) << "id=" << msgid << "sender=" << sender << "recv=" << receiver;
473 qCDebug(KDEGAMESPRIVATE_KGAME_LOG) << "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
static void extractHeader(QDataStream &msg, quint32 &sender, quint32 &receiver, int &msgid)
Retrieves the information like cookie,sender,receiver,... from a message header.
Definition kgamemessage.cpp:53
static void createHeader(QDataStream &msg, quint32 sender, quint32 receiver, int msgid)
Creates a message header given cookie,sender,receiver,...
Definition kgamemessage.cpp:48
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
static quint32 rawGameId(quint32 playerid)
Returns the raw game id, that is, the game id the player belongs to.
Definition kgamemessage.cpp:29
KMessageServer * messageServer() const
Don't use this unless you really know what you are doing! You might experience some strange behaviour...
Definition kgamenetwork.cpp:99
KMessageClient * messageClient() const
Don't use this unless you really know what you're doing! You might experience some strange behaviour ...
Definition kgamenetwork.cpp:94
bool isAdmin() const
The admin of a game is the one who initializes newly connected clients using negotiateNetworkGame and...
Definition kgamenetwork.cpp:89
void signalClientConnected(quint32 clientID)
This signal is emitted whenever the KMessageServer sends us a message that a new client connected.
bool connectToServer(const QString &host, quint16 port)
Inits a network game as a network CLIENT.
Definition kgamenetwork.cpp:193
virtual void lock()
You should call this before doing thigs like, e.g.
Definition kgamenetwork.cpp:353
KGameNetwork(int cookie=42, QObject *parent=nullptr)
Create a KGameNetwork object.
Definition kgamenetwork.cpp:41
virtual void networkTransmission(QDataStream &, int, quint32, quint32, quint32 clientID)=0
Called by ReceiveNetworkTransmission().
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:327
void slotResetConnection()
Called when the network connection is terminated.
Definition kgamenetwork.cpp:321
void disconnect()
Disconnect the current connection and establish a new local one.
Definition kgamenetwork.cpp:273
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:444
void aboutToLoseConnection(quint32 id)
Called when the network connection is about to terminate.
Definition kgamenetwork.cpp:315
bool isOfferingConnections() const
Are we still offer offering server connections - only for game MASTER.
Definition kgamenetwork.cpp:268
void setMaxClients(int max)
Changes the maximal connection number of the KMessageServer to max.
Definition kgamenetwork.cpp:340
bool offerConnections(quint16 port)
Inits a network game as network MASTER.
Definition kgamenetwork.cpp:163
void slotAdminStatusChanged(bool isAdmin)
This KGame object receives or loses the admin status.
Definition kgamenetwork.cpp:489
void signalConnectionBroken()
Our connection to the KMessageServer has broken.
void signalNetworkErrorMessage(int error, const QString &text)
A network error occurred.
void signalClientDisconnected(quint32 clientID, bool broken)
This signal is emitted whenever the KMessageServer sends us a message that a connection to a client w...
void receiveNetworkTransmission(const QByteArray &a, quint32 clientID)
Called by KMessageClient::broadcastReceived() and will check if the message format is valid.
Definition kgamenetwork.cpp:459
bool stopServerConnection()
Stops offering server connections - only for game MASTER.
Definition kgamenetwork.cpp:257
void sendError(int error, const QByteArray &message, quint32 receiver=0, quint32 sender=0)
Sends a network message.
Definition kgamenetwork.cpp:449
void signalAdminStatusChanged(bool isAdmin)
This client gets or loses the admin status.
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:390
void lock()
Once this function is called no message will be received anymore.
Definition kmessageclient.cpp:313
void eventClientConnected(quint32 clientID)
This signal is emitted when another client has connected to the server.
void broadcastReceived(const QByteArray &msg, quint32 senderID)
This signal is emitted when the client receives a broadcast message from the KMessageServer,...
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 connectionBroken()
This signal is emitted when the connection to the KMessageServer is broken.
void adminStatusChanged(bool isAdmin)
This signal is emitted when this client becomes the admin client or when it loses the admin client st...
void unlock()
Deliver every message that was delayed by lock() and actually deliver all messages that get received ...
Definition kmessageclient.cpp:318
void aboutToDisconnect(quint32 id)
This signal is emitted right before the client disconnects.
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,...
This abstract base class represents one end of a message connections between two clients.
Definition kmessageio.h:44
A server for message sending and broadcasting, using TCP/IP connections.
Definition kmessageserver.h:167
This class implements the message communication using a TCP/IP socket.
Definition kmessageio.h:150
char * data()
qsizetype size() const const
QIODevice * device() const const
int writeRawData(const char *s, int len)
WriteOnly
Q_EMITQ_EMIT
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
QObject * sender() const const
bool isEmpty() const const
QByteArray toLatin1() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Dec 20 2024 11:50:49 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Dec 20 2024 11:50:49 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.