helpops: add duplication guards on helper/dehelper state changes

This commit is contained in:
William Pitcock 2016-09-18 17:11:00 -05:00
parent 56fbe141a1
commit b1c32af98e

View file

@ -23,6 +23,8 @@ static void h_hdl_client_exit(hook_data_client_exit *hdata);
static void h_hdl_umode_changed(hook_data_umode_changed *hdata); static void h_hdl_umode_changed(hook_data_umode_changed *hdata);
static void h_hdl_whois(hook_data_client *hdata); static void h_hdl_whois(hook_data_client *hdata);
static void recurse_client_exit(struct Client *client_p); static void recurse_client_exit(struct Client *client_p);
static void helper_add(struct Client *client_p);
static void helper_delete(struct Client *client_p);
static void mo_dehelper(struct MsgBuf *, struct Client *, struct Client *, int, const char **); static void mo_dehelper(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
static void me_dehelper(struct MsgBuf *, struct Client *, struct Client *, int, const char **); static void me_dehelper(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
static void do_dehelper(struct Client *source_p, struct Client *target_p); static void do_dehelper(struct Client *source_p, struct Client *target_p);
@ -152,11 +154,26 @@ h_hdl_stats_request(hook_data_int *hdata)
hdata->result = 1; hdata->result = 1;
} }
static void
helper_add(struct Client *client_p)
{
if (rb_dlinkFind(client_p, &helper_list) != NULL)
return;
rb_dlinkAddAlloc(client_p, &helper_list);
}
static void
helper_delete(struct Client *client_p)
{
rb_dlinkFindDestroy(client_p, &helper_list);
}
static void static void
h_hdl_new_remote_user(struct Client *client_p) h_hdl_new_remote_user(struct Client *client_p)
{ {
if (client_p->umodes & UMODE_HELPOPS) if (client_p->umodes & UMODE_HELPOPS)
rb_dlinkAddAlloc(client_p, &helper_list); helper_add(client_p);
} }
static void static void
@ -165,7 +182,7 @@ recurse_client_exit(struct Client *client_p)
if (IsPerson(client_p)) if (IsPerson(client_p))
{ {
if (client_p->umodes & UMODE_HELPOPS) if (client_p->umodes & UMODE_HELPOPS)
rb_dlinkFindDestroy(client_p, &helper_list); helper_delete(client_p);
} }
else if (IsServer(client_p)) else if (IsServer(client_p))
{ {
@ -203,10 +220,10 @@ h_hdl_umode_changed(hook_data_umode_changed *hdata)
return; return;
} }
rb_dlinkAddAlloc(source_p, &helper_list); helper_add(source_p);
} }
else if (!(source_p->umodes & UMODE_HELPOPS)) else if (!(source_p->umodes & UMODE_HELPOPS))
rb_dlinkFindDestroy(source_p, &helper_list); helper_delete(source_p);
} }
static void static void