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(void *hdata
);
21 static void h_hdl_new_remote_user(void *client_p
);
22 static void h_hdl_client_exit(void *hdata
);
23 static void h_hdl_umode_changed(void *hdata
);
24 static void h_hdl_whois(void *hdata
);
25 static void recurse_client_exit(struct Client
*client_p
);
26 static void helper_add(struct Client
*client_p
);
27 static void helper_delete(struct Client
*client_p
);
28 static void mo_dehelper(struct MsgBuf
*, struct Client
*, struct Client
*, int, const char **);
29 static void me_dehelper(struct MsgBuf
*, struct Client
*, struct Client
*, int, const char **);
30 static void do_dehelper(struct Client
*source_p
, struct Client
*target_p
);
32 mapi_hfn_list_av1 helpops_hfnlist
[] = {
33 { "doing_stats", h_hdl_stats_request
},
34 { "new_remote_user", h_hdl_new_remote_user
},
35 { "client_exit", h_hdl_client_exit
},
36 { "umode_changed", h_hdl_umode_changed
},
37 { "doing_whois", h_hdl_whois
},
38 { "doing_whois_global", h_hdl_whois
},
42 #define UMODECHAR_HELPOPS 'h'
44 struct Message dehelper_msgtab
= {
45 "DEHELPER", 0, 0, 0, 0,
46 {mg_unreg
, mg_not_oper
, mg_not_oper
, mg_ignore
, {me_dehelper
, 2}, {mo_dehelper
, 2}}
49 mapi_clist_av1 helpops_clist
[] = { &dehelper_msgtab
, NULL
};
52 mo_dehelper(struct MsgBuf
*msgbuf_p
, struct Client
*client_p
, struct Client
*source_p
, int parc
, const char **parv
)
54 struct Client
*target_p
;
56 if (!HasPrivilege(source_p
, "oper:dehelper"))
58 sendto_one(source_p
, form_str(ERR_NOPRIVS
), me
.name
, source_p
->name
, "dehelper");
62 if(!(target_p
= find_named_person(parv
[1])))
64 sendto_one_numeric(source_p
, ERR_NOSUCHNICK
, form_str(ERR_NOSUCHNICK
), parv
[1]);
68 if(MyClient(target_p
))
69 do_dehelper(source_p
, target_p
);
71 sendto_one(target_p
, ":%s ENCAP %s DEHELPER %s",
72 use_id(source_p
), target_p
->servptr
->name
, use_id(target_p
));
76 me_dehelper(struct MsgBuf
*msgbuf_p
, struct Client
*client_p
, struct Client
*source_p
, int parc
, const char **parv
)
78 struct Client
*target_p
= find_person(parv
[1]);
81 sendto_one_numeric(source_p
, ERR_NOSUCHNICK
, form_str(ERR_NOSUCHNICK
), parv
[1]);
84 if(!MyClient(target_p
))
87 do_dehelper(source_p
, target_p
);
91 do_dehelper(struct Client
*source_p
, struct Client
*target_p
)
93 const char *fakeparv
[4];
94 static const char minus_helpops
[3] = {'-', UMODECHAR_HELPOPS
, '\0'};
96 if(!(target_p
->umodes
& user_modes
[UMODECHAR_HELPOPS
]))
99 sendto_realops_snomask(SNO_GENERAL
, L_NETWIDE
, "%s is using DEHELPER on %s",
100 source_p
->name
, target_p
->name
);
101 sendto_one_notice(target_p
, ":*** %s is using DEHELPER on you", source_p
->name
);
103 fakeparv
[0] = fakeparv
[1] = target_p
->name
;
104 fakeparv
[2] = minus_helpops
;
106 user_mode(target_p
, target_p
, 3, fakeparv
);
114 user_modes
[UMODECHAR_HELPOPS
] = find_umode_slot();
115 construct_umodebuf();
117 RB_DLINK_FOREACH (ptr
, global_client_list
.head
)
119 struct Client
*client_p
= ptr
->data
;
120 if (IsPerson(client_p
) && (client_p
->umodes
& user_modes
[UMODECHAR_HELPOPS
]))
121 helper_add(client_p
);
130 rb_dlink_node
*n
, *tn
;
132 user_modes
[UMODECHAR_HELPOPS
] = 0;
133 construct_umodebuf();
135 RB_DLINK_FOREACH_SAFE(n
, tn
, helper_list
.head
)
136 rb_dlinkDestroy(n
, &helper_list
);
140 h_hdl_stats_request(void *data
)
142 hook_data_int
*hdata
= data
;
143 struct Client
*target_p
;
144 rb_dlink_node
*helper_ptr
;
145 unsigned int count
= 0;
147 if (hdata
->arg2
!= 'p')
150 RB_DLINK_FOREACH (helper_ptr
, helper_list
.head
)
152 target_p
= helper_ptr
->data
;
154 if(target_p
->user
->away
)
159 if (IsOper(hdata
->client
) && SeesOper(target_p
, hdata
->client
)
160 && !EmptyString(target_p
->user
->opername
))
161 sendto_one_numeric(hdata
->client
, RPL_STATSDEBUG
,
162 "p :%s (%s@%s) {%s}",
163 target_p
->name
, target_p
->username
, target_p
->host
,
164 target_p
->user
->opername
);
166 sendto_one_numeric(hdata
->client
, RPL_STATSDEBUG
,
168 target_p
->name
, target_p
->username
, target_p
->host
);
171 sendto_one_numeric(hdata
->client
, RPL_STATSDEBUG
,
172 "p :%u staff members", count
);
178 helper_add(struct Client
*client_p
)
180 if (rb_dlinkFind(client_p
, &helper_list
) != NULL
)
183 rb_dlinkAddAlloc(client_p
, &helper_list
);
187 helper_delete(struct Client
*client_p
)
189 rb_dlinkFindDestroy(client_p
, &helper_list
);
193 h_hdl_new_remote_user(void *data
)
195 struct Client
*client_p
= data
;
196 if (client_p
->umodes
& user_modes
[UMODECHAR_HELPOPS
])
197 helper_add(client_p
);
201 recurse_client_exit(struct Client
*client_p
)
203 if (IsPerson(client_p
))
205 if (client_p
->umodes
& user_modes
[UMODECHAR_HELPOPS
])
206 helper_delete(client_p
);
208 else if (IsServer(client_p
))
212 RB_DLINK_FOREACH(nptr
, client_p
->serv
->users
.head
)
213 recurse_client_exit(nptr
->data
);
215 RB_DLINK_FOREACH(nptr
, client_p
->serv
->servers
.head
)
216 recurse_client_exit(nptr
->data
);
221 h_hdl_client_exit(void *data
)
223 hook_data_client_exit
*hdata
= data
;
224 recurse_client_exit(hdata
->target
);
228 h_hdl_umode_changed(void *data
)
230 hook_data_umode_changed
*hdata
= data
;
231 struct Client
*source_p
= hdata
->client
;
233 /* didn't change +h umode, we don't need to do anything */
234 bool changed
= (hdata
->oldumodes
^ source_p
->umodes
) & user_modes
[UMODECHAR_HELPOPS
];
236 if (source_p
->umodes
& user_modes
[UMODECHAR_HELPOPS
])
238 if (MyClient(source_p
) && !HasPrivilege(source_p
, "usermode:helpops"))
240 source_p
->umodes
&= ~user_modes
[UMODECHAR_HELPOPS
];
241 sendto_one(source_p
, form_str(ERR_NOPRIVS
), me
.name
, source_p
->name
, "usermode:helpops");
242 /* they didn't ask for +h so we must be removing it */
244 helper_delete(source_p
);
249 helper_add(source_p
);
253 helper_delete(source_p
);
258 h_hdl_whois(void *data
)
260 hook_data_client
*hdata
= data
;
261 struct Client
*source_p
= hdata
->client
;
262 struct Client
*target_p
= hdata
->target
;
264 if ((target_p
->umodes
& user_modes
[UMODECHAR_HELPOPS
]) && EmptyString(target_p
->user
->away
))
266 sendto_one_numeric(source_p
, RPL_WHOISHELPOP
, form_str(RPL_WHOISHELPOP
), target_p
->name
);
270 DECLARE_MODULE_AV2(helpops
, _modinit
, _moddeinit
, helpops_clist
, NULL
, helpops_hfnlist
, NULL
, NULL
, helpops_desc
);