Added funcions for sending notifications to operators.
Notifications could be compared to some sort of a log message, but since it is broadcasted to operators live in the hub it draws attention to them.
This commit is contained in:
parent
5b78c0826d
commit
f91f3ea68c
|
@ -353,6 +353,7 @@ static int command_kick(struct command_base* cbase, struct hub_user* user, struc
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
hub_notify(cbase->hub, notify_info, "Kicking user \"%s\" (%s)", target->id.nick, user->id.nick);
|
||||||
cbuf_append_format(buf, "Kicking user \"%s\".", target->id.nick);
|
cbuf_append_format(buf, "Kicking user \"%s\".", target->id.nick);
|
||||||
hub_disconnect_user(cbase->hub, target, quit_kicked);
|
hub_disconnect_user(cbase->hub, target, quit_kicked);
|
||||||
}
|
}
|
||||||
|
@ -362,6 +363,7 @@ static int command_kick(struct command_base* cbase, struct hub_user* user, struc
|
||||||
static int command_reload(struct command_base* cbase, struct hub_user* user, struct hub_command* cmd)
|
static int command_reload(struct command_base* cbase, struct hub_user* user, struct hub_command* cmd)
|
||||||
{
|
{
|
||||||
cbase->hub->status = hub_status_restart;
|
cbase->hub->status = hub_status_restart;
|
||||||
|
hub_notify(cbase->hub, notify_info, "Reloading configuration (%s)", user->id.nick);
|
||||||
return command_status(cbase, user, cmd, cbuf_create_const("Reloading configuration..."));
|
return command_status(cbase, user, cmd, cbuf_create_const("Reloading configuration..."));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -384,6 +386,7 @@ static int command_unload(struct command_base* cbase, struct hub_user* user, str
|
||||||
|
|
||||||
static int command_shutdown_hub(struct command_base* cbase, struct hub_user* user, struct hub_command* cmd)
|
static int command_shutdown_hub(struct command_base* cbase, struct hub_user* user, struct hub_command* cmd)
|
||||||
{
|
{
|
||||||
|
hub_notify(cbase->hub, notify_warn, "Shutting down hub (%s)", user->id.nick);
|
||||||
cbase->hub->status = hub_status_shutdown;
|
cbase->hub->status = hub_status_shutdown;
|
||||||
return command_status(cbase, user, cmd, cbuf_create_const("Hub shutting down..."));
|
return command_status(cbase, user, cmd, cbuf_create_const("Hub shutting down..."));
|
||||||
}
|
}
|
||||||
|
|
|
@ -653,6 +653,7 @@ static struct net_connection* start_listening_socket(const char* bind_addr, uint
|
||||||
if (ret == -1)
|
if (ret == -1)
|
||||||
{
|
{
|
||||||
LOG_ERROR("hub_start_service(): Unable to bind to TCP local address. errno=%d, str=%s", net_error(), net_error_string(net_error()));
|
LOG_ERROR("hub_start_service(): Unable to bind to TCP local address. errno=%d, str=%s", net_error(), net_error_string(net_error()));
|
||||||
|
hub_notify(hub, notify_error, "Unable to bind to network address %s on port %d: %s (%d)", bind_addr, port, net_error_string(net_error()), net_error());
|
||||||
net_close(sd);
|
net_close(sd);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -671,6 +672,60 @@ static struct net_connection* start_listening_socket(const char* bind_addr, uint
|
||||||
return server;
|
return server;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int hub_is_running(struct hub_info* hub)
|
||||||
|
{
|
||||||
|
return hub->status == hub_status_running || hub->status == hub_status_restart;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void hub_notify(struct hub_info* hub, enum notify_verbosity verbosity, const char* fmt, ...)
|
||||||
|
{
|
||||||
|
struct cbuffer* buf;
|
||||||
|
struct adc_message* msg;
|
||||||
|
va_list args;
|
||||||
|
char temp[1024];
|
||||||
|
|
||||||
|
va_start(args, fmt);
|
||||||
|
vsnprintf(temp, sizeof(temp), fmt, args);
|
||||||
|
va_end(args);
|
||||||
|
|
||||||
|
buf = cbuf_create(strlen(temp) + 8);
|
||||||
|
|
||||||
|
switch (verbosity)
|
||||||
|
{
|
||||||
|
case notify_error:
|
||||||
|
cbuf_append(buf, "ERROR: ");
|
||||||
|
LOG_ERROR(temp);
|
||||||
|
break;
|
||||||
|
case notify_warn:
|
||||||
|
cbuf_append(buf, "WARN: ");
|
||||||
|
LOG_WARN(temp);
|
||||||
|
break;
|
||||||
|
case notify_info:
|
||||||
|
cbuf_append(buf, "INFO: ");
|
||||||
|
LOG_INFO(temp);
|
||||||
|
break;
|
||||||
|
case notify_debug:
|
||||||
|
cbuf_append(buf, "DEBUG: ");
|
||||||
|
LOG_DEBUG(temp);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
cbuf_append(buf, temp);
|
||||||
|
|
||||||
|
if (hub_is_running(hub))
|
||||||
|
{
|
||||||
|
msg = adc_msg_construct(ADC_CMD_IMSG, 5 + adc_msg_escape_length(cbuf_get(buf)) + 2);
|
||||||
|
adc_msg_add_argument_string(msg, cbuf_get(buf));
|
||||||
|
route_to_operators(hub, msg);
|
||||||
|
adc_msg_free(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
cbuf_destroy(buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
struct server_alt_port_data
|
struct server_alt_port_data
|
||||||
{
|
{
|
||||||
struct hub_info* hub;
|
struct hub_info* hub;
|
||||||
|
|
|
@ -106,7 +106,7 @@ struct hub_info
|
||||||
struct adc_message* command_support; /* The hub's SUP command */
|
struct adc_message* command_support; /* The hub's SUP command */
|
||||||
struct adc_message* command_banner; /* The default welcome message */
|
struct adc_message* command_banner; /* The default welcome message */
|
||||||
time_t tm_started;
|
time_t tm_started;
|
||||||
int status;
|
enum hub_state status;
|
||||||
char* recvbuf; /* Global receive buffer */
|
char* recvbuf; /* Global receive buffer */
|
||||||
char* sendbuf; /* Global send buffer */
|
char* sendbuf; /* Global send buffer */
|
||||||
|
|
||||||
|
@ -233,6 +233,20 @@ extern void hub_set_variables(struct hub_info* hub, struct acl_handle* acl);
|
||||||
*/
|
*/
|
||||||
extern void hub_free_variables(struct hub_info* hub);
|
extern void hub_free_variables(struct hub_info* hub);
|
||||||
|
|
||||||
|
|
||||||
|
enum notify_verbosity
|
||||||
|
{
|
||||||
|
notify_error = 0,
|
||||||
|
notify_warn = 1,
|
||||||
|
notify_info = 2,
|
||||||
|
notify_debug = 3,
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send a notification message to operators.
|
||||||
|
*/
|
||||||
|
extern void hub_notify(struct hub_info* hub, enum notify_verbosity verbosity, const char* fmt, ...);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a string for the given status_message (See enum status_message).
|
* Returns a string for the given status_message (See enum status_message).
|
||||||
*/
|
*/
|
||||||
|
@ -350,6 +364,10 @@ 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);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns 1 if the hub is running, and 0 otherwise.
|
||||||
|
*/
|
||||||
|
extern int hub_is_running(struct hub_info* hub);
|
||||||
|
|
||||||
#endif /* HAVE_UHUB_HUB_H */
|
#endif /* HAVE_UHUB_HUB_H */
|
||||||
|
|
||||||
|
|
|
@ -31,6 +31,10 @@ void on_login_success(struct hub_info* hub, struct hub_user* u)
|
||||||
user_set_state(u, state_normal);
|
user_set_state(u, state_normal);
|
||||||
uman_add(hub->users, u);
|
uman_add(hub->users, u);
|
||||||
|
|
||||||
|
// Make operators receive hub notifications by default.
|
||||||
|
if (user_is_protected(u))
|
||||||
|
user_flag_set(u, flag_opnotify);
|
||||||
|
|
||||||
/* 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))
|
||||||
route_info_message(hub, u);
|
route_info_message(hub, u);
|
||||||
|
|
Loading…
Reference in New Issue