[Kde-games-devel] Re: Sending a message to one KGame client
Andreas Beckermann
kde-games-devel@mail.kde.org
Tue, 18 Feb 2003 19:56:48 +0100
On Tuesday 18 February 2003 05:19, Neil Stevens wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Might as well make this a new thread, as I'm asking a specific technical
> question instead of the broader philosophical and design questions.
Hehe :)
> After poking around in the system-only parts of the docs, I have an idea
> that seems promising: To send a secret message from server to player, the
> server can get the KMessageServer from the KGame, then use use
> KMessageServer::sendMessage to send the message. To receive the message
> on the client side, I have to get the KMessageClient from the KGame, and
> hook up to KMessageClient::serverMessageReceived to receive the messages.
>
> Is this correct?
Hm.
serverMessageReceived() is emitted for *every* message that gets sent from the
server (even those that are forwarded from the clients).
Since the server acts as a client when you send messages to other clients I'd
say use forwardReceived() instead (unless Burkhard says something different
of course - he knows more on KMessage*).
I guess you can do this directly in KGameNetwork. Connect
KMessageClient::forwardReceived() to KGameNetwork::networkTransmission() just
as it is done with broadcastReceived().
Or maybe connect the forwardReceived() signal to the broadcastReceived()
signal, as stated in the KMessage* docs.
Once you did that you can modify KGameNetwork::sendSystemMessage() to
recognize the receivers param. I believe you have to use a different ID for
the client, as sendSystemMessage() uses KGame IDs, if I'm not wrong. I'll
have a look and send you the necessary code if you want.
Then you'll simply use KGame::sendMessage() with the receiver param and you're
done without modifying your program :)
> And if so, do the client IDs in the KMessageServer match
> the KPlayer::id()s?
No.
It might be possible that the KGame ID matches the KMessageClient id, but I am
not sure. I will have a look.
About the player ID: the *cannot* match the KMessageClient id. E.g. if you
have two different players on one client you need to be able to distinguish a
message to player A from a message to player B, although the message is for
the same client.
> Thanks again,
> - --
> Neil Stevens - neil@qualityassistant.com
CU
Andi