KDEGames

kgamemessage.h
1/*
2 This file is part of the KDE games library
3 SPDX-FileCopyrightText: 2001 Martin Heni <kde at heni-online.de>
4 SPDX-FileCopyrightText: 2001 Andreas Beckermann <b_mann@gmx.de>
5
6 SPDX-License-Identifier: LGPL-2.0-only
7*/
8
9#ifndef __KGAMEMESSAGE_H_
10#define __KGAMEMESSAGE_H_
11
12// own
13#include "kdegamesprivate_export.h"
14// Qt
15#include <QDataStream>
16
17/**
18 * \class KGameMessage kgamemessage.h <KGame/KGameMessage>
19 *
20 * Namespace-like class for message-related static functions.
21 */
22class KDEGAMESPRIVATE_EXPORT KGameMessage
23{
24public:
25 /**
26 * Creates a fully qualified player ID which contains the original
27 * player id in the lower bits and the game number in the higher bits.
28 * Do not rely on the exact bit positions as they are internal.
29 *
30 * See also @ref rawPlayerId and @ref rawGameId which are the inverse
31 * operations
32 *
33 * @param player The player id - can include a gameid (will get removed)
34 * @param game The game id (<64). 0 For broadcast.
35 * @return The new player id
36 */
37 static quint32 createPlayerId(int player, quint32 game);
38
39 /**
40 * Returns the raw playerid, that is, a id which does not
41 * contain the game number encoded in it. See also @ref createPlayerId which
42 * is the inverse operation.
43 *
44 * @param playerid The player id
45 * @return The raw player id
46 */
47 static int rawPlayerId(quint32 playerid);
48
49 /**
50 * Returns the raw game id, that is, the game id the player
51 * belongs to. Se also @ref createPlayerId which is the inverse operation.
52 *
53 * @param playerid The player id
54 * @return The raw game id
55 */
56 static quint32 rawGameId(quint32 playerid);
57
58 /**
59 * Checks whether a message receiver/sender is a player
60 *
61 * @param id The ID of the sender/receiver
62 * @return true/false
63 */
64 static bool isPlayer(quint32 id);
65
66 /**
67 * Checks whether the sender/receiver of a message is a game
68 *
69 * @param id The ID of the sender/receiver
70 * @return true/false
71 */
72 static bool isGame(quint32 id);
73
74 /**
75 * Creates a message header given cookie,sender,receiver,...
76 *
77 * Also puts "hidden" header into the stream which are used by KGameClient
78 * (message length and magic cookie). If you don't need them remove them
79 * with dropExternalHeader
80 */
81 static void createHeader(QDataStream &msg, quint32 sender, quint32 receiver, int msgid);
82
83 /**
84 * Retrieves the information like cookie,sender,receiver,... from a message header
85 *
86 * Note that it could be necessary to call dropExternalHeader first
87 */
88 static void extractHeader(QDataStream &msg, quint32 &sender, quint32 &receiver, int &msgid);
89
90 /**
91 * Creates a property header given the property id
92 */
93 static void createPropertyHeader(QDataStream &msg, int id);
94
95 /**
96 * Retrieves the property id from a property message header
97 */
98 static void extractPropertyHeader(QDataStream &msg, int &id);
99
100 /**
101 * Creates a property header given the property id
102 */
103 static void createPropertyCommand(QDataStream &msg, int cmdid, int pid, int cmd);
104
105 /**
106 * Retrieves the property id from a property message header
107 */
108 static void extractPropertyCommand(QDataStream &msg, int &pid, int &cmd);
109
110 /**
111 * @return Version of the network library
112 */
113 static int version();
114
115 /**
116 * This function takes a @ref GameMessageIds as argument and returns a
117 * suitable string for it. This string can't be used to identify a message
118 * (as it is i18n'ed) but it can make debugging more easy.
119 * @return Either a i18n'ed string (the name of the id) or QString() if
120 * the msgid is unknown
121 */
122 static QString messageId2Text(int msgid);
123
124 /**
125 * Message Ids used inside @ref KGame.
126 *
127 * You can use your own custom message Id by adding @p IdUser to it.
128 */
129 // please document every new id with a short comment
131 // game init, game load, disconnect, ...
132 IdSetupGame = 1, // sent to a newly connected player
133 IdSetupGameContinue = 2, // continue the setup
134 IdGameLoad = 3, // load/save the game to the client
135 IdGameConnected = 4, // Client successfully connected to master
136 IdSyncRandom = 5, // new random seed set - sync games
137 IdDisconnect = 6, // KGame object disconnects from game
138 IdGameSetupDone = 7, // New game client is now operational
139
140 // properties
141 IdPlayerProperty = 20, // a player property changed
142 IdGameProperty = 21, // a game property changed
143
144 // player management
145 IdAddPlayer = 30, // add a player
146 IdRemovePlayer = 31, // the player will be removed
147 IdActivatePlayer = 32, // Activate a player
148 IdInactivatePlayer = 33, // Inactivate a player
149 IdTurn = 34, // Turn to be prepared
150
151 // to-be-categorized
152 IdError = 100, // an error occurred
153 IdPlayerInput = 101, // a player input occurred
154 IdIOAdded = 102, // KGameIO got added to a player...init this IO
155
156 // special ids for computer player
157 IdProcessQuery = 220, // Process queries data (process only)
158 IdPlayerId = 221, // PlayerId got changed (process only)
159
160 IdUser = 256 // a user specified message
161 };
162};
163
164#endif
Namespace-like class for message-related static functions.
GameMessageIds
Message Ids used inside KGame.
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 16:59:04 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.