From 4e479e0045c5387f1b77c9ef6b7a6e93c03ad52e Mon Sep 17 00:00:00 2001 From: Gergely POLONKAI Date: Thu, 17 May 2012 22:18:04 +0200 Subject: [PATCH] Fixed connection closing method, and fixed a logout/login problem Signed-off-by: Gergely POLONKAI --- wmud/game-networking.c | 7 +++++-- wmud/wmud-types.h | 1 + 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/wmud/game-networking.c b/wmud/game-networking.c index 1d83c9b..a23fc7f 100644 --- a/wmud/game-networking.c +++ b/wmud/game-networking.c @@ -79,9 +79,11 @@ wmud_client_close(wmudClient *client, gboolean send_goodbye) wmud_client_send(client, "\r\nHave a nice real-world day!\r\n\r\n"); g_log(G_LOG_DOMAIN, G_LOG_LEVEL_INFO, "Connection closed."); - g_socket_close(client->socket, NULL); + g_socket_shutdown(client->socket, TRUE, TRUE, NULL); clients = g_slist_remove(clients, client); - wmud_player_free(&(client->player)); + if (client->player) + if (!client->player->registered) + wmud_player_free(&(client->player)); if (client->buffer) g_string_free(client->buffer, TRUE); g_source_destroy(client->socket_source); @@ -201,6 +203,7 @@ wmud_client_callback(GSocket *client_socket, GIOCondition condition, wmudClient { client->state = WMUD_CLIENT_STATE_PASSWAIT; client->player = player; + client->player->registered = TRUE; wmud_client_send(client, "Please provide us your password: %c%c%c", TELNET_IAC, TELNET_WILL, TELNET_ECHO); } } diff --git a/wmud/wmud-types.h b/wmud/wmud-types.h index 834d400..baac57a 100644 --- a/wmud/wmud-types.h +++ b/wmud/wmud-types.h @@ -83,6 +83,7 @@ typedef struct _wmudPlayer { gchar *cpassword; gchar *email; gint fail_count; + gboolean registered; } wmudPlayer; typedef struct _wmudClient wmudClient;