botserv.cpp

Go to the documentation of this file.
00001 /* BotServ functions
00002  *
00003  * (C) 2003-2012 Anope Team
00004  * Contact us at team@anope.org
00005  *
00006  * Please read COPYING and README for further details.
00007  *
00008  * Based on the original code of Epona by Lara.
00009  * Based on the original code of Services by Andy Church.
00010  */
00011 
00012 /*************************************************************************/
00013 
00014 #include "services.h"
00015 #include "anope.h"
00016 #include "protocol.h"
00017 #include "bots.h"
00018 #include "regchannel.h"
00019 #include "language.h"
00020 #include "extern.h"
00021 #include "access.h"
00022 #include "channels.h"
00023 #include "account.h"
00024 
00025 BotInfo* findbot(const Anope::string &nick)
00026 {
00027         BotInfo *bi = NULL;
00028         if (isdigit(nick[0]) && ircdproto->RequiresID)
00029         {
00030                 botinfo_map::iterator it = BotListByUID->find(nick);
00031                 if (it != BotListByUID->end())
00032                         bi = it->second;
00033         }
00034         else
00035         {
00036                 botinfo_map::iterator it = BotListByNick->find(nick);
00037                 if (it != BotListByNick->end())
00038                         bi = it->second;
00039         }
00040 
00041         if (bi)
00042                 bi->QueueUpdate();
00043         return bi;
00044 }
00045 
00046 
00047 /*************************************************************************/
00048 
00049 /* Makes a simple ban and kicks the target
00050  * @param requester The user requesting the kickban
00051  * @param ci The channel
00052  * @param u The user being kicked
00053  * @param reason The reason
00054  */
00055 void bot_raw_ban(User *requester, ChannelInfo *ci, User *u, const Anope::string &reason)
00056 {
00057         if (!u || !ci)
00058                 return;
00059 
00060         if (ModeManager::FindUserModeByName(UMODE_PROTECTED) && u->IsProtected() && requester != u)
00061         {
00062                 ircdproto->SendPrivmsg(ci->bi, ci->name, "%s", translate(requester, ACCESS_DENIED));
00063                 return;
00064         }
00065 
00066         AccessGroup u_access = ci->AccessFor(u), req_access = ci->AccessFor(requester);
00067         if (ci->HasFlag(CI_PEACE) && u != requester && u_access >= req_access)
00068                 return;
00069 
00070         if (matches_list(ci->c, u, CMODE_EXCEPT))
00071         {
00072                 ircdproto->SendPrivmsg(ci->bi, ci->name, "%s", translate(requester, _("User matches channel except.")));
00073                 return;
00074         }
00075 
00076         Anope::string mask;
00077         get_idealban(ci, u, mask);
00078 
00079         ci->c->SetMode(NULL, CMODE_BAN, mask);
00080 
00081         /* Check if we need to do a signkick or not -GD */
00082         if (ci->HasFlag(CI_SIGNKICK) || (ci->HasFlag(CI_SIGNKICK_LEVEL) && !req_access.HasPriv("SIGNKICK")))
00083                 ci->c->Kick(ci->bi, u, "%s (%s)", !reason.empty() ? reason.c_str() : ci->bi->nick.c_str(), requester->nick.c_str());
00084         else
00085                 ci->c->Kick(ci->bi, u, "%s", !reason.empty() ? reason.c_str() : ci->bi->nick.c_str());
00086 }
00087 
00088 /*************************************************************************/
00089 
00090 /* Makes a kick with a "dynamic" reason ;)
00091  * @param requester The user requesting the kick
00092  * @param ci The channel
00093  * @param u The user being kicked
00094  * @param reason The reason for the kick
00095  */
00096 void bot_raw_kick(User *requester, ChannelInfo *ci, User *u, const Anope::string &reason)
00097 {
00098         if (!u || !ci || !ci->c || !ci->c->FindUser(u))
00099                 return;
00100 
00101         if (ModeManager::FindUserModeByName(UMODE_PROTECTED) && u->IsProtected() && requester != u)
00102         {
00103                 ircdproto->SendPrivmsg(ci->bi, ci->name, "%s", translate(requester, ACCESS_DENIED));
00104                 return;
00105         }
00106 
00107         AccessGroup u_access = ci->AccessFor(u), req_access = ci->AccessFor(requester);
00108         if (ci->HasFlag(CI_PEACE) && requester != u && u_access >= req_access)
00109                 return;
00110 
00111         if (ci->HasFlag(CI_SIGNKICK) || (ci->HasFlag(CI_SIGNKICK_LEVEL) && !req_access.HasPriv("SIGNKICK")))
00112                 ci->c->Kick(ci->bi, u, "%s (%s)", !reason.empty() ? reason.c_str() : ci->bi->nick.c_str(), requester->nick.c_str());
00113         else
00114                 ci->c->Kick(ci->bi, u, "%s", !reason.empty() ? reason.c_str() : ci->bi->nick.c_str());
00115 }
00116