]>
jfr.im git - irc/quakenet/newserv.git/blob - helpmod2/hban.c
6 #include "../channel/channel.h"
7 #include "../nick/nick.h"
8 #include "../lib/sstring.h"
9 #include "../localuser/localuserchannel.h"
17 hban
*hban_add(const char* pat
, const char* rsn
, time_t exp
, int now
)
22 if (hban_get(pat
) || exp
<= time(NULL
))
25 if ((tmp
= makeban(pat
)) == NULL
) /* bad ban */
28 ptr
= (hban
*)malloc(sizeof(hban
));
30 ptr
->expiration
= exp
;
35 ptr
->reason
= getsstring(rsn
, strlen(rsn
));
40 { /* additional logic here */
42 for (tmpu
= husers
;tmpu
;tmpu
= tmpu
->next
)
43 if (nickmatchban(tmpu
->real_user
, tmp
, 0) && !IsOper(tmpu
->real_user
))
45 hchannel
*assert_hchan
= NULL
;
46 while (tmpu
->hchannels
)
48 if (tmpu
->hchannels
->hchan
== assert_hchan
)
50 Error("helpmod", ERR_ERROR
, "hban.c hban_add() current channel is the previous channel. Preventing lockup.");
53 assert_hchan
= tmpu
->hchannels
->hchan
;
54 helpmod_setban(tmpu
->hchannels
->hchan
, bantostring(ptr
->real_ban
), HELPMOD_BAN_DURATION
, MCB_ADD
, now
);
55 helpmod_kick(tmpu
->hchannels
->hchan
, tmpu
, "%s", hban_get_reason(ptr
));
63 hban
*hban_huser(huser
*husr
, const char* rsn
, time_t exp
, int now
)
65 const char *banmask
= hban_ban_string(husr
->real_user
, HBAN_HOST
);
67 return hban_add(banmask
, rsn
, exp
, now
);
70 hban
*hban_del(hban
* hb
, int now
)
73 for (;*ptr
;ptr
= &(*ptr
)->next
)
76 hban
*tmp
= (*ptr
)->next
;
78 { /* additional logic here */
80 for (hchan
= hchannels
;hchan
;hchan
= hchan
->next
)
81 helpmod_setban(hchan
, bantostring((*ptr
)->real_ban
), 0, MCB_DEL
, now
);
84 freechanban((*ptr
)->real_ban
); /* evil ? */
85 freesstring((*ptr
)->reason
);
94 hban
*hban_get(const char* pat
)
97 for (;tmp
;tmp
= tmp
->next
)
98 if (!ci_strcmp(bantostring(tmp
->real_ban
),pat
))
108 for (;hb
;hb
= hb
->next
)
113 hban
*hban_check(nick
*nck
)
116 for (;ptr
;ptr
= ptr
->next
)
117 if (nickmatchban(nck
, ptr
->real_ban
, 0))
122 void hban_remove_expired(void)
126 if ((*ptr
)->expiration
<= time(NULL
)) /* expired */
133 void hban_del_all(void)
139 const char *hban_get_reason(hban
* hb
)
142 return "error (please contact strutsi)";
143 else if (hb
->reason
== NULL
)
146 return hb
->reason
->content
;
149 const char *hban_ban_string(nick
*nck
, int banflags
)
151 static char buffer
[256];
154 if (banflags
& HBAN_NICK
)
155 strcat(buffer
, nck
->nick
);
161 if (banflags
& HBAN_IDENT
)
162 strcat(buffer
, nck
->ident
);
168 if ((banflags
& HBAN_HOST
) && IsAccount(nck
) && IsHideHost(nck
))
170 strcat(buffer
, nck
->authname
);
171 strcat(buffer
, ".users.quakenet.org");
173 else if ((banflags
& HBAN_REAL_HOST
) || ((banflags
& HBAN_HOST
)))
176 strcat(buffer
, nck
->sethost
->content
);
178 strcat(buffer
, nck
->host
->name
->content
);
183 assert(strcmp(buffer
, "*!*@*"));