Add hub function for plugins to get list of currently connected users.
Can be filtered to include only users of a certain credential level, or users of a certain credential level or greater. Results are returned as a linked list of plugin_user objects. Hub function to free the memory used by the list also added. As plugins may store the list, users may disconnect before the list is used. Hence a copy of each user is made for the list, so that if a plugin tries to send a message to a user who has left the hub it will be ignored, rather than the hub trying to access memory that was free()d when the user disconnected. The lookup function to turn a plugin_user into a hub_user for some of the other hub functions is changed accordingly. (I think this description is possibly more confusing than just looking at the code, but oh well...)
This commit is contained in:
@@ -305,6 +305,15 @@ int cbfunc_ucmd_add_pm(struct plugin_handle* plugin, struct plugin_ucmd* ucmd, c
|
||||
|
||||
int cbfunc_ucmd_send(struct plugin_handle* plugin, struct plugin_user* user, struct plugin_ucmd* ucmd)
|
||||
{
|
||||
/* Check the user is still connected. */
|
||||
struct hub_info* hub = plugin_get_hub(plugin);
|
||||
struct hub_user* huser = uman_get_user_by_sid(hub, user->sid);
|
||||
if(huser == NULL)
|
||||
{
|
||||
plugin->error_msg = "User is not connected to the hub.";
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Make sure we have a command. */
|
||||
if(!ucmd->length && !(ucmd->separator || ucmd->remove))
|
||||
{
|
||||
@@ -359,7 +368,7 @@ int cbfunc_ucmd_send(struct plugin_handle* plugin, struct plugin_user* user, str
|
||||
}
|
||||
|
||||
/* Send it. */
|
||||
route_to_user(plugin_get_hub(plugin), (struct hub_user*)user, message);
|
||||
route_to_user(hub, huser, message);
|
||||
|
||||
/* Success. */
|
||||
adc_msg_free(message);
|
||||
|
||||
Reference in New Issue
Block a user