]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/xline.cpp
Added m_alias module which provides command aliases.
[user/henk/code/inspircd.git] / src / xline.cpp
index 152ca6e822b2f649e3466c0621e438d4581d8b5c..9e756abe58cbcfa53d9f985033562b98323ab5ba 100644 (file)
@@ -227,6 +227,7 @@ void add_qline(long duration, char* source, char* reason, char* nickname)
        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);
 }
@@ -242,6 +243,7 @@ void add_zline(long duration, char* source, char* reason, char* ipaddr)
        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);
 }
@@ -291,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)
@@ -483,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;
@@ -491,67 +552,56 @@ 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;
+                                       }
                                }
                        }
                }
-
        }
 }