Added logging of chat messages in the plugin API.

This commit is contained in:
Jan Vidar Krey 2010-08-11 18:44:02 +02:00
parent 5419d07efe
commit 4c960cb977
4 changed files with 89 additions and 80 deletions

View File

@ -257,6 +257,7 @@ int hub_handle_chat_message(struct hub_info* hub, struct hub_user* u, struct adc
int ret = 0;
int relay = 1;
int broadcast;
int private_msg;
int command;
int offset;
@ -269,7 +270,8 @@ int hub_handle_chat_message(struct hub_info* hub, struct hub_user* u, struct adc
return 0;
}
broadcast = (cmd->cache[0] == 'B' || cmd->cache[0] == 'F');
broadcast = (cmd->cache[0] == 'B');
private_msg = (cmd->cache[0] == 'D' || cmd->cache[0] == 'E');
command = (message[0] == '!' || message[0] == '+');
if (broadcast && command)
@ -297,7 +299,6 @@ int hub_handle_chat_message(struct hub_info* hub, struct hub_user* u, struct adc
relay = 0;
}
if (relay)
{
plugin_st status;
@ -305,7 +306,7 @@ int hub_handle_chat_message(struct hub_info* hub, struct hub_user* u, struct adc
{
status = plugin_handle_chat_message(hub, u, message, 0);
}
else
else if (private_msg)
{
struct hub_user* target = uman_get_user_by_sid(hub, cmd->target);
status = plugin_handle_private_message(hub, u, target, message, 0);
@ -318,10 +319,11 @@ int hub_handle_chat_message(struct hub_info* hub, struct hub_user* u, struct adc
if (relay)
{
/* adc_msg_remove_named_argument(cmd, "PM"); */
/* FIXME: Plugin should do history management */
if (cmd->cache[0] == 'B')
if (broadcast)
{
hub_chat_history_add(hub, u, cmd);
plugin_log_chat_message(hub, u, message, 0);
}
ret = route_message(hub, u, cmd);
}
hub_free(message);

View File

@ -63,15 +63,10 @@
}); \
return status
#define PLUGIN_INVOKE_1(HUB, FUNCNAME, ARG1) \
INVOKE(HUB, FUNCNAME, { \
plugin->funcs.FUNCNAME(plugin, ARG1); \
})
#define PLUGIN_INVOKE_1(HUB, FUNCNAME, ARG1) INVOKE(HUB, FUNCNAME, { plugin->funcs.FUNCNAME(plugin, ARG1); })
#define PLUGIN_INVOKE_2(HUB, FUNCNAME, ARG1, ARG2) INVOKE(HUB, FUNCNAME, { plugin->funcs.FUNCNAME(plugin, ARG1, ARG2); })
#define PLUGIN_INVOKE_3(HUB, FUNCNAME, ARG1, ARG2, ARG3) INVOKE(HUB, FUNCNAME, { plugin->funcs.FUNCNAME(plugin, ARG1, ARG2, ARG3); })
#define PLUGIN_INVOKE_2(HUB, FUNCNAME, ARG1, ARG2) \
INVOKE(HUB, FUNCNAME, { \
plugin->funcs.FUNCNAME(plugin, ARG1, ARG2); \
})
static void convert_user_type(struct plugin_user* puser, struct hub_user* user)
{
@ -140,6 +135,13 @@ void plugin_log_user_update_error(struct hub_info* hub, struct hub_user* who, co
PLUGIN_INVOKE_2(hub, on_user_update_error, &user, reason);
}
void plugin_log_chat_message(struct hub_info* hub, struct hub_user* who, const char* message, int flags)
{
struct plugin_user user;
convert_user_type(&user, who);
PLUGIN_INVOKE_3(hub, on_user_chat_message, &user, message, flags);
}
plugin_st plugin_handle_chat_message(struct hub_info* hub, struct hub_user* from, const char* message, int flags)
{
struct plugin_user user;

View File

@ -28,6 +28,7 @@
struct hub_info;
struct ip_addr_encap;
/* All log related functions */
void plugin_log_connection_accepted(struct hub_info* hub, struct ip_addr_encap* addr);
void plugin_log_connection_denied(struct hub_info* hub, struct ip_addr_encap* addr);
void plugin_log_user_login_success(struct hub_info* hub, struct hub_user* user);
@ -35,11 +36,13 @@ void plugin_log_user_login_error(struct hub_info* hub, struct hub_user* user, co
void plugin_log_user_logout(struct hub_info* hub, struct hub_user* user, const char* reason);
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);
void plugin_log_chat_message(struct hub_info* hub, struct hub_user* from, const char* message, int flags);
/* 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);
/* Nickname allow/deny handling */
plugin_st plugin_check_nickname_valid(struct hub_info* hub, const char* nick);
plugin_st plugin_check_nickname_reserved(struct hub_info* hub, const char* nick);

View File

@ -96,6 +96,7 @@ typedef void (*on_user_login_error_t)(struct plugin_handle*, struct plugin_user*
typedef void (*on_user_logout_t)(struct plugin_handle*, struct plugin_user*, const char* reason);
typedef void (*on_user_nick_change_t)(struct plugin_handle*, struct plugin_user*, const char* new_nick);
typedef void (*on_user_update_error_t)(struct plugin_handle*, struct plugin_user*, const char* reason);
typedef void (*on_user_chat_msg_t)(struct plugin_handle*, struct plugin_user*, const char* message, int flags);
typedef plugin_st (*on_change_nick_t)(struct plugin_handle*, struct plugin_user*, const char* new_nick);
@ -118,6 +119,7 @@ struct plugin_funcs
on_user_logout_t on_user_logout; /* A user has logged out of the hub (was previously logged in) */
on_user_nick_change_t on_user_nick_change; /* A user has changed nickname */
on_user_update_error_t on_user_update_error;/* A user has failed to update - nickname, etc. */
on_user_chat_msg_t on_user_chat_message;/* A user has sent a public chat message */
// Activity events (can be intercepted and refused by a plugin)
on_chat_msg_t on_chat_msg; /* A public chat message is about to be sent (can be intercepted) */