diff options
-rw-r--r-- | include/xline.h | 15 | ||||
-rw-r--r-- | src/cmd_nick.cpp | 6 | ||||
-rw-r--r-- | src/users.cpp | 18 | ||||
-rw-r--r-- | src/xline.cpp | 60 |
4 files changed, 52 insertions, 47 deletions
diff --git a/include/xline.h b/include/xline.h index 8c18ab37e..daefe8a1e 100644 --- a/include/xline.h +++ b/include/xline.h @@ -42,6 +42,7 @@ class XLine : public classbase { source = strdup(src); reason = strdup(re); + expiry = set_time + duration; } virtual ~XLine() @@ -64,6 +65,10 @@ class XLine : public classbase /** Reason for the ban */ char* reason; + + /** Expiry time + */ + time_t expiry; }; /** KLine class @@ -342,31 +347,31 @@ class XLineManager * @return nick The nick to check against * @return The reason for the line if there is a match, or NULL if there is no match */ - char* matches_qline(const char* nick); + QLine* matches_qline(const char* nick); /** Check if a hostname matches a GLine * @param user The user to check against * @return The reason for the line if there is a match, or NULL if there is no match */ - char* matches_gline(userrec* user); + GLine* matches_gline(userrec* user); /** Check if a IP matches a ZLine * @param ipaddr The IP to check against * @return The reason for the line if there is a match, or NULL if there is no match */ - char* matches_zline(const char* ipaddr); + ZLine* matches_zline(const char* ipaddr); /** Check if a hostname matches a KLine * @param user The user to check against * @return The reason for the line if there is a match, or NULL if there is no match */ - char* matches_kline(userrec* user); + KLine* matches_kline(userrec* user); /** Check if a hostname matches a ELine * @param user The user to check against * @return The reason for the line if there is a match, or NULL if there is no match */ - char* matches_exception(userrec* user); + ELine* matches_exception(userrec* user); /** Expire any pending non-permenant lines */ diff --git a/src/cmd_nick.cpp b/src/cmd_nick.cpp index 44d29cbbc..911c80bd8 100644 --- a/src/cmd_nick.cpp +++ b/src/cmd_nick.cpp @@ -67,11 +67,11 @@ CmdResult cmd_nick::Handle (const char** parameters, int pcnt, userrec *user) } else { - char* mq = ServerInstance->XLines->matches_qline(parameters[0]); + QLine* mq = ServerInstance->XLines->matches_qline(parameters[0]); if (mq) { - ServerInstance->SNO->WriteToSnoMask('x', "Q-Lined nickname %s from %s!%s@%s: %s", parameters[0], user->nick, user->ident, user->host, mq); - user->WriteServ("432 %s %s :Invalid nickname: %s",user->nick,parameters[0], mq); + ServerInstance->SNO->WriteToSnoMask('x', "Q-Lined nickname %s from %s!%s@%s: %s", parameters[0], user->nick, user->ident, user->host, mq->reason); + user->WriteServ("432 %s %s :Invalid nickname: %s",user->nick,parameters[0], mq->reason); return CMD_FAILURE; } if ((ServerInstance->FindNick(parameters[0])) && (ServerInstance->FindNick(parameters[0]) != user) && (ServerInstance->IsNick(parameters[0]))) diff --git a/src/users.cpp b/src/users.cpp index 8c6711d64..46d841de5 100644 --- a/src/users.cpp +++ b/src/users.cpp @@ -973,14 +973,14 @@ void userrec::AddClient(InspIRCd* Instance, int socket, int port, bool iscached, userrec::QuitUser(Instance, _new,"Server is full"); return; } - char* e = Instance->XLines->matches_exception(_new); + ELine* e = Instance->XLines->matches_exception(_new); if (!e) { - char* r = Instance->XLines->matches_zline(ipaddr); + ZLine* r = Instance->XLines->matches_zline(ipaddr); if (r) { char reason[MAXBUF]; - snprintf(reason,MAXBUF,"Z-Lined: %s",r); + snprintf(reason,MAXBUF,"Z-Lined: %s",r->reason); userrec::QuitUser(Instance, _new,reason); return; } @@ -1068,26 +1068,26 @@ void userrec::FullConnect(CullList* Goners) return; } - char* e = ServerInstance->XLines->matches_exception(this); + ELine* e = ServerInstance->XLines->matches_exception(this); if (!e) { - char* r = ServerInstance->XLines->matches_gline(this); + GLine* r = ServerInstance->XLines->matches_gline(this); if (r) { char reason[MAXBUF]; - snprintf(reason,MAXBUF,"G-Lined: %s",r); + snprintf(reason,MAXBUF,"G-Lined: %s",r->reason); Goners->AddItem(this, reason); return; } - r = ServerInstance->XLines->matches_kline(this); + KLine* n = ServerInstance->XLines->matches_kline(this); - if (r) + if (n) { char reason[MAXBUF]; - snprintf(reason,MAXBUF,"K-Lined: %s",r); + snprintf(reason,MAXBUF,"K-Lined: %s",n->reason); Goners->AddItem(this, reason); return; } diff --git a/src/xline.cpp b/src/xline.cpp index 7bb5ec1fb..24a1fccd0 100644 --- a/src/xline.cpp +++ b/src/xline.cpp @@ -356,22 +356,22 @@ bool XLineManager::del_kline(const char* hostmask) // returns a pointer to the reason if a nickname matches a qline, NULL if it didnt match -char* XLineManager::matches_qline(const char* nick) +QLine* XLineManager::matches_qline(const char* nick) { if ((qlines.empty()) && (pqlines.empty())) return NULL; for (std::vector<QLine*>::iterator i = qlines.begin(); i != qlines.end(); i++) if (match(nick,(*i)->nick)) - return (*i)->reason; + return (*i); for (std::vector<QLine*>::iterator i = pqlines.begin(); i != pqlines.end(); i++) if (match(nick,(*i)->nick)) - return (*i)->reason; + return (*i); return NULL; } // returns a pointer to the reason if a host matches a gline, NULL if it didnt match -char* XLineManager::matches_gline(userrec* user) +GLine* XLineManager::matches_gline(userrec* user) { if ((glines.empty()) && (pglines.empty())) return NULL; @@ -381,7 +381,7 @@ char* XLineManager::matches_gline(userrec* user) { if ((match(user->host,(*i)->hostmask, true)) || (match(user->GetIPString(),(*i)->hostmask, true))) { - return (*i)->reason; + return (*i); } } } @@ -391,14 +391,14 @@ char* XLineManager::matches_gline(userrec* user) { if ((match(user->host,(*i)->hostmask, true)) || (match(user->GetIPString(),(*i)->hostmask, true))) { - return (*i)->reason; + return (*i); } } } return NULL; } -char* XLineManager::matches_exception(userrec* user) +ELine* XLineManager::matches_exception(userrec* user) { if ((elines.empty()) && (pelines.empty())) return NULL; @@ -410,7 +410,7 @@ char* XLineManager::matches_exception(userrec* user) { if ((match(user->host,(*i)->hostmask, true)) || (match(user->GetIPString(),(*i)->hostmask, true))) { - return (*i)->reason; + return (*i); } } } @@ -420,7 +420,7 @@ char* XLineManager::matches_exception(userrec* user) { if ((match(user->host,(*i)->hostmask, true)) || (match(user->GetIPString(),(*i)->hostmask, true))) { - return (*i)->reason; + return (*i); } } } @@ -514,22 +514,22 @@ void XLineManager::zline_set_creation_time(const char* ip, time_t create_time) // returns a pointer to the reason if an ip address matches a zline, NULL if it didnt match -char* XLineManager::matches_zline(const char* ipaddr) +ZLine* XLineManager::matches_zline(const char* ipaddr) { if ((zlines.empty()) && (pzlines.empty())) return NULL; for (std::vector<ZLine*>::iterator i = zlines.begin(); i != zlines.end(); i++) if (match(ipaddr,(*i)->ipaddr, true)) - return (*i)->reason; + return (*i); for (std::vector<ZLine*>::iterator i = pzlines.begin(); i != pzlines.end(); i++) if (match(ipaddr,(*i)->ipaddr, true)) - return (*i)->reason; + return (*i); return NULL; } // returns a pointer to the reason if a host matches a kline, NULL if it didnt match -char* XLineManager::matches_kline(userrec* user) +KLine* XLineManager::matches_kline(userrec* user) { if ((klines.empty()) && (pklines.empty())) return NULL; @@ -539,7 +539,7 @@ char* XLineManager::matches_kline(userrec* user) { if ((match(user->host,(*i)->hostmask, true)) || (match(user->GetIPString(),(*i)->hostmask, true))) { - return (*i)->reason; + return (*i); } } } @@ -549,7 +549,7 @@ char* XLineManager::matches_kline(userrec* user) { if ((match(user->host,(*i)->hostmask, true)) || (match(user->GetIPString(),(*i)->hostmask, true))) { - return (*i)->reason; + return (*i); } } } @@ -558,27 +558,27 @@ char* XLineManager::matches_kline(userrec* user) bool XLineManager::GSortComparison ( const GLine* one, const GLine* two ) { - return (one->duration + one->set_time) < (two->duration + two->set_time); + return (one->expiry) < (two->expiry); } bool XLineManager::ESortComparison ( const ELine* one, const ELine* two ) { - return (one->duration + one->set_time) < (two->duration + two->set_time); + return (one->expiry) < (two->expiry); } bool XLineManager::ZSortComparison ( const ZLine* one, const ZLine* two ) { - return (one->duration + one->set_time) < (two->duration + two->set_time); + return (one->expiry) < (two->expiry); } bool XLineManager::KSortComparison ( const KLine* one, const KLine* two ) { - return (one->duration + one->set_time) < (two->duration + two->set_time); + return (one->expiry) < (two->expiry); } bool XLineManager::QSortComparison ( const QLine* one, const QLine* two ) { - return (one->duration + one->set_time) < (two->duration + two->set_time); + return (one->expiry) < (two->expiry); } // removes lines that have expired @@ -592,35 +592,35 @@ void XLineManager::expire_lines() * none left at the head of the queue that are after the current time. */ - while ((glines.size()) && (current > ((*glines.begin())->duration + (*glines.begin())->set_time))) + while ((glines.size()) && (current > (*glines.begin())->expiry)) { std::vector<GLine*>::iterator i = glines.begin(); ServerInstance->SNO->WriteToSnoMask('x',"Expiring timed G-Line %s (set by %s %d seconds ago)",(*i)->hostmask,(*i)->source,(*i)->duration); glines.erase(i); } - while ((elines.size()) && (current > ((*elines.begin())->duration + (*elines.begin())->set_time))) + while ((elines.size()) && (current > (*elines.begin())->expiry)) { std::vector<ELine*>::iterator i = elines.begin(); ServerInstance->SNO->WriteToSnoMask('x',"Expiring timed E-Line %s (set by %s %d seconds ago)",(*i)->hostmask,(*i)->source,(*i)->duration); elines.erase(i); } - while ((zlines.size()) && (current > ((*zlines.begin())->duration + (*zlines.begin())->set_time))) + while ((zlines.size()) && (current > (*zlines.begin())->expiry)) { std::vector<ZLine*>::iterator i = zlines.begin(); ServerInstance->SNO->WriteToSnoMask('x',"Expiring timed Z-Line %s (set by %s %d seconds ago)",(*i)->ipaddr,(*i)->source,(*i)->duration); zlines.erase(i); } - while ((klines.size()) && (current > ((*klines.begin())->duration + (*klines.begin())->set_time))) + while ((klines.size()) && (current > (*klines.begin())->expiry)) { std::vector<KLine*>::iterator i = klines.begin(); ServerInstance->SNO->WriteToSnoMask('x',"Expiring timed K-Line %s (set by %s %d seconds ago)",(*i)->hostmask,(*i)->source,(*i)->duration); klines.erase(i); } - while ((qlines.size()) && (current > ((*qlines.begin())->duration + (*qlines.begin())->set_time))) + while ((qlines.size()) && (current > (*qlines.begin())->expiry)) { std::vector<QLine*>::iterator i = qlines.begin(); ServerInstance->SNO->WriteToSnoMask('x',"Expiring timed Q-Line %s (set by %s %d seconds ago)",(*i)->nick,(*i)->source,(*i)->duration); @@ -640,7 +640,7 @@ void XLineManager::apply_lines(const int What) return; CullList* Goners = new CullList(ServerInstance); - char* check = NULL; + XLine* check = NULL; for (std::vector<userrec*>::const_iterator u2 = ServerInstance->local_users.begin(); u2 != ServerInstance->local_users.end(); u2++) { userrec* u = (userrec*)(*u2); @@ -655,7 +655,7 @@ void XLineManager::apply_lines(const int What) { if ((check = matches_gline(u))) { - snprintf(reason,MAXBUF,"G-Lined: %s",check); + snprintf(reason,MAXBUF,"G-Lined: %s",check->reason); Goners->AddItem(u,reason); } } @@ -663,7 +663,7 @@ void XLineManager::apply_lines(const int What) { if ((check = matches_kline(u))) { - snprintf(reason,MAXBUF,"K-Lined: %s",check); + snprintf(reason,MAXBUF,"K-Lined: %s",check->reason); Goners->AddItem(u,reason); } } @@ -671,7 +671,7 @@ void XLineManager::apply_lines(const int What) { if ((check = matches_qline(u->nick))) { - snprintf(reason,MAXBUF,"Q-Lined: %s",check); + snprintf(reason,MAXBUF,"Q-Lined: %s",check->reason); Goners->AddItem(u,reason); } } @@ -679,7 +679,7 @@ void XLineManager::apply_lines(const int What) { if ((check = matches_zline(u->GetIPString()))) { - snprintf(reason,MAXBUF,"Z-Lined: %s",check); + snprintf(reason,MAXBUF,"Z-Lined: %s",check->reason); Goners->AddItem(u,reason); } } |