113 * NETCONN_STATE_ROOM and NETCONN_STATE_INGAME states. |
111 * NETCONN_STATE_ROOM and NETCONN_STATE_INGAME states. |
114 */ |
112 */ |
115 bool flib_netconn_is_chief(flib_netconn *conn); |
113 bool flib_netconn_is_chief(flib_netconn *conn); |
116 |
114 |
117 /** |
115 /** |
118 * Returns the playername. This is *probably* the one provided on creation, but |
116 * Returns the playername. This is *probably* the one provided on creation, but if that name was |
119 * if that name was already taken, a different one could have been set by the |
117 * already taken, a different one could have been set by the onNickTaken callback or its default |
120 * onNickTaken callback or its default implementation. |
118 * implementation. |
121 */ |
119 */ |
122 const char *flib_netconn_get_playername(flib_netconn *conn); |
120 const char *flib_netconn_get_playername(flib_netconn *conn); |
123 |
121 |
124 /** |
122 /** |
125 * Generate a game setup from the current room state. |
123 * Generate a game setup from the current room state. |
126 * Returns NULL if the room state does not contain enough information |
124 * Returns NULL if the room state does not contain enough information for a complete game setup, |
127 * for a complete game setup, or if an error occurs. |
125 * or if an error occurs. |
128 * |
126 * |
129 * The new gamesetup must be destroyed with flib_gamesetup_destroy(). |
127 * The new gamesetup must be destroyed with flib_gamesetup_destroy(). |
130 */ |
128 */ |
131 flib_gamesetup *flib_netconn_create_gamesetup(flib_netconn *conn); |
129 flib_gamesetup *flib_netconn_create_gamesetup(flib_netconn *conn); |
132 |
130 |
133 /** |
131 |
134 * quitmsg may be null |
132 |
135 */ |
133 |
136 int flib_netconn_send_quit(flib_netconn *conn, const char *quitmsg); |
134 // Send functions needed when connecting and disconnecting |
137 int flib_netconn_send_chat(flib_netconn *conn, const char *chat); |
135 |
138 |
136 /** |
139 /** |
137 * Request a different nickname. |
140 * Send a teamchat message, forwarded from the engine. Only makes sense ingame. |
138 * This function only makes sense in reaction to an onNickTaken callback, because the netconn |
141 * The server does not send a reply. In contrast to a Chat message, the server |
139 * automatically requests the nickname you provide on creation, and once the server accepts the |
142 * automatically converts this into an engine message and passes it on to the other |
140 * nickname it can no longer be changed. |
143 * clients. |
141 */ |
144 */ |
142 int flib_netconn_send_nick(flib_netconn *conn, const char *nick); |
145 int flib_netconn_send_teamchat(flib_netconn *conn, const char *msg); |
143 |
146 |
144 /** |
147 /** |
145 * Send the password in reply to a password request. |
148 * Send the password in reply to a password request. |
146 * If the server does not accept the password, you will be disconnected |
149 * If the server does not accept the password, you will be disconnected (NETCONN_DISCONNECT_AUTH_FAILED) |
147 * (NETCONN_DISCONNECT_AUTH_FAILED) |
150 */ |
148 */ |
151 int flib_netconn_send_password(flib_netconn *conn, const char *passwd); |
149 int flib_netconn_send_password(flib_netconn *conn, const char *passwd); |
152 |
150 |
153 /** |
151 /** |
154 * Request a different nickname. |
152 * Tell the server that you want to leave. If successful, the server will disconnect you. |
155 * This function only makes sense in reaction to an onNickTaken callback, because the netconn automatically |
153 */ |
156 * requests the nickname you provide on creation, and once the server accepts the nickname it can no longer |
154 int flib_netconn_send_quit(flib_netconn *conn, const char *quitmsg); |
157 * be changed. |
155 |
158 */ |
156 |
159 int flib_netconn_send_nick(flib_netconn *conn, const char *nick); |
157 // Send functions that make sense both in the lobby and in rooms |
160 |
158 |
161 /** |
159 /** |
162 * Request an update of the room list. Only makes sense when in lobby state. |
160 * Send a chat message. This message is either sent to the lobby or the room, depending on |
163 * If the action succeeds, you will receive an onRoomlist callback containing the current room data. |
161 * whether you are in a room at the moment. The message is not echoed back to you. |
164 */ |
162 */ |
165 int flib_netconn_send_request_roomlist(flib_netconn *conn); |
163 int flib_netconn_send_chat(flib_netconn *conn, const char *chat); |
166 |
164 |
167 /** |
165 /** |
168 * Join a room as guest (not chief). Only makes sense when in lobby state. If the action succeeds, you will |
166 * Kick a player. This has different meanings in the lobby and in a room; |
169 * receive an onEnterRoom callback with chief=false. |
167 * In the lobby, it will kick the player from the server, and you need to be a server admin to |
170 */ |
168 * do it. In a room, it will kick the player from the room, and you need to be room chief. |
171 int flib_netconn_send_joinRoom(flib_netconn *conn, const char *room); |
169 */ |
172 |
170 int flib_netconn_send_kick(flib_netconn *conn, const char *playerName); |
173 /** |
171 |
174 * Create and join a new room. Only makes sense when in lobby state. If the action succeeds, you will |
172 /** |
175 * receive an onEnterRoom callback with chief=true. |
173 * Request information about a player (e.g. current room, version, partial IP). If the action |
176 */ |
174 * succeeds, you will receive an onMessage callback with NETCONN_MSG_TYPE_PLAYERINFO containing |
177 int flib_netconn_send_createRoom(flib_netconn *conn, const char *room); |
175 * the requested information. |
178 |
176 */ |
179 /** |
177 int flib_netconn_send_playerInfo(flib_netconn *conn, const char *playerName); |
180 * Rename the current room. Only makes sense in room state and if you are chief. If the action succeeds, you will |
178 |
181 * receive an onRoomUpdate callback containing the change. |
179 |
182 */ |
180 // Send functions that only make sense in the lobby |
183 int flib_netconn_send_renameRoom(flib_netconn *conn, const char *roomName); |
181 |
184 |
182 /** |
185 /** |
183 * Request an update of the room list. Only makes sense when in lobby state. |
186 * Leave the room for the lobby. Only makes sense in room state. msg can be NULL if you don't want to |
184 * If the action succeeds, you will receive an onRoomlist callback containing the current room |
187 * send a message. The server always accepts a part message, so once you send it off, you can just |
185 * data. |
188 * assume that you are back in the lobby. |
186 */ |
189 */ |
187 int flib_netconn_send_request_roomlist(flib_netconn *conn); |
190 int flib_netconn_send_leaveRoom(flib_netconn *conn, const char *msg); |
188 |
191 |
189 /** |
192 /** |
190 * Join a room as guest (not chief). Only makes sense when in lobby state. If the action |
193 * Change your "ready" status in the room. Only makes sense when in room state. If the action succeeds, you will |
191 * succeeds, you will receive an onEnterRoom callback with chief=false. |
194 * receive an onReadyState callback containing the change. |
192 */ |
195 */ |
193 int flib_netconn_send_joinRoom(flib_netconn *conn, const char *room); |
196 int flib_netconn_send_toggleReady(flib_netconn *conn); |
194 |
197 |
195 /** |
198 /** |
196 * Follow a player. Only valid in the lobby. If the player is in a room (or in a game), this |
199 * Add a team to the current room. Apart from the "fixed" team information, this also includes |
197 * command is analogous to calling flib_netconn_send_joinRoom with that room. |
200 * the color, but not the number of hogs. Only makes sense when in room state. If the action |
198 */ |
201 * succeeds, you will receive an onTeamAccepted callback with the name of the team. |
199 int flib_netconn_send_playerFollow(flib_netconn *conn, const char *playerName); |
202 */ |
200 |
203 int flib_netconn_send_addTeam(flib_netconn *conn, const flib_team *team); |
201 /** |
204 |
202 * Create and join a new room. Only makes sense when in lobby state. If the action succeeds, |
205 /** |
203 * you will receive an onEnterRoom callback with chief=true. |
206 * Remove the team with the name teamname. Only makes sense when in room state. |
204 */ |
207 * The server does not send a reply on success. |
205 int flib_netconn_send_createRoom(flib_netconn *conn, const char *room); |
208 */ |
206 |
209 int flib_netconn_send_removeTeam(flib_netconn *conn, const char *teamname); |
207 /** |
210 |
208 * Ban a player. You need to be in the lobby and a server admin for this to work. |
211 /** |
209 */ |
212 * Send an engine message. Only makes sense when ingame. In a networked game, you have to |
210 int flib_netconn_send_ban(flib_netconn *conn, const char *playerName); |
213 * pass all the engine messages from the engine here, and they will be spread to all other |
211 |
214 * clients in the game to keep the game in sync. |
212 /** |
215 */ |
213 * Does something administrator-y. At any rate you need to be an administrator and in the lobby |
216 int flib_netconn_send_engineMessage(flib_netconn *conn, const uint8_t *message, size_t size); |
214 * to use this command. |
217 |
215 */ |
218 /** |
216 int flib_netconn_send_clearAccountsCache(flib_netconn *conn); |
219 * Set the number of hogs for a team. Only makes sense in room state and if you are chief. |
217 |
220 * The server does not send a reply. |
218 /** |
221 */ |
219 * Sets a server variable to the indicated value. Only makes sense if you are server admin and |
222 int flib_netconn_send_teamHogCount(flib_netconn *conn, const char *teamname, int hogcount); |
220 * in the lobby. Known variables are MOTD_NEW, MOTD_OLD and LATEST_PROTO. MOTD_OLD is shown to |
223 |
221 * players with older protocol versions, to inform them that they might want to update. |
224 /** |
222 */ |
225 * Set the teamcolor of a team. Only makes sense in room state and if you are chief. |
223 int flib_netconn_send_setServerVar(flib_netconn *conn, const char *name, const char *value); |
226 * The server does not send a reply. |
224 |
227 */ |
225 /** |
228 int flib_netconn_send_teamColor(flib_netconn *conn, const char *teamname, int colorIndex); |
226 * Queries all server variables. Only makes sense if you are server admin and in the lobby. |
229 |
227 * If the action succeeds, you will receive several onServerVar callbacks with the |
230 /** |
228 * current values of all server variables. |
231 * Set the weaponset for the room. Only makes sense in room state and if you are chief. |
229 */ |
232 * The server does not send a reply. |
230 int flib_netconn_send_getServerVars(flib_netconn *conn); |
233 */ |
231 |
234 int flib_netconn_send_weaponset(flib_netconn *conn, const flib_weaponset *weaponset); |
232 |
235 |
233 // Send functions that only make sense in a room |
236 /** |
234 |
237 * Set the map for the room. Only makes sense in room state and if you are chief. |
235 /** |
238 * The server does not send a reply. |
236 * Leave the room for the lobby. Only makes sense in room state. msg can be NULL if you don't |
239 */ |
237 * want to send a message. The server always accepts a part message, so once you send it off, |
240 int flib_netconn_send_map(flib_netconn *conn, const flib_map *map); |
238 * you can just assume that you are back in the lobby. |
241 |
239 */ |
242 /** |
240 int flib_netconn_send_leaveRoom(flib_netconn *conn, const char *msg); |
243 * Set the mapname. Only makes sense in room state and if you are chief. |
241 |
244 * The server does not send a reply. |
242 /** |
245 */ |
243 * Change your "ready" status in the room. Only makes sense when in room state. If the action |
246 int flib_netconn_send_mapName(flib_netconn *conn, const char *mapName); |
244 * succeeds, you will receive an onReadyState callback containing the change. |
247 |
245 */ |
248 /** |
246 int flib_netconn_send_toggleReady(flib_netconn *conn); |
249 * Set the map generator. Only makes sense in room state and if you are chief. |
247 |
250 * The server does not send a reply. |
248 /** |
251 */ |
249 * Add a team to the current room. Apart from the "fixed" team information, this also includes |
252 int flib_netconn_send_mapGen(flib_netconn *conn, int mapGen); |
250 * the color, but not the number of hogs. Only makes sense when in room state. If the action |
253 |
251 * succeeds, you will receive an onTeamAccepted callback with the name of the team. |
254 /** |
252 * |
255 * Set the map template for regular maps. Only makes sense in room state and if you are chief. |
253 * Notes: Technically, sending a color here is the only way for a non-chief to set the color of |
256 * The server does not send a reply. |
254 * her own team. The server remembers this color and even generates a separate teamColor message |
257 */ |
255 * to inform everyone of it. However, at the moment the frontends generally override this color |
258 int flib_netconn_send_mapTemplate(flib_netconn *conn, int templateFilter); |
256 * with one they choose themselves in order to deal with unfortunate behavior of the QtFrontend, |
259 |
257 * which always sends color index 0 when adding a team but thinks that the team has a random |
260 /** |
258 * color. The chief always sends a new color in order to bring the QtFrontend back into sync. |
261 * Set the maze template (maze size) for mazes. Only makes sense in room state and if you are chief. |
259 */ |
262 * The server does not send a reply. |
260 int flib_netconn_send_addTeam(flib_netconn *conn, const flib_team *team); |
263 */ |
261 |
264 int flib_netconn_send_mapMazeSize(flib_netconn *conn, int mazeSize); |
262 /** |
265 |
263 * Remove the team with the name teamname. Only makes sense when in room state. |
266 /** |
264 * The server does not send a reply on success. |
267 * Set the seed for the map. Only makes sense in room state and if you are chief. |
265 */ |
268 * The server does not send a reply. |
266 int flib_netconn_send_removeTeam(flib_netconn *conn, const char *teamname); |
269 */ |
267 |
270 int flib_netconn_send_mapSeed(flib_netconn *conn, const char *seed); |
268 |
271 |
269 // Send functions that only make sense in a room and if you are room chief |
272 /** |
270 |
273 * Set the theme for the map. Only makes sense in room state and if you are chief. |
271 /** |
274 * The server does not send a reply. |
272 * Rename the current room. Only makes sense in room state and if you are chief. If the action |
275 */ |
273 * succeeds, you (and everyone else on the server) will receive an onRoomUpdate message |
276 int flib_netconn_send_mapTheme(flib_netconn *conn, const char *theme); |
274 * containing the change. |
277 |
275 */ |
278 /** |
276 int flib_netconn_send_renameRoom(flib_netconn *conn, const char *roomName); |
279 * Set the draw data for the drawn map. Only makes sense in room state and if you are chief. |
277 |
280 * The server does not send a reply. |
278 /** |
281 */ |
279 * Set the number of hogs for a team. Only makes sense in room state and if you are chief. |
282 int flib_netconn_send_mapDrawdata(flib_netconn *conn, const uint8_t *drawData, size_t size); |
280 * The server does not send a reply. |
283 |
281 */ |
284 /** |
282 int flib_netconn_send_teamHogCount(flib_netconn *conn, const char *teamname, int hogcount); |
285 * Set the script (game style). Only makes sense in room state and if you are chief. |
283 |
286 * The server does not send a reply. |
284 /** |
287 */ |
285 * Set the teamcolor of a team. Only makes sense in room state and if you are chief. |
288 int flib_netconn_send_script(flib_netconn *conn, const char *scriptName); |
286 * The server does not send a reply. |
289 |
287 */ |
290 /** |
288 int flib_netconn_send_teamColor(flib_netconn *conn, const char *teamname, int colorIndex); |
291 * Set the scheme. Only makes sense in room state and if you are chief. |
289 |
292 * The server does not send a reply. |
290 /** |
293 */ |
291 * Set the weaponset for the room. Only makes sense in room state and if you are chief. |
294 int flib_netconn_send_scheme(flib_netconn *conn, const flib_scheme *scheme); |
292 * The server does not send a reply. |
295 |
293 */ |
296 /** |
294 int flib_netconn_send_weaponset(flib_netconn *conn, const flib_weaponset *weaponset); |
297 * Inform the server that the round has ended. Call this when the engine |
295 |
298 * has disconnected, passing 1 if the round ended normally, 0 otherwise. |
296 /** |
299 */ |
297 * Set the map for the room. Only makes sense in room state and if you are chief. |
300 int flib_netconn_send_roundfinished(flib_netconn *conn, bool withoutError); |
298 * The server does not send a reply. |
301 |
299 */ |
302 /** |
300 int flib_netconn_send_map(flib_netconn *conn, const flib_map *map); |
303 * Ban a player. You need to be in the lobby and a server admin for this to work. |
301 |
304 */ |
302 /** |
305 int flib_netconn_send_ban(flib_netconn *conn, const char *playerName); |
303 * Set the mapname. Only makes sense in room state and if you are chief. |
306 |
304 * The server does not send a reply. |
307 /** |
305 */ |
308 * Kick a player. This has different meanings in the lobby and in a room; |
306 int flib_netconn_send_mapName(flib_netconn *conn, const char *mapName); |
309 * In the lobby, it will kick the player from the server, and you need to be a server admin to do it. |
307 |
310 * In a room, it will kick the player from the room, and you need to be room chief. |
308 /** |
311 */ |
309 * Set the map generator (regular, maze, drawn, named). Only makes sense in room state and if |
312 int flib_netconn_send_kick(flib_netconn *conn, const char *playerName); |
310 * you are chief. |
313 |
311 * The server does not send a reply. |
314 /** |
312 */ |
315 * Request information about a player. If the action succeeds, you will |
313 int flib_netconn_send_mapGen(flib_netconn *conn, int mapGen); |
316 * receive an onMessage callback with NETCONN_MSG_TYPE_PLAYERINFO containing |
314 |
317 * the requested information. |
315 /** |
318 */ |
316 * Set the map template for regular maps. Only makes sense in room state and if you are chief. |
319 int flib_netconn_send_playerInfo(flib_netconn *conn, const char *playerName); |
317 * The server does not send a reply. |
320 |
318 */ |
321 /** |
319 int flib_netconn_send_mapTemplate(flib_netconn *conn, int templateFilter); |
322 * Follow a player. Only valid in the lobby. If the player is in a room (or in a game), |
320 |
323 * this command is analogous to calling flib_netconn_send_joinRoom with that room. |
321 /** |
324 */ |
322 * Set the maze template (maze size) for mazes. Only makes sense in room state and if you are |
325 int flib_netconn_send_playerFollow(flib_netconn *conn, const char *playerName); |
323 * chief. The server does not send a reply. |
326 |
324 */ |
327 /** |
325 int flib_netconn_send_mapMazeSize(flib_netconn *conn, int mazeSize); |
328 * Signal that you want to start the game. Only makes sense in room state and if you are chief. |
326 |
329 * The server will check whether all players are ready and whether it believes the setup makes |
327 /** |
330 * sense (e.g. more than one clan). If the server is satisfied, you will receive an onRunGame |
328 * Set the seed for the map. Only makes sense in room state and if you are chief. |
331 * callback (all other clients in the room are notified the same way). Otherwise the server |
329 * The server does not send a reply. |
332 * might answer with a warning, or might not answer at all. |
330 */ |
333 */ |
331 int flib_netconn_send_mapSeed(flib_netconn *conn, const char *seed); |
334 int flib_netconn_send_startGame(flib_netconn *conn); |
332 |
335 |
333 /** |
336 /** |
334 * Set the theme for the map. Only makes sense in room state and if you are chief. |
337 * Allow/forbid players to join the room. Only makes sense in room state and if you are chief. |
335 * The server does not send a reply. |
338 * The server does not send a reply. |
336 */ |
339 */ |
337 int flib_netconn_send_mapTheme(flib_netconn *conn, const char *theme); |
340 int flib_netconn_send_toggleRestrictJoins(flib_netconn *conn); |
338 |
341 |
339 /** |
342 /** |
340 * Set the draw data for the drawn map. Only makes sense in room state and if you are chief. |
343 * Allow/forbid adding teams to the room. Only makes sense in room state and if you are chief. |
341 * The server does not send a reply. |
344 * The server does not send a reply. |
342 */ |
345 */ |
343 int flib_netconn_send_mapDrawdata(flib_netconn *conn, const uint8_t *drawData, size_t size); |
346 int flib_netconn_send_toggleRestrictTeams(flib_netconn *conn); |
344 |
347 |
345 /** |
348 /** |
346 * Set the script (game style). Only makes sense in room state and if you are chief. |
349 * Does something administrator-y. At any rate you need to be an administrator and in the lobby |
347 * The server does not send a reply. |
350 * to use this command. |
348 */ |
351 */ |
349 int flib_netconn_send_script(flib_netconn *conn, const char *scriptName); |
352 int flib_netconn_send_clearAccountsCache(flib_netconn *conn); |
350 |
353 |
351 /** |
354 /** |
352 * Set the scheme. Only makes sense in room state and if you are chief. |
355 * Sets a server variable to the indicated value. Only makes sense if you are server admin. |
353 * The server does not send a reply. |
356 * Known variables are MOTD_NEW, MOTD_OLD and LATEST_PROTO. |
354 */ |
357 */ |
355 int flib_netconn_send_scheme(flib_netconn *conn, const flib_scheme *scheme); |
358 int flib_netconn_send_setServerVar(flib_netconn *conn, const char *name, const char *value); |
356 |
359 |
357 /** |
360 /** |
358 * Signal that you want to start the game. Only makes sense in room state and if you are chief. |
361 * Queries all server variables. Only makes sense if you are server admin. |
359 * The server will check whether all players are ready and whether it believes the setup makes |
362 * If the action succeeds, you will receive several onServerVar callbacks with the |
360 * sense (e.g. more than one clan). If the server is satisfied, you will receive an onRunGame |
363 * current values of all server variables. |
361 * callback (all other clients in the room are notified the same way). Otherwise the server |
364 */ |
362 * might answer with a warning, or might not answer at all. |
365 int flib_netconn_send_getServerVars(flib_netconn *conn); |
363 */ |
366 |
364 int flib_netconn_send_startGame(flib_netconn *conn); |
367 |
365 |
368 |
366 /** |
369 |
367 * Allow/forbid players to join the room. Only makes sense in room state and if you are chief. |
370 |
368 * The server does not send a reply. |
371 |
369 */ |
372 |
370 int flib_netconn_send_toggleRestrictJoins(flib_netconn *conn); |
373 |
371 |
374 |
372 /** |
375 |
373 * Allow/forbid adding teams to the room. Only makes sense in room state and if you are chief. |
376 /** |
374 * The server does not send a reply. |
377 * Callback for several informational messages that should be displayed to the user |
375 */ |
378 * (e.g. in the chat window), but do not require a reaction. If a game is running, you might |
376 int flib_netconn_send_toggleRestrictTeams(flib_netconn *conn); |
379 * want to redirect some of these messages to the engine as well so the user will see them. |
377 |
380 */ |
378 |
381 void flib_netconn_onMessage(flib_netconn *conn, void (*callback)(void *context, int msgtype, const char *msg), void* context); |
379 // Send functions that are only needed for running a game |
382 |
380 |
383 /** |
381 /** |
384 * We received a chat message. Where this message belongs depends on the current state (lobby/room/game). In particular, |
382 * Send a teamchat message, forwarded from the engine. Only makes sense ingame. |
385 * if a game is running the message should be passed to the engine. |
383 * The server does not send a reply. In contrast to a Chat message, the server |
386 */ |
384 * automatically converts this into an engine message and passes it on to the other |
387 void flib_netconn_onChat(flib_netconn *conn, void (*callback)(void *context, const char *nick, const char *msg), void* context); |
385 * clients. |
388 |
386 */ |
389 /** |
387 int flib_netconn_send_teamchat(flib_netconn *conn, const char *msg); |
390 * This is called when we receive a CONNECTED message from the server, which should be the first |
388 |
391 * message arriving from the server. |
389 /** |
392 */ |
390 * Send an engine message. Only makes sense when ingame. In a networked game, you have to pass |
393 void flib_netconn_onConnected(flib_netconn *conn, void (*callback)(void *context), void* context); |
391 * all the engine messages from the engine here, and they will be spread to all other clients |
394 |
392 * in the game to keep the game in sync. |
395 /** |
393 */ |
396 * This is *always* the last callback (unless the netconn is destroyed early), and the netconn should be destroyed when it is received. |
394 int flib_netconn_send_engineMessage(flib_netconn *conn, const uint8_t *message, size_t size); |
397 * The reason is one of the NETCONN_DISCONNECT_ constants. Sometime a message is included as well, but that parameter might |
395 |
398 * also be NULL. |
396 /** |
399 */ |
397 * Inform the server that the round has ended. Call this when the engine has disconnected, |
400 void flib_netconn_onDisconnected(flib_netconn *conn, void (*callback)(void *context, int reason, const char *message), void* context); |
398 * passing 1 if the round ended normally, 0 otherwise. |
401 |
399 */ |
402 /** |
400 int flib_netconn_send_roundfinished(flib_netconn *conn, bool withoutError); |
403 * Callbacks for room list updates. The roomlist can be queried with flib_netconn_send_request_roomlist(), which will |
401 |
404 * trigger flib_netconn_onRoomlist once the server replies. Additionally, the roomAdd/delete/update callbacks will fire |
402 |
405 * whenever the server informs about these events, which can happen *before* the roomlist is first received - so be sure |
403 |
406 * not to blindly reference your room list in these callbacks. The server currently only sends updates when a room changes |
404 |
407 * its name, so in order to update other room information you need to query the roomlist again. |
405 |
408 */ |
406 // Callbacks that are important for connecting/disconnecting |
409 void flib_netconn_onRoomlist(flib_netconn *conn, void (*callback)(void *context, const flib_room **rooms, int roomCount), void* context); |
407 |
410 void flib_netconn_onRoomAdd(flib_netconn *conn, void (*callback)(void *context, const flib_room *room), void* context); |
408 /** |
411 void flib_netconn_onRoomDelete(flib_netconn *conn, void (*callback)(void *context, const char *name), void* context); |
409 * onNickTaken is called when connecting to the server, if it turns out that there is already a |
412 void flib_netconn_onRoomUpdate(flib_netconn *conn, void (*callback)(void *context, const char *oldName, const flib_room *room), void* context); |
410 * player with the same nick. |
413 |
411 * In order to proceed, a new nickname needs to be sent to the server using |
414 /** |
412 * flib_netconn_send_nick() (or of course you can bail out and send a QUIT). |
415 * Callbacks for players joining or leaving the lobby. If join is true it's a join, otherwise a leave. |
413 * If you don't set a callback, the netconn will automatically react by generating a new name. |
416 * NOTE: partMessage is null if no parting message was given. |
414 */ |
417 */ |
415 void flib_netconn_onNickTaken(flib_netconn *conn, void (*callback)(void *context, const char *nick), void* context); |
418 void flib_netconn_onLobbyJoin(flib_netconn *conn, void (*callback)(void *context, const char *nick), void* context); |
416 |
419 void flib_netconn_onLobbyLeave(flib_netconn *conn, void (*callback)(void *context, const char *nick, const char *partMessage), void* context); |
417 /** |
420 |
418 * When connecting with a registered nickname, the server will ask for a password before |
421 /** |
419 * admitting you in. This callback is called when that happens. As a reaction, you can send the |
422 * onNickTaken is called on connecting to the server, if it turns out that there is already a player with the same nick. |
420 * password using flib_netconn_send_password. If you don't register a callback, the default |
423 * In order to proceed, a new nickname needs to be sent to the server using flib_netconn_send_nick() (or of course you can |
421 * behavior is to just quit in a way that will cause a disconnect with |
424 * bail out and send a QUIT). If you don't set a callback, the netconn will automatically react by generating a new name. |
422 * NETCONN_DISCONNECT_AUTH_FAILED. |
425 * Once the server accepts a name, you will be informed with an onNickAccept callback. |
423 * |
426 */ |
424 * You can't just choose a new nickname when you receive this callback, because at that point |
427 void flib_netconn_onNickTaken(flib_netconn *conn, void (*callback)(void *context, const char *nick), void* context); |
425 * the server has already accepted your nick. |
428 |
426 */ |
429 /** |
427 void flib_netconn_onPasswordRequest(flib_netconn *conn, void (*callback)(void *context, const char *nick), void* context); |
430 * When connecting with a registered nickname, the server will ask for a password before admitting you in. |
428 |
431 * This callback is called when that happens. As a reaction, you can send the password using |
429 /** |
432 * flib_netconn_send_password or choose a different nick. If you don't register a callback, |
430 * This is called when the server has accepted our nickname (and possibly password) and we have |
433 * the default behavior is to just quit in a way that will cause a disconnect with NETCONN_DISCONNECT_AUTH_FAILED. |
431 * entered the lobby. |
434 */ |
432 */ |
435 void flib_netconn_onPasswordRequest(flib_netconn *conn, void (*callback)(void *context, const char *nick), void* context); |
433 void flib_netconn_onConnected(flib_netconn *conn, void (*callback)(void *context), void* context); |
436 |
434 |
437 /** |
435 /** |
438 * You just left the lobby and entered a room. |
436 * This is always the last callback (unless the netconn is destroyed early), and the netconn |
439 * If chief is true, you can and should send a full configuration for the room now. |
437 * should be destroyed when it is received. The reason for the disconnect is passed as one of |
440 * This consists of ammo, scheme, script and map, where map apparently has to come last. |
438 * the NETCONN_DISCONNECT_ constants. Sometimes a message is included as well, but that |
441 */ |
439 * parameter might also be NULL. |
442 void flib_netconn_onEnterRoom(flib_netconn *conn, void (*callback)(void *context, bool chief), void *context); |
440 */ |
443 |
441 void flib_netconn_onDisconnected(flib_netconn *conn, void (*callback)(void *context, int reason, const char *message), void* context); |
444 |
442 |
445 /** |
443 |
446 * The following callbacks are only relevant in room state. |
444 // Callbacks that make sense in most situations |
447 */ |
445 |
448 |
446 /** |
449 /** |
447 * Callback for several informational messages that should be displayed to the user |
450 * This callback informs about changes to your room chief status, i.e. whether you are allowed to |
448 * (e.g. in the chat window), but do not require a reaction. If a game is running, you might |
451 * modify the current room. Generally when you create a room you start out being room chief, and |
449 * want to redirect some of these messages to the engine as well so the user will see them. |
452 * when you join an existing room you are not. However, in some situations room ownership can change, |
450 */ |
453 * and if that happens this callback is called with the new status. |
451 void flib_netconn_onMessage(flib_netconn *conn, void (*callback)(void *context, int msgtype, const char *msg), void* context); |
454 * |
452 |
455 * Note: This callback does not automatically fire when joining a room. You can always query the |
453 /** |
456 * current chief status using flib_netconn_is_chief(). |
454 * We received a chat message. Where this message belongs depends on the current state |
457 */ |
455 * (lobby/room). If a game is running the message should be passed to the engine. |
458 void flib_netconn_onRoomChiefStatus(flib_netconn *conn, void (*callback)(void *context, bool chief), void* context); |
456 */ |
459 |
457 void flib_netconn_onChat(flib_netconn *conn, void (*callback)(void *context, const char *nick, const char *msg), void* context); |
460 /** |
458 |
461 * One of the players in the room (possibly you!) changed their ready state. |
459 /** |
462 */ |
460 * Callbacks for incremental room list updates. They will fire whenever these events occur, |
463 void flib_netconn_onReadyState(flib_netconn *conn, void (*callback)(void *context, const char *nick, bool ready), void* context); |
461 * even before you first query the actual roomlist - so be sure not to blindly reference your |
464 |
462 * room list in these callbacks. The server currently only sends updates when a room changes |
465 /** |
463 * its name, so in order to update other room information you need to query the roomlist again |
466 * You just left a room and entered the lobby again. |
464 * (see send_request_roomlist / onRoomlist). |
467 * reason is one of the NETCONN_ROOMLEAVE_ constants. |
465 */ |
468 * This will not be called when you actively leave a room using PART. |
466 void flib_netconn_onRoomAdd(flib_netconn *conn, void (*callback)(void *context, const flib_room *room), void* context); |
469 */ |
467 void flib_netconn_onRoomDelete(flib_netconn *conn, void (*callback)(void *context, const char *name), void* context); |
470 void flib_netconn_onLeaveRoom(flib_netconn *conn, void (*callback)(void *context, int reason, const char *message), void *context); |
468 void flib_netconn_onRoomUpdate(flib_netconn *conn, void (*callback)(void *context, const char *oldName, const flib_room *room), void* context); |
471 |
469 |
472 /** |
470 /** |
473 * A new team was added to the room. The person who adds a team does NOT receive this callback (he gets onTeamAccepted instead). |
471 * Callbacks for players joining or leaving the lobby. In contrast to the roomlist updates, you |
474 * The team does not contain bindings, stats, weaponset, color or the number of hogs. |
472 * will get a JOIN callback for every player already on the server when you join (and there is |
475 * |
473 * no direct way to query the current playerlist) |
476 * If you receive this message and you are the room chief, you are expected to provide a color and hog count for this team using |
474 * |
477 * flib_netconn_send_teamHogCount / teamColor. |
475 * NOTE: partMessage may be NULL. |
478 */ |
476 */ |
479 void flib_netconn_onTeamAdd(flib_netconn *conn, void (*callback)(void *context, const flib_team *team), void *context); |
477 void flib_netconn_onLobbyJoin(flib_netconn *conn, void (*callback)(void *context, const char *nick), void* context); |
480 |
478 void flib_netconn_onLobbyLeave(flib_netconn *conn, void (*callback)(void *context, const char *nick, const char *partMessage), void* context); |
481 /** |
479 |
482 * A team was removed from the room. |
480 |
483 */ |
481 // Callbacks that happen only in response to specific requests |
484 void flib_netconn_onTeamDelete(flib_netconn *conn, void (*callback)(void *context, const char *teamname), void *context); |
482 |
485 |
483 /** |
486 void flib_netconn_onRoomJoin(flib_netconn *conn, void (*callback)(void *context, const char *nick), void* context); |
484 * Response to flib_netconn_send_request_roomlist(). |
487 void flib_netconn_onRoomLeave(flib_netconn *conn, void (*callback)(void *context, const char *nick, const char *partMessage), void* context); |
485 * The rooms array contains the current state of all rooms on the server. |
488 |
486 */ |
489 /** |
487 void flib_netconn_onRoomlist(flib_netconn *conn, void (*callback)(void *context, const flib_room **rooms, int roomCount), void* context); |
490 * The game is starting. Fire up the engine and join in! |
488 |
491 * You can let the netconn generate the right game setup using flib_netconn_create_gamesetup |
489 /** |
492 */ |
490 * Response to flib_netconn_send_joinRoom, flib_netconn_send_playerFollow or |
493 void flib_netconn_onRunGame(flib_netconn *conn, void (*callback)(void *context), void *context); |
491 * flib_netconn_send_createRoom. |
494 |
492 * |
495 /** |
493 * You just left the lobby and entered a room. |
496 * When you ask for a team to be added, the server might reject it for several reasons, e.g. because it has the same name |
494 * If chief is true, you can and should send a full configuration for the room now. This |
497 * as an existing team, or because the room chief restricted adding new teams. If the team is accepted by the server, |
495 * consists of ammo, scheme, script and map, where map apparently has to come last. |
498 * this callback is fired. |
496 */ |
499 * |
497 void flib_netconn_onEnterRoom(flib_netconn *conn, void (*callback)(void *context, bool chief), void *context); |
500 * If you are the room chief, you are expected to provide the hog count for your own team now using flib_netconn_send_teamHogCount. |
498 |
501 * The color of the team is already set to the one you provided in addTeam, but the QtFrontend apparently always uses 0 there and |
499 /** |
502 * instead sets the color after the team is accepted. |
500 * Response to flib_netconn_send_addTeam. |
503 */ |
501 * The server might reject your team for several reasons, e.g. because it has the same name as |
504 void flib_netconn_onTeamAccepted(flib_netconn *conn, void (*callback)(void *context, const char *team), void *context); |
502 * an existing team, or because the room chief restricted adding new teams. If the team is |
505 |
503 * accepted by the server, this callback is fired. |
506 /** |
504 * |
507 * The number of hogs in a team has been changed by the room chief. If you are the chief and change the number of hogs yourself, |
505 * If you are the room chief, you are expected to provide the hog count for your own team now |
508 * you will not receive this callback! |
506 * using flib_netconn_send_teamHogCount. The color of the team is already set to the one you |
509 */ |
507 * provided in addTeam. |
510 void flib_netconn_onHogCountChanged(flib_netconn *conn, void (*callback)(void *context, const char *teamName, int hogs), void *context); |
508 */ |
511 |
509 void flib_netconn_onTeamAccepted(flib_netconn *conn, void (*callback)(void *context, const char *team), void *context); |
512 /** |
510 |
513 * The color of a team has been changed by the room chief. If you are the chief and change the color yourself, |
511 /** |
514 * you will not receive this callback! |
512 * When you query the server vars with flib_netconn_send_getServerVars (only works as admin), |
515 */ |
513 * the server replies with a list of them. This callback is called for each entry in that list. |
516 void flib_netconn_onTeamColorChanged(flib_netconn *conn, void (*callback)(void *context, const char *teamName, int colorIndex), void *context); |
514 */ |
517 |
515 void flib_netconn_onServerVar(flib_netconn *conn, void (*callback)(void *context, const char *name, const char *value), void *context); |
518 void flib_netconn_onEngineMessage(flib_netconn *conn, void (*callback)(void *context, const uint8_t *message, size_t size), void *context); |
516 |
519 |
517 |
520 void flib_netconn_onCfgScheme(flib_netconn *conn, void (*callback)(void *context, const flib_scheme *scheme), void *context); |
518 // Callbacks that are only relevant in a room |
521 |
519 |
522 /** |
520 /** |
523 * This is called when the map configuration in a room is changed (or first received). Only non-chiefs receive these messages. |
521 * This callback informs about changes to your room chief status, i.e. whether you are allowed |
524 * To reduce the number of callback functions, the netconn keeps track of the current map settings and always passes the entire |
522 * to modify the current room. Generally when you create a room you start out being room chief, |
525 * current map config, but informs the callee about what has changed (see the NETCONN_MAPCHANGE_ constants). |
523 * and when you join an existing room you are not. However, if the original chief leaves a room, |
526 * The map parameter passed to the callback is an internally held map config. If you want to keep it around, best make a copy |
524 * the server can choose a new chief, and if that happens this callback is called with the new |
527 * or it may or may not change while you are not looking. |
525 * status. |
528 * |
526 * |
529 * Caution: Due to the way the protocol works, the map might not be complete at this point if it is a hand-drawn map, because |
527 * Note: This callback does not automatically fire when joining a room. You can always query the |
530 * the "full" map config does not include the drawn map data. |
528 * current chief status using flib_netconn_is_chief(). |
531 */ |
529 */ |
532 void flib_netconn_onMapChanged(flib_netconn *conn, void (*callback)(void *context, const flib_map *map, int changetype), void *context); |
530 void flib_netconn_onRoomChiefStatus(flib_netconn *conn, void (*callback)(void *context, bool chief), void* context); |
533 |
531 |
534 /** |
532 /** |
535 * The "game style" script has been changed by the room chief. If you are the chief and change the script yourself, |
533 * One of the players in the room (possibly you) changed their ready state. |
536 * you will not receive this callback! |
534 */ |
537 */ |
535 void flib_netconn_onReadyState(flib_netconn *conn, void (*callback)(void *context, const char *nick, bool ready), void* context); |
538 void flib_netconn_onScriptChanged(flib_netconn *conn, void (*callback)(void *context, const char *script), void *context); |
536 |
539 |
537 /** |
540 /** |
538 * You just left a room and entered the lobby again. |
541 * The weaponset has been changed by the room chief. If you are the chief and change the weaponset yourself, |
539 * reason is one of the NETCONN_ROOMLEAVE_ constants (usually a kick). |
542 * you will not receive this callback! |
540 * This will not be called when you actively leave a room using PART. |
543 */ |
541 * Don't confuse with onRoomLeave, which indicates that *someone else* left the room. |
544 void flib_netconn_onWeaponsetChanged(flib_netconn *conn, void (*callback)(void *context, const flib_weaponset *weaponset), void *context); |
542 */ |
545 |
543 void flib_netconn_onLeaveRoom(flib_netconn *conn, void (*callback)(void *context, int reason, const char *message), void *context); |
546 /** |
544 |
547 * This callback is called if the server informs us that we have admin rights. |
545 /** |
548 */ |
546 * Someone joined or left the room you are currently in. |
549 void flib_netconn_onAdminAccess(flib_netconn *conn, void (*callback)(void *context), void *context); |
547 * Analogous to onLobbyJoin/leave, you will receive the join callback for all players that are |
550 |
548 * already in the room when you join, including for yourself (this is actually how it is |
551 /** |
549 * determined that you joined a room). |
552 * When you query the server vars with flib_netconn_send_getServerVars (only works as admin), the server |
550 * |
553 * replies with a list of them. This callback is called for each entry in that list. |
551 * However, you will *not* receive onRoomLeave messages for everyone when you leave the room. |
554 */ |
552 */ |
555 void flib_netconn_onServerVar(flib_netconn *conn, void (*callback)(void *context, const char *name, const char *value), void *context); |
553 void flib_netconn_onRoomJoin(flib_netconn *conn, void (*callback)(void *context, const char *nick), void* context); |
|
554 void flib_netconn_onRoomLeave(flib_netconn *conn, void (*callback)(void *context, const char *nick, const char *partMessage), void* context); |
|
555 |
|
556 /** |
|
557 * A new team was added to the room. The person who adds a team does NOT receive this callback |
|
558 * (he gets onTeamAccepted instead). |
|
559 * |
|
560 * The team does not contain bindings, stats, weaponset, color or the number of hogs (but it is |
|
561 * assumed to be the default of 4). |
|
562 * |
|
563 * If you receive this message and you are the room chief, you may want to send a color and hog |
|
564 * count for this team using flib_netconn_send_teamHogCount / teamColor for QtFrontend |
|
565 * compatibility. |
|
566 * |
|
567 * The server currently sends another message with the color of the team to the same recipients |
|
568 * as this teamAdd message, which will trigger an onTeamColorChanged callback. See the |
|
569 * description of flib_netconn_send_addTeam for more information. |
|
570 */ |
|
571 void flib_netconn_onTeamAdd(flib_netconn *conn, void (*callback)(void *context, const flib_team *team), void *context); |
|
572 |
|
573 /** |
|
574 * A team was removed from the room. The person who removed the team will not receive this |
|
575 * callback. |
|
576 */ |
|
577 void flib_netconn_onTeamDelete(flib_netconn *conn, void (*callback)(void *context, const char *teamname), void *context); |
|
578 |
|
579 /** |
|
580 * The number of hogs in a team has been changed by the room chief. If you are the chief and |
|
581 * change the number of hogs yourself, you will not receive this callback. |
|
582 */ |
|
583 void flib_netconn_onHogCountChanged(flib_netconn *conn, void (*callback)(void *context, const char *teamName, int hogs), void *context); |
|
584 |
|
585 /** |
|
586 * The color of a team has been set or changed. The client who set or changed the color will |
|
587 * not receive this callback. |
|
588 * |
|
589 * Normally, only the chief can change the color of a team. However, this message is also |
|
590 * generated when a team is added, so you can receive it even as chief. |
|
591 */ |
|
592 void flib_netconn_onTeamColorChanged(flib_netconn *conn, void (*callback)(void *context, const char *teamName, int colorIndex), void *context); |
|
593 |
|
594 /** |
|
595 * The room chief has changed the game scheme (or you just joined a room). |
|
596 * You will not receive this callback if you changed the scheme yourself. |
|
597 */ |
|
598 void flib_netconn_onSchemeChanged(flib_netconn *conn, void (*callback)(void *context, const flib_scheme *scheme), void *context); |
|
599 |
|
600 /** |
|
601 * The room chief has changed the map (or you just joined a room). Only non-chiefs receive these |
|
602 * messages. |
|
603 * |
|
604 * To reduce the number of callback functions, the netconn keeps track of the current map |
|
605 * settings and always passes the entire current map config, but informs the callee about what |
|
606 * has changed (see the NETCONN_MAPCHANGE_ constants). |
|
607 * |
|
608 * Caution: Due to the way the protocol works, the map might not be complete at this point if it |
|
609 * is a hand-drawn map, because the "full" map config does not include the drawn map data. |
|
610 */ |
|
611 void flib_netconn_onMapChanged(flib_netconn *conn, void (*callback)(void *context, const flib_map *map, int changetype), void *context); |
|
612 |
|
613 /** |
|
614 * The room chief has changed the game style (or you just joined a room). If you are the chief |
|
615 * and change the style yourself, you will not receive this callback. |
|
616 */ |
|
617 void flib_netconn_onScriptChanged(flib_netconn *conn, void (*callback)(void *context, const char *script), void *context); |
|
618 |
|
619 /** |
|
620 * The room chief has changed the weaponset (or you just joined a room). If you are the chief |
|
621 * and change the weaponset yourself, you will not receive this callback. |
|
622 */ |
|
623 void flib_netconn_onWeaponsetChanged(flib_netconn *conn, void (*callback)(void *context, const flib_weaponset *weaponset), void *context); |
|
624 |
|
625 /** |
|
626 * The game is starting. Fire up the engine and join in! |
|
627 * You can let the netconn generate the right game setup using flib_netconn_create_gamesetup |
|
628 */ |
|
629 void flib_netconn_onRunGame(flib_netconn *conn, void (*callback)(void *context), void *context); |
|
630 |
|
631 /** |
|
632 * You are in a room, a game is in progress, and the server is sending you the new input for the |
|
633 * engine to keep up to date with the current happenings. Pass it on to the engine using |
|
634 * flib_gameconn_send_enginemsg. |
|
635 */ |
|
636 void flib_netconn_onEngineMessage(flib_netconn *conn, void (*callback)(void *context, const uint8_t *message, size_t size), void *context); |
|
637 |
|
638 |
|
639 // Callbacks only needed for admin stuffs |
|
640 |
|
641 /** |
|
642 * This callback is called if the server informs us that we have admin rights. |
|
643 */ |
|
644 void flib_netconn_onAdminAccess(flib_netconn *conn, void (*callback)(void *context), void *context); |
556 |
645 |
557 #endif |
646 #endif |