#include <string.h>
#include <assert.h>
-#include "../core/hooks.h"
-#include "../localuser/localuser.h"
-
#include "helpmod.h"
#include "hchannel.h"
#include "haccount.h"
#include "hqueue.h"
#include "hgen.h"
#include "hstat.h"
-
+/*
void helpmod_hook_quit(int unused, void *args)
{
nick *nck = ((nick**)args)[0];
huser *husr = huser_get(nck);
- /* it was someone we didn't even know */
+ / * it was someone we didn't even know * /
if (husr == NULL)
return;
}
+*/
+
/*
void helpmod_hook_part(int unused, void *args)
{
nick *nck = ((nick**)args)[1];
huser *husr;
-
}
*/
-void helpmod_hook_join(int unused, void *args)
+static void helpmod_hook_join(int unused, void *args)
{
channel *chan = ((channel**)args)[0];
hchannel *hchan = hchannel_get_by_channel(chan);
nick *nck = ((nick**)args)[1];
huser *husr;
- /* if we're not on this channel, the event is of no interest */
- if (hchan == NULL)
+ /* if we're not on this channel or the target is G, the event is of no interest */
+ if (hchan == NULL || nck == helpmodnick)
return;
husr = huser_get(nck);
assert(husr != NULL); /* hook_channel_newnick should fix this */
- if (hchan->flags & H_JOINFLOOD_PROTECTION & !(hchan->flags & H_PASSIVE))
+ if ((hchan->flags & H_JOINFLOOD_PROTECTION) && !(hchan->flags & H_PASSIVE))
{
if (hchan->jf_control < time(NULL))
hchan->jf_control = time(NULL);
else
hchan->jf_control++;
- if (hchan->jf_control - time(NULL) > 25 && !IsRegOnly(hchan))
+ if (hchan->jf_control - time(NULL) > 12 && !IsRegOnly(hchan))
{
if (hchan->flags & H_REPORT && hchannel_is_valid(hchan->report_to))
- helpmod_message_channel(hchan->report_to, "Warning: Possible join flood on %s, setting +r", hchannel_get_name(hchan));
- hchannel_activate_join_flood(hchan);
- }
+ helpmod_message_channel(hchan->report_to, "Warning: Possible join flood on %s, setting +r", hchannel_get_name(hchan));
+ hchannel_activate_join_flood(hchan);
+ }
}
if (hchan->flags & H_PASSIVE)
return;
}
- if (huser_get_level(husr) > H_PEON && (huser_get_account_flags(husr) & H_AUTO_OP) && hchannel_authority(hchan, husr))
+ if (huser_get_level(husr) >= H_STAFF && (huser_get_account_flags(husr) & H_AUTO_OP) && hchannel_authority(hchan, husr))
helpmod_channick_modes(husr, hchan ,MC_OP,HNOW);
- if (huser_get_level(husr) > H_PEON && (huser_get_account_flags(husr) & H_AUTO_VOICE) && hchannel_authority(hchan, husr))
+ if (huser_get_level(husr) >= H_TRIAL && (huser_get_account_flags(husr) & H_AUTO_VOICE) && hchannel_authority(hchan, husr))
helpmod_channick_modes(husr, hchan, MC_VOICE,HNOW);
if (hchan->flags & H_WELCOME && *hchan->real_channel->index->name->content)
}
}
-void helpmod_hook_channel_newnick(int unused, void *args)
+static void helpmod_hook_channel_newnick(int unused, void *args)
{
channel *chan = ((channel**)args)[0];
hchannel *hchan = hchannel_get_by_channel(chan);
nick *nck = ((nick**)args)[1];
huser *husr;
- /* if we're not on this channel, the event is of no interest */
- if (hchan == NULL)
+ /* if we're not on this channel or the target is G, the event is of no interest */
+ if (hchan == NULL || nck == helpmodnick)
return;
if ((husr = huser_get(nck)) == NULL)
husr = huser_add(nck);
-/*
- fprintf(hdebug_file, "%d ADD %s to %s\n", time(NULL), husr->real_user->nick, hchannel_get_name(hchan));
- fflush(hdebug_file);
-*/
+
assert(huser_on_channel(husr, hchan) == NULL);
assert(hchannel_on_channel(hchan, husr) == NULL);
if (hchan->flags & H_PASSIVE)
return;
- if (huser_get_level(husr) == H_LAMER || (huser_get_level(husr) == H_PEON && hban_check(nck)))
+ huser_activity(husr, NULL);
+
+ if (huser_get_level(husr) == H_LAMER || (huser_get_level(husr) <= H_TRIAL && hban_check(nck)))
{
hban *hb = hban_check(nck);
helpmod_setban(hchan, banmask, time(NULL) + 1 * HDEF_d, MCB_ADD, HNOW);
if (hb)
- helpmod_kick(hchan, husr,hban_get_reason(hb));
+ helpmod_kick(hchan, husr, "%s", hban_get_reason(hb));
else
helpmod_kick(hchan, husr, "Your presence on channel %s is not wanted", hchannel_get_name(hchan));
hqueue_handle_queue(hchan, NULL);
}
-void helpmod_hook_channel_lostnick(int unused, void *args)
+static void helpmod_hook_channel_lostnick(int unused, void *args)
{
channel *chan = ((channel**)args)[0];
hchannel *hchan = hchannel_get_by_channel(chan);
nick *nck = ((nick**)args)[1];
huser *husr;
+ /* In event that G was kicked, nothing is done */
+ if (nck == helpmodnick)
+ return;
+
/* hackery, can't think of a better way to do this */
huser *oper = NULL;
int handle_queue = 0;
assert(husr != NULL);
huserchan = huser_on_channel(husr, hchan);
-/*
- fprintf(hdebug_file, "%d DEL %s from %s\n", time(NULL), husr->real_user->nick, hchannel_get_name(hchan));
- fflush(hdebug_file);
-*/
+
assert(hchannel_on_channel(hchan, husr) != NULL);
assert(huserchan != NULL);
{ /* if H left the channel, we remove all the users from the channel */
while (hchan->channel_users)
{
- /*
- fprintf(hdebug_file, "%d DEL %s from %s\n", time(NULL), hchan->channel_users->husr->real_user->nick, hchannel_get_name(hchan));
- fflush(hdebug_file);
- */
huser_del_channel(hchan->channel_users->husr, hchan);
hchannel_del_user(hchan, hchan->channel_users->husr);
}
hqueue_handle_queue(hchan, oper);
}
-void helpmod_hook_nick_lostnick(int unused, void *args)
+static void helpmod_hook_nick_lostnick(int unused, void *args)
{
- nick *nck = ((nick**)args)[0];
+ nick *nck = (nick*)args;
huser *husr = huser_get(nck);
/* it was someone we didn't even know */
huser_del(husr);
}
-void helpmod_hook_channel_opped(int unused, void *args)
+static void helpmod_hook_channel_opped(int unused, void *args)
{
hchannel *hchan = hchannel_get_by_channel(((channel**)args)[0]);
huser_channel *huserchan;
return;
/* if the +o was given by a network service, G will not interfere */
- if (husr2 == NULL || strlen(husr2->real_user->nick) == 1)
+ if (husr2 == NULL || strlen(huser_get_nick(husr2)) == 1)
return;
if (huser_get_level(husr) < H_STAFF)
helpmod_channick_modes(husr, hchan, MC_DEOP ,HNOW);
}
-void helpmod_hook_channel_deopped(int unused, void *args)
+static void helpmod_hook_channel_deopped(int unused, void *args)
{
hchannel *hchan = hchannel_get_by_channel(((channel**)args)[0]);
huser_channel *huserchan;
assert(huserchan != NULL);
huserchan->flags &= ~HCUMODE_OP;
-
}
-void helpmod_hook_channel_voiced(int unused, void *args)
+static void helpmod_hook_channel_voiced(int unused, void *args)
{
hchannel *hchan = hchannel_get_by_channel(((channel**)args)[0]);
huser_channel *huserchan;
}
}
-void helpmod_hook_channel_devoiced(int unused, void *args)
+static void helpmod_hook_channel_devoiced(int unused, void *args)
{
hchannel *hchan = hchannel_get_by_channel(((channel**)args)[0]);
huser_channel *huserchan;
if (serverlist[homeserver(husr->real_user->numeric)].linkstate != LS_SQUIT)
{ /* if it was a netsplit, we do not trigger autoqueue */
hqueue_handle_queue(hchan, huserchan->responsible_oper);
- /*if (huser_valid(huserchan->responsible_oper) && huser_on_channel(huserchan->responsible_oper, hchan))
- hqueue_advance(hchan, huserchan->responsible_oper, 1);
- else
- hqueue_advance(hchan, huserchan->responsible_oper, 1);
- */
}
}
}
-void helpmod_hook_channel_topic(int unused, void *args)
+static void helpmod_hook_channel_topic(int unused, void *args)
{
hchannel *hchan = hchannel_get_by_channel(((channel**)args)[0]);
huser *husr;
}
}
-void helpmod_hook_nick_account(int unused, void *args)
+static void helpmod_hook_nick_account(int unused, void *args)
{
nick *nck = (nick*)args;
huser *husr = huser_get(nck);
+ huser_channel *huserchan, *huserchannext;
if (husr == NULL)
return;
else
- husr->account = haccount_get_by_name(nck->authname);
+ husr->account = haccount_get_by_name(nck->authname);
+
+ if (huser_get_level(husr) == H_LAMER) {
+ for (huserchan = husr->hchannels; huserchan; huserchan = huserchannext) {
+ huserchannext = huserchan->next;
+ helpmod_kick(huserchan->hchan, husr, "Your presence on channel %s is not wanted", hchannel_get_name(huserchan->hchan));
+ }
+ }
+}
+
+static void helpmod_hook_server_newserver(int unused, void *args)
+{
+ hchannel *hchan;
+ long numeric = (long)args;
+ server srv = serverlist[numeric];
+
+ /* check linkstate to prevent spam */
+ if (srv.linkstate == LS_LINKING)
+ {
+ for (hchan = hchannels;hchan != NULL;hchan = hchan->next)
+ if ((hchan->flags & H_HANDLE_TOPIC) && (hchan->topic != NULL))
+ hchannel_set_topic(hchan);
+ }
}
void helpmod_registerhooks(void)
{
- registerhook(HOOK_NICK_QUIT, &helpmod_hook_quit);
+/* registerhook(HOOK_NICK_QUIT, &helpmod_hook_quit); */
/*if (registerhook(HOOK_CHANNEL_PART, &helpmod_hook_part));*/
registerhook(HOOK_CHANNEL_JOIN, &helpmod_hook_join);
registerhook(HOOK_NICK_LOSTNICK, &helpmod_hook_nick_lostnick);
registerhook(HOOK_CHANNEL_DEVOICED, &helpmod_hook_channel_devoiced);
registerhook(HOOK_CHANNEL_TOPIC, &helpmod_hook_channel_topic);
registerhook(HOOK_NICK_ACCOUNT, &helpmod_hook_nick_account);
+ registerhook(HOOK_SERVER_NEWSERVER, &helpmod_hook_server_newserver);
}
void helpmod_deregisterhooks(void)
{
- deregisterhook(HOOK_NICK_QUIT, &helpmod_hook_quit);
+/* deregisterhook(HOOK_NICK_QUIT, &helpmod_hook_quit); */
/*if (deregisterhook(HOOK_CHANNEL_PART, &helpmod_hook_part));*/
deregisterhook(HOOK_CHANNEL_JOIN, &helpmod_hook_join);
deregisterhook(HOOK_NICK_LOSTNICK, &helpmod_hook_nick_lostnick);
deregisterhook(HOOK_CHANNEL_DEVOICED, &helpmod_hook_channel_devoiced);
deregisterhook(HOOK_CHANNEL_TOPIC, &helpmod_hook_channel_topic);
deregisterhook(HOOK_NICK_ACCOUNT, &helpmod_hook_nick_account);
+ deregisterhook(HOOK_SERVER_NEWSERVER, &helpmod_hook_server_newserver);
}