project_files/frontlib/net/netconn.h
changeset 7314 6171f0bad318
parent 7275 15f722e0b96f
child 7316 f7b49b2c5d84
equal deleted inserted replaced
7312:d1db8aaa8edc 7314:6171f0bad318
       
     1 /*
       
     2  * Hedgewars, a free turn based strategy game
       
     3  * Copyright (C) 2012 Simeon Maxein <smaxein@googlemail.com>
       
     4  *
       
     5  * This program is free software; you can redistribute it and/or
       
     6  * modify it under the terms of the GNU General Public License
       
     7  * as published by the Free Software Foundation; either version 2
       
     8  * of the License, or (at your option) any later version.
       
     9  *
       
    10  * This program is distributed in the hope that it will be useful,
       
    11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
       
    13  * GNU General Public License for more details.
       
    14  *
       
    15  * You should have received a copy of the GNU General Public License
       
    16  * along with this program; if not, write to the Free Software
       
    17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
       
    18  */
       
    19 
     1 #ifndef NETCONN_H_
    20 #ifndef NETCONN_H_
     2 #define NETCONN_H_
    21 #define NETCONN_H_
     3 
    22 
     4 #include "../model/gamesetup.h"
    23 #include "../model/gamesetup.h"
     5 #include "../model/cfg.h"
    24 #include "../model/cfg.h"
    73 /**
    92 /**
    74  * Generate a game setup from the current room state.
    93  * Generate a game setup from the current room state.
    75  * Returns NULL if the room state does not contain enough information
    94  * Returns NULL if the room state does not contain enough information
    76  * for a complete game setup, or if an error occurs.
    95  * for a complete game setup, or if an error occurs.
    77  *
    96  *
    78  * The new gamesetup must be destroyed TODO function for that...
    97  * The new gamesetup must be destroyed with flib_gamesetup_destroy().
    79  */
    98  */
    80 flib_gamesetup *flib_netconn_create_gameSetup(flib_netconn *conn);
    99 flib_gamesetup *flib_netconn_create_gamesetup(flib_netconn *conn);
    81 
   100 
    82 /**
   101 /**
    83  * quitmsg may be null
   102  * quitmsg may be null
    84  */
   103  */
    85 int flib_netconn_send_quit(flib_netconn *conn, const char *quitmsg);
   104 int flib_netconn_send_quit(flib_netconn *conn, const char *quitmsg);
    86 int flib_netconn_send_chat(flib_netconn *conn, const char *chat);
   105 int flib_netconn_send_chat(flib_netconn *conn, const char *chat);
    87 
   106 
    88 /**
   107 /**
    89  * Send a teamchat message, forwarded from the engine. Only makes sense ingame.
   108  * Send a teamchat message, forwarded from the engine. Only makes sense ingame.
    90  * The server does not send a reply. TODO figure out details
   109  * The server does not send a reply. In contrast to a Chat message, the server
       
   110  * automatically converts this into an engine message and passes it on to the other
       
   111  * clients.
    91  */
   112  */
    92 int flib_netconn_send_teamchat(flib_netconn *conn, const char *msg);
   113 int flib_netconn_send_teamchat(flib_netconn *conn, const char *msg);
    93 
   114 
    94 /**
   115 /**
    95  * Note: Most other functions in this lib accept UTF-8, but the password needs to be
   116  * Send the password in reply to a password request.
    96  * sent as latin1
   117  */
    97  */
   118 int flib_netconn_send_password(flib_netconn *conn, const char *passwd);
    98 int flib_netconn_send_password(flib_netconn *conn, const char *latin1Passwd);
       
    99 
   119 
   100 /**
   120 /**
   101  * Request a different nickname.
   121  * Request a different nickname.
   102  * This function only makes sense in reaction to an onNickTaken callback, because the netconn automatically
   122  * This function only makes sense in reaction to an onNickTaken callback, because the netconn automatically
   103  * requests the nickname you provide on creation, and once the server accepts the nickname it can no longer
   123  * requests the nickname you provide on creation, and once the server accepts the nickname it can no longer
   116  * receive an onEnterRoom callback with chief=true.
   136  * receive an onEnterRoom callback with chief=true.
   117  */
   137  */
   118 int flib_netconn_send_createRoom(flib_netconn *conn, const char *room);
   138 int flib_netconn_send_createRoom(flib_netconn *conn, const char *room);
   119 
   139 
   120 /**
   140 /**
   121  * Rename the current room. Only makes sense in room state and if you are chief.
   141  * Rename the current room. Only makes sense in room state and if you are chief. If the action succeeds, you will
   122  * TODO: reply
   142  * receive an onRoomUpdate callback containing the change.
   123  */
   143  */
   124 int flib_netconn_send_renameRoom(flib_netconn *conn, const char *roomName);
   144 int flib_netconn_send_renameRoom(flib_netconn *conn, const char *roomName);
   125 
   145 
   126 /**
   146 /**
   127  * Leave the room for the lobby. Only makes sense in room state.
   147  * Leave the room for the lobby. Only makes sense in room state. msg can be NULL if you don't want to
   128  * TODO: reply, TODO can you send a message?
   148  * send a message. The server always accepts a part message, so once you send it off, you can just
   129  */
   149  * assume that you are back in the lobby.
   130 int flib_netconn_send_leaveRoom(flib_netconn *conn);
   150  */
   131 
   151 int flib_netconn_send_leaveRoom(flib_netconn *conn, const char *msg);
   132 /**
   152 
   133  * Change your "ready" status in the room. Only makes sense when in room state.
   153 /**
   134  * TODO: reply
   154  * Change your "ready" status in the room. Only makes sense when in room state. If the action succeeds, you will
       
   155  * receive an onReadyState callback containing the change.
   135  */
   156  */
   136 int flib_netconn_send_toggleReady(flib_netconn *conn);
   157 int flib_netconn_send_toggleReady(flib_netconn *conn);
   137 
   158 
   138 /**
   159 /**
   139  * Add a team to the current room. The message includes the team color, but not
   160  * Add a team to the current room. The message includes the team color, but not
   142  */
   163  */
   143 int flib_netconn_send_addTeam(flib_netconn *conn, const flib_team *team);
   164 int flib_netconn_send_addTeam(flib_netconn *conn, const flib_team *team);
   144 
   165 
   145 /**
   166 /**
   146  * Remove the team with the name teamname. Only makes sense when in room state.
   167  * Remove the team with the name teamname. Only makes sense when in room state.
   147  * TODO: reply
   168  * The server does not send a reply on success.
   148  */
   169  */
   149 int flib_netconn_send_removeTeam(flib_netconn *conn, const char *teamname);
   170 int flib_netconn_send_removeTeam(flib_netconn *conn, const char *teamname);
   150 
   171 
   151 /**
   172 /**
   152  * Send an engine message. Only makes sense when ingame.
   173  * Send an engine message. Only makes sense when ingame. In a networked game, you have to
   153  * TODO: reply
   174  * pass all the engine messages from the engine here, and they will be spread to all other
       
   175  * clients in the game to keep the game in sync.
   154  */
   176  */
   155 int flib_netconn_send_engineMessage(flib_netconn *conn, const uint8_t *message, size_t size);
   177 int flib_netconn_send_engineMessage(flib_netconn *conn, const uint8_t *message, size_t size);
   156 
   178 
   157 /**
   179 /**
   158  * Set the number of hogs for a team. Only makes sense in room state and if you are chief.
   180  * Set the number of hogs for a team. Only makes sense in room state and if you are chief.
   231  * The server does not send a reply.
   253  * The server does not send a reply.
   232  */
   254  */
   233 int flib_netconn_send_scheme(flib_netconn *conn, const flib_cfg *scheme);
   255 int flib_netconn_send_scheme(flib_netconn *conn, const flib_cfg *scheme);
   234 
   256 
   235 /**
   257 /**
   236  * Inform the server that the round has ended. TODO: Figure out details
   258  * Inform the server that the round has ended. Call this when the engine
       
   259  * has disconnected, passing 1 if the round ended normally, 0 otherwise.
   237  */
   260  */
   238 int flib_netconn_send_roundfinished(flib_netconn *conn, bool withoutError);
   261 int flib_netconn_send_roundfinished(flib_netconn *conn, bool withoutError);
   239 
   262 
   240 /**
   263 /**
   241  * Ban a player. TODO: Figure out details
   264  * Ban a player. TODO: Figure out details
   259  */
   282  */
   260 int flib_netconn_send_playerFollow(flib_netconn *conn, const char *playerName);
   283 int flib_netconn_send_playerFollow(flib_netconn *conn, const char *playerName);
   261 
   284 
   262 /**
   285 /**
   263  * Signal that you want to start the game. Only makes sense in room state and if you are chief.
   286  * Signal that you want to start the game. Only makes sense in room state and if you are chief.
   264  * TODO figure out details
   287  * TODO details
   265  */
   288  */
   266 int flib_netconn_send_startGame(flib_netconn *conn);
   289 int flib_netconn_send_startGame(flib_netconn *conn);
   267 
   290 
   268 /**
   291 /**
   269  * Allow/forbid players to join the room. Only makes sense in room state and if you are chief.
   292  * Allow/forbid players to join the room. Only makes sense in room state and if you are chief.
   364 void flib_netconn_onPasswordRequest(flib_netconn *conn, void (*callback)(void *context, const char *nick), void* context);
   387 void flib_netconn_onPasswordRequest(flib_netconn *conn, void (*callback)(void *context, const char *nick), void* context);
   365 
   388 
   366 /**
   389 /**
   367  * You just left the lobby and entered a room.
   390  * You just left the lobby and entered a room.
   368  * If chief is true, you can and should send a full configuration for the room now.
   391  * If chief is true, you can and should send a full configuration for the room now.
   369  * This consists of TODO
   392  * This consists of ammo, scheme, script and map, where map apparently has to come last.
   370  */
   393  */
   371 void flib_netconn_onEnterRoom(flib_netconn *conn, void (*callback)(void *context, bool chief), void *context);
   394 void flib_netconn_onEnterRoom(flib_netconn *conn, void (*callback)(void *context, bool chief), void *context);
   372 
   395 
   373 
   396 
   374 /**
   397 /**
   412 void flib_netconn_onRoomJoin(flib_netconn *conn, void (*callback)(void *context, const char *nick), void* context);
   435 void flib_netconn_onRoomJoin(flib_netconn *conn, void (*callback)(void *context, const char *nick), void* context);
   413 void flib_netconn_onRoomLeave(flib_netconn *conn, void (*callback)(void *context, const char *nick, const char *partMessage), void* context);
   436 void flib_netconn_onRoomLeave(flib_netconn *conn, void (*callback)(void *context, const char *nick, const char *partMessage), void* context);
   414 
   437 
   415 /**
   438 /**
   416  * The game is starting. Fire up the engine and join in!
   439  * The game is starting. Fire up the engine and join in!
   417  * TODO: How?
   440  * You can let the netconn generate the right game setup using flib_netconn_create_gamesetup
   418  */
   441  */
   419 void flib_netconn_onRunGame(flib_netconn *conn, void (*callback)(void *context), void *context);
   442 void flib_netconn_onRunGame(flib_netconn *conn, void (*callback)(void *context), void *context);
   420 
   443 
   421 /**
   444 /**
   422  * 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
   445  * 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