Add a quit reason to the log messages printed by !log.

This commit is contained in:
Jan Vidar Krey 2009-08-02 22:53:25 +02:00
parent 1f24bd6812
commit 4666311516
7 changed files with 32 additions and 30 deletions

View File

@ -459,7 +459,7 @@ static int command_log(struct hub_info* hub, struct hub_user* user, struct hub_c
if (show) 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); send_message(hub, user, tmp);
} }
log = (struct hub_logout_info*) list_get_next(messages); log = (struct hub_logout_info*) list_get_next(messages);

View File

@ -995,7 +995,6 @@ void hub_disconnect_user(struct hub_info* hub, struct hub_user* user, int reason
} }
else else
{ {
user->quit_reason = quit_unknown;
hub_schedule_destroy_user(hub, user); hub_schedule_destroy_user(hub, user);
} }
} }

View File

@ -85,7 +85,7 @@ struct hub_logout_info
char cid[MAX_CID_LEN+1]; char cid[MAX_CID_LEN+1];
char nick[MAX_NICK_LEN+1]; char nick[MAX_NICK_LEN+1];
struct ip_addr_encap addr; struct ip_addr_encap addr;
int reason; enum user_quit_reason reason;
}; };
struct hub_info 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); extern void hub_logout_log(struct hub_info* hub, struct hub_user* user);
#endif /* HAVE_UHUB_HUB_H */ #endif /* HAVE_UHUB_HUB_H */

View File

@ -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) void on_logout_user(struct hub_info* hub, struct hub_user* user)
{ {
const char* reason = ""; const char* reason = user_get_quit_reason_string(user->quit_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;
}
log_user_logout(user, reason); log_user_logout(user, reason);
hub_logout_log(hub, user); hub_logout_log(hub, user);
user->quit_reason = 0;
} }

View File

@ -351,4 +351,25 @@ void user_set_timeout(struct hub_user* user, int seconds)
evtimer_add(&user->net.timeout, &timeout); 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";
}

View File

@ -70,6 +70,9 @@ enum user_quit_reason
quit_ghost_timeout = 11, /** The user is a ghost, and trying to login from another connection */ 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 struct hub_user_info
{ {
sid_t sid; /** session ID */ 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 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_info* hub; /** The hub instance this user belong to */
struct hub_user_limits limits; /** Data used for limitation */ 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); extern void user_reset_last_read(struct hub_user* user);
#endif /* HAVE_UHUB_USER_H */ #endif /* HAVE_UHUB_USER_H */