Anope IRC Services

Please login or register.

Login with username, password and session length
Advanced search  

News:

Pages: [1]   Go Down

Author Topic: bs_fantsy-vhost  (Read 19 times)

0 Members and 1 Guest are viewing this topic.

sys

  • Anope User
  • Offline Offline
  • Posts: 1
bs_fantsy-vhost
« on: January 27, 2023, 07:41:14 PM »

Hello, guys! This is module for BotServ fantasy command in channel #vhost.
Is it posiable someone make me any changes. I need before host to be set to be checked is it exist? If is exist will not gonna set it, if is not exist will be set to the user.

-----ANOPE-2.0.12-----

/* BotServ vhost function
 *
 * Requires Fantasy setting to be on to work using in channel
 * command !vhost <host>.
 *
 * This sets a TEMPORARY vhost.  If the user wants a pernanent
 * vhost they should use the normal vhost request system in
 * hostserv.
 *
 *
 *
 * You need to set
 *    /chanserv levels #channel FANTASIA 0
 * to allow anyone in the active channel to issue the command.
 *
 *
 * ***** Configuration:  *****
 *
 * add the folloing to your botserv config file:

module
{
        name = "bs_fantasy_vhost";
        vHostRestricted = "admin ircop suck fuck shit damn test";
        vHostChannel = "#help";
}
command { service = "BotServ"; name = "VHOST"; command = "botserv/vhost"; }
fantasy { name = "VHOST"; command = "botserv/vhost"; }
 
 *
 * vHostChannel = "#help"   
 *   ^^^--- only allow it to work in this channel
 *
 * vHostRestricted = "space speperated list of prohibited words"
 *   ^^^--- Prohibit these words from appearing.  Note, these will match
 *          within other words as well.
 *
 * if vHostRestricted is empty, by defalt, only "admin" and "ircop" are protected.
 * if vHostRestricted beginxgs with "none" then nothing is protected.
 *
 * *****  Example:  *****
 *
 * vHostRestricted = "admin ircop damn turn jerk suck";
 *
 * This would prevent any vhost mask that contained admin, ircop, damn, turn, jerk, or suck.
 * Examples:
 *  !vhost I.am.an.admin
 *  !vhost Ircops.are.idiots
 *  !vhost damn.the.torpedos
 *  !vhost turn.up.the.volume
 *  !vhost you.are.akk.jerks
 *  !vhost you.are.suckers
 *
 * These would be prevented from being set by the example line above.
 *
 */

#include "module.h"

class CommandBSVhost : public Command
{

   std::vector<Anope::string> defaults;
   int vHostRestrictedNr;

 private:

        bool isvalidchar(char c)
        {               
                if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || (c >= '0' && c <= '9') || c == '.' || c == '-')
                        return true;
                return false;
        }     

 public:
   CommandBSVhost(Module *creator) : Command(creator, "botserv/vhost", 1, 2)
   {
      this->SetDesc(_("Enable a temporary vhost."));
      this->SetSyntax(_("\037host name\037"));
   }

   void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
   {
      const Anope::string &vhost = params[0];
      const Anope::string &vhost2 = params.size() > 1 ? params[1] : "";
      const Anope::string &onlychan = Config->GetModule("bs_fantasy_vhost")->Get<const Anope::string>("vHostChannel","#help");
      User *u = source.GetUser();
      const NickAlias *na = NickAlias::Find(u->nick);
      const Anope::string &nid = u->GetIdent();
      Anope::string target = "";
      Anope::string chan = "";
      Anope::string host = "";
      Anope::string user = "";
      spacesepstream(Config->GetModule("bs_fantasy_vhost")->Get<const Anope::string>("vHostRestricted","")).GetTokens(defaults);
      if (defaults.empty())
      {
         defaults.push_back("ircop");
         defaults.push_back("admin");
      }
      else if (defaults[0].equals_ci("none"))
         defaults.clear();
      vHostRestrictedNr = defaults.size();
      if (vhost[0] == '#')
      {
         chan = vhost.c_str();
         target = vhost2.c_str();
      }
      else
      {
         target = vhost.c_str();
      }
      if (!chan.empty())
      {
         if(chan.equals_ci(onlychan.c_str()) != 1)
         {
            source.Reply(_("You can only issue this command in %s"),onlychan.c_str());
            return;
         }
      }
       size_t a = target.find('@');
      if (a == Anope::string::npos)
         host = target.c_str();
      else
      {
         user = target.substr(0, a);
         host = target.substr(a + 1);
      }
      if (host.empty())
      {
         this->OnSyntaxError(source, "");
         return;
      }
      if (!user.empty())
      {
         if (user.length() > Config->GetBlock("networkinfo")->Get<unsigned>("userlen"))
         {
            source.Reply(HOST_SET_IDENTTOOLONG, Config->GetBlock("networkinfo")->Get<unsigned>("userlen"));
            return;
         }
         else if (!IRCD->CanSetVIdent)
         {
            source.Reply(HOST_NO_VIDENT);
            return;
         }
         for (Anope::string::iterator s = user.begin(), s_end = user.end(); s != s_end; ++s)
            if (!isvalidchar(*s))
            {
               source.Reply(HOST_SET_IDENT_ERROR);
               return;
            }
      }
      if (host.length() > Config->GetBlock("networkinfo")->Get<unsigned>("hostlen"))
      {
         source.Reply(HOST_SET_TOOLONG, Config->GetBlock("networkinfo")->Get<unsigned>("hostlen"));
         return;
      }

      if (!IRCD->IsHostValid(host))
      {
         source.Reply(HOST_SET_ERROR);
         return;
      }
      int idx;
      for (idx = 0; idx < vHostRestrictedNr; idx++)
      {
         if (target.find_ci(defaults[idx]) != Anope::string::npos)
         {
            source.Reply(_("Vhost invalid.  Containes prohibited word %s."),defaults[idx].c_str());
            return;
         }
      }

      if(na && u->Account() == na->nc && !na->HasVhost() && (u->chost.equals_ci(u->GetDisplayedHost()) || u->host.equals_ci(u->GetDisplayedHost()) ) )
      {
         Log(LOG_COMMAND,source,this) << "to set Vhost to " << target.c_str();
         IRCD->SendVhost(u, nid.c_str(), target.c_str());
         u->SetDisplayedHost(target.c_str());
         source.Reply(_("Vhost %s set."),target.c_str());
      }
      else
      {
         source.Reply(_("You already have a vhost.  You cannot set a temporary one."));
         return;
      }
   }

   bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
   {
      this->SendSyntax(source);
      source.Reply(" ");
      source.Reply(_("Allows you to set a temproary vhost."));
      return true;
   }

   
};

class BSVhost : public Module
{
   CommandBSVhost commandbsvhost;

 public:
   BSVhost(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR),
      commandbsvhost(this)
   {
      if (!IRCD || !IRCD->CanSetVHost)
         throw ModuleException("Your IRCd does not support vhosts");
      if (Anope::VersionMajor() < 2)
      {
         throw ModuleException("Requires version 2 of Anope.");
      }
      this->SetAuthor("Azander");
      this->SetVersion("1.0.2");
   }
};

MODULE_INIT(BSVhost)
Logged
Pages: [1]   Go Up