2009-02-19 16:14:09 +00:00
|
|
|
/*
|
|
|
|
* uhub - A tiny ADC p2p connection hub
|
|
|
|
* Copyright (C) 2007-2009, Jan Vidar Krey
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "uhub.h"
|
|
|
|
|
2009-03-20 16:40:50 +00:00
|
|
|
static void log_user_login(struct user* u)
|
|
|
|
{
|
2009-03-20 17:54:05 +00:00
|
|
|
const char* cred = get_user_credential_string(u->credentials);
|
2009-05-26 17:46:51 +00:00
|
|
|
const char* addr = ip_convert_to_string(&u->net.ipaddr);
|
2009-03-20 17:54:05 +00:00
|
|
|
hub_log(log_user, "LoginOK %s/%s %s \"%s\" (%s) \"%s\"", sid_to_string(u->id.sid), u->id.cid, addr, u->id.nick, cred, u->user_agent);
|
2009-03-20 16:40:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void log_user_login_error(struct user* u, enum status_message msg)
|
|
|
|
{
|
2009-05-26 17:46:51 +00:00
|
|
|
const char* addr = ip_convert_to_string(&u->net.ipaddr);
|
2009-03-23 14:47:54 +00:00
|
|
|
const char* message = hub_get_status_message_log(u->hub, msg);
|
2009-03-20 16:40:50 +00:00
|
|
|
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)
|
|
|
|
{
|
2009-05-26 17:46:51 +00:00
|
|
|
const char* addr = ip_convert_to_string(&u->net.ipaddr);
|
2009-03-20 16:40:50 +00:00
|
|
|
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)
|
|
|
|
{
|
2009-05-26 17:46:51 +00:00
|
|
|
const char* addr = ip_convert_to_string(&u->net.ipaddr);
|
2009-03-20 16:40:50 +00:00
|
|
|
hub_log(log_user, "NickChange %s/%s %s \"%s\" -> \"%s\"", sid_to_string(u->id.sid), u->id.cid, addr, u->id.nick, nick);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-02-19 16:14:09 +00:00
|
|
|
/* Send MOTD, do logging etc */
|
2009-05-15 16:45:26 +00:00
|
|
|
void on_login_success(struct hub_info* hub, struct user* u)
|
2009-02-19 16:14:09 +00:00
|
|
|
{
|
|
|
|
struct timeval timeout = { TIMEOUT_IDLE, 0 };
|
|
|
|
|
|
|
|
/* Send user list of all existing users */
|
2009-05-18 14:30:17 +00:00
|
|
|
if (!uman_send_user_list(hub, u))
|
2009-02-19 16:14:09 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
/* Mark as being in the normal state, and add user to the user list */
|
|
|
|
user_set_state(u, state_normal);
|
2009-05-16 01:14:20 +00:00
|
|
|
uman_add(hub, u);
|
2009-02-19 16:14:09 +00:00
|
|
|
|
|
|
|
/* Print log message */
|
2009-03-20 16:40:50 +00:00
|
|
|
log_user_login(u);
|
2009-02-19 16:14:09 +00:00
|
|
|
|
|
|
|
/* Announce new user to all connected users */
|
|
|
|
if (user_is_logged_in(u))
|
2009-05-18 14:30:17 +00:00
|
|
|
route_info_message(hub, u);
|
2009-02-19 16:14:09 +00:00
|
|
|
|
|
|
|
/* Send message of the day (if any) */
|
|
|
|
if (user_is_logged_in(u)) /* Previous send() can fail! */
|
2009-05-15 16:45:26 +00:00
|
|
|
hub_send_motd(hub, u);
|
2009-02-19 16:14:09 +00:00
|
|
|
|
|
|
|
/* reset to idle timeout */
|
2009-05-26 17:46:51 +00:00
|
|
|
if (u->net.ev_read)
|
|
|
|
event_add(u->net.ev_read, &timeout);
|
2009-02-19 16:14:09 +00:00
|
|
|
}
|
|
|
|
|
2009-05-15 16:45:26 +00:00
|
|
|
void on_login_failure(struct hub_info* hub, struct user* u, enum status_message msg)
|
2009-02-19 16:14:09 +00:00
|
|
|
{
|
2009-03-20 16:40:50 +00:00
|
|
|
log_user_login_error(u, msg);
|
2009-05-15 16:45:26 +00:00
|
|
|
hub_send_status(hub, u, msg, status_level_fatal);
|
2009-05-18 14:30:17 +00:00
|
|
|
hub_disconnect_user(hub, u, quit_logon_error);
|
2009-02-19 16:14:09 +00:00
|
|
|
}
|
|
|
|
|
2009-05-15 16:45:26 +00:00
|
|
|
void on_nick_change(struct hub_info* hub, struct user* u, const char* nick)
|
2009-02-19 16:14:09 +00:00
|
|
|
{
|
|
|
|
if (user_is_logged_in(u))
|
|
|
|
{
|
2009-03-20 16:40:50 +00:00
|
|
|
log_user_nick_change(u, nick);
|
2009-02-19 16:14:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-05-15 16:45:26 +00:00
|
|
|
void on_logout_user(struct hub_info* hub, struct user* user)
|
2009-02-19 16:14:09 +00:00
|
|
|
{
|
|
|
|
const char* reason = "";
|
|
|
|
|
|
|
|
/* These are used for logging purposes */
|
|
|
|
switch (user->quit_reason)
|
|
|
|
{
|
2009-03-20 16:40:50 +00:00
|
|
|
case quit_disconnected: reason = "disconnected"; break;
|
2009-02-19 16:14:09 +00:00
|
|
|
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;
|
2009-03-20 16:40:50 +00:00
|
|
|
case quit_ghost_timeout: reason = "ghost"; break;
|
2009-02-19 16:14:09 +00:00
|
|
|
default:
|
2009-05-15 16:45:26 +00:00
|
|
|
if (hub->status == hub_status_shutdown)
|
2009-02-19 16:14:09 +00:00
|
|
|
reason = "hub shutdown";
|
|
|
|
else
|
|
|
|
reason = "unknown error";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2009-03-20 16:40:50 +00:00
|
|
|
log_user_logout(user, reason);
|
2009-02-19 16:14:09 +00:00
|
|
|
user->quit_reason = 0;
|
|
|
|
}
|
|
|
|
|