14 #include "s_newconf.h"
17 static const char helpops_desc
[] = "The helpops system as used by freenode";
19 static rb_dlink_list helper_list
= { NULL
, NULL
, 0 };
20 static void h_hdl_stats_request(hook_data_int
*hdata
);
21 static void h_hdl_new_remote_user(struct Client
*client_p
);
22 static void h_hdl_client_exit(hook_data_client_exit
*hdata
);
23 static void h_hdl_umode_changed(hook_data_umode_changed
*hdata
);
24 static void h_hdl_whois(hook_data_client
*hdata
);
25 static void recurse_client_exit(struct Client
*client_p
);
26 static void mo_dehelper(struct MsgBuf
*, struct Client
*, struct Client
*, int, const char **);
27 static void me_dehelper(struct MsgBuf
*, struct Client
*, struct Client
*, int, const char **);
28 static void do_dehelper(struct Client
*source_p
, struct Client
*target_p
);
30 mapi_hfn_list_av1 helpops_hfnlist
[] = {
31 { "doing_stats", (hookfn
) h_hdl_stats_request
},
32 { "new_remote_user", (hookfn
) h_hdl_new_remote_user
},
33 { "client_exit", (hookfn
) h_hdl_client_exit
},
34 { "umode_changed", (hookfn
) h_hdl_umode_changed
},
35 { "doing_whois", (hookfn
) h_hdl_whois
},
36 { "doing_whois_global", (hookfn
) h_hdl_whois
},
40 static int UMODE_HELPOPS
= 0;
42 struct Message dehelper_msgtab
= {
43 "DEHELPER", 0, 0, 0, 0,
44 {mg_unreg
, mg_not_oper
, mg_not_oper
, mg_ignore
, {me_dehelper
, 2}, {mo_dehelper
, 2}}
47 mapi_clist_av1 helpops_clist
[] = { &dehelper_msgtab
, NULL
};
50 mo_dehelper(struct MsgBuf
*msgbuf_p
, struct Client
*client_p
, struct Client
*source_p
, int parc
, const char **parv
)
52 struct Client
*target_p
;
54 if (!IsOperAdmin(source_p
))
56 sendto_one(source_p
, form_str(ERR_NOPRIVS
), me
.name
, source_p
->name
, "admin");
60 if(!(target_p
= find_named_person(parv
[1])))
62 sendto_one_numeric(source_p
, ERR_NOSUCHNICK
, form_str(ERR_NOSUCHNICK
), parv
[1]);
66 if(MyClient(target_p
))
67 do_dehelper(source_p
, target_p
);
69 sendto_one(target_p
, ":%s ENCAP %s DEHELPER %s",
70 use_id(source_p
), target_p
->servptr
->name
, use_id(target_p
));
74 me_dehelper(struct MsgBuf
*msgbuf_p
, struct Client
*client_p
, struct Client
*source_p
, int parc
, const char **parv
)
76 struct Client
*target_p
= find_person(parv
[1]);
79 sendto_one_numeric(source_p
, ERR_NOSUCHNICK
, form_str(ERR_NOSUCHNICK
), parv
[1]);
82 if(!MyClient(target_p
))
85 do_dehelper(source_p
, target_p
);
89 do_dehelper(struct Client
*source_p
, struct Client
*target_p
)
91 const char *fakeparv
[4];
93 if(!(target_p
->umodes
& UMODE_HELPOPS
))
96 sendto_realops_snomask(SNO_GENERAL
, L_NETWIDE
, "%s is using DEHELPER on %s",
97 source_p
->name
, target_p
->name
);
98 sendto_one_notice(target_p
, ":*** %s is using DEHELPER on you", source_p
->name
);
100 fakeparv
[0] = fakeparv
[1] = target_p
->name
;
103 user_mode(target_p
, target_p
, 3, fakeparv
);
109 /* add the usermode to the available slot */
110 user_modes
['H'] = UMODE_HELPOPS
= find_umode_slot();
111 construct_umodebuf();
119 /* disable the umode and remove it from the available list */
120 user_modes
['H'] = UMODE_HELPOPS
= 0;
121 construct_umodebuf();
125 h_hdl_stats_request(hook_data_int
*hdata
)
127 struct Client
*target_p
;
128 rb_dlink_node
*helper_ptr
;
129 unsigned int count
= 0;
131 if (hdata
->arg2
!= 'p')
134 RB_DLINK_FOREACH (helper_ptr
, helper_list
.head
)
136 target_p
= helper_ptr
->data
;
138 if(target_p
->user
->away
)
143 sendto_one_numeric(hdata
->client
, RPL_STATSDEBUG
,
145 target_p
->name
, target_p
->username
,
149 sendto_one_numeric(hdata
->client
, RPL_STATSDEBUG
,
150 "p :%u staff members", count
);
156 h_hdl_new_remote_user(struct Client
*client_p
)
158 if (client_p
->umodes
& UMODE_HELPOPS
)
159 rb_dlinkAddAlloc(client_p
, &helper_list
);
163 recurse_client_exit(struct Client
*client_p
)
165 if (IsPerson(client_p
))
167 if (client_p
->umodes
& UMODE_HELPOPS
)
168 rb_dlinkFindDestroy(client_p
, &helper_list
);
170 else if (IsServer(client_p
))
174 RB_DLINK_FOREACH(nptr
, client_p
->serv
->users
.head
)
175 recurse_client_exit(nptr
->data
);
177 RB_DLINK_FOREACH(nptr
, client_p
->serv
->servers
.head
)
178 recurse_client_exit(nptr
->data
);
183 h_hdl_client_exit(hook_data_client_exit
*hdata
)
185 recurse_client_exit(hdata
->target
);
189 h_hdl_umode_changed(hook_data_umode_changed
*hdata
)
191 struct Client
*source_p
= hdata
->client
;
193 /* didn't change +H umode, we don't need to do anything */
194 if (!((hdata
->oldumodes
^ source_p
->umodes
) & UMODE_HELPOPS
))
197 if (source_p
->umodes
& UMODE_HELPOPS
)
199 if (MyClient(source_p
) && !HasPrivilege(source_p
, "usermode:helpops"))
201 source_p
->umodes
&= ~UMODE_HELPOPS
;
202 sendto_one(source_p
, form_str(ERR_NOPRIVS
), me
.name
, source_p
->name
, "usermode:helpops");
206 rb_dlinkAddAlloc(source_p
, &helper_list
);
208 else if (!(source_p
->umodes
& UMODE_HELPOPS
))
209 rb_dlinkFindDestroy(source_p
, &helper_list
);
213 h_hdl_whois(hook_data_client
*hdata
)
215 struct Client
*source_p
= hdata
->client
;
216 struct Client
*target_p
= hdata
->target
;
218 if ((target_p
->umodes
& UMODE_HELPOPS
) && EmptyString(target_p
->user
->away
))
220 sendto_one_numeric(source_p
, RPL_WHOISHELPOP
, form_str(RPL_WHOISHELPOP
), target_p
->name
);
224 DECLARE_MODULE_AV2(helpops
, _modinit
, _moddeinit
, helpops_clist
, NULL
, helpops_hfnlist
, NULL
, NULL
, helpops_desc
);