Added a Yes/No question client state, while removing the quitwait state

Signed-off-by: Gergely POLONKAI (W00d5t0ck) <polesz@w00d5t0ck.info>
This commit is contained in:
Polonkai Gergely 2012-05-17 16:52:01 +00:00
parent d6f18441c1
commit a25364a98c
2 changed files with 27 additions and 8 deletions

View File

@ -278,8 +278,19 @@ wmud_client_callback(GSocket *client_socket, GIOCondition condition, wmudClient
case WMUD_CLIENT_STATE_INGAME: case WMUD_CLIENT_STATE_INGAME:
wmud_interpret_game_command(client); wmud_interpret_game_command(client);
break; break;
case WMUD_CLIENT_STATE_QUITWAIT: case WMUD_CLIENT_STATE_YESNO:
//wmud_interpret_quit_answer(client); if (g_ascii_strcasecmp(client->buffer->str, "y") == 0)
{
(client->yesNoCallback)(client, TRUE);
}
else if (g_ascii_strcasecmp(client->buffer->str, "n") == 0)
{
(client->yesNoCallback)(client, FALSE);
}
else
{
wmud_client_send(client, "Please enter a 'Y' or 'N' character: ");
}
break; break;
case WMUD_CLIENT_STATE_NEWCHAR: case WMUD_CLIENT_STATE_NEWCHAR:
if (g_ascii_strcasecmp(client->buffer->str, "n") == 0) if (g_ascii_strcasecmp(client->buffer->str, "n") == 0)

View File

@ -39,9 +39,12 @@
* main game menu * main game menu
* @WMUD_CLIENT_STATE_INGAME: Character login was successful, player is now * @WMUD_CLIENT_STATE_INGAME: Character login was successful, player is now
* in-game * in-game
* @WMUD_CLIENT_STATE_QUITWAIT: Player entered the in-game QUIT command, and we * @WMUD_CLIENT_STATE_YESNO: Player was asked a yes/no question, and we are
* are now waiting for an answer if they really want to quit * waiting for the answer. client.yesNoCallback MUST be set at this point!
* Will be removed soon, this should work totally different (TODO) * TODO: if wmudClient had a prevState field, and there would be some hooks
* 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 * @WMUD_CLIENT_STATE_NEWCHAR: Player name entered on the login screen was
* invalid. Waiting for answer if this is a new player * invalid. Waiting for answer if this is a new player
* @WMUD_CLIENT_STATE_REGISTERING: Registering a new player. Waiting for the * @WMUD_CLIENT_STATE_REGISTERING: Registering a new player. Waiting for the
@ -56,7 +59,7 @@ typedef enum {
WMUD_CLIENT_STATE_PASSWAIT, WMUD_CLIENT_STATE_PASSWAIT,
WMUD_CLIENT_STATE_MENU, WMUD_CLIENT_STATE_MENU,
WMUD_CLIENT_STATE_INGAME, WMUD_CLIENT_STATE_INGAME,
WMUD_CLIENT_STATE_QUITWAIT, WMUD_CLIENT_STATE_YESNO,
WMUD_CLIENT_STATE_NEWCHAR, WMUD_CLIENT_STATE_NEWCHAR,
WMUD_CLIENT_STATE_REGISTERING, WMUD_CLIENT_STATE_REGISTERING,
WMUD_CLIENT_STATE_REGEMAIL_CONFIRM WMUD_CLIENT_STATE_REGEMAIL_CONFIRM
@ -82,6 +85,10 @@ typedef struct _wmudPlayer {
gint fail_count; gint fail_count;
} wmudPlayer; } wmudPlayer;
typedef struct _wmudClient wmudClient;
typedef void (*wmudYesNoCallback)(wmudClient *client, gboolean answer);
/** /**
* wmudClient: * wmudClient:
* @socket: The assigned GSocket object * @socket: The assigned GSocket object
@ -99,7 +106,7 @@ typedef struct _wmudPlayer {
* <structname>wmudClient</structname> contains all properties of a connected * <structname>wmudClient</structname> contains all properties of a connected
* game client. * game client.
*/ */
typedef struct _wmudClient { struct _wmudClient {
GSocket *socket; GSocket *socket;
GSource *socket_source; GSource *socket_source;
GString *buffer; GString *buffer;
@ -108,7 +115,8 @@ typedef struct _wmudClient {
wmudPlayer *player; wmudPlayer *player;
gboolean bademail; gboolean bademail;
gint login_try_count; gint login_try_count;
} wmudClient; wmudYesNoCallback yesNoCallback;
};
#endif /* __WMUD_TYPES_H__ */ #endif /* __WMUD_TYPES_H__ */