From 4666311516213f3bd114091c4df66c4c302ed6e3 Mon Sep 17 00:00:00 2001 From: Jan Vidar Krey Date: Sun, 2 Aug 2009 22:53:25 +0200 Subject: [PATCH] Add a quit reason to the log messages printed by !log. --- src/core/commands.c | 2 +- src/core/hub.c | 1 - src/core/hub.h | 3 ++- src/core/hubevent.c | 26 +------------------------- src/core/user.c | 21 +++++++++++++++++++++ src/core/user.h | 7 ++++++- src/core/usermanager.c | 2 +- 7 files changed, 32 insertions(+), 30 deletions(-) diff --git a/src/core/commands.c b/src/core/commands.c index 9d58b08..1988414 100644 --- a/src/core/commands.c +++ b/src/core/commands.c @@ -459,7 +459,7 @@ static int command_log(struct hub_info* hub, struct hub_user* user, struct hub_c if (show) { - sprintf(tmp, "* %s %s, %s (%s)", get_timestamp(log->time), log->cid, log->nick, ip_convert_to_string(&log->addr)); + sprintf(tmp, "* %s %s, %s [%s] - %s", get_timestamp(log->time), log->cid, log->nick, ip_convert_to_string(&log->addr), user_get_quit_reason_string(log->reason)); send_message(hub, user, tmp); } log = (struct hub_logout_info*) list_get_next(messages); diff --git a/src/core/hub.c b/src/core/hub.c index 878a5f3..6c93db3 100644 --- a/src/core/hub.c +++ b/src/core/hub.c @@ -995,7 +995,6 @@ void hub_disconnect_user(struct hub_info* hub, struct hub_user* user, int reason } else { - user->quit_reason = quit_unknown; hub_schedule_destroy_user(hub, user); } } diff --git a/src/core/hub.h b/src/core/hub.h index 6a28222..381277f 100644 --- a/src/core/hub.h +++ b/src/core/hub.h @@ -85,7 +85,7 @@ struct hub_logout_info char cid[MAX_CID_LEN+1]; char nick[MAX_NICK_LEN+1]; struct ip_addr_encap addr; - int reason; + enum user_quit_reason reason; }; struct hub_info @@ -358,5 +358,6 @@ extern void hub_disconnect_user(struct hub_info* hub, struct hub_user* user, int */ extern void hub_logout_log(struct hub_info* hub, struct hub_user* user); + #endif /* HAVE_UHUB_HUB_H */ diff --git a/src/core/hubevent.c b/src/core/hubevent.c index 35a43d1..6e0bac2 100644 --- a/src/core/hubevent.c +++ b/src/core/hubevent.c @@ -89,32 +89,8 @@ void on_nick_change(struct hub_info* hub, struct hub_user* u, const char* nick) void on_logout_user(struct hub_info* hub, struct hub_user* user) { - const char* reason = ""; - - /* These are used for logging purposes */ - switch (user->quit_reason) - { - case quit_disconnected: reason = "disconnected"; break; - case quit_kicked: reason = "kicked"; break; - case quit_banned: reason = "banned"; break; - case quit_timeout: reason = "timeout"; break; - case quit_send_queue: reason = "send queue"; break; - case quit_memory_error: reason = "out of memory"; break; - case quit_socket_error: reason = "socket error"; break; - case quit_protocol_error: reason = "protocol error"; break; - case quit_logon_error: reason = "login error"; break; - case quit_hub_disabled: reason = "hub disabled"; break; - case quit_ghost_timeout: reason = "ghost"; break; - default: - if (hub->status == hub_status_shutdown) - reason = "hub shutdown"; - else - reason = "unknown error"; - break; - } - + const char* reason = user_get_quit_reason_string(user->quit_reason); log_user_logout(user, reason); hub_logout_log(hub, user); - user->quit_reason = 0; } diff --git a/src/core/user.c b/src/core/user.c index d21c870..706659d 100644 --- a/src/core/user.c +++ b/src/core/user.c @@ -351,4 +351,25 @@ void user_set_timeout(struct hub_user* user, int seconds) evtimer_add(&user->net.timeout, &timeout); } +const char* user_get_quit_reason_string(enum user_quit_reason reason) +{ + switch (reason) + { + case quit_unknown: return "unknown"; break; + case quit_disconnected: return "disconnected"; break; + case quit_kicked: return "kicked"; break; + case quit_banned: return "banned"; break; + case quit_timeout: return "timeout"; break; + case quit_send_queue: return "send queue"; break; + case quit_memory_error: return "out of memory"; break; + case quit_socket_error: return "socket error"; break; + case quit_protocol_error: return "protocol error"; break; + case quit_logon_error: return "login error"; break; + case quit_hub_disabled: return "hub disabled"; break; + case quit_ghost_timeout: return "ghost"; break; + } + + return "unknown"; +} + diff --git a/src/core/user.h b/src/core/user.h index 1a1b22a..d1693e0 100644 --- a/src/core/user.h +++ b/src/core/user.h @@ -70,6 +70,9 @@ enum user_quit_reason quit_ghost_timeout = 11, /** The user is a ghost, and trying to login from another connection */ }; +/** Returns an apropriate string for the given quit reason */ +extern const char* user_get_quit_reason_string(enum user_quit_reason); + struct hub_user_info { sid_t sid; /** session ID */ @@ -117,7 +120,7 @@ struct hub_user struct adc_message* info; /** ADC 'INF' message (broadcasted to everyone joining the hub) */ struct hub_info* hub; /** The hub instance this user belong to */ struct hub_user_limits limits; /** Data used for limitation */ - int quit_reason; /** Quit reason (see user_quit_reason) */ + enum user_quit_reason quit_reason; /** Quit reason (see user_quit_reason) */ }; @@ -282,6 +285,8 @@ extern void user_reset_last_write(struct hub_user* user); */ extern void user_reset_last_read(struct hub_user* user); + + #endif /* HAVE_UHUB_USER_H */ diff --git a/src/core/usermanager.c b/src/core/usermanager.c index 39ac76d..419a99e 100644 --- a/src/core/usermanager.c +++ b/src/core/usermanager.c @@ -98,7 +98,7 @@ int uman_init(struct hub_info* hub) users->list = list_create(); users->sids = sid_pool_create(net_get_max_sockets()); - + if (!users->list) { list_destroy(users->list);