diff --git a/wmud/game-networking.c b/wmud/game-networking.c index a23fc7f..4c91c18 100644 --- a/wmud/game-networking.c +++ b/wmud/game-networking.c @@ -211,7 +211,8 @@ wmud_client_callback(GSocket *client_socket, GIOCondition condition, wmudClient { client->player = g_new0(wmudPlayer, 1); client->player->player_name = g_strdup(client->buffer->str); - client->state = WMUD_CLIENT_STATE_NEWCHAR; + client->state = WMUD_CLIENT_STATE_YESNO; + client->yesNoCallback = wmud_client_newchar_answer; wmud_client_send(client, "Is %s new to this game? [Y/N] ", client->buffer->str); } } @@ -295,23 +296,6 @@ wmud_client_callback(GSocket *client_socket, GIOCondition condition, wmudClient wmud_client_send(client, "Please enter a 'Y' or 'N' character: "); } break; - case WMUD_CLIENT_STATE_NEWCHAR: - if (g_ascii_strcasecmp(client->buffer->str, "n") == 0) - { - wmud_client_send(client, "What is your player-name, then? "); - client->state = WMUD_CLIENT_STATE_FRESH; - } - else if (g_ascii_strcasecmp(client->buffer->str, "y") == 0) - { - g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Creating new player\n"); - wmud_client_send(client, "Welcome to this MUD!\r\nPlease enter your e-mail address: "); - client->state = WMUD_CLIENT_STATE_REGISTERING; - } - else - { - wmud_client_send(client, "Sorry, but for this question I only understand 'Y' or 'N'.\r\nIs %s a new player here? [Y/N] ", client->player->player_name); - } - break; case WMUD_CLIENT_STATE_REGISTERING: if (!*(client->buffer->str)) { @@ -608,3 +592,20 @@ wmud_client_quitanswer(wmudClient *client, gboolean answer) client->state = WMUD_CLIENT_STATE_MENU; } } + +void +wmud_client_newchar_answer(wmudClient *client, gboolean answer) +{ + if (answer) + { + g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Creating new player\n"); + wmud_client_send(client, "Welcome to this MUD!\r\nPlease enter your e-mail address: "); + client->state = WMUD_CLIENT_STATE_REGISTERING; + } + else + { + wmud_client_send(client, "What is your player-name, then? "); + client->state = WMUD_CLIENT_STATE_FRESH; + } +} + diff --git a/wmud/game-networking.h b/wmud/game-networking.h index f710ae6..bc3986d 100644 --- a/wmud/game-networking.h +++ b/wmud/game-networking.h @@ -65,5 +65,6 @@ extern GSList *clients; gboolean wmud_networking_init(guint port_number, GMainContext *game_context, GSList *menu_items, GError **err); void wmud_client_send(wmudClient *client, const gchar *fmt, ...); void wmud_client_quitanswer(wmudClient *client, gboolean answer); +void wmud_client_newchar_answer(wmudClient *client, gboolean answer); #endif diff --git a/wmud/wmud-types.h b/wmud/wmud-types.h index baac57a..e4c176f 100644 --- a/wmud/wmud-types.h +++ b/wmud/wmud-types.h @@ -45,8 +45,6 @@ * that are called before and after the client enters a new state, this * could be a three-state stuff, in which the player can enter e.g ? as * the answer, so they would be presented with the question again. - * @WMUD_CLIENT_STATE_NEWCHAR: Player name entered on the login screen was - * invalid. Waiting for answer if this is a new player * @WMUD_CLIENT_STATE_REGISTERING: Registering a new player. Waiting for the * e-mail address to be given * @WMUD_CLIENT_STATE_REGEMAIL_CONFIRM: E-mail address entered séms valid, @@ -60,7 +58,6 @@ typedef enum { WMUD_CLIENT_STATE_MENU, WMUD_CLIENT_STATE_INGAME, WMUD_CLIENT_STATE_YESNO, - WMUD_CLIENT_STATE_NEWCHAR, WMUD_CLIENT_STATE_REGISTERING, WMUD_CLIENT_STATE_REGEMAIL_CONFIRM } wmudClientState;