*/
#include "stdinc.h"
-#include "tools.h"
#include "channel.h"
+#include "chmode.h"
#include "client.h"
#include "common.h"
#include "hash.h"
#include "hook.h"
-#include "irc_string.h"
-#include "sprintf_irc.h"
+#include "match.h"
#include "ircd.h"
#include "numeric.h"
#include "s_serv.h" /* captab */
#include "whowas.h"
#include "s_conf.h" /* ConfigFileEntry, ConfigChannel */
#include "s_newconf.h"
-#include "event.h"
-#include "memory.h"
-#include "balloc.h"
-#include "s_log.h"
+#include "logger.h"
+#include "ipv4_from_ipv6.h"
-extern dlink_list global_channel_list;
-
-extern struct config_channel_entry ConfigChannel;
-extern BlockHeap *channel_heap;
-extern BlockHeap *ban_heap;
-extern BlockHeap *topic_heap;
-extern BlockHeap *member_heap;
+struct config_channel_entry ConfigChannel;
+rb_dlink_list global_channel_list;
+static rb_bh *channel_heap;
+static rb_bh *ban_heap;
+static rb_bh *topic_heap;
+static rb_bh *member_heap;
static int channel_capabs[] = { CAP_EX, CAP_IE,
CAP_SERVICE,
static void free_topic(struct Channel *chptr);
static int h_can_join;
+static int h_can_send;
+int h_get_channel_access;
/* init_channels()
*
void
init_channels(void)
{
- channel_heap = BlockHeapCreate(sizeof(struct Channel), CHANNEL_HEAP_SIZE);
- ban_heap = BlockHeapCreate(sizeof(struct Ban), BAN_HEAP_SIZE);
- topic_heap = BlockHeapCreate(TOPICLEN + 1 + USERHOST_REPLYLEN, TOPIC_HEAP_SIZE);
- member_heap = BlockHeapCreate(sizeof(struct membership), MEMBER_HEAP_SIZE);
+ channel_heap = rb_bh_create(sizeof(struct Channel), CHANNEL_HEAP_SIZE, "channel_heap");
+ ban_heap = rb_bh_create(sizeof(struct Ban), BAN_HEAP_SIZE, "ban_heap");
+ topic_heap = rb_bh_create(TOPICLEN + 1 + USERHOST_REPLYLEN, TOPIC_HEAP_SIZE, "topic_heap");
+ member_heap = rb_bh_create(sizeof(struct membership), MEMBER_HEAP_SIZE, "member_heap");
h_can_join = register_hook("can_join");
+ h_can_send = register_hook("can_send");
+ h_get_channel_access = register_hook("get_channel_access");
}
/*
allocate_channel(const char *chname)
{
struct Channel *chptr;
- chptr = BlockHeapAlloc(channel_heap);
- DupString(chptr->chname, chname);
+ chptr = rb_bh_alloc(channel_heap);
+ chptr->chname = rb_strdup(chname);
return (chptr);
}
void
free_channel(struct Channel *chptr)
{
- MyFree(chptr->chname);
- BlockHeapFree(channel_heap, chptr);
+ rb_free(chptr->chname);
+ rb_free(chptr->mode_lock);
+ rb_bh_free(channel_heap, chptr);
}
struct Ban *
-allocate_ban(const char *banstr, const char *who)
+allocate_ban(const char *banstr, const char *who, const char *forward)
{
struct Ban *bptr;
- bptr = BlockHeapAlloc(ban_heap);
- DupString(bptr->banstr, banstr);
- DupString(bptr->who, who);
+ bptr = rb_bh_alloc(ban_heap);
+ bptr->banstr = rb_strdup(banstr);
+ bptr->who = rb_strdup(who);
+ bptr->forward = forward ? rb_strdup(forward) : NULL;
return (bptr);
}
void
free_ban(struct Ban *bptr)
{
- MyFree(bptr->banstr);
- MyFree(bptr->who);
- BlockHeapFree(ban_heap, bptr);
+ rb_free(bptr->banstr);
+ rb_free(bptr->who);
+ rb_free(bptr->forward);
+ rb_bh_free(ban_heap, bptr);
}
+/*
+ * send_channel_join()
+ *
+ * input - channel to join, client joining.
+ * output - none
+ * side effects - none
+ */
+void
+send_channel_join(struct Channel *chptr, struct Client *client_p)
+{
+ if (!IsClient(client_p))
+ return;
+
+ sendto_channel_local_with_capability(ALL_MEMBERS, NOCAPS, CLICAP_EXTENDED_JOIN, chptr, ":%s!%s@%s JOIN %s",
+ client_p->name, client_p->username, client_p->host, chptr->chname);
+
+ sendto_channel_local_with_capability(ALL_MEMBERS, CLICAP_EXTENDED_JOIN, NOCAPS, chptr, ":%s!%s@%s JOIN %s %s :%s",
+ client_p->name, client_p->username, client_p->host, chptr->chname,
+ EmptyString(client_p->user->suser) ? "*" : client_p->user->suser,
+ client_p->info);
+}
/* find_channel_membership()
*
find_channel_membership(struct Channel *chptr, struct Client *client_p)
{
struct membership *msptr;
- dlink_node *ptr;
+ rb_dlink_node *ptr;
if(!IsClient(client_p))
return NULL;
/* Pick the most efficient list to use to be nice to things like
* CHANSERV which could be in a large number of channels
*/
- if(dlink_list_length(&chptr->members) < dlink_list_length(&client_p->user->channel))
+ if(rb_dlink_list_length(&chptr->members) < rb_dlink_list_length(&client_p->user->channel))
{
- DLINK_FOREACH(ptr, chptr->members.head)
+ RB_DLINK_FOREACH(ptr, chptr->members.head)
{
msptr = ptr->data;
}
else
{
- DLINK_FOREACH(ptr, client_p->user->channel.head)
+ RB_DLINK_FOREACH(ptr, client_p->user->channel.head)
{
msptr = ptr->data;
if(client_p->user == NULL)
return;
- msptr = BlockHeapAlloc(member_heap);
+ msptr = rb_bh_alloc(member_heap);
msptr->chptr = chptr;
msptr->client_p = client_p;
msptr->flags = flags;
- dlinkAdd(msptr, &msptr->usernode, &client_p->user->channel);
- dlinkAdd(msptr, &msptr->channode, &chptr->members);
+ rb_dlinkAdd(msptr, &msptr->usernode, &client_p->user->channel);
+ rb_dlinkAdd(msptr, &msptr->channode, &chptr->members);
if(MyClient(client_p))
- dlinkAdd(msptr, &msptr->locchannode, &chptr->locmembers);
+ rb_dlinkAdd(msptr, &msptr->locchannode, &chptr->locmembers);
}
/* remove_user_from_channel()
client_p = msptr->client_p;
chptr = msptr->chptr;
- dlinkDelete(&msptr->usernode, &client_p->user->channel);
- dlinkDelete(&msptr->channode, &chptr->members);
+ rb_dlinkDelete(&msptr->usernode, &client_p->user->channel);
+ rb_dlinkDelete(&msptr->channode, &chptr->members);
if(client_p->servptr == &me)
- dlinkDelete(&msptr->locchannode, &chptr->locmembers);
+ rb_dlinkDelete(&msptr->locchannode, &chptr->locmembers);
- chptr->users_last = CurrentTime;
-
- if(!(chptr->mode.mode & MODE_PERMANENT) && dlink_list_length(&chptr->members) <= 0)
+ if(!(chptr->mode.mode & MODE_PERMANENT) && rb_dlink_list_length(&chptr->members) <= 0)
destroy_channel(chptr);
- BlockHeapFree(member_heap, msptr);
+ rb_bh_free(member_heap, msptr);
return;
}
{
struct Channel *chptr;
struct membership *msptr;
- dlink_node *ptr;
- dlink_node *next_ptr;
+ rb_dlink_node *ptr;
+ rb_dlink_node *next_ptr;
if(client_p == NULL)
return;
- DLINK_FOREACH_SAFE(ptr, next_ptr, client_p->user->channel.head)
+ RB_DLINK_FOREACH_SAFE(ptr, next_ptr, client_p->user->channel.head)
{
msptr = ptr->data;
chptr = msptr->chptr;
- dlinkDelete(&msptr->channode, &chptr->members);
+ rb_dlinkDelete(&msptr->channode, &chptr->members);
if(client_p->servptr == &me)
- dlinkDelete(&msptr->locchannode, &chptr->locmembers);
-
- chptr->users_last = CurrentTime;
+ rb_dlinkDelete(&msptr->locchannode, &chptr->locmembers);
- if(!(chptr->mode.mode & MODE_PERMANENT) && dlink_list_length(&chptr->members) <= 0)
+ if(!(chptr->mode.mode & MODE_PERMANENT) && rb_dlink_list_length(&chptr->members) <= 0)
destroy_channel(chptr);
- BlockHeapFree(member_heap, msptr);
+ rb_bh_free(member_heap, msptr);
}
client_p->user->channel.head = client_p->user->channel.tail = NULL;
invalidate_bancache_user(struct Client *client_p)
{
struct membership *msptr;
- dlink_node *ptr;
+ rb_dlink_node *ptr;
if(client_p == NULL)
return;
- DLINK_FOREACH(ptr, client_p->user->channel.head)
+ RB_DLINK_FOREACH(ptr, client_p->user->channel.head)
{
msptr = ptr->data;
msptr->bants = 0;
/* free_channel_list()
*
- * input - dlink list to free
+ * input - rb_dlink list to free
* output -
* side effects - list of b/e/I modes is cleared
*/
void
-free_channel_list(dlink_list * list)
+free_channel_list(rb_dlink_list * list)
{
- dlink_node *ptr;
- dlink_node *next_ptr;
+ rb_dlink_node *ptr;
+ rb_dlink_node *next_ptr;
struct Ban *actualBan;
- DLINK_FOREACH_SAFE(ptr, next_ptr, list->head)
+ RB_DLINK_FOREACH_SAFE(ptr, next_ptr, list->head)
{
actualBan = ptr->data;
free_ban(actualBan);
void
destroy_channel(struct Channel *chptr)
{
- dlink_node *ptr, *next_ptr;
+ rb_dlink_node *ptr, *next_ptr;
- DLINK_FOREACH_SAFE(ptr, next_ptr, chptr->invites.head)
+ RB_DLINK_FOREACH_SAFE(ptr, next_ptr, chptr->invites.head)
{
del_invite(chptr, ptr->data);
}
/* Free the topic */
free_topic(chptr);
- dlinkDelete(&chptr->node, &global_channel_list);
+ rb_dlinkDelete(&chptr->node, &global_channel_list);
del_from_channel_hash(chptr->chname, chptr);
free_channel(chptr);
}
{
struct membership *msptr;
struct Client *target_p;
- dlink_node *ptr;
+ rb_dlink_node *ptr;
char lbuf[BUFSIZE];
char *t;
int mlen;
t = lbuf + cur_len;
- DLINK_FOREACH(ptr, chptr->members.head)
+ RB_DLINK_FOREACH(ptr, chptr->members.head)
{
msptr = ptr->data;
target_p = msptr->client_p;
void
del_invite(struct Channel *chptr, struct Client *who)
{
- dlinkFindDestroy(who, &chptr->invites);
- dlinkFindDestroy(chptr, &who->user->invited);
+ rb_dlinkFindDestroy(who, &chptr->invites);
+ rb_dlinkFindDestroy(chptr, &who->user->invited);
}
-/* is_banned()
+/* is_banned_list()
*
- * input - channel to check bans for, user to check bans against
- * optional prebuilt buffers
+ * input - channel to check bans for, ban list (banlist or quietlist),
+ * user to check bans against, optional prebuilt buffers,
+ * optional forward channel pointer
* output - 1 if banned, else 0
* side effects -
*/
-int
-is_banned(struct Channel *chptr, struct Client *who, struct membership *msptr,
- const char *s, const char *s2)
+static int
+is_banned_list(struct Channel *chptr, rb_dlink_list *list,
+ struct Client *who, struct membership *msptr,
+ const char *s, const char *s2, const char **forward)
{
char src_host[NICKLEN + USERLEN + HOSTLEN + 6];
char src_iphost[NICKLEN + USERLEN + HOSTLEN + 6];
char src_althost[NICKLEN + USERLEN + HOSTLEN + 6];
+ char src_ip4host[NICKLEN + USERLEN + HOSTLEN + 6];
char *s3 = NULL;
- dlink_node *ptr;
+ char *s4 = NULL;
+ struct sockaddr_in ip4;
+ rb_dlink_node *ptr;
struct Ban *actualBan = NULL;
struct Ban *actualExcept = NULL;
s3 = src_althost;
}
}
+#ifdef RB_IPV6
+ if(who->localClient->ip.ss_family == AF_INET6 &&
+ ipv4_from_ipv6((const struct sockaddr_in6 *)&who->localClient->ip, &ip4))
+ {
+ rb_sprintf(src_ip4host, "%s!%s@", who->name, who->username);
+ s4 = src_ip4host + strlen(src_ip4host);
+ rb_inet_ntop_sock((struct sockaddr *)&ip4,
+ s4, src_ip4host + sizeof src_ip4host - s4);
+ s4 = src_ip4host;
+ }
+#endif
- DLINK_FOREACH(ptr, chptr->banlist.head)
+ RB_DLINK_FOREACH(ptr, list->head)
{
actualBan = ptr->data;
if(match(actualBan->banstr, s) ||
match(actualBan->banstr, s2) ||
match_cidr(actualBan->banstr, s2) ||
match_extban(actualBan->banstr, who, chptr, CHFL_BAN) ||
- (s3 != NULL && match(actualBan->banstr, s3)))
+ (s3 != NULL && match(actualBan->banstr, s3))
+#ifdef RB_IPV6
+ ||
+ (s4 != NULL && (match(actualBan->banstr, s4) || match_cidr(actualBan->banstr, s4)))
+#endif
+ )
break;
else
actualBan = NULL;
if((actualBan != NULL) && ConfigChannel.use_except)
{
- DLINK_FOREACH(ptr, chptr->exceptlist.head)
+ RB_DLINK_FOREACH(ptr, chptr->exceptlist.head)
{
actualExcept = ptr->data;
}
}
+ if (actualBan && actualBan->forward && forward)
+ *forward = actualBan->forward;
+
return ((actualBan ? CHFL_BAN : 0));
}
+/* is_banned()
+ *
+ * input - channel to check bans for, user to check bans against
+ * optional prebuilt buffers, optional forward channel pointer
+ * output - 1 if banned, else 0
+ * side effects -
+ */
+int
+is_banned(struct Channel *chptr, struct Client *who, struct membership *msptr,
+ const char *s, const char *s2, const char **forward)
+{
+ return is_banned_list(chptr, &chptr->banlist, who, msptr, s, s2,
+ forward);
+}
+
/* is_quieted()
*
* input - channel to check bans for, user to check bans against
is_quieted(struct Channel *chptr, struct Client *who, struct membership *msptr,
const char *s, const char *s2)
{
- char src_host[NICKLEN + USERLEN + HOSTLEN + 6];
- char src_iphost[NICKLEN + USERLEN + HOSTLEN + 6];
- char src_althost[NICKLEN + USERLEN + HOSTLEN + 6];
- char *s3 = NULL;
- dlink_node *ptr;
- struct Ban *actualBan = NULL;
- struct Ban *actualExcept = NULL;
-
- if(!MyClient(who))
- return 0;
-
- /* if the buffers havent been built, do it here */
- if(s == NULL)
- {
- rb_sprintf(src_host, "%s!%s@%s", who->name, who->username, who->host);
- rb_sprintf(src_iphost, "%s!%s@%s", who->name, who->username, who->sockhost);
-
- s = src_host;
- s2 = src_iphost;
- }
- if(who->localClient->mangledhost != NULL)
- {
- /* if host mangling mode enabled, also check their real host */
- if(!strcmp(who->host, who->localClient->mangledhost))
- {
- rb_sprintf(src_althost, "%s!%s@%s", who->name, who->username, who->orighost);
- s3 = src_althost;
- }
- /* if host mangling mode not enabled and no other spoof,
- * also check the mangled form of their host */
- else if (!IsDynSpoof(who))
- {
- rb_sprintf(src_althost, "%s!%s@%s", who->name, who->username, who->localClient->mangledhost);
- s3 = src_althost;
- }
- }
-
- DLINK_FOREACH(ptr, chptr->quietlist.head)
- {
- actualBan = ptr->data;
- if(match(actualBan->banstr, s) ||
- match(actualBan->banstr, s2) ||
- match_cidr(actualBan->banstr, s2) ||
- match_extban(actualBan->banstr, who, chptr, CHFL_QUIET) ||
- (s3 != NULL && match(actualBan->banstr, s3)))
- break;
- else
- actualBan = NULL;
- }
-
- if((actualBan != NULL) && ConfigChannel.use_except)
- {
- DLINK_FOREACH(ptr, chptr->exceptlist.head)
- {
- actualExcept = ptr->data;
-
- /* theyre exempted.. */
- if(match(actualExcept->banstr, s) ||
- match(actualExcept->banstr, s2) ||
- match_cidr(actualExcept->banstr, s2) ||
- match_extban(actualExcept->banstr, who, chptr, CHFL_EXCEPTION) ||
- (s3 != NULL && match(actualExcept->banstr, s3)))
- {
- /* cache the fact theyre not banned */
- if(msptr != NULL)
- {
- msptr->bants = chptr->bants;
- msptr->flags &= ~CHFL_BANNED;
- }
-
- return CHFL_EXCEPTION;
- }
- }
- }
-
- /* cache the banned/not banned status */
- if(msptr != NULL)
- {
- msptr->bants = chptr->bants;
-
- if(actualBan != NULL)
- {
- msptr->flags |= CHFL_BANNED;
- return CHFL_BAN;
- }
- else
- {
- msptr->flags &= ~CHFL_BANNED;
- return 0;
- }
- }
-
- return ((actualBan ? CHFL_BAN : 0));
+ return is_banned_list(chptr, &chptr->quietlist, who, msptr, s, s2,
+ NULL);
}
/* can_join()
*
* input - client to check, channel to check for, key
- * output - reason for not being able to join, else 0
+ * output - reason for not being able to join, else 0, channel name to forward to
* side effects -
+ * caveats - this function should only be called on a local user.
*/
int
-can_join(struct Client *source_p, struct Channel *chptr, char *key)
+can_join(struct Client *source_p, struct Channel *chptr, const char *key, const char **forward)
{
- dlink_node *invite = NULL;
- dlink_node *ptr;
+ rb_dlink_node *invite = NULL;
+ rb_dlink_node *ptr;
struct Ban *invex = NULL;
char src_host[NICKLEN + USERLEN + HOSTLEN + 6];
char src_iphost[NICKLEN + USERLEN + HOSTLEN + 6];
s_assert(source_p->localClient != NULL);
+ moduledata.client = source_p;
+ moduledata.chptr = chptr;
+ moduledata.approved = 0;
+
rb_sprintf(src_host, "%s!%s@%s", source_p->name, source_p->username, source_p->host);
rb_sprintf(src_iphost, "%s!%s@%s", source_p->name, source_p->username, source_p->sockhost);
if(source_p->localClient->mangledhost != NULL)
}
}
- if((is_banned(chptr, source_p, NULL, src_host, src_iphost)) == CHFL_BAN)
- return (ERR_BANNEDFROMCHAN);
+ if((is_banned(chptr, source_p, NULL, src_host, src_iphost, forward)) == CHFL_BAN)
+ {
+ moduledata.approved = ERR_BANNEDFROMCHAN;
+ goto finish_join_check;
+ }
+
+ if(*chptr->mode.key && (EmptyString(key) || irccmp(chptr->mode.key, key)))
+ {
+ moduledata.approved = ERR_BADCHANNELKEY;
+ goto finish_join_check;
+ }
+
+ /* All checks from this point on will forward... */
+ if(forward)
+ *forward = chptr->mode.forward;
if(chptr->mode.mode & MODE_INVITEONLY)
{
- DLINK_FOREACH(invite, source_p->user->invited.head)
+ RB_DLINK_FOREACH(invite, source_p->user->invited.head)
{
if(invite->data == chptr)
break;
if(invite == NULL)
{
if(!ConfigChannel.use_invex)
- return (ERR_INVITEONLYCHAN);
- DLINK_FOREACH(ptr, chptr->invexlist.head)
+ moduledata.approved = ERR_INVITEONLYCHAN;
+ RB_DLINK_FOREACH(ptr, chptr->invexlist.head)
{
invex = ptr->data;
if(match(invex->banstr, src_host)
break;
}
if(ptr == NULL)
- return (ERR_INVITEONLYCHAN);
+ moduledata.approved = ERR_INVITEONLYCHAN;
}
}
- if(*chptr->mode.key && (EmptyString(key) || irccmp(chptr->mode.key, key)))
- return (ERR_BADCHANNELKEY);
-
if(chptr->mode.limit &&
- dlink_list_length(&chptr->members) >= (unsigned long) chptr->mode.limit)
+ rb_dlink_list_length(&chptr->members) >= (unsigned long) chptr->mode.limit)
i = ERR_CHANNELISFULL;
if(chptr->mode.mode & MODE_REGONLY && EmptyString(source_p->user->suser))
i = ERR_NEEDREGGEDNICK;
/* join throttling stuff --nenolod */
else if(chptr->mode.join_num > 0 && chptr->mode.join_time > 0)
{
- if ((CurrentTime - chptr->join_delta <=
+ if ((rb_current_time() - chptr->join_delta <=
chptr->mode.join_time) && (chptr->join_count >=
chptr->mode.join_num))
i = ERR_THROTTLE;
/* allow /invite to override +l/+r/+j also -- jilles */
if (i != 0 && invite == NULL)
{
- DLINK_FOREACH(invite, source_p->user->invited.head)
+ RB_DLINK_FOREACH(invite, source_p->user->invited.head)
{
if(invite->data == chptr)
break;
}
if (invite == NULL)
- return i;
+ moduledata.approved = i;
}
- moduledata.client = source_p;
- moduledata.chptr = chptr;
- moduledata.approved = 0;
-
+finish_join_check:
call_hook(h_can_join, &moduledata);
return moduledata.approved;
int
can_send(struct Channel *chptr, struct Client *source_p, struct membership *msptr)
{
+ hook_data_channel_approval moduledata;
+
+ moduledata.approved = CAN_SEND_NONOP;
+
if(IsServer(source_p) || IsService(source_p))
return CAN_SEND_OPV;
if(MyClient(source_p) && hash_find_resv(chptr->chname) &&
!IsOper(source_p) && !IsExemptResv(source_p))
- return CAN_SEND_NO;
+ moduledata.approved = CAN_SEND_NO;
if(msptr == NULL)
{
* theres no possibility of caching them --fl
*/
if(chptr->mode.mode & MODE_NOPRIVMSGS || chptr->mode.mode & MODE_MODERATED)
- return CAN_SEND_NO;
+ moduledata.approved = CAN_SEND_NO;
else
- return CAN_SEND_NONOP;
+ moduledata.approved = CAN_SEND_NONOP;
+
+ return moduledata.approved;
}
}
- if(is_chanop_voiced(msptr))
- return CAN_SEND_OPV;
-
if(chptr->mode.mode & MODE_MODERATED)
- return CAN_SEND_NO;
+ moduledata.approved = CAN_SEND_NO;
if(MyClient(source_p))
{
if(msptr->bants == chptr->bants)
{
if(can_send_banned(msptr))
- return CAN_SEND_NO;
+ moduledata.approved = CAN_SEND_NO;
}
- else if(is_banned(chptr, source_p, msptr, NULL, NULL) == CHFL_BAN
+ else if(is_banned(chptr, source_p, msptr, NULL, NULL, NULL) == CHFL_BAN
|| is_quieted(chptr, source_p, msptr, NULL, NULL) == CHFL_BAN)
- return CAN_SEND_NO;
+ moduledata.approved = CAN_SEND_NO;
+ }
+
+ if(is_chanop_voiced(msptr))
+ moduledata.approved = CAN_SEND_OPV;
+
+ moduledata.client = source_p;
+ moduledata.chptr = msptr->chptr;
+ moduledata.msptr = msptr;
+ moduledata.target = NULL;
+
+ call_hook(h_can_send, &moduledata);
+
+ return moduledata.approved;
+}
+
+/*
+ * flood_attack_channel
+ * inputs - flag 0 if PRIVMSG 1 if NOTICE. RFC
+ * says NOTICE must not auto reply
+ * - pointer to source Client
+ * - pointer to target channel
+ * output - 1 if target is under flood attack
+ * side effects - check for flood attack on target chptr
+ */
+int
+flood_attack_channel(int p_or_n, struct Client *source_p, struct Channel *chptr, char *chname)
+{
+ int delta;
+
+ if(GlobalSetOptions.floodcount && MyClient(source_p))
+ {
+ if((chptr->first_received_message_time + 1) < rb_current_time())
+ {
+ delta = rb_current_time() - chptr->first_received_message_time;
+ chptr->received_number_of_privmsgs -= delta;
+ chptr->first_received_message_time = rb_current_time();
+ if(chptr->received_number_of_privmsgs <= 0)
+ {
+ chptr->received_number_of_privmsgs = 0;
+ chptr->flood_noticed = 0;
+ }
+ }
+
+ if((chptr->received_number_of_privmsgs >= GlobalSetOptions.floodcount)
+ || chptr->flood_noticed)
+ {
+ if(chptr->flood_noticed == 0)
+ {
+ sendto_realops_snomask(SNO_BOTS, *chptr->chname == '&' ? L_ALL : L_NETWIDE,
+ "Possible Flooder %s[%s@%s] on %s target: %s",
+ source_p->name, source_p->username,
+ source_p->orighost,
+ source_p->servptr->name, chptr->chname);
+ chptr->flood_noticed = 1;
+
+ /* Add a bit of penalty */
+ chptr->received_number_of_privmsgs += 2;
+ }
+ if(MyClient(source_p) && (p_or_n != 1))
+ sendto_one(source_p,
+ ":%s NOTICE %s :*** Message to %s throttled due to flooding",
+ me.name, source_p->name, chptr->chname);
+ return 1;
+ }
+ else
+ chptr->received_number_of_privmsgs++;
}
- return CAN_SEND_NONOP;
+ return 0;
}
/* find_bannickchange_channel()
{
struct Channel *chptr;
struct membership *msptr;
- dlink_node *ptr;
+ rb_dlink_node *ptr;
char src_host[NICKLEN + USERLEN + HOSTLEN + 6];
char src_iphost[NICKLEN + USERLEN + HOSTLEN + 6];
rb_sprintf(src_host, "%s!%s@%s", client_p->name, client_p->username, client_p->host);
rb_sprintf(src_iphost, "%s!%s@%s", client_p->name, client_p->username, client_p->sockhost);
- DLINK_FOREACH(ptr, client_p->user->channel.head)
+ RB_DLINK_FOREACH(ptr, client_p->user->channel.head)
{
msptr = ptr->data;
chptr = msptr->chptr;
if (can_send_banned(msptr))
return chptr;
}
- else if (is_banned(chptr, client_p, msptr, src_host, src_iphost) == CHFL_BAN
+ else if (is_banned(chptr, client_p, msptr, src_host, src_iphost, NULL) == CHFL_BAN
|| is_quieted(chptr, client_p, msptr, src_host, src_iphost) == CHFL_BAN)
return chptr;
}
source_p->localClient->oper_warn_count_down--;
else
source_p->localClient->oper_warn_count_down = 0;
- if(source_p->localClient->oper_warn_count_down == 0)
+ if(source_p->localClient->oper_warn_count_down == 0 &&
+ name != NULL)
{
/* Its already known as a possible spambot */
- if(name != NULL)
- sendto_realops_snomask(SNO_BOTS, L_NETWIDE,
- "User %s (%s@%s) trying to join %s is a possible spambot",
- source_p->name,
- source_p->username, source_p->orighost, name);
- else
- sendto_realops_snomask(SNO_BOTS, L_NETWIDE,
- "User %s (%s@%s) is a possible spambot",
- source_p->name,
- source_p->username, source_p->orighost);
+ sendto_realops_snomask(SNO_BOTS, L_NETWIDE,
+ "User %s (%s@%s) trying to join %s is a possible spambot",
+ source_p->name,
+ source_p->username, source_p->orighost, name);
source_p->localClient->oper_warn_count_down = OPER_SPAM_COUNTDOWN;
}
}
else
{
if((t_delta =
- (CurrentTime - source_p->localClient->last_leave_time)) >
+ (rb_current_time() - source_p->localClient->last_leave_time)) >
JOIN_LEAVE_COUNT_EXPIRE_TIME)
{
decrement_count = (t_delta / JOIN_LEAVE_COUNT_EXPIRE_TIME);
- if(decrement_count > source_p->localClient->join_leave_count)
+ if(name != NULL)
+ ;
+ else if(decrement_count > source_p->localClient->join_leave_count)
source_p->localClient->join_leave_count = 0;
else
source_p->localClient->join_leave_count -= decrement_count;
}
else
{
- if((CurrentTime -
+ if((rb_current_time() -
(source_p->localClient->last_join_time)) < GlobalSetOptions.spam_time)
{
/* oh, its a possible spambot */
}
}
if(name != NULL)
- source_p->localClient->last_join_time = CurrentTime;
+ source_p->localClient->last_join_time = rb_current_time();
else
- source_p->localClient->last_leave_time = CurrentTime;
+ source_p->localClient->last_leave_time = rb_current_time();
}
}
splitmode = 1;
sendto_realops_snomask(SNO_GENERAL, L_ALL,
"Network split, activating splitmode");
- eventAddIsh("check_splitmode", check_splitmode, NULL, 2);
+ check_splitmode_ev = rb_event_addish("check_splitmode", check_splitmode, NULL, 2);
}
}
/* in splitmode, check whether its finished */
sendto_realops_snomask(SNO_GENERAL, L_ALL,
"Network rejoined, deactivating splitmode");
- eventDelete(check_splitmode, NULL);
+ rb_event_delete(check_splitmode_ev);
+ check_splitmode_ev = NULL;
}
}
}
if(chptr == NULL)
return;
- ptr = BlockHeapAlloc(topic_heap);
+ ptr = rb_bh_alloc(topic_heap);
/* Basically we allocate one large block for the topic and
* the topic info. We then split it up into two and shove it
* MUST change this as well
*/
ptr = chptr->topic;
- BlockHeapFree(topic_heap, ptr);
+ rb_bh_free(topic_heap, ptr);
chptr->topic = NULL;
chptr->topic_info = NULL;
}
{
if(chptr->topic == NULL)
allocate_topic(chptr);
- strlcpy(chptr->topic, topic, TOPICLEN + 1);
- strlcpy(chptr->topic_info, topic_info, USERHOST_REPLYLEN);
+ rb_strlcpy(chptr->topic, topic, TOPICLEN + 1);
+ rb_strlcpy(chptr->topic_info, topic_info, USERHOST_REPLYLEN);
chptr->topic_time = topicts;
}
else
}
}
-const struct mode_letter chmode_flags[] =
-{
- {MODE_INVITEONLY, 'i'},
- {MODE_MODERATED, 'm'},
- {MODE_NOPRIVMSGS, 'n'},
- {MODE_PRIVATE, 'p'},
- {MODE_SECRET, 's'},
- {MODE_TOPICLIMIT, 't'},
- {MODE_NOCOLOR, 'c'},
- {MODE_FREEINVITE, 'g'},
- {MODE_OPMODERATE, 'z'},
- {MODE_EXLIMIT, 'L'},
- {MODE_PERMANENT, 'P'},
- {MODE_FREETARGET, 'F'},
- {MODE_DISFORWARD, 'Q'},
- {MODE_REGONLY, 'r'},
- {0, '\0'}
-};
-
/* channel_modes()
*
* inputs - pointer to channel
*mbuf++ = '+';
*pbuf = '\0';
- for (i = 0; chmode_flags[i].mode; ++i)
- if(chptr->mode.mode & chmode_flags[i].mode)
- *mbuf++ = chmode_flags[i].letter;
+ for (i = 0; i < 256; i++)
+ if(chptr->mode.mode & chmode_flags[i])
+ *mbuf++ = i;
if(chptr->mode.limit)
{
chptr->mode.join_time);
}
- if(*chptr->mode.forward && (ConfigChannel.use_forward || !IsClient(client_p)))
+ if(*chptr->mode.forward &&
+ (ConfigChannel.use_forward || !IsClient(client_p)))
{
*mbuf++ = 'f';
*mbuf = '\0';
- strlcpy(final, buf1, sizeof final);
- strlcat(final, buf2, sizeof final);
+ rb_strlcpy(final, buf1, sizeof final);
+ rb_strlcat(final, buf2, sizeof final);
return final;
}
cap = chcap_combos[j].cap_yes;
nocap = chcap_combos[j].cap_no;
- if(cap & CAP_TS6)
- mbl = preflen = rb_sprintf(modebuf, ":%s TMODE %ld %s ",
- use_id(source_p), (long) chptr->channelts,
- chptr->chname);
- else
- mbl = preflen = rb_sprintf(modebuf, ":%s MODE %s ",
- source_p->name, chptr->chname);
+ mbl = preflen = rb_sprintf(modebuf, ":%s TMODE %ld %s ",
+ use_id(source_p), (long) chptr->channelts,
+ chptr->chname);
/* loop the list of - modes we have */
for (i = 0; i < mode_count; i++)
|| ((nocap & mode_changes[i].nocaps) != mode_changes[i].nocaps))
continue;
- if((cap & CAP_TS6) && !EmptyString(mode_changes[i].id))
+ if(!EmptyString(mode_changes[i].id))
arg = mode_changes[i].id;
else
arg = mode_changes[i].arg;
sendto_server(client_p, chptr, cap, nocap, "%s %s", modebuf, parabuf);
}
}
+
+void
+resv_chan_forcepart(const char *name, const char *reason, int temp_time)
+{
+ rb_dlink_node *ptr;
+ rb_dlink_node *next_ptr;
+ struct Channel *chptr;
+ struct membership *msptr;
+ struct Client *target_p;
+
+ if(!ConfigChannel.resv_forcepart)
+ return;
+
+ /* for each user on our server in the channel list
+ * send them a PART, and notify opers.
+ */
+ chptr = find_channel(name);
+ if(chptr != NULL)
+ {
+ RB_DLINK_FOREACH_SAFE(ptr, next_ptr, chptr->locmembers.head)
+ {
+ msptr = ptr->data;
+ target_p = msptr->client_p;
+
+ if(IsExemptResv(target_p))
+ continue;
+
+ sendto_server(target_p, chptr, CAP_TS6, NOCAPS,
+ ":%s PART %s", target_p->id, chptr->chname);
+
+ sendto_channel_local(ALL_MEMBERS, chptr, ":%s!%s@%s PART %s :%s",
+ target_p->name, target_p->username,
+ target_p->host, chptr->chname, target_p->name);
+
+ remove_user_from_channel(msptr);
+
+ /* notify opers & user they were removed from the channel */
+ sendto_realops_snomask(SNO_GENERAL, L_ALL,
+ "Forced PART for %s!%s@%s from %s (%s)",
+ target_p->name, target_p->username,
+ target_p->host, name, reason);
+
+ if(temp_time > 0)
+ sendto_one_notice(target_p, ":*** Channel %s is temporarily unavailable on this server.",
+ name);
+ else
+ sendto_one_notice(target_p, ":*** Channel %s is no longer available on this server.",
+ name);
+ }
+ }
+}