Merge pull request #25 from schreda/master

added broadcast message and getter for user count in plugin API
This commit is contained in:
Jan Vidar Krey 2014-10-17 00:09:56 +02:00
commit 05edfa48b2
2 changed files with 24 additions and 0 deletions

View File

@ -65,6 +65,17 @@ static int cbfunc_send_message(struct plugin_handle* plugin, struct plugin_user*
return 1; return 1;
} }
static int cbfunc_send_broadcast(struct plugin_handle* plugin, const char* message)
{
char* buffer = adc_msg_escape(message);
struct adc_message* command = adc_msg_construct(ADC_CMD_IMSG, strlen(buffer) + 6);
adc_msg_add_argument(command, buffer);
route_to_all(plugin_get_hub(plugin), command);
adc_msg_free(command);
hub_free(buffer);
return 1;
}
static int cbfunc_send_status(struct plugin_handle* plugin, struct plugin_user* user, int code, const char* message) static int cbfunc_send_status(struct plugin_handle* plugin, struct plugin_user* user, int code, const char* message)
{ {
char code_str[4]; char code_str[4];
@ -128,6 +139,12 @@ struct plugin_command_arg_data* cbfunc_command_arg_next(struct plugin_handle* pl
return (struct plugin_command_arg_data*) hub_command_arg_next((struct hub_command*) cmd, (enum hub_command_arg_type) t); return (struct plugin_command_arg_data*) hub_command_arg_next((struct hub_command*) cmd, (enum hub_command_arg_type) t);
} }
static size_t cbfunc_get_usercount(struct plugin_handle* plugin)
{
struct hub_info* hub = plugin_get_hub(plugin);
return hub->users->count;
}
static char* cbfunc_get_hub_name(struct plugin_handle* plugin) static char* cbfunc_get_hub_name(struct plugin_handle* plugin)
{ {
struct hub_info* hub = plugin_get_hub(plugin); struct hub_info* hub = plugin_get_hub(plugin);
@ -183,12 +200,14 @@ static void cbfunc_set_hub_description(struct plugin_handle* plugin, const char*
void plugin_register_callback_functions(struct plugin_handle* handle) void plugin_register_callback_functions(struct plugin_handle* handle)
{ {
handle->hub.send_message = cbfunc_send_message; handle->hub.send_message = cbfunc_send_message;
handle->hub.send_broadcast_message = cbfunc_send_broadcast;
handle->hub.send_status_message = cbfunc_send_status; handle->hub.send_status_message = cbfunc_send_status;
handle->hub.user_disconnect = cbfunc_user_disconnect; handle->hub.user_disconnect = cbfunc_user_disconnect;
handle->hub.command_add = cbfunc_command_add; handle->hub.command_add = cbfunc_command_add;
handle->hub.command_del = cbfunc_command_del; handle->hub.command_del = cbfunc_command_del;
handle->hub.command_arg_reset = cbfunc_command_arg_reset; handle->hub.command_arg_reset = cbfunc_command_arg_reset;
handle->hub.command_arg_next = cbfunc_command_arg_next; handle->hub.command_arg_next = cbfunc_command_arg_next;
handle->hub.get_usercount = cbfunc_get_usercount;
handle->hub.get_name = cbfunc_get_hub_name; handle->hub.get_name = cbfunc_get_hub_name;
handle->hub.set_name = cbfunc_set_hub_name; handle->hub.set_name = cbfunc_set_hub_name;
handle->hub.get_description = cbfunc_get_hub_description; handle->hub.get_description = cbfunc_get_hub_description;

View File

@ -110,6 +110,7 @@ struct plugin_command;
struct plugin_command_arg_data; struct plugin_command_arg_data;
typedef int (*hfunc_send_message)(struct plugin_handle*, struct plugin_user* user, const char* message); typedef int (*hfunc_send_message)(struct plugin_handle*, struct plugin_user* user, const char* message);
typedef int (*hfunc_send_broadcast_message)(struct plugin_handle*, const char* message);
typedef int (*hfunc_send_status)(struct plugin_handle*, struct plugin_user* to, int code, const char* message); typedef int (*hfunc_send_status)(struct plugin_handle*, struct plugin_user* to, int code, const char* message);
typedef int (*hfunc_user_disconnect)(struct plugin_handle*, struct plugin_user* user); typedef int (*hfunc_user_disconnect)(struct plugin_handle*, struct plugin_user* user);
typedef int (*hfunc_command_add)(struct plugin_handle*, struct plugin_command_handle*); typedef int (*hfunc_command_add)(struct plugin_handle*, struct plugin_command_handle*);
@ -118,6 +119,8 @@ typedef int (*hfunc_command_del)(struct plugin_handle*, struct plugin_command_ha
typedef size_t (*hfunc_command_arg_reset)(struct plugin_handle*, struct plugin_command*); typedef size_t (*hfunc_command_arg_reset)(struct plugin_handle*, struct plugin_command*);
typedef struct plugin_command_arg_data* (*hfunc_command_arg_next)(struct plugin_handle*, struct plugin_command*, enum plugin_command_arg_type); typedef struct plugin_command_arg_data* (*hfunc_command_arg_next)(struct plugin_handle*, struct plugin_command*, enum plugin_command_arg_type);
typedef size_t (*hfunc_get_usercount)(struct plugin_handle*);
typedef char* (*hfunc_get_hub_name)(struct plugin_handle*); typedef char* (*hfunc_get_hub_name)(struct plugin_handle*);
typedef void (*hfunc_set_hub_name)(struct plugin_handle*, const char*); typedef void (*hfunc_set_hub_name)(struct plugin_handle*, const char*);
typedef char* (*hfunc_get_hub_description)(struct plugin_handle*); typedef char* (*hfunc_get_hub_description)(struct plugin_handle*);
@ -130,12 +133,14 @@ typedef void (*hfunc_set_hub_description)(struct plugin_handle*, const char*);
struct plugin_hub_funcs struct plugin_hub_funcs
{ {
hfunc_send_message send_message; hfunc_send_message send_message;
hfunc_send_broadcast_message send_broadcast_message;
hfunc_send_status send_status_message; hfunc_send_status send_status_message;
hfunc_user_disconnect user_disconnect; hfunc_user_disconnect user_disconnect;
hfunc_command_add command_add; hfunc_command_add command_add;
hfunc_command_del command_del; hfunc_command_del command_del;
hfunc_command_arg_reset command_arg_reset; hfunc_command_arg_reset command_arg_reset;
hfunc_command_arg_next command_arg_next; hfunc_command_arg_next command_arg_next;
hfunc_get_usercount get_usercount;
hfunc_get_hub_name get_name; hfunc_get_hub_name get_name;
hfunc_set_hub_name set_name; hfunc_set_hub_name set_name;
hfunc_get_hub_description get_description; hfunc_get_hub_description get_description;