]> jfr.im git - irc/rqf/shadowircd.git/blobdiff - src/channel.c
WHOIS 330 (services login name) does not need a remote whois.
[irc/rqf/shadowircd.git] / src / channel.c
index 4dc13cb6396dd1bbe4c6377195f0a2edc8ec969a..80bf5c5c2f5573d87e9055ace7f1f46a9396688d 100644 (file)
  */
 
 #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"
 
-extern rb_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,
@@ -77,10 +72,10 @@ static int h_can_join;
 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");
 }
@@ -92,25 +87,25 @@ struct Channel *
 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_bh_free(channel_heap, chptr);
 }
 
 struct Ban *
 allocate_ban(const char *banstr, const char *who)
 {
        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);
 
        return (bptr);
 }
@@ -118,9 +113,9 @@ allocate_ban(const char *banstr, const char *who)
 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_bh_free(ban_heap, bptr);
 }
 
 
@@ -209,7 +204,7 @@ add_user_to_channel(struct Channel *chptr, struct Client *client_p, int flags)
        if(client_p->user == NULL)
                return;
 
-       msptr = BlockHeapAlloc(member_heap);
+       msptr = rb_bh_alloc(member_heap);
 
        msptr->chptr = chptr;
        msptr->client_p = client_p;
@@ -246,12 +241,10 @@ remove_user_from_channel(struct membership *msptr)
        if(client_p->servptr == &me)
                rb_dlinkDelete(&msptr->locchannode, &chptr->locmembers);
 
-       chptr->users_last = CurrentTime;
-
        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;
 }
@@ -283,12 +276,10 @@ remove_user_from_channels(struct Client *client_p)
                if(client_p->servptr == &me)
                        rb_dlinkDelete(&msptr->locchannode, &chptr->locmembers);
 
-               chptr->users_last = CurrentTime;
-
                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;
@@ -788,7 +779,7 @@ can_join(struct Client *source_p, struct Channel *chptr, char *key)
        /* 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;
@@ -927,26 +918,21 @@ check_spambot_warning(struct Client *source_p, const char *name)
                        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);
@@ -957,7 +943,7 @@ check_spambot_warning(struct Client *source_p, const char *name)
                }
                else
                {
-                       if((CurrentTime -
+                       if((rb_current_time() -
                            (source_p->localClient->last_join_time)) < GlobalSetOptions.spam_time)
                        {
                                /* oh, its a possible spambot */
@@ -965,9 +951,9 @@ check_spambot_warning(struct Client *source_p, const char *name)
                        }
                }
                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();
        }
 }
 
@@ -993,7 +979,7 @@ check_splitmode(void *unused)
                                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 */
@@ -1004,7 +990,8 @@ check_splitmode(void *unused)
                        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;
                }
        }
 }
@@ -1024,7 +1011,7 @@ allocate_topic(struct Channel *chptr)
        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
@@ -1054,7 +1041,7 @@ free_topic(struct Channel *chptr)
         * 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;
 }
@@ -1072,8 +1059,8 @@ set_channel_topic(struct Channel *chptr, const char *topic, const char *topic_in
        {
                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
@@ -1084,25 +1071,6 @@ set_channel_topic(struct Channel *chptr, const char *topic, const char *topic_in
        }
 }
 
-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
@@ -1125,9 +1093,9 @@ channel_modes(struct Channel *chptr, struct Client *client_p)
        *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)
        {
@@ -1164,8 +1132,8 @@ channel_modes(struct Channel *chptr, struct Client *client_p)
 
        *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;
 }
 
@@ -1308,13 +1276,9 @@ send_cap_mode_changes(struct Client *client_p, struct Client *source_p,
                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++)
@@ -1328,7 +1292,7 @@ send_cap_mode_changes(struct Client *client_p, struct Client *source_p,
                           || ((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;