14 #include "s_newconf.h"
17 static rb_dlink_list helper_list
= { NULL
, NULL
, 0 };
18 static void h_hdl_stats_request(hook_data_int
*hdata
);
19 static void h_hdl_new_remote_user(struct Client
*client_p
);
20 static void h_hdl_client_exit(hook_data_client_exit
*hdata
);
21 static void h_hdl_umode_changed(hook_data_umode_changed
*hdata
);
22 static void h_hdl_whois(hook_data_client
*hdata
);
23 static int mo_dehelper(struct MsgBuf
*, struct Client
*, struct Client
*, int, const char **);
24 static int me_dehelper(struct MsgBuf
*, struct Client
*, struct Client
*, int, const char **);
25 static int do_dehelper(struct Client
*source_p
, struct Client
*target_p
);
27 mapi_hfn_list_av1 helpops_hfnlist
[] = {
28 { "doing_stats", (hookfn
) h_hdl_stats_request
},
29 { "new_remote_user", (hookfn
) h_hdl_new_remote_user
},
30 { "client_exit", (hookfn
) h_hdl_client_exit
},
31 { "umode_changed", (hookfn
) h_hdl_umode_changed
},
32 { "doing_whois", (hookfn
) h_hdl_whois
},
33 { "doing_whois_global", (hookfn
) h_hdl_whois
},
37 static int UMODE_HELPOPS
= 0;
39 struct Message dehelper_msgtab
= {
40 "DEHELPER", 0, 0, 0, 0,
41 {mg_unreg
, mg_not_oper
, mg_not_oper
, mg_ignore
, {me_dehelper
, 2}, {mo_dehelper
, 2}}
44 mapi_clist_av1 helpops_clist
[] = { &dehelper_msgtab
, NULL
};
46 static int mo_dehelper(struct MsgBuf
*msgbuf_p
, struct Client
*client_p
, struct Client
*source_p
, int parc
, const char **parv
)
48 struct Client
*target_p
;
50 if (!IsOperAdmin(source_p
))
52 sendto_one(source_p
, form_str(ERR_NOPRIVS
), me
.name
, source_p
->name
, "admin");
56 if(!(target_p
= find_named_person(parv
[1])))
58 sendto_one_numeric(source_p
, ERR_NOSUCHNICK
, form_str(ERR_NOSUCHNICK
), parv
[1]);
62 if(MyClient(target_p
))
63 do_dehelper(source_p
, target_p
);
65 sendto_one(target_p
, ":%s ENCAP %s DEHELPER %s",
66 use_id(source_p
), target_p
->servptr
->name
, use_id(target_p
));
71 static int me_dehelper(struct MsgBuf
*msgbuf_p
, struct Client
*client_p
, struct Client
*source_p
, int parc
, const char **parv
)
73 struct Client
*target_p
= find_person(parv
[1]);
76 sendto_one_numeric(source_p
, ERR_NOSUCHNICK
, form_str(ERR_NOSUCHNICK
), parv
[1]);
79 if(!MyClient(target_p
))
82 do_dehelper(source_p
, target_p
);
86 static int do_dehelper(struct Client
*source_p
, struct Client
*target_p
)
88 const char *fakeparv
[4];
90 if(!(target_p
->umodes
& UMODE_HELPOPS
))
93 sendto_realops_snomask(SNO_GENERAL
, L_NETWIDE
, "%s is using DEHELPER on %s",
94 source_p
->name
, target_p
->name
);
95 sendto_one_notice(target_p
, ":*** %s is using DEHELPER on you", source_p
->name
);
97 fakeparv
[0] = fakeparv
[1] = target_p
->name
;
100 user_mode(target_p
, target_p
, 3, fakeparv
);
107 /* add the usermode to the available slot */
108 user_modes
['H'] = UMODE_HELPOPS
= find_umode_slot();
109 construct_umodebuf();
117 /* disable the umode and remove it from the available list */
118 user_modes
['H'] = UMODE_HELPOPS
= 0;
119 construct_umodebuf();
123 h_hdl_stats_request(hook_data_int
*hdata
)
125 struct Client
*target_p
;
126 rb_dlink_node
*helper_ptr
;
127 unsigned int count
= 0;
129 if (hdata
->arg2
!= 'p')
132 RB_DLINK_FOREACH (helper_ptr
, helper_list
.head
)
134 target_p
= helper_ptr
->data
;
136 if(target_p
->user
->away
)
141 sendto_one_numeric(hdata
->client
, RPL_STATSDEBUG
,
143 target_p
->name
, target_p
->username
,
147 sendto_one_numeric(hdata
->client
, RPL_STATSDEBUG
,
148 "p :%u staff members", count
);
154 h_hdl_new_remote_user(struct Client
*client_p
)
156 if (client_p
->umodes
& UMODE_HELPOPS
)
157 rb_dlinkAddAlloc(client_p
, &helper_list
);
161 h_hdl_client_exit(hook_data_client_exit
*hdata
)
163 if (hdata
->target
->umodes
& UMODE_HELPOPS
)
164 rb_dlinkFindDestroy(hdata
->target
, &helper_list
);
168 h_hdl_umode_changed(hook_data_umode_changed
*hdata
)
170 struct Client
*source_p
= hdata
->client
;
172 /* didn't change +H umode, we don't need to do anything */
173 if (!((hdata
->oldumodes
^ source_p
->umodes
) & UMODE_HELPOPS
))
176 if (source_p
->umodes
& UMODE_HELPOPS
)
178 if (MyClient(source_p
) && !HasPrivilege(source_p
, "usermode:helpops"))
180 source_p
->umodes
&= ~UMODE_HELPOPS
;
181 sendto_one(source_p
, form_str(ERR_NOPRIVS
), me
.name
, source_p
->name
, "usermode:helpops");
185 rb_dlinkAddAlloc(source_p
, &helper_list
);
187 else if (!(source_p
->umodes
& UMODE_HELPOPS
))
188 rb_dlinkFindDestroy(source_p
, &helper_list
);
192 h_hdl_whois(hook_data_client
*hdata
)
194 struct Client
*source_p
= hdata
->client
;
195 struct Client
*target_p
= hdata
->target
;
197 if ((target_p
->umodes
& UMODE_HELPOPS
) && EmptyString(target_p
->user
->away
))
199 sendto_one_numeric(source_p
, RPL_WHOISHELPOP
, form_str(RPL_WHOISHELPOP
), target_p
->name
);
203 DECLARE_MODULE_AV2(helpops
, _modinit
, _moddeinit
, helpops_clist
, NULL
, helpops_hfnlist
, NULL
, NULL
, NULL
);