]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/xline.cpp
Added +O mode support through m_operchans.so
[user/henk/code/inspircd.git] / src / xline.cpp
index 6ca005bad2714a05cc7cbcdd14ba86850431ce3b..9e756abe58cbcfa53d9f985033562b98323ab5ba 100644 (file)
@@ -205,6 +205,7 @@ void read_xline_defaults()
 
 void add_gline(long duration, char* source, char* reason, char* hostmask)
 {
+       del_gline(hostmask);
        GLine item;
        item.duration = duration;
        strncpy(item.hostmask,hostmask,MAXBUF);
@@ -219,12 +220,14 @@ void add_gline(long duration, char* source, char* reason, char* hostmask)
 
 void add_qline(long duration, char* source, char* reason, char* nickname)
 {
+       del_qline(nickname);
        QLine item;
        item.duration = duration;
        strncpy(item.nick,nickname,MAXBUF);
        strncpy(item.reason,reason,MAXBUF);
        strncpy(item.source,source,MAXBUF);
        item.n_matches = 0;
+       item.is_global = false;
        item.set_time = time(NULL);
        qlines.push_back(item);
 }
@@ -233,12 +236,14 @@ void add_qline(long duration, char* source, char* reason, char* nickname)
 
 void add_zline(long duration, char* source, char* reason, char* ipaddr)
 {
+       del_zline(ipaddr);
        ZLine item;
        item.duration = duration;
        strncpy(item.ipaddr,ipaddr,MAXBUF);
        strncpy(item.reason,reason,MAXBUF);
        strncpy(item.source,source,MAXBUF);
        item.n_matches = 0;
+       item.is_global = false;
        item.set_time = time(NULL);
        zlines.push_back(item);
 }
@@ -247,6 +252,7 @@ void add_zline(long duration, char* source, char* reason, char* ipaddr)
 
 void add_kline(long duration, char* source, char* reason, char* hostmask)
 {
+       del_kline(hostmask);
        KLine item;
        item.duration = duration;
        strncpy(item.hostmask,hostmask,MAXBUF);
@@ -287,6 +293,62 @@ bool del_qline(char* nickname)
        return false;
 }
 
+bool qline_make_global(char* nickname)
+{
+       for (std::vector<QLine>::iterator i = qlines.begin(); i != qlines.end(); i++)
+       {
+               if (!strcasecmp(nickname,i->nick))
+               {
+                       i->is_global = true;
+                       return true;
+               }
+       }
+       return false;
+}
+
+bool zline_make_global(char* ipaddr)
+{
+       for (std::vector<ZLine>::iterator i = zlines.begin(); i != zlines.end(); i++)
+       {
+               if (!strcasecmp(ipaddr,i->ipaddr))
+               {
+                       i->is_global = true;
+                       return true;
+               }
+       }
+       return false;
+}
+
+void sync_xlines(serverrec* serv, char* tcp_host)
+{
+       char data[MAXBUF];
+       
+       // for zlines and qlines, we should first check if theyre global...
+       for (std::vector<ZLine>::iterator i = zlines.begin(); i != zlines.end(); i++)
+       {
+               if (i->is_global)
+               {
+                       snprintf(data,MAXBUF,"} %s %s %ld %ld :%s",i->ipaddr,i->source,i->set_time,i->duration,i->reason);
+                       serv->SendPacket(data,tcp_host);
+               }
+       }
+       for (std::vector<QLine>::iterator i = qlines.begin(); i != qlines.end(); i++)
+       {
+               if (i->is_global)
+               {
+                       snprintf(data,MAXBUF,"{ %s %s %ld %ld :%s",i->nick,i->source,i->set_time,i->duration,i->reason);
+                       serv->SendPacket(data,tcp_host);
+               }
+       }
+       // glines are always global, so no need to check
+       for (std::vector<GLine>::iterator i = glines.begin(); i != glines.end(); i++)
+       {
+               snprintf(data,MAXBUF,"# %s %s %ld %ld :%s",i->hostmask,i->source,i->set_time,i->duration,i->reason);
+               serv->SendPacket(data,tcp_host);
+       }
+}
+
+
 // deletes a z:line, returns true if the line existed and was removed
 
 bool del_zline(char* ipaddr)
@@ -345,6 +407,45 @@ char* matches_gline(const char* host)
        return NULL;
 }
 
+void gline_set_creation_time(char* host, time_t create_time)
+{
+       for (std::vector<GLine>::iterator i = glines.begin(); i != glines.end(); i++)
+       {
+               if (!strcasecmp(host,i->hostmask))
+               {
+                       i->set_time = create_time;
+                       return;
+               }
+       }
+       return ;        
+}
+
+void qline_set_creation_time(char* nick, time_t create_time)
+{
+       for (std::vector<QLine>::iterator i = qlines.begin(); i != qlines.end(); i++)
+       {
+               if (!strcasecmp(nick,i->nick))
+               {
+                       i->set_time = create_time;
+                       return;
+               }
+       }
+       return ;        
+}
+
+void zline_set_creation_time(char* ip, time_t create_time)
+{
+       for (std::vector<ZLine>::iterator i = zlines.begin(); i != zlines.end(); i++)
+       {
+               if (!strcasecmp(ip,i->ipaddr))
+               {
+                       i->set_time = create_time;
+                       return;
+               }
+       }
+       return ;        
+}
+
 // returns a pointer to the reason if an ip address matches a zline, NULL if it didnt match
 
 char* matches_zline(const char* ipaddr)
@@ -440,6 +541,9 @@ void apply_lines()
        char reason[MAXBUF];
        char host[MAXBUF];
        
