Cleanup logging.
Signed-off-by: Jan Vidar Krey <janvidar@extatic.org>
This commit is contained in:
parent
998c6c36ce
commit
b1f84b5b4a
@ -491,7 +491,7 @@ struct hub_info* hub_start_service(struct hub_config* config)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
hub_log(log_info, "Starting server, listening on %s:%d...", address_buf, config->server_port);
|
hub_log(log_info, "Starting " PRODUCT "/" VERSION ", listening on %s:%d...", address_buf, config->server_port);
|
||||||
|
|
||||||
server_tcp = net_socket_create(af, SOCK_STREAM, IPPROTO_TCP);
|
server_tcp = net_socket_create(af, SOCK_STREAM, IPPROTO_TCP);
|
||||||
if (server_tcp == -1)
|
if (server_tcp == -1)
|
||||||
|
@ -19,12 +19,36 @@
|
|||||||
|
|
||||||
#include "uhub.h"
|
#include "uhub.h"
|
||||||
|
|
||||||
|
static void log_user_login(struct user* u)
|
||||||
|
{
|
||||||
|
const char* credentials_string[] = { "", "link", "guest", "user", "operator", "super", "admin" };
|
||||||
|
const char* addr = ip_convert_to_string(&u->ipaddr);
|
||||||
|
hub_log(log_user, "LoginOK %s/%s %s \"%s\" (%s) \"%s\"", sid_to_string(u->id.sid), u->id.cid, addr, u->id.nick, credentials_string[u->credentials], u->user_agent);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void log_user_login_error(struct user* u, enum status_message msg)
|
||||||
|
{
|
||||||
|
const char* addr = ip_convert_to_string(&u->ipaddr);
|
||||||
|
const char* message = hub_get_status_message(u->hub, msg);
|
||||||
|
hub_log(log_user, "LoginError %s/%s %s \"%s\" (%s) \"%s\"", sid_to_string(u->id.sid), u->id.cid, addr, u->id.nick, message, u->user_agent);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void log_user_logout(struct user* u, const char* message)
|
||||||
|
{
|
||||||
|
const char* addr = ip_convert_to_string(&u->ipaddr);
|
||||||
|
hub_log(log_user, "Logout %s/%s %s \"%s\" (%s)", sid_to_string(u->id.sid), u->id.cid, addr, u->id.nick, message);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void log_user_nick_change(struct user* u, const char* nick)
|
||||||
|
{
|
||||||
|
const char* addr = ip_convert_to_string(&u->ipaddr);
|
||||||
|
hub_log(log_user, "NickChange %s/%s %s \"%s\" -> \"%s\"", sid_to_string(u->id.sid), u->id.cid, addr, u->id.nick, nick);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Send MOTD, do logging etc */
|
/* Send MOTD, do logging etc */
|
||||||
void on_login_success(struct user* u)
|
void on_login_success(struct user* u)
|
||||||
{
|
{
|
||||||
/* Logging - FIXME: Move this to a plugin */
|
|
||||||
const char* addr = ip_convert_to_string(&u->ipaddr);
|
|
||||||
const char* credentials_string[] = { "!none!", "link", "guest", "user", "operator", "super", "admin" };
|
|
||||||
struct timeval timeout = { TIMEOUT_IDLE, 0 };
|
struct timeval timeout = { TIMEOUT_IDLE, 0 };
|
||||||
|
|
||||||
/* Send user list of all existing users */
|
/* Send user list of all existing users */
|
||||||
@ -36,7 +60,7 @@ void on_login_success(struct user* u)
|
|||||||
user_manager_add(u);
|
user_manager_add(u);
|
||||||
|
|
||||||
/* Print log message */
|
/* Print log message */
|
||||||
hub_log(log_user, "Login OK %s/%s \"%s\" [%s] (%s) \"%s\"", sid_to_string(u->id.sid), u->id.cid, u->id.nick, addr, credentials_string[u->credentials], u->user_agent);
|
log_user_login(u);
|
||||||
|
|
||||||
/* Announce new user to all connected users */
|
/* Announce new user to all connected users */
|
||||||
if (user_is_logged_in(u))
|
if (user_is_logged_in(u))
|
||||||
@ -51,31 +75,24 @@ void on_login_success(struct user* u)
|
|||||||
event_add(u->ev_read, &timeout);
|
event_add(u->ev_read, &timeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void on_login_failure(struct user* u, enum status_message msg)
|
void on_login_failure(struct user* u, enum status_message msg)
|
||||||
{
|
{
|
||||||
const char* addr = ip_convert_to_string(&u->ipaddr);
|
log_user_login_error(u, msg);
|
||||||
const char* message = hub_get_status_message(u->hub, msg);
|
|
||||||
hub_log(log_user, "Login FAIL %s/%s \"%s\" [%s] (%s) \"%s\"", sid_to_string(u->id.sid), u->id.cid, u->id.nick, addr, message, u->user_agent);
|
|
||||||
|
|
||||||
hub_send_status(u, msg, status_level_fatal);
|
hub_send_status(u, msg, status_level_fatal);
|
||||||
user_disconnect(u, quit_logon_error);
|
user_disconnect(u, quit_logon_error);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void on_nick_change(struct user* u, const char* nick)
|
void on_nick_change(struct user* u, const char* nick)
|
||||||
{
|
{
|
||||||
if (user_is_logged_in(u))
|
if (user_is_logged_in(u))
|
||||||
{
|
{
|
||||||
hub_log(log_user, "Nick change %s/%s \"%s\" -> \"%s\"", sid_to_string(u->id.sid), u->id.cid, u->id.nick, nick);
|
log_user_nick_change(u, nick);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void on_logout_user(struct user* user)
|
void on_logout_user(struct user* user)
|
||||||
{
|
{
|
||||||
const char* reason = "";
|
const char* reason = "";
|
||||||
const char* addr;
|
|
||||||
|
|
||||||
/* These are used for logging purposes */
|
/* These are used for logging purposes */
|
||||||
switch (user->quit_reason)
|
switch (user->quit_reason)
|
||||||
@ -90,6 +107,7 @@ void on_logout_user(struct user* user)
|
|||||||
case quit_protocol_error: reason = "protocol error"; break;
|
case quit_protocol_error: reason = "protocol error"; break;
|
||||||
case quit_logon_error: reason = "login error"; break;
|
case quit_logon_error: reason = "login error"; break;
|
||||||
case quit_hub_disabled: reason = "hub disabled"; break;
|
case quit_hub_disabled: reason = "hub disabled"; break;
|
||||||
|
case quit_ghost_timeout: reason = "ghost"; break;
|
||||||
default:
|
default:
|
||||||
if (user->hub->status == hub_status_shutdown)
|
if (user->hub->status == hub_status_shutdown)
|
||||||
reason = "hub shutdown";
|
reason = "hub shutdown";
|
||||||
@ -98,10 +116,7 @@ void on_logout_user(struct user* user)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
addr = ip_convert_to_string(&user->ipaddr);
|
log_user_logout(user, reason);
|
||||||
hub_log(log_user, "Logout %s/%s \"%s\" [%s] (%s)", sid_to_string(user->id.sid), user->id.cid, user->id.nick, addr, reason);
|
|
||||||
|
|
||||||
|
|
||||||
user->quit_reason = 0;
|
user->quit_reason = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -332,7 +332,7 @@ static int check_logged_in(struct user* user, struct adc_message* cmd)
|
|||||||
if (lookup1 == lookup2)
|
if (lookup1 == lookup2)
|
||||||
{
|
{
|
||||||
hub_log(log_debug, "check_logged_in: exact same user is logged in: %s", user->id.nick);
|
hub_log(log_debug, "check_logged_in: exact same user is logged in: %s", user->id.nick);
|
||||||
user_disconnect(lookup1, quit_timeout);
|
user_disconnect(lookup1, quit_ghost_timeout);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -177,8 +177,8 @@ void hub_log(int log_verbosity, const char *format, ...)
|
|||||||
if (log_verbosity < verbosity)
|
if (log_verbosity < verbosity)
|
||||||
{
|
{
|
||||||
t = time(NULL);
|
t = time(NULL);
|
||||||
tmp = gmtime(&t);
|
tmp = localtime(&t);
|
||||||
strftime(timestamp, 32, "%a, %d %b %Y %H:%M:%S +0000", tmp);
|
strftime(timestamp, 32, "%Y-%m-%d %H:%M:%S %z", tmp);
|
||||||
va_start(args, format);
|
va_start(args, format);
|
||||||
vsnprintf(logmsg, 1024, format, args);
|
vsnprintf(logmsg, 1024, format, args);
|
||||||
va_end(args);
|
va_end(args);
|
||||||
|
@ -68,6 +68,7 @@ enum user_quit_reason
|
|||||||
quit_protocol_error = 8, /** Fatal protocol error */
|
quit_protocol_error = 8, /** Fatal protocol error */
|
||||||
quit_logon_error = 9, /** Unable to login (wrong password, CID/PID, etc) */
|
quit_logon_error = 9, /** Unable to login (wrong password, CID/PID, etc) */
|
||||||
quit_hub_disabled = 10, /** Hub is disabled. No new connections allowed */
|
quit_hub_disabled = 10, /** Hub is disabled. No new connections allowed */
|
||||||
|
quit_ghost_timeout = 11, /** The user is a ghost, and trying to login from another connection */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user