58 */ |
66 */ |
59 int flib_netconn_send_quit(flib_netconn *conn, const char *quitmsg); |
67 int flib_netconn_send_quit(flib_netconn *conn, const char *quitmsg); |
60 int flib_netconn_send_chat(flib_netconn *conn, const char *chat); |
68 int flib_netconn_send_chat(flib_netconn *conn, const char *chat); |
61 |
69 |
62 /** |
70 /** |
|
71 * Send a teamchat message, forwarded from the engine. Only makes sense ingame. |
|
72 * The server does not send a reply. TODO figure out details |
|
73 */ |
|
74 int flib_netconn_send_teamchat(flib_netconn *conn, const char *msg); |
|
75 |
|
76 /** |
63 * Note: Most other functions in this lib accept UTF-8, but the password needs to be |
77 * Note: Most other functions in this lib accept UTF-8, but the password needs to be |
64 * sent as latin1 |
78 * sent as latin1 |
65 */ |
79 */ |
66 int flib_netconn_send_password(flib_netconn *conn, const char *latin1Passwd); |
80 int flib_netconn_send_password(flib_netconn *conn, const char *latin1Passwd); |
67 |
81 |
68 /** |
82 /** |
69 * Request a different nickname. |
83 * Request a different nickname. |
70 * This function only makes sense in reaction to an onNickTaken callback, because the netconn automatically |
84 * This function only makes sense in reaction to an onNickTaken callback, because the netconn automatically |
71 * requests the nickname you provide on creation, and once the server accepts the nickname (onNickAccept) |
85 * requests the nickname you provide on creation, and once the server accepts the nickname it can no longer |
72 * it can no longer be changed. |
86 * be changed. |
73 * |
|
74 * As a response to the nick change request, the server will either reply with a confirmation (onNickAccept) |
|
75 * or a rejection (onNickTaken). Note that the server confirms a nick even if it is password protected, the |
|
76 * password request happens afterwards. |
|
77 */ |
87 */ |
78 int flib_netconn_send_nick(flib_netconn *conn, const char *nick); |
88 int flib_netconn_send_nick(flib_netconn *conn, const char *nick); |
|
89 |
|
90 /** |
|
91 * Join a room as guest (not chief). Only makes sense when in lobby state. If the action succeeds, you will |
|
92 * receive an onEnterRoom callback with chief=false. |
|
93 */ |
|
94 int flib_netconn_send_joinRoom(flib_netconn *conn, const char *room); |
|
95 |
|
96 /** |
|
97 * Create and join a new room. Only makes sense when in lobby state. If the action succeeds, you will |
|
98 * receive an onEnterRoom callback with chief=true. |
|
99 */ |
|
100 int flib_netconn_send_createRoom(flib_netconn *conn, const char *room); |
|
101 |
|
102 /** |
|
103 * Rename the current room. Only makes sense in room state and if you are chief. |
|
104 * TODO: reply |
|
105 */ |
|
106 int flib_netconn_send_renameRoom(flib_netconn *conn, const char *roomName); |
|
107 |
|
108 /** |
|
109 * Leave the room for the lobby. Only makes sense in room state. |
|
110 * TODO: reply, TODO can you send a message? |
|
111 */ |
|
112 int flib_netconn_send_leaveRoom(flib_netconn *conn); |
|
113 |
|
114 /** |
|
115 * Change your "ready" status in the room. Only makes sense when in room state. |
|
116 * TODO: reply |
|
117 */ |
|
118 int flib_netconn_send_toggleReady(flib_netconn *conn); |
|
119 |
|
120 /** |
|
121 * Add a team to the current room. The message includes the team color, but not |
|
122 * the number of hogs. Only makes sense when in room state. If the action succeeds, you will |
|
123 * receive an onTeamAccepted callback with the name of the team. |
|
124 */ |
|
125 int flib_netconn_send_addTeam(flib_netconn *conn, const flib_team *team); |
|
126 |
|
127 /** |
|
128 * Remove the team with the name teamname. Only makes sense when in room state. |
|
129 * TODO: reply |
|
130 */ |
|
131 int flib_netconn_send_removeTeam(flib_netconn *conn, const char *teamname); |
|
132 |
|
133 /** |
|
134 * Send an engine message. Only makes sense when ingame. |
|
135 * TODO: reply |
|
136 */ |
|
137 int flib_netconn_send_engineMessage(flib_netconn *conn, const uint8_t *message, size_t size); |
|
138 |
|
139 /** |
|
140 * Set the number of hogs for a team. Only makes sense in room state and if you are chief. |
|
141 * The server does not send a reply. |
|
142 */ |
|
143 int flib_netconn_send_teamHogCount(flib_netconn *conn, const char *teamname, int hogcount); |
|
144 |
|
145 /** |
|
146 * Set the teamcolor of a team. Only makes sense in room state and if you are chief. |
|
147 * The server does not send a reply. |
|
148 */ |
|
149 int flib_netconn_send_teamColor(flib_netconn *conn, const char *teamname, uint32_t colorRGB); |
|
150 |
|
151 /** |
|
152 * Set the weaponset for the room. Only makes sense in room state and if you are chief. |
|
153 * The server does not send a reply. |
|
154 */ |
|
155 int flib_netconn_send_weaponset(flib_netconn *conn, const flib_weaponset *weaponset); |
|
156 |
|
157 /** |
|
158 * Set the map for the room. Only makes sense in room state and if you are chief. |
|
159 * The server does not send a reply. |
|
160 */ |
|
161 int flib_netconn_send_map(flib_netconn *conn, const flib_map *map); |
|
162 |
|
163 /** |
|
164 * Set the mapname. Only makes sense in room state and if you are chief. |
|
165 * The server does not send a reply. |
|
166 */ |
|
167 int flib_netconn_send_mapName(flib_netconn *conn, const char *mapName); |
|
168 |
|
169 /** |
|
170 * Set the map generator. Only makes sense in room state and if you are chief. |
|
171 * The server does not send a reply. |
|
172 */ |
|
173 int flib_netconn_send_mapGen(flib_netconn *conn, int mapGen); |
|
174 |
|
175 /** |
|
176 * Set the map template for regular maps. Only makes sense in room state and if you are chief. |
|
177 * The server does not send a reply. |
|
178 */ |
|
179 int flib_netconn_send_mapTemplate(flib_netconn *conn, int templateFilter); |
|
180 |
|
181 /** |
|
182 * Set the maze template (maze size) for mazes. Only makes sense in room state and if you are chief. |
|
183 * The server does not send a reply. |
|
184 */ |
|
185 int flib_netconn_send_mapMazeSize(flib_netconn *conn, int mazeSize); |
|
186 |
|
187 /** |
|
188 * Set the seed for the map. Only makes sense in room state and if you are chief. |
|
189 * The server does not send a reply. |
|
190 */ |
|
191 int flib_netconn_send_mapSeed(flib_netconn *conn, const char *seed); |
|
192 |
|
193 /** |
|
194 * Set the theme for the map. Only makes sense in room state and if you are chief. |
|
195 * The server does not send a reply. |
|
196 */ |
|
197 int flib_netconn_send_mapTheme(flib_netconn *conn, const char *theme); |
|
198 |
|
199 /** |
|
200 * Set the draw data for the drawn map. Only makes sense in room state and if you are chief. |
|
201 * The server does not send a reply. |
|
202 */ |
|
203 int flib_netconn_send_mapDrawdata(flib_netconn *conn, const uint8_t *drawData, size_t size); |
|
204 |
|
205 /** |
|
206 * Set the script (game style). Only makes sense in room state and if you are chief. |
|
207 * The server does not send a reply. |
|
208 */ |
|
209 int flib_netconn_send_script(flib_netconn *conn, const char *scriptName); |
|
210 |
|
211 /** |
|
212 * Set the scheme. Only makes sense in room state and if you are chief. |
|
213 * The server does not send a reply. |
|
214 */ |
|
215 int flib_netconn_send_scheme(flib_netconn *conn, const flib_cfg *scheme); |
|
216 |
|
217 /** |
|
218 * Inform the server that the round has ended. TODO: Figure out details |
|
219 */ |
|
220 int flib_netconn_send_roundfinished(flib_netconn *conn, bool withoutError); |
|
221 |
|
222 /** |
|
223 * Ban a player. TODO: Figure out details |
|
224 */ |
|
225 int flib_netconn_send_ban(flib_netconn *conn, const char *playerName); |
|
226 |
|
227 /** |
|
228 * Kick a player. TODO: Figure out details |
|
229 */ |
|
230 int flib_netconn_send_kick(flib_netconn *conn, const char *playerName); |
|
231 |
|
232 /** |
|
233 * Request information about a player. If the action succeeds, you will |
|
234 * receive an onMessage callback with NETCONN_MSG_TYPE_PLAYERINFO containing |
|
235 * the requested information. |
|
236 */ |
|
237 int flib_netconn_send_playerInfo(flib_netconn *conn, const char *playerName); |
|
238 |
|
239 /** |
|
240 * Follow a player. TODO figure out details |
|
241 */ |
|
242 int flib_netconn_send_playerFollow(flib_netconn *conn, const char *playerName); |
|
243 |
|
244 /** |
|
245 * Signal that you want to start the game. Only makes sense in room state and if you are chief. |
|
246 * TODO figure out details |
|
247 */ |
|
248 int flib_netconn_send_startGame(flib_netconn *conn); |
|
249 |
|
250 /** |
|
251 * Allow/forbid players to join the room. Only makes sense in room state and if you are chief. |
|
252 * The server does not send a reply. |
|
253 */ |
|
254 int flib_netconn_send_toggleRestrictJoins(flib_netconn *conn); |
|
255 |
|
256 /** |
|
257 * Allow/forbid adding teams to the room. Only makes sense in room state and if you are chief. |
|
258 * The server does not send a reply. |
|
259 */ |
|
260 int flib_netconn_send_toggleRestrictTeams(flib_netconn *conn); |
|
261 |
|
262 /** |
|
263 * Probably does something administrator-y. |
|
264 */ |
|
265 int flib_netconn_send_clearAccountsCache(flib_netconn *conn); |
|
266 |
|
267 /** |
|
268 * Sets a server variable to the indicated value. Only makes sense if you are server admin. |
|
269 * Known variables are MOTD_NEW, MOTD_OLD and LATEST_PROTO. |
|
270 * TODO reply? |
|
271 */ |
|
272 int flib_netconn_send_setServerVar(flib_netconn *conn, const char *name, const char *value); |
|
273 |
|
274 /** |
|
275 * Queries all server variables. Only makes sense if you are server admin. (TODO: try) |
|
276 * If the action succeeds, you will receive several onServerVar callbacks with the |
|
277 * current values of all server variables. |
|
278 */ |
|
279 int flib_netconn_send_getServerVars(flib_netconn *conn); |
|
280 |
|
281 |
|
282 |
|
283 |
|
284 |
|
285 |
|
286 |
|
287 |
|
288 |
79 |
289 |
80 /** |
290 /** |
81 * Callback for several informational messages that should be displayed to the user |
291 * Callback for several informational messages that should be displayed to the user |
82 * (e.g. in the chat window), but do not require a reaction. If a game is running, you might |
292 * (e.g. in the chat window), but do not require a reaction. If a game is running, you might |
83 * want to redirect some of these messages to the engine as well so the user will see them. |
293 * want to redirect some of these messages to the engine as well so the user will see them. |
111 void flib_netconn_onRoomAdd(flib_netconn *conn, void (*callback)(void *context, const flib_roomlist_room *room), void* context); |
321 void flib_netconn_onRoomAdd(flib_netconn *conn, void (*callback)(void *context, const flib_roomlist_room *room), void* context); |
112 void flib_netconn_onRoomDelete(flib_netconn *conn, void (*callback)(void *context, const char *name), void* context); |
322 void flib_netconn_onRoomDelete(flib_netconn *conn, void (*callback)(void *context, const char *name), void* context); |
113 void flib_netconn_onRoomUpdate(flib_netconn *conn, void (*callback)(void *context, const char *oldName, const flib_roomlist_room *room), void* context); |
323 void flib_netconn_onRoomUpdate(flib_netconn *conn, void (*callback)(void *context, const char *oldName, const flib_roomlist_room *room), void* context); |
114 |
324 |
115 /** |
325 /** |
116 * Callbacks for players joining or leaving a room or the lobby. If join is true it's a join, otherwise a leave. |
326 * Callbacks for players joining or leaving the lobby. If join is true it's a join, otherwise a leave. |
117 * NOTE: partMessage is null if no parting message was given. |
327 * NOTE: partMessage is null if no parting message was given. |
118 */ |
328 */ |
119 void flib_netconn_onLobbyJoin(flib_netconn *conn, void (*callback)(void *context, const char *nick), void* context); |
329 void flib_netconn_onLobbyJoin(flib_netconn *conn, void (*callback)(void *context, const char *nick), void* context); |
120 void flib_netconn_onLobbyLeave(flib_netconn *conn, void (*callback)(void *context, const char *nick, const char *partMessage), void* context); |
330 void flib_netconn_onLobbyLeave(flib_netconn *conn, void (*callback)(void *context, const char *nick, const char *partMessage), void* context); |
121 void flib_netconn_onRoomJoin(flib_netconn *conn, void (*callback)(void *context, const char *nick), void* context); |
|
122 void flib_netconn_onRoomLeave(flib_netconn *conn, void (*callback)(void *context, const char *nick, const char *partMessage), void* context); |
|
123 |
331 |
124 /** |
332 /** |
125 * onNickTaken is called on connecting to the server, if it turns out that there is already a player with the same nick. |
333 * onNickTaken is called on connecting to the server, if it turns out that there is already a player with the same nick. |
126 * In order to proceed, a new nickname needs to be sent to the server using flib_netconn_send_nick() (or of course you can |
334 * In order to proceed, a new nickname needs to be sent to the server using flib_netconn_send_nick() (or of course you can |
127 * bail out and send a QUIT). If you don't set a callback, the netconn will automatically react by generating a new name. |
335 * bail out and send a QUIT). If you don't set a callback, the netconn will automatically react by generating a new name. |
128 * Once the server accepts a name, you will be informed with an onNickAccept callback. |
336 * Once the server accepts a name, you will be informed with an onNickAccept callback. |
129 */ |
337 */ |
130 void flib_netconn_onNickTaken(flib_netconn *conn, void (*callback)(void *context, const char *nick), void* context); |
338 void flib_netconn_onNickTaken(flib_netconn *conn, void (*callback)(void *context, const char *nick), void* context); |
131 |
339 |
132 /** |
340 /** |
133 * onNickAccept informs that your nickname has been accepted by the server, i.e. there was nobody with that nick already |
|
134 * on the server. |
|
135 * Note that a nick request is sent automatically by the netconn when you join the server, so you should receive this |
|
136 * callback shortly after connecting. |
|
137 */ |
|
138 void flib_netconn_onNickAccept(flib_netconn *conn, void (*callback)(void *context, const char *nick), void* context); |
|
139 |
|
140 /** |
|
141 * When connecting with a registered nickname, the server will ask for a password before admitting you in. |
341 * When connecting with a registered nickname, the server will ask for a password before admitting you in. |
142 * This callback is called when that happens. As a reaction, you can send the password using |
342 * This callback is called when that happens. As a reaction, you can send the password using |
143 * flib_netconn_send_password or choose a different nick. If you don't register a callback, |
343 * flib_netconn_send_password or choose a different nick. If you don't register a callback, |
144 * the default behavior is to just quit in a way that will cause a disconnect with NETCONN_DISCONNECT_AUTH_FAILED. |
344 * the default behavior is to just quit in a way that will cause a disconnect with NETCONN_DISCONNECT_AUTH_FAILED. |
145 */ |
345 */ |
146 void flib_netconn_onPasswordRequest(flib_netconn *conn, void (*callback)(void *context, const char *nick), void* context); |
346 void flib_netconn_onPasswordRequest(flib_netconn *conn, void (*callback)(void *context, const char *nick), void* context); |
|
347 |
|
348 /** |
|
349 * You just left the lobby and entered a room. |
|
350 * If chief is true, you can and should send a full configuration for the room now. |
|
351 * This consists of TODO |
|
352 */ |
|
353 void flib_netconn_onEnterRoom(flib_netconn *conn, void (*callback)(void *context, bool chief), void *context); |
|
354 |
|
355 |
|
356 /** |
|
357 * The following callbacks are only relevant in room state. |
|
358 */ |
147 |
359 |
148 /** |
360 /** |
149 * This callback informs about changes to your room chief status, i.e. whether you are allowed to |
361 * This callback informs about changes to your room chief status, i.e. whether you are allowed to |
150 * modify the current room. Generally when you create a room you start out being room chief, and |
362 * modify the current room. Generally when you create a room you start out being room chief, and |
151 * when you join an existing room you are not. However, in some situations room ownership can change, |
363 * when you join an existing room you are not. However, in some situations room ownership can change, |
157 void flib_netconn_onRoomChiefStatus(flib_netconn *conn, void (*callback)(void *context, bool chief), void* context); |
369 void flib_netconn_onRoomChiefStatus(flib_netconn *conn, void (*callback)(void *context, bool chief), void* context); |
158 |
370 |
159 /** |
371 /** |
160 * One of the players in the room (possibly you!) changed their ready state. |
372 * One of the players in the room (possibly you!) changed their ready state. |
161 */ |
373 */ |
162 void flib_netconn_onReadyStateCb(flib_netconn *conn, void (*callback)(void *context, const char *nick, bool ready), void* context); |
374 void flib_netconn_onReadyState(flib_netconn *conn, void (*callback)(void *context, const char *nick, bool ready), void* context); |
163 |
|
164 /** |
|
165 * You just left the lobby and entered a room. |
|
166 * If chief is true, you can and should send a full configuration for the room now. |
|
167 */ |
|
168 void flib_netconn_onEnterRoomCb(flib_netconn *conn, void (*callback)(void *context, bool chief), void *context); |
|
169 |
375 |
170 /** |
376 /** |
171 * You just left a room and entered the lobby again. |
377 * You just left a room and entered the lobby again. |
172 * reason is one of the NETCONN_ROOMLEAVE_ constants. |
378 * reason is one of the NETCONN_ROOMLEAVE_ constants. |
173 * This will not be called when you actively leave a room using PART. |
379 * This will not be called when you actively leave a room using PART. |
174 */ |
380 */ |
175 void flib_netconn_onLeaveRoomCb(flib_netconn *conn, void (*callback)(void *context, int reason, const char *message), void *context); |
381 void flib_netconn_onLeaveRoom(flib_netconn *conn, void (*callback)(void *context, int reason, const char *message), void *context); |
176 |
382 |
177 void flib_netconn_onTeamAddCb(flib_netconn *conn, void (*callback)(void *context, flib_team *team), void *context); |
383 /** |
|
384 * A new team was added to the room. The person who adds a team does NOT receive this callback (he gets onTeamAccepted instead). |
|
385 * The team does not contain bindings, stats, weaponset, color or the number of hogs. |
|
386 */ |
|
387 void flib_netconn_onTeamAdd(flib_netconn *conn, void (*callback)(void *context, flib_team *team), void *context); |
|
388 |
|
389 /** |
|
390 * A team was removed from the room. |
|
391 */ |
|
392 void flib_netconn_onTeamDelete(flib_netconn *conn, void (*callback)(void *context, const char *teamname), void *context); |
|
393 |
|
394 void flib_netconn_onRoomJoin(flib_netconn *conn, void (*callback)(void *context, const char *nick), void* context); |
|
395 void flib_netconn_onRoomLeave(flib_netconn *conn, void (*callback)(void *context, const char *nick, const char *partMessage), void* context); |
|
396 |
|
397 /** |
|
398 * The game is starting. Fire up the engine and join in! |
|
399 * TODO: How? |
|
400 */ |
|
401 void flib_netconn_onRunGame(flib_netconn *conn, void (*callback)(void *context), void *context); |
|
402 |
|
403 /** |
|
404 * 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 |
|
405 * as an existing team, or because the room chief restricted adding new teams. If the team is accepted by the server, |
|
406 * this callback is fired. |
|
407 */ |
|
408 void flib_netconn_onTeamAccepted(flib_netconn *conn, void (*callback)(void *context, const char *teamName), void *context); |
|
409 |
|
410 /** |
|
411 * 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, |
|
412 * you will not receive this callback! |
|
413 */ |
|
414 void flib_netconn_onHogCountChanged(flib_netconn *conn, void (*callback)(void *context, const char *teamName, int hogs), void *context); |
|
415 |
|
416 /** |
|
417 * The color of a team has been changed by the room chief. If you are the chief and change the color yourself, |
|
418 * you will not receive this callback! |
|
419 */ |
|
420 void flib_netconn_onTeamColorChanged(flib_netconn *conn, void (*callback)(void *context, const char *teamName, uint32_t colorARGB), void *context); |
|
421 |
|
422 void flib_netconn_onEngineMessage(flib_netconn *conn, void (*callback)(void *context, const char *message, int size), void *context); |
|
423 |
|
424 void flib_netconn_onCfgScheme(flib_netconn *conn, void (*callback)(void *context, flib_cfg *scheme), void *context); |
|
425 |
|
426 /** |
|
427 * This is called when the map configuration in a room is changed (or first received). Only non-chiefs receive these messages. |
|
428 * To reduce the number of callback functions, the netconn keeps track of the current map settings and always passes the entire |
|
429 * current map config, but informs the callee about what has changed (see the NETCONN_MAPCHANGE_ constants). |
|
430 * The map parameter passed to the callback is an internally held map config. If you want to keep it around, best make a copy |
|
431 * or it may or may not change while you are not looking. |
|
432 * |
|
433 * 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 |
|
434 * the "full" map config does not include the drawn map data. |
|
435 */ |
|
436 void flib_netconn_onMapChanged(flib_netconn *conn, void (*callback)(void *context, const flib_map *map, int changetype), void *context); |
|
437 |
|
438 /** |
|
439 * The "game style" script has been changed by the room chief. If you are the chief and change the script yourself, |
|
440 * you will not receive this callback! |
|
441 */ |
|
442 void flib_netconn_onScriptChanged(flib_netconn *conn, void (*callback)(void *context, const char *script), void *context); |
|
443 |
|
444 /** |
|
445 * The weaponset has been changed by the room chief. If you are the chief and change the weaponset yourself, |
|
446 * you will not receive this callback! |
|
447 */ |
|
448 void flib_netconn_onWeaponsetChanged(flib_netconn *conn, void (*callback)(void *context, flib_weaponset *weaponset), void *context); |
|
449 |
|
450 /** |
|
451 * This callback is called if the server informs us that we have admin rights. |
|
452 */ |
|
453 void flib_netconn_onAdminAccess(flib_netconn *conn, void (*callback)(void *context), void *context); |
|
454 |
|
455 /** |
|
456 * When you query the server vars with GET_SERVER_VAR (TODO probably only works as admin), the server |
|
457 * replies with a list of them. This callback is called for each entry in that list. |
|
458 */ |
|
459 void flib_netconn_onServerVar(flib_netconn *conn, void (*callback)(void *context, const char *name, const char *value), void *context); |
178 |
460 |
179 #endif |
461 #endif |