+       if ((!glines.size()) && (!klines.size()) && (!zlines.size()) && (!qlines.size()))
+               return;
+       
        while (go_again)
        {
                go_again = false;
@@ -448,68 +552,90 @@ void apply_lines()
                        if (!strcasecmp(u->second->server,ServerName))
                        {
                                snprintf(host,MAXBUF,"%s@%s",u->second->ident,u->second->host);
-                               char* check = matches_gline(host);
-                               if (check)
+                               if (glines.size())
                                {
-                                       WriteOpers("*** User %s matches G-Line: %s",u->second->nick,check);
-                                       snprintf(reason,MAXBUF,"G-Lined: %s",check);
-                                       kill_link(u->second,reason);
-                                       go_again = true;
-                                       break;
+                                       char* check = matches_gline(host);
+                                       if (check)
+                                       {
+                                               WriteOpers("*** User %s matches G-Line: %s",u->second->nick,check);
+                                               snprintf(reason,MAXBUF,"G-Lined: %s",check);
+                                               kill_link(u->second,reason);
+                                               go_again = true;
+                                               break;
+                                       }
                                }
-                       }
-               }
-
-               for (user_hash::const_iterator u = clientlist.begin(); u != clientlist.end(); u++)
-               {
-                       if (!strcasecmp(u->second->server,ServerName))
-                       {
-                               snprintf(host,MAXBUF,"%s@%s",u->second->ident,u->second->host);
-                               char* check = matches_kline(host);
-                               if (check)
+                               if (klines.size())
                                {
-                                       WriteOpers("*** User %s matches K-Line: %s",u->second->nick,check);
-                                       snprintf(reason,MAXBUF,"K-Lined: %s",check);
-                                       kill_link(u->second,reason);
-                                       go_again = true;
-                                       break;
+                                       char* check = matches_kline(host);
+                                       if (check)
+                                       {
+                                               WriteOpers("*** User %s matches K-Line: %s",u->second->nick,check);
+                                               snprintf(reason,MAXBUF,"K-Lined: %s",check);
+                                               kill_link(u->second,reason);
+                                               go_again = true;
+                                               break;
+                                       }
                                }
-                       }
-               }
-
-               for (user_hash::const_iterator u = clientlist.begin(); u != clientlist.end(); u++)
-               {
-                       if (!strcasecmp(u->second->server,ServerName))
-                       {
-                               char* check = matches_qline(u->second->nick);
-                               if (check)
+                               if (qlines.size())
                                {
-                                       snprintf(reason,MAXBUF,"Matched Q-Lined nick: %s",check);
-                                       WriteOpers("*** Q-Lined nickname %s from %s: %s",u->second->nick,u->second->host,check);
-                                       WriteServ(u->second->fd,"432 %s %s :Invalid nickname: %s",u->second->nick,u->second->nick,check);
-                                       kill_link(u->second,reason);
-                                       go_again = true;
-                                       break;
+                                       char* check = matches_qline(u->second->nick);
+                                       if (check)
+                                       {
+                                               snprintf(reason,MAXBUF,"Matched Q-Lined nick: %s",check);
+                                               WriteOpers("*** Q-Lined nickname %s from %s: %s",u->second->nick,u->second->host,check);
+                                               kill_link(u->second,reason);
+                                               go_again = true;
+                                               break;
+                                       }
                                }
-                       }
-               }
-
-               for (user_hash::const_iterator u = clientlist.begin(); u != clientlist.end(); u++)
-               {
-                       if (!strcasecmp(u->second->server,ServerName))
-                       {
-                               char* check = matches_zline(u->second->ip);
-                               if (check)
+                               if (zlines.size())
                                {
-                                       WriteOpers("*** User %s matches Z-Line: %s",u->second->nick,u->second->host,check);
-                                       WriteServ(u->second->fd,"432 %s %s :Invalid nickname: %s",u->second->nick,u->second->nick,check);
-                                       go_again = true;
-                                       break;
+                                       char* check = matches_zline(u->second->ip);
+                                       if (check)
+                                       {
+                                               snprintf(reason,MAXBUF,"Z-Lined: %s",check);
+                                               WriteOpers("*** User %s matches Z-Line: %s",u->second->nick,u->second->host,check);
+                                               kill_link(u->second,reason);
+                                               go_again = true;
+                                               break;
+                                       }
                                }
                        }
                }
+       }
+}
+
+void stats_k(userrec* user)
+{
+       for (std::vector<KLine>::iterator i = klines.begin(); i != klines.end(); i++)
+       {
+               WriteServ(user->fd,"216 %s :%s %d %d %s %s",user->nick,i->hostmask,i->set_time,i->duration,i->source,i->reason);
+       }
+}
 
+void stats_g(userrec* user)
+{
+       for (std::vector<GLine>::iterator i = glines.begin(); i != glines.end(); i++)
+       {
+               WriteServ(user->fd,"223 %s :%s %d %d %s %s",user->nick,i->hostmask,i->set_time,i->duration,i->source,i->reason);
        }
 }
 
+void stats_q(userrec* user)
+{
+       for (std::vector<QLine>::iterator i = qlines.begin(); i != qlines.end(); i++)
+       {
+               WriteServ(user->fd,"217 %s :%s %d %d %s %s",user->nick,i->nick,i->set_time,i->duration,i->source,i->reason);
+       }
+}
+
+void stats_z(userrec* user)
+{
+       for (std::vector<ZLine>::iterator i = zlines.begin(); i != zlines.end(); i++)
+       {
+               WriteServ(user->fd,"223 %s :%s %d %d %s %s",user->nick,i->ipaddr,i->set_time,i->duration,i->source,i->reason);
+       }
+}
+
+