Refactored menu sending to a separate function
This commit is contained in:
parent
d87a26dbe1
commit
c2c14d107b
@ -53,12 +53,6 @@ struct AcceptData {
|
||||
*/
|
||||
GSList *clients = NULL;
|
||||
|
||||
/**
|
||||
* game_menu:
|
||||
* The list of menu items to display after a successful login
|
||||
*/
|
||||
static GSList *game_menu = NULL;
|
||||
|
||||
static GRegex *email_regex = NULL;
|
||||
|
||||
void wmud_client_interpret_newplayer_email(wmudClient *client);
|
||||
@ -99,13 +93,6 @@ wmud_client_close(wmudClient *client, gboolean send_goodbye)
|
||||
g_free(client);
|
||||
}
|
||||
|
||||
void
|
||||
send_menu_item(wmudMenu *item, wmudClient *client)
|
||||
{
|
||||
/* TODO: Send ANSI menu item only to ANSI players! */
|
||||
wmud_client_send(client, "%s\r\n", item->display_text_ansi);
|
||||
}
|
||||
|
||||
/**
|
||||
* wmud_client_callback:
|
||||
* @client: the socket of the client on which the data arrived
|
||||
@ -504,13 +491,7 @@ state_passwait(wmudClient *client)
|
||||
/* TODO: send MOTD */
|
||||
|
||||
wmud_text_send_to_client("motd", client);
|
||||
|
||||
/* TODO: send menu items */
|
||||
|
||||
g_slist_foreach(game_menu, (GFunc)send_menu_item, client);
|
||||
client->state = WMUD_CLIENT_STATE_MENU;
|
||||
|
||||
/* TODO: send menu prologue */
|
||||
wmud_menu_present(client);
|
||||
} else {
|
||||
wmud_client_send(client, "%c%c%cThis password doesn't"
|
||||
" seem to be valid. Let's try it again..."
|
||||
|
25
wmud/menu.c
25
wmud/menu.c
@ -36,6 +36,12 @@
|
||||
|
||||
GHashTable *mcmd_table = NULL;
|
||||
|
||||
/**
|
||||
* game_menu:
|
||||
* The list of menu items to display after a successful login
|
||||
*/
|
||||
GSList *game_menu = NULL;
|
||||
|
||||
GQuark
|
||||
wmud_menu_error_quark()
|
||||
{
|
||||
@ -123,7 +129,7 @@ menu_item_prepare(wmudMenu *item, GHashTable *cmdtable)
|
||||
g_string_prepend_c(dsa, ' ');
|
||||
g_string_prepend_c(dsa, g_ascii_toupper(item->menuchar));
|
||||
}
|
||||
|
||||
|
||||
g_string_insert_c(ds, found - item->text, '(');
|
||||
g_string_insert_c(ds, found - item->text + 2, ')');
|
||||
|
||||
@ -279,3 +285,20 @@ wmud_menu_execute_command(wmudClient *client, gchar *command)
|
||||
else
|
||||
func(client);
|
||||
}
|
||||
|
||||
void
|
||||
send_menu_item(wmudMenu *item, wmudClient *client)
|
||||
{
|
||||
/* TODO: Send ANSI menu item only to ANSI players! */
|
||||
wmud_client_send(client, "%s\r\n", item->display_text_ansi);
|
||||
}
|
||||
|
||||
void
|
||||
wmud_menu_present(wmudClient *client)
|
||||
{
|
||||
g_slist_foreach(game_menu, (GFunc)send_menu_item, client);
|
||||
client->state = WMUD_CLIENT_STATE_MENU;
|
||||
|
||||
/* TODO: send menu prologue */
|
||||
}
|
||||
|
||||
|
@ -58,6 +58,8 @@ typedef void (*wmudMenuCommandFunc)(wmudClient *client);
|
||||
*/
|
||||
#define WMUD_MENU_COMMAND(name) void wmud_mcmd_ ## name(wmudClient *client)
|
||||
|
||||
GSList *game_menu;
|
||||
|
||||
#define WMUD_MENU_ERROR wmud_menu_error_quark()
|
||||
GQuark wmud_menu_error_quark();
|
||||
gboolean wmud_menu_init(GSList **menu);
|
||||
@ -65,6 +67,7 @@ gboolean wmud_menu_items_check(GSList *menu_items, GError **err);
|
||||
void wmud_menu_items_free(GSList **menu_items);
|
||||
gchar *wmud_menu_get_command_by_menuchar(gchar menuchar, GSList *game_menu);
|
||||
void wmud_menu_execute_command(wmudClient *client, gchar *command);
|
||||
void wmud_menu_present(wmudClient *client);
|
||||
|
||||
#endif /* __WMUD_MENU_H__ */
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user