Make sure chat messages are routed through plugins.

This commit is contained in:
Jan Vidar Krey 2010-08-03 23:19:39 +02:00
parent 4a977da514
commit 0c6a58d35a
3 changed files with 52 additions and 2 deletions

View File

@ -25,6 +25,7 @@ struct hub_info* g_hub = 0;
if (hub->config->chat_only && u->credentials < auth_cred_operator) \
break
/* FIXME: Flood control should be done in a plugin! */
#define CHECK_FLOOD(TYPE, WARN) \
if (flood_control_check(&u->flood_ ## TYPE , hub->config->flood_ctl_ ## TYPE, hub->config->flood_ctl_interval, net_get_time())) \
{ \
@ -255,6 +256,8 @@ int hub_handle_chat_message(struct hub_info* hub, struct hub_user* u, struct adc
char* message = adc_msg_get_argument(cmd, 0);
int ret = 0;
int relay = 1;
int broadcast;
int command;
int offset;
if (!message)
@ -266,7 +269,10 @@ int hub_handle_chat_message(struct hub_info* hub, struct hub_user* u, struct adc
return 0;
}
if ((cmd->cache[0] == 'B') && (message[0] == '!' || message[0] == '+'))
broadcast = (cmd->cache[0] == 'B' || cmd->cache[0] == 'F');
command = (message[0] == '!' || message[0] == '+');
if (broadcast && command)
{
/*
* A message such as "++message" is handled as "+message", by removing the first character.
@ -285,14 +291,35 @@ int hub_handle_chat_message(struct hub_info* hub, struct hub_user* u, struct adc
}
}
if (((hub->config->chat_is_privileged && !user_is_protected(u)) || (user_flag_get(u, flag_muted))) && (cmd->cache[0] == 'B' || cmd->cache[0] == 'F'))
/* FIXME: Plugin should do this! */
if (relay && (((hub->config->chat_is_privileged && !user_is_protected(u)) || (user_flag_get(u, flag_muted))) && broadcast))
{
relay = 0;
}
if (relay)
{
plugin_st status;
if (broadcast)
{
status = plugin_handle_chat_message(hub, u, message, 0);
}
else
{
struct hub_user* target = uman_get_user_by_sid(hub, cmd->target);
status = plugin_handle_private_message(hub, u, target, message, 0);
}
if (status == st_deny)
relay = 0;
}
if (relay)
{
/* adc_msg_remove_named_argument(cmd, "PM"); */
/* FIXME: Plugin should do history management */
if (cmd->cache[0] == 'B')
hub_chat_history_add(hub, u, cmd);
ret = route_message(hub, u, cmd);

View File

@ -36,6 +36,7 @@ void plugin_log_user_logout(struct hub_info* hub, struct hub_user* user, const c
void plugin_log_user_nick_change(struct hub_info* hub, struct hub_user* user, const char* new_nick);
void plugin_log_user_update_error(struct hub_info* hub, struct hub_user* user, const char* reason);
/* IP ban related */
plugin_st plugin_check_ip_early(struct hub_info* hub, struct ip_addr_encap* addr);
plugin_st plugin_check_ip_late(struct hub_info* hub, struct ip_addr_encap* addr);

View File

@ -34,6 +34,11 @@
#define MAX_PASS_LEN 64
#endif
#ifndef MAX_CID_LEN
#define MAX_CID_LEN 39
#endif
struct plugin_handle;
struct plugin_user
@ -61,6 +66,23 @@ struct auth_info
enum auth_credentials credentials;
};
enum ban_flags
{
ban_nickname = 0x01, /* Nickname is banned */
ban_cid = 0x02, /* CID is banned */
ban_ip = 0x04, /* IP address (range) is banned */
};
struct ban_info
{
unsigned int flags; /* See enum ban_flags. */
char nickname[MAX_NICK_LEN+1]; /* Nickname - only defined if (ban_nickname & flags). */
char cid[MAX_CID_LEN+1]; /* CID - only defined if (ban_cid & flags). */
struct ip_addr_encap ip_addr_lo; /* Low IP address of an IP range */
struct ip_addr_encap ip_addr_hi; /* High IP address of an IP range */
time_t expiry; /* Time when the ban record expires */
};
typedef plugin_st (*on_chat_msg_t)(struct plugin_handle*, struct plugin_user* from, const char* message);
typedef plugin_st (*on_private_msg_t)(struct plugin_handle*, struct plugin_user* from, struct plugin_user* to, const char* message);
typedef plugin_st (*on_search_t)(struct plugin_handle*, struct plugin_user* from, const char* data);