Now sending prepared menu items to logged in players

Signed-off-by: Gergely POLONKAI (W00d5t0ck) <polesz@w00d5t0ck.info>
This commit is contained in:
Polonkai Gergely 2012-05-16 19:54:48 +00:00
parent 0c725d75ec
commit 93bf11c446
2 changed files with 58 additions and 2 deletions

View File

@ -91,7 +91,8 @@ wmud_client_close(wmudClient *client, gboolean send_goodbye)
void void
send_menu_item(wmudMenu *item, wmudClient *client) send_menu_item(wmudMenu *item, wmudClient *client)
{ {
wmud_client_send(client, "Item\r\n"); /* TODO: Send ANSI menu item only to ANSI players! */
wmud_client_send(client, "%s\r\n", item->display_text_ansi);
} }
/** /**
@ -228,7 +229,7 @@ wmud_client_callback(GSocket *client_socket, GIOCondition condition, wmudClient
client->state = WMUD_CLIENT_STATE_MENU; client->state = WMUD_CLIENT_STATE_MENU;
/* TODO: send MOTD */ /* TODO: send MOTD */
/* TODO: send menu items */ /* TODO: send menu items */
//g_slist_foreach(game_menu, (GFunc)send_menu_item, client); g_slist_foreach(game_menu, (GFunc)send_menu_item, client);
/* TODO: send menu prologue */ /* TODO: send menu prologue */
} }
else else

View File

@ -76,6 +76,58 @@ wmud_menu_items_free(GSList **menu_items)
} }
} }
void
menu_item_prepare(wmudMenu *item, gpointer data)
{
gchar m1, m2;
gchar *a,
*found = NULL;
GString *ds, *dsa;
g_debug("Preparing menu item %s", item->text);
m1 = g_ascii_tolower(item->menuchar);
m2 = g_ascii_toupper(item->menuchar);
for (a = item->text; *a; a++)
if ((*a == m1) || (*a == m2))
{
found = a;
break;
}
if (found)
{
gchar *tmp;
tmp = g_ascii_strdown(item->text, -1);
ds = g_string_new(tmp);
dsa = g_string_new(tmp);
g_free(tmp);
ds->str[found - item->text] = g_ascii_toupper(item->menuchar);
dsa->str[found - item->text] = g_ascii_toupper(item->menuchar);
}
else
{
found = item->text;
ds = g_string_new(item->text);
dsa = g_string_new(item->text);
g_string_prepend_c(ds, ' ');
g_string_prepend_c(ds, g_ascii_toupper(item->menuchar));
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, ')');
g_string_insert(dsa, found - item->text, "\x1b[31;1m");
g_string_insert(dsa, found - item->text + 8, "\x1b[0m");
item->display_text = g_string_free(ds, FALSE);
item->display_text_ansi = g_string_free(dsa, FALSE);
g_debug("Prepared as %s %s", item->display_text, item->display_text_ansi);
}
gboolean gboolean
wmud_menu_init(GSList **menu) wmud_menu_init(GSList **menu)
{ {
@ -105,8 +157,11 @@ wmud_menu_init(GSList **menu)
return FALSE; return FALSE;
} }
/* TODO: free previous menu list, if *menu is not NULL */
*menu = menu_items; *menu = menu_items;
g_slist_foreach(*menu, (GFunc)menu_item_prepare, NULL);
return TRUE; return TRUE;
} }