Added the +rules command.

Also added the +motd command to see the message of the day, which is sent while connecting.
This commit is contained in:
Jan Vidar Krey 2010-01-19 23:20:19 +01:00
parent 80c6ad9d76
commit e45511827f
6 changed files with 68 additions and 2 deletions

View File

@ -518,6 +518,20 @@ static int command_log(struct hub_info* hub, struct hub_user* user, struct hub_c
return 0;
}
static int command_rules(struct hub_info* hub, struct hub_user* user, struct hub_command* cmd)
{
if (!hub_send_rules(hub, user))
return command_status(hub, user, cmd, "no rules defined.");
return 0;
}
static int command_motd(struct hub_info* hub, struct hub_user* user, struct hub_command* cmd)
{
if (!hub_send_motd(hub, user))
return command_status(hub, user, cmd, "no motd defined.");
return 0;
}
#ifdef CRASH_DEBUG
static int command_crash(struct hub_info* hub, struct hub_user* user, struct hub_command* cmd)
{
@ -589,6 +603,8 @@ static struct commands_handler command_handlers[] = {
{ "log", 3, 0, cred_operator, command_log, "Display log" },
{ "mute", 4, "n", cred_operator, command_mute, "Mute user" },
{ "unmute", 6, "n", cred_operator, command_mute, "Unmute user" },
{ "rules", 5, 0, cred_guest, command_rules, "Show the hub rules" },
{ "motd", 4, 0, cred_guest, command_motd, "Show the message of the day" },
#ifdef CRASH_DEBUG
{ "crash", 5, 0, cred_admin, command_crash, "Crash the hub (DEBUG)." },
#endif

View File

@ -116,6 +116,7 @@
#define DEF_HUB_ENABLED 1
#define DEF_FILE_ACL ""
#define DEF_FILE_MOTD ""
#define DEF_FILE_RULES ""
#define DEF_MAX_USERS 500
#define DEF_MAX_CHAT_HISTORY 20
#define DEF_MAX_LOGOUT_LOG 100
@ -180,6 +181,7 @@ void config_defaults(struct hub_config* config)
DEFAULT_BOOLEAN(hub_enabled, DEF_HUB_ENABLED);
DEFAULT_STRING (file_acl, DEF_FILE_ACL);
DEFAULT_STRING (file_motd, DEF_FILE_MOTD);
DEFAULT_STRING (file_rules, DEF_FILE_RULES);
DEFAULT_INTEGER(server_port, DEF_SERVER_PORT);
DEFAULT_INTEGER(server_listen_backlog, DEF_SERVER_BACKLOG);
DEFAULT_INTEGER(max_users, DEF_MAX_USERS);
@ -249,6 +251,7 @@ static int apply_config(struct hub_config* config, char* key, char* data, int li
{
GET_STR (file_acl);
GET_STR (file_motd);
GET_STR (file_rules);
GET_STR (server_bind_addr);
GET_INT (server_port);
GET_INT (server_listen_backlog);
@ -327,6 +330,7 @@ void free_config(struct hub_config* config)
hub_free(config->server_bind_addr);
hub_free(config->file_motd);
hub_free(config->file_acl);
hub_free(config->file_rules);
hub_free(config->hub_name);
hub_free(config->hub_description);
@ -398,6 +402,7 @@ void dump_config(struct hub_config* config, int ignore_defaults)
{
DUMP_STR (file_acl, DEF_FILE_ACL);
DUMP_STR (file_motd, DEF_FILE_MOTD);
DUMP_STR (file_rules, DEF_FILE_RULES);
DUMP_STR (server_bind_addr, DEF_SERVER_BIND_ADDR);
DUMP_INT (server_port, DEF_SERVER_PORT);
DUMP_INT (server_listen_backlog, DEF_SERVER_BACKLOG);

View File

@ -33,6 +33,7 @@ struct hub_config
int chat_is_privileged; /**<<< "Allow chat for operators and above only (default: 0) */
char* file_motd; /**<<< "File containing the 'message of the day' (default: '' - no motd)" */
char* file_acl; /**<<< "File containing user database (default: '' - no known users)" */
char* file_rules; /**<<< "File containing the rules (default: '' - no rules)" */
char* hub_name; /**<<< "Name of hub (default: 'My uhub hub')" */
char* hub_description; /**<<< "Name of hub (default: 'no description')" */
int max_recv_buffer; /**<<< "Max read buffer before parse, per user (default: 4096)" */

View File

@ -361,14 +361,27 @@ void hub_send_handshake(struct hub_info* hub, struct hub_user* u)
}
}
void hub_send_motd(struct hub_info* hub, struct hub_user* u)
int hub_send_motd(struct hub_info* hub, struct hub_user* u)
{
if (hub->command_motd)
{
route_to_user(hub, u, hub->command_motd);
return 1;
}
return 0;
}
int hub_send_rules(struct hub_info* hub, struct hub_user* u)
{
if (hub->command_rules)
{
route_to_user(hub, u, hub->command_rules);
return 1;
}
return 0;
}
void hub_send_password_challenge(struct hub_info* hub, struct hub_user* u)
{
struct adc_message* igpa;
@ -669,6 +682,22 @@ void hub_set_variables(struct hub_info* hub, struct acl_handle* acl)
close(fd);
}
hub->command_rules = 0;
fd = (hub->config->file_rules && *hub->config->file_rules) ? open(hub->config->file_rules, 0) : -1;
if (fd != -1)
{
ret = read(fd, buf, MAX_RECV_BUF);
if (ret > 0)
{
buf[ret] = 0;
tmp = adc_msg_escape(buf);
hub->command_rules = adc_msg_construct(ADC_CMD_IMSG, 6 + strlen(tmp));
adc_msg_add_argument(hub->command_rules, tmp);
hub_free(tmp);
}
close(fd);
}
hub->command_support = adc_msg_construct(ADC_CMD_ISUP, 6 + strlen(ADC_PROTO_SUPPORT));
if (hub->command_support)
{
@ -697,6 +726,9 @@ void hub_free_variables(struct hub_info* hub)
if (hub->command_motd)
adc_msg_free(hub->command_motd);
if (hub->command_rules)
adc_msg_free(hub->command_rules);
adc_msg_free(hub->command_support);
}

View File

@ -103,6 +103,7 @@ struct hub_info
struct adc_message* command_info; /* The hub's INF command */
struct adc_message* command_support; /* The hub's SUP command */
struct adc_message* command_motd; /* The message of the day */
struct adc_message* command_rules; /* The hub rules */
struct adc_message* command_banner; /* The default welcome message */
time_t tm_started;
int status;
@ -203,8 +204,15 @@ extern void hub_send_handshake(struct hub_info* hub, struct hub_user* u);
/**
* Send a welcome message containing the message of the day to
* one particular user. This can be sent in any point in time.
* @return 1 if the motd were sent.
*/
extern void hub_send_motd(struct hub_info* hub, struct hub_user* u);
extern int hub_send_motd(struct hub_info* hub, struct hub_user* u);
/**
* Send the rules if configured.
* @return 1 if the rules were sent.
*/
extern int hub_send_rules(struct hub_info* hub, struct hub_user* u);
/**
* Send a password challenge to a user.

View File

@ -68,6 +68,10 @@ void on_login_success(struct hub_info* hub, struct hub_user* u)
if (user_is_logged_in(u)) /* Previous send() can fail! */
hub_send_motd(hub, u);
/* Send message of the day (if any) */
if (user_is_logged_in(u)) /* Previous send() can fail! */
hub_send_rules(hub, u);
/* reset timeout */
net_con_clear_timeout(u->connection);
}