15 hchannel
*hchannel_add(const char *cname
)
20 cp
= findchannel((char*)cname
);
23 localcreatechannel(helpmodnick
, (char*)cname
);
24 cp
= findchannel((char*)cname
);
28 localjoinchannel(helpmodnick
, cp
);
29 localgetops(helpmodnick
, cp
);
32 hchan
= (hchannel
*)malloc(sizeof(hchannel
));
34 hchan
->welcome
[0] = '\0';
35 hchan
->real_channel
= cp
;
36 hchan
->flags
= H_CHANFLAGS_DEFAULT
;
37 hchan
->channel_users
= NULL
;
38 hchan
->channel_hterms
= NULL
;
39 hchan
->max_idle
= 5 * HDEF_m
;
41 hchan
->report_to
= NULL
;
44 hchan
->jf_control
= time(NULL
);
45 hchan
->lc_profile
= NULL
;
48 hchan
->htickets
= NULL
;
49 hchan
->ticket_message
= NULL
;
51 hchan
->last_activity
= time(NULL
);
52 hchan
->last_staff_activity
= time(NULL
);
53 hchan
->stats
= get_hstat_channel();
55 hchan
->next
= hchannels
;
63 for (i
=0;i
< hchan
->real_channel
->users
->hashsize
;i
++)
65 nck
= getnickbynumeric(hchan
->real_channel
->users
->content
[i
]);
66 if (!nck
) /* it's a hash, not an array */
69 if ((husr
= huser_get(nck
)) == NULL
)
70 husr
= huser_add(nck
);
72 tmp
= huser_add_channel(husr
, hchan
);
73 hchannel_add_user(hchan
, husr
);
75 if (hchan
->real_channel
->users
->content
[i
] & CUMODE_OP
)
76 tmp
->flags
|= HCUMODE_OP
;
77 if (hchan
->real_channel
->users
->content
[i
] & CUMODE_VOICE
)
78 tmp
->flags
|= HCUMODE_VOICE
;
84 int hchannel_del(hchannel
*hchan
)
86 hchannel
*tmp
, **ptr
= &hchannels
;
88 for (;*ptr
;ptr
= &(*ptr
)->next
)
96 hcensor_del_all(&(hchan
->censor
));
97 hterm_del_all(&hchan
->channel_hterms
);
98 htopic_del_all(&hchan
->topic
);
99 hstat_del_channel(hchan
);
102 while (hchan
->htickets
)
103 hticket_del(hchan
->htickets
, hchan
);
105 localpartchannel(helpmodnick
, hchan
->real_channel
);
114 int hchannel_authority(hchannel
*hchan
, struct huser_struct
*husr
)
116 if ((hchan
->flags
& H_OPER_ONLY
) && (huser_get_level(husr
) < H_OPER
))
121 hchannel
*hchannel_get_by_name(const char *cname
)
123 hchannel
*tmp
= hchannels
;
124 for (;tmp
;tmp
=tmp
->next
)
125 if (!ircd_strcmp(cname
, tmp
->real_channel
->index
->name
->content
))
130 hchannel
*hchannel_get_by_channel(channel
*chan
)
138 for (;tmp
;tmp
=tmp
->next
)
139 if (tmp
->real_channel
== chan
)
144 const char *hchannel_get_name(hchannel
*hchan
)
146 return hchan
->real_channel
->index
->name
->content
;
149 void hchannel_del_all(void)
152 hchannel_del(hchannels
);
155 hchannel_user
*hchannel_on_channel(hchannel
*hchan
, struct huser_struct
*husr
)
157 hchannel_user
*ptr
= hchan
->channel_users
;
158 for (;ptr
;ptr
= ptr
->next
)
159 if (ptr
->husr
== husr
)
164 hchannel_user
*hchannel_add_user(hchannel
*hchan
, struct huser_struct
*husr
)
166 hchannel_user
**tmp
= &(hchan
->channel_users
);
167 assert(hchannel_on_channel(hchan
, husr
) == NULL
);
169 for (;*tmp
;tmp
= &(*tmp
)->next
);
171 *tmp
= (hchannel_user
*)malloc(sizeof(hchannel_user
));
173 (*tmp
)->time_joined
= time(NULL
);
176 assert(hchannel_on_channel(hchan
, husr
) != NULL
);
181 hchannel_user
*hchannel_del_user(hchannel
*hchan
, struct huser_struct
*husr
)
183 hchannel_user
**tmp
= &(hchan
->channel_users
);
184 assert(hchannel_on_channel(hchan
, husr
) != NULL
);
186 for (;*tmp
;tmp
= &(*tmp
)->next
)
187 if ((*tmp
)->husr
== husr
)
189 hchannel_user
*ptr
= (*tmp
)->next
;
193 assert(hchannel_on_channel(hchan
, husr
) == NULL
);
199 void hchannel_remove_inactive_users(void)
201 hchannel
*hchan
= hchannels
;
203 for (;hchan
;hchan
= hchan
->next
)
205 if (hchan
->flags
& H_ANTI_IDLE
&& !(hchan
->flags
& H_PASSIVE
))
207 hchannel_user
**hchanuser
= &hchan
->channel_users
;
211 (huser_get_level((*hchanuser
)->husr
) == H_PEON
) &&
212 (time(NULL
) - huser_on_channel((*hchanuser
)->husr
,hchan
)->last_activity
>= hchan
->max_idle
) &&
213 !(on_queue((*hchanuser
)->husr
, huser_on_channel((*hchanuser
)->husr
, hchan
))) &&
214 !IsSetHost((*hchanuser
)->husr
->real_user
)
217 if (huser_on_channel((*hchanuser
)->husr
, hchan
)->flags
& H_IDLE_WARNING
)
219 const char *banmask
= hban_ban_string((*hchanuser
)->husr
->real_user
, HBAN_HOST
);
220 helpmod_setban(hchan
, banmask
, time(NULL
) + 10 * HDEF_m
, MCB_ADD
, HLAZY
);
222 helpmod_kick(hchan
, (*hchanuser
)->husr
, "Please do not idle in %s", hchannel_get_name(hchan
));
227 helpmod_reply((*hchanuser
)->husr
, NULL
, "You are currently idle in %s. Please part the channel if you have nothing to do there", hchannel_get_name(hchan
));
228 huser_on_channel((*hchanuser
)->husr
, hchan
)->flags
|= H_IDLE_WARNING
;
232 hchanuser
= &(*hchanuser
)->next
;
236 /* Additionally, test if the channel has queue but no idle opers / staff */
237 if (hchan
->flags
& H_QUEUE
&& hchan
->flags
& H_QUEUE_TIMEOUT
)
240 for (tmp
= hchan
->channel_users
;tmp
;tmp
= tmp
->next
)
241 if (huser_get_level(tmp
->husr
) >= H_TRIAL
)
243 huser_channel
*huserchan
= huser_on_channel(tmp
->husr
, hchan
);
244 if ((time(NULL
) - huserchan
->last_activity
< HELPMOD_QUEUE_TIMEOUT
) && (huserchan
->last_activity
!= tmp
->time_joined
))
249 hchan
->flags
&= ~H_QUEUE
;
250 if (hchan
->flags
& H_REPORT
&& hchannel_is_valid(hchan
->report_to
))
251 helpmod_message_channel(hchan
->report_to
, "%s: Channel queue deactivated because of inactivity", hchannel_get_name(hchan
));
252 hchannel_conf_change(hchan
, hchan
->flags
| H_QUEUE
);
258 void hchannel_report(void)
260 hchannel
*hchan
= hchannels
;
261 for (;hchan
;hchan
= hchan
->next
)
262 if (hchan
->flags
& H_REPORT
&& !(hchan
->flags
& H_PASSIVE
) && hchannel_is_valid(hchan
->report_to
))
264 int total
= hchannel_count_users(hchan
, H_ANY
);
265 int peons
= hchannel_count_users(hchan
, H_PEON
);
266 int services
= hchannel_count_users(hchan
, H_SERVICE
);
271 if (hchan
->flags
& H_QUEUE
)
273 int peons_queue
= hchannel_count_queue(hchan
);
274 helpmod_message_channel(hchan
->report_to
, "%s: %d user%s in queue and %d user%s currently receiving support. %d Non-user%s. Average queue time %s", hchannel_get_name(hchan
), peons_queue
, (peons_queue
==1)?"":"s", peons
- peons_queue
, (peons
- peons_queue
== 1)?"":"s", total
-peons
-services
, (total
-peons
-services
== 1)?"":"s", helpmod_strtime(hqueue_average_time(hchan
)));
277 helpmod_message_channel(hchan
->report_to
, "%s: %d user%s and %d non-user%s", hchannel_get_name(hchan
), peons
, (peons
== 1)?"":"s", total
-peons
-services
, (total
-peons
-services
== 1)?"":"s");
281 void hchannel_set_topic(hchannel
*hchan
)
283 if (hchan
->flags
& H_HANDLE_TOPIC
)
284 helpmod_set_topic(hchan
, htopic_construct(hchan
->topic
));
287 void hchannels_match_accounts(void)
289 hchannel
*hchan
= hchannels
;
290 hchannel_user
*hchanuser
;
291 for (;hchan
;hchan
= hchan
->next
)
292 for (hchanuser
= hchan
->channel_users
;hchanuser
;hchanuser
= hchanuser
->next
)
293 if (hchanuser
->husr
->account
== NULL
&& IsAccount(hchanuser
->husr
->real_user
))
294 hchanuser
->husr
->account
= haccount_get_by_name(huser_get_auth(hchanuser
->husr
));
297 int hchannels_on_queue(huser
*husr
)
299 huser_channel
*huserchan
= husr
->hchannels
;
300 for (;huserchan
;huserchan
= huserchan
->next
)
301 if (on_queue(husr
, huserchan
))
306 int hchannels_on_desk(struct huser_struct
* husr
)
308 huser_channel
*huserchan
= husr
->hchannels
;
309 for (;huserchan
;huserchan
= huserchan
->next
)
310 if (on_desk(husr
, huserchan
))
315 void hchannels_dnmo(struct huser_struct
*husr
)
317 hchannel
*hchan
= hchannels
;
318 for (;hchan
;hchan
= hchan
->next
)
320 huser_channel
*huserchan
= huser_on_channel(husr
, hchan
);
321 /*if (on_queue(husr, huserchan) || on_desk(husr, huserchan))*/
322 if (huserchan
!= NULL
)
324 hchannel_user
*tmp
= NULL
, **hchanuser
= &hchan
->channel_users
;
325 for (;*hchanuser
;hchanuser
= &(*hchanuser
)->next
)
326 if ((*hchanuser
)->husr
== husr
)
329 *hchanuser
= (*hchanuser
)->next
;
334 (*hchanuser
)->next
= NULL
;
335 if (on_desk(husr
, huserchan
))
337 helpmod_channick_modes(husr
, hchan
, MC_DEVOICE
, HLAZY
);
338 huserchan
->flags
&= ~HQUEUE_DONE
;
344 int hchannel_count_users(hchannel
*hchan
, hlevel lvl
)
347 hchannel_user
*hchanuser
= hchan
->channel_users
;
348 for (;hchanuser
;hchanuser
= hchanuser
->next
)
351 else if (huser_get_level(hchanuser
->husr
) == lvl
)
356 int hchannel_count_queue(hchannel
*hchan
)
359 hchannel_user
*hchanuser
= hchan
->channel_users
;
360 for (;hchanuser
;hchanuser
= hchanuser
->next
)
362 if (on_queue(hchanuser
->husr
, huser_on_channel(hchanuser
->husr
, hchan
)))
368 int hchannel_is_valid(hchannel
*hchan
)
370 hchannel
*ptr
= hchannels
;
371 for (;ptr
;ptr
= ptr
->next
)
377 void hchannel_mode_check(hchannel
*hchan
)
379 if (((hchan
->flags
& H_MAINTAIN_M
) || (hchan
->flags
& H_QUEUE
)) && !IsModerated(hchan
->real_channel
))
380 helpmod_simple_modes(hchan
, CHANMODE_MODERATE
, 0,0);
381 else if (!((hchan
->flags
& H_MAINTAIN_M
) || (hchan
->flags
& H_QUEUE
)) && IsModerated(hchan
->real_channel
))
382 helpmod_simple_modes(hchan
, 0, CHANMODE_MODERATE
,0);
383 if (hchan
->flags
& H_MAINTAIN_I
&& !IsInviteOnly(hchan
->real_channel
))
384 helpmod_simple_modes(hchan
, CHANMODE_INVITEONLY
, 0,0);
385 else if (!(hchan
->flags
& H_MAINTAIN_I
) && IsInviteOnly(hchan
->real_channel
))
386 helpmod_simple_modes(hchan
, 0, CHANMODE_INVITEONLY
, 0);
389 void hchannel_conf_change(hchannel
*hchan
, int old_flags
)
394 for (i
=0;i
<HCHANNEL_CONF_COUNT
;i
++)
396 if ((hchan
->flags
^ old_flags
) & (1 << i
))
398 change
= (hchan
->flags
& (1 << i
))?H_ON
:H_OFF
;
402 hchannel_mode_check(hchan
);
404 helpmod_message_channel(hchan
, "Channel queue has been activated, all users enqueued");
406 helpmod_message_channel(hchan
, "Channel queue has been deactivated");
410 hchannel_mode_check(hchan
);
417 int hchannel_count(void)
419 hchannel
*hchan
= hchannels
;
421 for (;hchan
;hchan
= hchan
->next
)
426 void hchannel_activate_join_flood(hchannel
*hchan
)
428 hchannel_user
**hchanuser
= &hchan
->channel_users
;
429 helpmod_simple_modes(hchan
, CHANMODE_REGONLY
, 0, 1);
431 /* clean the channel of the already joined clients */
433 if (((*hchanuser
)->time_joined
> (time(NULL
) - 5)) && huser_get_level((*hchanuser
)->husr
) < H_STAFF
)
434 helpmod_kick(hchan
, (*hchanuser
)->husr
, "Join flood");
436 hchanuser
= &(*hchanuser
)->next
;
438 hchan
->flags
|= H_JOIN_FLOOD
;
440 scheduleoneshot(time(NULL
) + 60, &hchannel_deactivate_join_flood
, NULL
);
443 /* goes to schedule */
444 void hchannel_deactivate_join_flood()
446 hchannel
*hchan
= hchannels
;
447 for (;hchan
;hchan
= hchan
->next
)
448 if (hchan
->flags
& H_JOIN_FLOOD
)
450 helpmod_simple_modes(hchan
, 0, CHANMODE_REGONLY
, 1);
451 hchan
->flags
&= ~H_JOIN_FLOOD
;
455 const char *hchannel_get_state(hchannel
* hchan
, int mask
)
457 if (hchan
->flags
& mask
)
463 int hchannel_highlight_detection(hchannel
*hchan
, const char *message
)
465 char buffer
[512], *buffer_ptr
= buffer
, *ptr
= buffer
;
468 strcpy(buffer
, message
);
471 for (i
=0;i
<512 && buffer
[i
] != '\0';i
++)
472 if (buffer
[i
] == ',')
475 /* reset i for loop */
481 huser_channel
*tmp_huserchan
;
486 while (*buffer_ptr
&& isspace(*buffer_ptr
))
489 if (*buffer_ptr
== '@')
494 ptr
= strchr(buffer_ptr
, ' ');
500 if ((tmp
= getnickbynick(buffer_ptr
)))
501 if ((tmp_huser
= huser_get(tmp
)))
502 if ((tmp_huserchan
= huser_on_channel(tmp_huser
, hchan
)))
503 if ((tmp_huserchan
->flags
& HCUMODE_OP
) && strlen(huser_get_nick(tmp_huser
)) > 1)
518 const char *hchannel_get_sname(int flag
)
520 if (flag
< 0 || flag
> HCHANNEL_CONF_COUNT
)
526 return "Passive state";
528 return "Welcome message";
530 return "JoinFlood protection";
534 return "Verbose queue (requires queue)";
536 return "Auto queue (requires queue)";
538 return "Channel status reporting";
540 return "Pattern censor";
542 return "Lamer control";
544 return "Idle user removal";
546 return "Keep channel moderated";
548 return "Keep channel invite only";
550 return "Handle channel topic";
552 return "Calculate statistic";
554 return "Remove joining trojans";
556 return "Channel commands";
558 return "Oper only channel";
560 return "Disallow bold, underline, etc.";
562 return "Queue inactivity deactivation";
564 return "Require a ticket to join";
566 return "Send a message on ticket issue";
568 return "Excessive highlight prevention";
570 return "Error, please contact strutsi";