Advertisement
Guest User

Untitled

a guest
Dec 2nd, 2015
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 49.98 KB | None | 0 0
  1. /**
  2.  * SETCommand.cc
  3.  *
  4.  * 28/12/2000 - David Henriksen <david@itwebnet.dk>
  5.  * Initial Version.
  6.  * 01/01/2001 - Greg Sikorski <gte@atomicrevs.demon.co.uk>
  7.  * Modifications.
  8.  * 10/02/2001 - David Henriksen <david@itwebnet.dk>
  9.  * Minor bug fixes.
  10.  *
  11.  * 20/02/2001 - Gator Robert White <gator@cajun-gator.net>
  12.  * removed AlwaysOp
  13.  * Sets channel options on the specified channel.
  14.  * 2001-03-16 - Perry Lorier <isomer@coders.net>
  15.  * Added 'DESC' as an alias for 'DESCRIPTION'
  16.  * 2001-04-16 - Alex Badea <vampire@go.ro>
  17.  * Changed the implementation for SET LANG, everything is dynamic now.
  18.  * 2012-04-16 - Seven <gergo_f@yahoo.com>
  19.  * Reimplemented NOFORCE channel flag
  20.  * Other minor modifications
  21.  * 2012-09-08 - Seven <gergo_f@yahoo.com>
  22.  * Added channel NOVOICE flag
  23.  *
  24.  * Caveats: None.
  25.  *
  26.  * This program is free software; you can redistribute it and/or
  27.  * modify it under the terms of the GNU General Public License
  28.  * as published by the Free Software Foundation; either version 2
  29.  * of the License, or (at your option) any later version.
  30.  *
  31.  * This program is distributed in the hope that it will be useful,
  32.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  33.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  34.  * GNU General Public License for more details.
  35.  *
  36.  * You should have received a copy of the GNU General Public License
  37.  * along with this program; if not, write to the Free Software
  38.  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,
  39.  * USA.
  40.  *
  41.  * $Id: SETCommand.cc,v 1.64 2008/04/16 20:34:44 danielaustin Exp $
  42.  */
  43.  
  44. #include    <string>
  45. #include    <sstream>
  46. #include    "StringTokenizer.h"
  47. #include    "cservice.h"
  48. #include    "Network.h"
  49. #include    "levels.h"
  50. #include    "responses.h"
  51. #include    "cservice_config.h"
  52. #include <stdio.h>
  53. #ifdef HAVE_LIBOATH
  54. extern "C" {
  55. #include <liboath/oath.h>
  56. }
  57. #endif
  58. const char SETCommand_cc_rcsId[] = "$Id: SETCommand.cc,v 1.64 2008/04/16 20:34:44 danielaustin Exp $" ;
  59.  
  60. namespace gnuworld
  61. {
  62. using namespace level;
  63.  
  64. bool SETCommand::Exec( iClient* theClient, const string& Message )
  65. {
  66. bot->incStat("COMMANDS.SET");
  67.  
  68. StringTokenizer st( Message ) ;
  69.  
  70. if( st.size() < 3 )
  71.     {
  72.     Usage(theClient);
  73.     return true;
  74.     }
  75.  
  76. /* Is the user authorised? */
  77.  
  78. sqlUser* theUser = bot->isAuthed(theClient, true);
  79. if(!theUser)
  80.     {
  81.     return false;
  82.     }
  83.  
  84. /*
  85.  * First, is this a #channel or user set?
  86.  */
  87.  
  88. if( st[1][0] != '#' ) // Didn't find a hash?
  89. {
  90.     // Look by user then.
  91.     string option = string_upper(st[1]);
  92.     string value = string_upper(st[2]);
  93.     if (option == "INVISIBLE")
  94.     {
  95.         if (value == "ON")
  96.         {
  97.             theUser->setFlag(sqlUser::F_INVIS);
  98.             theUser->commit(theClient);
  99.             bot->Notice(theClient,
  100.                 bot->getResponse(theUser,
  101.                     language::invis_on,
  102.                     string("Your INVISIBLE setting is now ON.")));
  103.             return true;
  104.         }
  105.  
  106.         if (value == "OFF")
  107.         {
  108.             theUser->removeFlag(sqlUser::F_INVIS);
  109.             theUser->commit(theClient);
  110.             bot->Notice(theClient,
  111.                 bot->getResponse(theUser,
  112.                     language::invis_off,
  113.                     string("Your INVISIBLE setting is now OFF.")));
  114.             return true;
  115.         }
  116.  
  117.         bot->Notice(theClient,
  118.             bot->getResponse(theUser,
  119.                 language::set_cmd_syntax_on_off,
  120.                 string("value of %s must be ON or OFF")).c_str(),
  121.             option.c_str());
  122.             return true;
  123.     }
  124.  
  125.     if (option == "NOADDUSER")
  126.     {
  127.         if (value == "ON")
  128.         {
  129.             theUser->setFlag(sqlUser::F_NOADDUSER);
  130.             theUser->commit(theClient);
  131.             bot->Notice(theClient,
  132.                 bot->getResponse(theUser,
  133.                     language::noadduser_on,
  134.                     string("Your NOADDUSER setting is now ON.")));
  135.             return true;
  136.         }
  137.  
  138.         if (value == "OFF")
  139.         {
  140.             theUser->removeFlag(sqlUser::F_NOADDUSER);
  141.             theUser->commit(theClient);
  142.             bot->Notice(theClient,
  143.                 bot->getResponse(theUser,
  144.                     language::noadduser_off,
  145.                     string("Your NOADDUSER setting is now OFF.")));
  146.             return true;
  147.         }
  148.  
  149.         bot->Notice(theClient,
  150.             bot->getResponse(theUser,
  151.                 language::set_cmd_syntax_on_off,
  152.                 string("value of %s must be ON or OFF")).c_str(),
  153.             option.c_str());
  154.         return true;
  155.     }
  156.  
  157. #ifdef USE_NOTES
  158.     if (option == "NONOTES")
  159.     {
  160.         if (value == "ON")
  161.         {
  162.             theUser->setFlag(sqlUser::F_NONOTES);
  163.             theUser->commit(theClient);
  164.             bot->Notice(theClient,"You are no longer able to receive notes from anyone.");
  165.             return true;
  166.         }
  167.  
  168.         if (value == "OFF")
  169.         {
  170.             theUser->removeFlag(sqlUser::F_NONOTES);
  171.             theUser->commit(theClient);
  172.             bot->Notice(theClient,"You are now able to receive notes.");
  173.             return true;
  174.         }
  175.  
  176.         bot->Notice(theClient,
  177.             bot->getResponse(theUser,
  178.                 language::set_cmd_syntax_on_off,
  179.                 string("value of %s must be ON or OFF")).c_str(),
  180.             option.c_str());
  181.             return true;
  182.     }
  183. #endif
  184. #ifdef USE_USERS_URL
  185.     if ((option == "URL") || (option == "DESC") || (option == "DESCRIPTION") || (option == "MOTTO"))
  186.     {
  187.         string url;
  188.         if (value == "OFF")
  189.         {
  190.             url = "";
  191.             bot->Notice(theClient, bot->getResponse(theUser, language::userurl_off,
  192.                 string("Cleared your %s")).c_str(),string_upper(option).c_str());
  193.         }
  194.         else
  195.         {
  196.             url = st.assemble(2);
  197.             bot->Notice(theClient, bot->getResponse(theUser, language::userurl_on,
  198.                 string("Set your %s to %s.")).c_str(),string_upper(option).c_str(),url.c_str());
  199.         }
  200.         theUser->setUrl(url);
  201.         theUser->commit(theClient);
  202.         return true;
  203.     }
  204. #endif
  205.     if (option == "DISABLEAUTH")
  206.     {
  207.         if (value == "ON")
  208.         {
  209.             /* only admins can use this command */
  210.             int admLevel = bot->getAdminAccessLevel(theUser);
  211.             if (admLevel > 0)
  212.             {
  213.                 theUser->setFlag(sqlUser::F_NOADMIN);
  214.                 theUser->commit(theClient);
  215.                 bot->Notice(theClient,"You have lost the force :(");
  216.                 bot->logAdminMessage("%s (%s) set DISABLEAUTH on!",
  217.                     theClient->getNickName().c_str(), theUser->getUserName().c_str());
  218.             } else {
  219.                 /* not an admin, return unknown command */
  220.                 bot->Notice(theClient,
  221.                     bot->getResponse(theUser,
  222.                     language::invalid_option,
  223.                     string("Invalid option.")));
  224.             }
  225.             return true;
  226.         }
  227.  
  228.         if (value == "OFF")
  229.         {
  230.             /* only allow removal if it is set! */
  231.             if (theUser->getFlag(sqlUser::F_NOADMIN))
  232.             {
  233.                 theUser->removeFlag(sqlUser::F_NOADMIN);
  234.                 theUser->commit(theClient);
  235.                 bot->Notice(theClient,"Welcome back, brave Jedi.");
  236.                 bot->logAdminMessage("%s (%s) set DISABLEAUTH off!",
  237.                     theClient->getNickName().c_str(), theUser->getUserName().c_str());
  238.             } else {
  239.                 /* not set?  pretend it's an unknown command */
  240.                 bot->Notice(theClient,
  241.                     bot->getResponse(theUser,
  242.                     language::invalid_option,
  243.                     string("Invalid option.")));
  244.             }
  245.             return true;
  246.         }
  247.  
  248.         bot->Notice(theClient,
  249.             bot->getResponse(theUser,
  250.                 language::set_cmd_syntax_on_off,
  251.                 string("value of %s must be ON or OFF")).c_str(),
  252.             option.c_str());
  253.             return true;
  254.     }
  255.     if (option == "NOPURGE")
  256.     {
  257.         int admLevel = bot->getAdminAccessLevel(theUser);
  258.         if (!admLevel)
  259.         {
  260.             /* not an admin, return unknown command */
  261.             bot->Notice(theClient,
  262.                 bot->getResponse(theUser,
  263.                 language::invalid_option,
  264.                 string("Invalid option.")));
  265.             return true;
  266.         }
  267.         sqlUser* targetUser = theUser;
  268.         if ((value != "ON") && (value != "OFF"))
  269.         {
  270.             targetUser = bot->getUserRecord(st[2]);
  271.             if (!targetUser)
  272.             {
  273.                 bot->Notice(theClient,
  274.                     bot->getResponse(theUser,
  275.                         language::not_registered,
  276.                         string("The user %s doesn't appear to be registered.")).c_str(),
  277.                     st[2].c_str());
  278.                 return true;
  279.             }
  280.             if (st.size() < 4)
  281.             {
  282.                 bot->Notice(theClient,"SYNTAX: SET NOPURGE user ON|OFF");
  283.                 return false;
  284.             }
  285.             else
  286.                 value = string_upper(st[3]);
  287.         }
  288.         if (value == "ON")
  289.         {
  290.             targetUser->setFlag(sqlUser::F_NOPURGE);
  291.             targetUser->commit(theClient);
  292.             bot->Notice(theClient,"NOPURGE setting for %s is now ON", targetUser->getUserName().c_str());
  293.             return true;
  294.         }
  295.         if (value == "OFF")
  296.         {
  297.             /* only allow removal if it is set! */
  298.             //if (targetUser->getFlag(sqlUser::F_NOPURGE))
  299.             //{
  300.                 targetUser->removeFlag(sqlUser::F_NOPURGE);
  301.                 targetUser->commit(theClient);
  302.             //}
  303.                 bot->Notice(theClient,"NOPURGE setting for %s is now OFF", targetUser->getUserName().c_str());
  304.             return true;
  305.         }
  306.         bot->Notice(theClient,
  307.             bot->getResponse(theUser,
  308.                 language::set_cmd_syntax_on_off,
  309.                 string("value of %s must be ON or OFF")).c_str(),
  310.             option.c_str());
  311.             return true;
  312.     }
  313.  
  314. #ifdef USE_SETMAXLOGINS
  315.     if (option == "MAXLOGINS")
  316.         {
  317.         unsigned int maxlogins = atoi(value.c_str());
  318.         if (maxlogins > 3 || maxlogins <= 0)
  319.             {
  320.                 bot->Notice(theClient, "Max Logins cannot be greater than 3 or less than 1");
  321.                 return false;
  322.             }
  323.  
  324.         theUser->setMaxLogins(maxlogins);
  325.         theUser->commit(theClient);
  326.  
  327.         bot->Notice(theClient, "Max Logins now set to %i", maxlogins);
  328.         return true;
  329.         }
  330. #endif
  331.  
  332.     if (option == "LANG")
  333.     {
  334.         cservice::languageTableType::iterator ptr = bot->languageTable.find(value);
  335.         if (ptr != bot->languageTable.end())
  336.         {
  337.             string lang = ptr->second.second;
  338.             theUser->setLanguageId(ptr->second.first);
  339.             theUser->commit(theClient);
  340.             bot->Notice(theClient,
  341.                 bot->getResponse(theUser,
  342.                         language::lang_set_to,
  343.                     string("Language is set to %s.")).c_str(), lang.c_str());
  344.             return true;
  345.         }
  346.  
  347.         bot->Notice(theClient,
  348.                 "ERROR: Invalid language selection.");
  349.         return true;
  350.     }
  351.  
  352. #ifdef TOTP_AUTH_ENABLED
  353.          if (option == "TOTP")
  354.          {      
  355.                  int admin = bot->getAdminAccessLevel(theUser);
  356.                  if((admin > 0) || (theUser->getFlag(sqlUser::F_OPER)) || (theClient->isOper())) {
  357.                          if(value == "ON") {
  358.                                  if(theUser->getFlag(sqlUser::F_TOTP_ENABLED)) {
  359.                                          bot->Notice(theClient,"TOTP is already enabled for your account");
  360.                                          return true;
  361.                                  }
  362.                                  if(st.size() == 3) {
  363.                                          bot->Notice(theClient,"WARNING:  This will enable time-based OTP (one time passwords).  Once enabled, in order to login you will require a device to generate the OTP token which has the stored secret key.  If you are sure, type: /msg X set totp ON -force");
  364.                                          return true;
  365.                                  }
  366.                                  if(string_upper(st[3]) == "-FORCE") {
  367.                                          //Create a random hex string 168bit long
  368.                                          char str_key2[20];
  369.                                          char hex_key[41];
  370.                                          srand(clock()*745+time(NULL));
  371.                                          hex_key[0] = 0;
  372.                                          for(int i=0; i < 20; i++) {
  373.                                                  str_key2[i]=((rand() %95) + 32);
  374.                                                  sprintf(hex_key+(i*2),"%02x",str_key2[i] & 0xFF);
  375.                                          }      
  376.                                          char* key;
  377.                                          int res = oath_base32_encode(str_key2,20,&key,NULL);
  378.                                          if(res != OATH_OK) {
  379.                                                  bot->Notice(theClient,"Failed to enable TOTP authentication, please contact a cservice representitive");
  380.                                                  return true;
  381.                                          }
  382.                                          theUser->setTotpKey(string(key));
  383.                                          theUser->setFlag(sqlUser::F_TOTP_ENABLED);
  384.                                          if(!theUser->commit(theClient)) {
  385.                                                  bot->Notice(theClient,"Failed to enable TOTP authentication, please contact a cservice representitive");
  386.                                                  free(key);
  387.                                                  return true;
  388.                                  }
  389.                          }
  390.                  }
  391.          }
  392. #endif
  393.     if (option == "POWER")
  394.     {
  395.         int admLevel = bot->getAdminAccessLevel(theUser);
  396.         if (!admLevel)
  397.         {
  398.             /* not an admin, return unknown command */
  399.             bot->Notice(theClient,
  400.                 bot->getResponse(theUser,
  401.                 language::invalid_option,
  402.                 string("Invalid option.")));
  403.             return true;
  404.         }
  405.         sqlUser* targetUser = theUser;
  406.         if ((value != "ON") && (value != "OFF"))
  407.         {
  408.             targetUser = bot->getUserRecord(st[2]);
  409.             if (!targetUser)
  410.             {
  411.                 bot->Notice(theClient,
  412.                     bot->getResponse(theUser,
  413.                         language::not_registered,
  414.                         string("The user %s doesn't appear to be registered.")).c_str(),
  415.                     st[2].c_str());
  416.                 return true;
  417.             }
  418.             if (st.size() < 4)
  419.             {
  420.                 bot->Notice(theClient,"SYNTAX: SET POWER user ON|OFF");
  421.                 return false;
  422.             }
  423.             else
  424.                 value = string_upper(st[3]);
  425.         }
  426.         if (value == "ON")
  427.         {
  428.             /* only admins can use this command */
  429.             if (((admLevel > 0) && (theUser->getFlag(sqlUser::F_POWER))) || ((theUser->getID() == 1) && (targetUser == theUser)))
  430.             {
  431.                 targetUser->setFlag(sqlUser::F_POWER);
  432.                 targetUser->commit(theClient);
  433.                 bot->Notice(theClient,"Set POWER to ON for user %s", targetUser->getUserName().c_str());
  434.             } else {
  435.                 /* not an admin, return unknown command */
  436.                 bot->Notice(theClient,
  437.                     bot->getResponse(theUser,
  438.                     language::invalid_option,
  439.                     string("Invalid option.")));
  440.             }
  441.             return true;
  442.         }
  443.         if (value == "OFF")
  444.         {
  445.             /* only allow removal if it is set! */
  446.             if (((admLevel > 0) && (theUser->getFlag(sqlUser::F_POWER)))
  447.                 && (targetUser->getFlag(sqlUser::F_POWER)))
  448.             {
  449.                 targetUser->removeFlag(sqlUser::F_POWER);
  450.                 targetUser->commit(theClient);
  451.                 bot->Notice(theClient,"Set POWER to OFF for user %s", targetUser->getUserName().c_str());
  452.             } else {
  453.                 /* not set?  pretend it's an unknown command */
  454.                 bot->Notice(theClient,
  455.                     bot->getResponse(theUser,
  456.                     language::invalid_option,
  457.                     string("Invalid option.")));
  458.             }
  459.             return true;
  460.         }
  461.         bot->Notice(theClient,
  462.             bot->getResponse(theUser,
  463.                 language::set_cmd_syntax_on_off,
  464.                 string("value of %s must be ON or OFF")).c_str(),
  465.             option.c_str());
  466.             return true;
  467.     }
  468.     if ((option == "HOST") || (option == "HOSTNAME"))
  469.     {
  470.         if (value == "OFF")
  471.         {
  472.             //theClient->clearFakeHost();
  473.             theUser->setHostName(string());
  474.             theUser->commit(theClient);
  475.             bot->Notice(theClient, "Your host was successfully cleared. Please reconnect to apply your original host.");
  476.         }
  477.         else
  478.         {
  479.             if (st[2].size() > 128)
  480.             {
  481.                 bot->Notice(theClient, "Hostname can be maximum 128 characters long.");
  482.                 return true;
  483.             }
  484.             if ((st[2].size() < 3) || (!validHostName(st[2])))
  485.             {
  486.                 bot->Notice(theClient, "Invalid hostname provided. A valid hostname has at least a 2 characters long domain, and contains at least one dot.");
  487.                 return true;
  488.             }
  489.             if (st[2].rfind("evilnet.org") != std::string::npos && bot->getAdminAccessLevel(theUser) < 600) { bot->Notice(theClient, "You don't have rights to set hostname to evilnet.org."); return true; }
  490.             theUser->setHostName(st[2]);
  491.             theUser->commit(theClient);
  492.             server->SendOutFakeHost(theClient, theUser->getHostName().c_str(), bot);
  493.             bot->Notice(theClient, "Your hostname is now set to %s", theUser->getHostName().c_str());
  494.         }
  495.         return true;
  496.     }
  497.     bot->Notice(theClient,
  498.         bot->getResponse(theUser,
  499.             language::invalid_option,
  500.             string("Invalid option.")));
  501.     return true;
  502. }
  503.  
  504. Channel* tmpChan = Network->findChannel(st[1]);
  505.  
  506. /* Is the channel registered? */
  507.  
  508. sqlChannel* theChan = bot->getChannelRecord(st[1]);
  509. if(!theChan)
  510.     {
  511.     bot->Notice(theClient,
  512.         bot->getResponse(theUser,
  513.             language::chan_not_reg,
  514.             string("Sorry, %s isn't registered with me.")).c_str(),
  515.         st[1].c_str());
  516.     return false;
  517.     }
  518.  
  519. // Check level.
  520.  
  521. int level = bot->getEffectiveAccessLevel(theUser, theChan, false);
  522. string option = string_upper(st[2]);
  523. string value;
  524. string reason;
  525.  
  526. if (st.size() < 4)
  527.     {
  528.     value = "";
  529.     }
  530. else
  531.     {
  532.     value = string_upper(st[3]);
  533.     if (st.size() < 5)
  534.         reason = "";
  535.     else
  536.         reason = st.assemble(4);
  537.     }
  538.  
  539.     /*
  540.      * Check the "Locked" status first, so admin's can bypas to turn it OFF :)
  541.      */
  542.  
  543.     if(option == "LOCKED")
  544.     {
  545.         // Check for admin access
  546.         int admLevel = bot->getAdminAccessLevel(theUser);
  547.         if (admLevel == 0) {
  548.         // No need to tell users about admin commands.
  549.         Usage(theClient);
  550.         return true;
  551.         }
  552.         if (admLevel < level::set::locked)
  553.         {
  554.         bot->Notice(theClient,
  555.         bot->getResponse(theUser,
  556.             language::insuf_access,
  557.             string("Sorry, you have insufficient access to perform that command.")));
  558.         return false;
  559.         }
  560.         if(value == "ON") theChan->setFlag(sqlChannel::F_LOCKED);
  561.         else if(value == "OFF") theChan->removeFlag(sqlChannel::F_LOCKED);
  562.         else
  563.         {
  564.         bot->Notice(theClient,
  565.             bot->getResponse(theUser,
  566.                 language::set_cmd_syntax_on_off,
  567.                 string("value of %s must be ON or OFF")).c_str(),
  568.             option.c_str());
  569.         return true;
  570.         }
  571.         theChan->commit();
  572.         bot->Notice(theClient,
  573.             bot->getResponse(theUser,
  574.                 language::set_cmd_status,
  575.                 string("%s for %s is %s")).c_str(),
  576.             option.c_str(),
  577.             theChan->getName().c_str(),
  578.             theChan->getFlag(sqlChannel::F_LOCKED) ? "ON" : "OFF");
  579.  
  580.         return true;
  581.     }
  582.  
  583.     /*
  584.      *  Check if the channel is "Locked", if so, only allow admins to change settings.
  585.      */
  586.  
  587.     if(theChan->getFlag(sqlChannel::F_LOCKED))
  588.     {
  589.         int admLevel = bot->getAdminAccessLevel(theUser);
  590.         if (admLevel < level::set::locked)
  591.             {
  592.             bot->Notice(theClient, "The channel settings for %s have been locked by a cservice"
  593.                 " administrator and cannot be changed.", theChan->getName().c_str());
  594.             return(true);
  595.             }
  596.     }
  597.  
  598.     if(option == "CAUTION")
  599.     {
  600.     // Check for admin access
  601.     int admLevel = bot->getAdminAccessLevel(theUser);
  602.     if(admLevel < level::set::caution)
  603.     if (admLevel == 0) {
  604.         // No need to tell users about admin commands.
  605.         Usage(theClient);
  606.         return true;
  607.     }
  608.     if (admLevel < level::set::noreg)
  609.     {
  610.         bot->Notice(theClient,
  611.         bot->getResponse(theUser,
  612.             language::insuf_access,
  613.             string("Sorry, you have insufficient access to perform that command.")));
  614.         return false;
  615.     }
  616.  
  617.     if(value == "ON") theChan->setFlag(sqlChannel::F_CAUTION);
  618.     else if(value == "OFF") theChan->removeFlag(sqlChannel::F_CAUTION);
  619.     else
  620.     {
  621.     bot->Notice(theClient,
  622.         bot->getResponse(theUser,
  623.             language::set_cmd_syntax_on_off,
  624.             string("value of %s must be ON or OFF")).c_str(),
  625.         option.c_str());
  626.     return true;
  627.     }
  628.  
  629.     theChan->commit();
  630.     bot->Notice(theClient,
  631.         bot->getResponse(theUser,
  632.             language::set_cmd_status,
  633.             string("%s for %s is %s")).c_str(),
  634.     option.c_str(),
  635.         theChan->getName().c_str(),
  636.         theChan->getFlag(sqlChannel::F_CAUTION) ? "ON" : "OFF");
  637.     return true;
  638.     }
  639.  
  640.     if(option == "NOREG")
  641.     {
  642.     // Check for admin access
  643.     int admLevel = bot->getAdminAccessLevel(theUser);
  644.     if(admLevel < level::set::noreg)
  645.     if (admLevel == 0) {
  646.         // No need to tell users about admin commands.
  647.         Usage(theClient);
  648.         return true;
  649.     }
  650.     if (admLevel < level::set::noreg)
  651.     {
  652.         bot->Notice(theClient,
  653.         bot->getResponse(theUser,
  654.             language::insuf_access,
  655.             string("Sorry, you have insufficient access to perform that command.")));
  656.         return false;
  657.     }
  658.     if(value == "ON") theChan->setFlag(sqlChannel::F_NOREG);
  659.     else if(value == "OFF") theChan->removeFlag(sqlChannel::F_NOREG);
  660.     else
  661.         {
  662.         bot->Notice(theClient,
  663.             bot->getResponse(theUser,
  664.                 language::set_cmd_syntax_on_off,
  665.                 string("value of %s must be ON or OFF")).c_str(),
  666.             option.c_str());
  667.         return true;
  668.         }
  669.     theChan->commit();
  670.     bot->Notice(theClient,
  671.         bot->getResponse(theUser,
  672.             language::set_cmd_status,
  673.             string("%s for %s is %s")).c_str(),
  674.         option.c_str(),
  675.         theChan->getName().c_str(),
  676.         theChan->getFlag(sqlChannel::F_NOREG) ? "ON" : "OFF");
  677.     return true;
  678.     }
  679.  
  680.     if(option == "SPECIAL")
  681.     {
  682.         // Check for admin access
  683.         int admLevel = bot->getAdminAccessLevel(theUser);
  684.         if (admLevel == 0) {
  685.             // No need to tell users about admin commands.
  686.             Usage(theClient);
  687.             return true;
  688.         }
  689.         if (admLevel < level::set::special)
  690.         {
  691.         bot->Notice(theClient,
  692.             bot->getResponse(theUser,
  693.                 language::insuf_access,
  694.                 string("Sorry, you have insufficient access to perform that command.")));
  695.         return false;
  696.         }
  697.         if(value == "ON") theChan->setFlag(sqlChannel::F_SPECIAL);
  698.         else if(value == "OFF") theChan->removeFlag(sqlChannel::F_SPECIAL);
  699.         else
  700.         {
  701.         bot->Notice(theClient,
  702.             bot->getResponse(theUser,
  703.                 language::set_cmd_syntax_on_off,
  704.                 string("value of %s must be ON or OFF")).c_str(),
  705.             option.c_str());
  706.         return true;
  707.         }
  708.         theChan->commit();
  709.         bot->Notice(theClient,
  710.             bot->getResponse(theUser,
  711.                 language::set_cmd_status,
  712.                 string("%s for %s is %s")).c_str(),
  713.             option.c_str(),
  714.             theChan->getName().c_str(),
  715.             theChan->getFlag(sqlChannel::F_SPECIAL) ? "ON" : "OFF");
  716.  
  717.         return true;
  718.     }
  719.  
  720.  
  721.     if(option == "NEVERREG")
  722.     {
  723.         // Check for admin access
  724.         int admLevel = bot->getAdminAccessLevel(theUser);
  725.         if (admLevel == 0) {
  726.             // No need to tell users about admin commands.
  727.             Usage(theClient);
  728.             return true;
  729.         }
  730.         if (admLevel < level::set::neverreg)
  731.         {
  732.         bot->Notice(theClient,
  733.             bot->getResponse(theUser,
  734.                 language::insuf_access,
  735.                 string("Sorry, you have insufficient access to perform that command.")));
  736.         return false;
  737.         }
  738.         if(value == "ON") theChan->setFlag(sqlChannel::F_NEVREG);
  739.         else if(value == "OFF") theChan->removeFlag(sqlChannel::F_NEVREG);
  740.         else
  741.         {
  742.         bot->Notice(theClient,
  743.             bot->getResponse(theUser,
  744.                 language::set_cmd_syntax_on_off,
  745.                 string("value of %s must be ON or OFF")).c_str(),
  746.             option.c_str());
  747.         return true;
  748.         }
  749.         theChan->commit();
  750.         bot->Notice(theClient,
  751.             bot->getResponse(theUser,
  752.                 language::set_cmd_status,
  753.                 string("%s for %s is %s")).c_str(),
  754.             option.c_str(),
  755.             theChan->getName().c_str(),
  756.             theChan->getFlag(sqlChannel::F_NEVREG) ? "ON" : "OFF");
  757.  
  758.         return true;
  759.     }
  760.  
  761.     if(option == "NOPURGE")
  762.     {
  763.         // Check for admin access
  764.         int admLevel = bot->getAdminAccessLevel(theUser);
  765.         if (admLevel == 0) {
  766.             // No need to tell users about admin commands.
  767.             Usage(theClient);
  768.             return true;
  769.         }
  770.         if (admLevel < level::set::nopurge)
  771.         {
  772.         bot->Notice(theClient,
  773.             bot->getResponse(theUser,
  774.                 language::insuf_access,
  775.                 string("Sorry, you have insufficient access to perform that command.")));
  776.         return false;
  777.         }
  778.         if(value == "ON") theChan->setFlag(sqlChannel::F_NOPURGE);
  779.         else if(value == "OFF") theChan->removeFlag(sqlChannel::F_NOPURGE);
  780.         else
  781.         {
  782.         bot->Notice(theClient,
  783.             bot->getResponse(theUser,
  784.                 language::set_cmd_syntax_on_off,
  785.                 string("value of %s must be ON or OFF")).c_str(),
  786.             option.c_str());
  787.         return true;
  788.         }
  789.         theChan->commit();
  790.         bot->Notice(theClient,
  791.             bot->getResponse(theUser,
  792.                 language::set_cmd_status,
  793.                 string("%s for %s is %s")).c_str(),
  794.             option.c_str(),
  795.             theChan->getName().c_str(),
  796.             theChan->getFlag(sqlChannel::F_NOPURGE) ? "ON" : "OFF");
  797.         return true;
  798.     }
  799.  
  800.     if(option == "SUSPEND")
  801.     {
  802.         // Check for admin access
  803.         int admLevel = bot->getAdminAccessLevel(theUser);
  804.         if (admLevel == 0) {
  805.             // No need to tell users about admin commands.
  806.             Usage(theClient);
  807.             return true;
  808.         }
  809.         if (admLevel < level::set::suspend)
  810.         {
  811.         bot->Notice(theClient,
  812.             bot->getResponse(theUser,
  813.                 language::insuf_access,
  814.                 string("Sorry, you have insufficient access to perform that command.")));
  815.         return false;
  816.         }
  817.             if (reason == "")
  818.             {
  819.                 bot->Notice(theClient, "No reason given! You must specify a reason after ON/OFF");
  820.                 return true;
  821.             }
  822.         if(value == "ON") theChan->setFlag(sqlChannel::F_SUSPEND);
  823.         else if(value == "OFF") theChan->removeFlag(sqlChannel::F_SUSPEND);
  824.         else
  825.         {
  826.         bot->Notice(theClient,
  827.             bot->getResponse(theUser,
  828.                 language::set_cmd_syntax_on_off,
  829.                 string("value of %s must be ON or OFF")).c_str(),
  830.             option.c_str());
  831.         return true;
  832.         }
  833.         theChan->commit();
  834.             /* write a channel log entry */
  835.             string logmsg;
  836.             if (!theChan->getFlag(sqlChannel::F_SUSPEND))
  837.                 logmsg += "un";
  838.             logmsg += "suspend reason: ";
  839.             logmsg += reason;
  840.             if (theChan->getFlag(sqlChannel::F_SUSPEND))
  841.             {
  842.                 bot->writeChannelLog(theChan, theClient, sqlChannel::EV_SUSPEND, logmsg);
  843.         /* inform admin channel */
  844.         bot->logAdminMessage("%s (%s) has suspended %s",
  845.             theClient->getNickName().c_str(), theUser->getUserName().c_str(),
  846.             theChan->getName().c_str());
  847.         if (tmpChan) bot->deopAllOnChan(tmpChan); // Deop everyone. :)
  848.             } else {
  849.                 bot->writeChannelLog(theChan, theClient, sqlChannel::EV_UNSUSPEND, logmsg);
  850.         /* inform admin channel */
  851.         bot->logAdminMessage("%s (%s) has unsuspended %s",
  852.             theClient->getNickName().c_str(), theUser->getUserName().c_str(),
  853.             theChan->getName().c_str());
  854.             }
  855.         bot->Notice(theClient,
  856.             bot->getResponse(theUser,
  857.                 language::set_cmd_status,
  858.                 string("%s for %s is %s")).c_str(),
  859.             option.c_str(),
  860.             theChan->getName().c_str(),
  861.             theChan->getFlag(sqlChannel::F_SUSPEND) ? "ON" : "OFF");
  862.         return true;
  863.     }
  864.  
  865.     if(option == "TEMPMAN")
  866.     {
  867.         // Check for admin access
  868.         int admLevel = bot->getAdminAccessLevel(theUser);
  869.         if (admLevel == 0) {
  870.             // No need to tell users about admin commands.
  871.             Usage(theClient);
  872.             return true;
  873.         }
  874.         if (admLevel < level::set::tempman)
  875.         {
  876.         bot->Notice(theClient,
  877.             bot->getResponse(theUser,
  878.                 language::insuf_access,
  879.                 string("Sorry, you have insufficient access to perform that command.")));
  880.         return false;
  881.         }
  882.         if(value == "ON") theChan->setFlag(sqlChannel::F_TEMP);
  883.         else if(value == "OFF") theChan->removeFlag(sqlChannel::F_TEMP);
  884.         else
  885.         {
  886.         bot->Notice(theClient,
  887.             bot->getResponse(theUser,
  888.                 language::set_cmd_syntax_on_off,
  889.                 string("value of %s must be ON or OFF")).c_str(),
  890.             option.c_str());
  891.         return true;
  892.         }
  893.         theChan->commit();
  894.         bot->Notice(theClient,
  895.             bot->getResponse(theUser,
  896.                 language::set_cmd_status,
  897.                 string("%s for %s is %s")).c_str(),
  898.             option.c_str(),
  899.             theChan->getName().c_str(),
  900.             theChan->getFlag(sqlChannel::F_TEMP) ? "ON" : "OFF");
  901.         return true;
  902.     }
  903.  
  904.     if(option == "VACATION")
  905.     {
  906.         // Check for admin access
  907.         int admLevel = bot->getAdminAccessLevel(theUser);
  908.         if (admLevel == 0) {
  909.             // No need to tell users about admin commands.
  910.             Usage(theClient);
  911.             return true;
  912.         }
  913.         if (admLevel < level::set::vacation)
  914.         {
  915.         bot->Notice(theClient,
  916.             bot->getResponse(theUser,
  917.                 language::insuf_access,
  918.                 string("Sorry, you have insufficient access to perform that command.")));
  919.         return false;
  920.         }
  921.         if(value == "ON") theChan->setFlag(sqlChannel::F_VACATION);
  922.         else if(value == "OFF") theChan->removeFlag(sqlChannel::F_VACATION);
  923.         else
  924.         {
  925.         bot->Notice(theClient,
  926.             bot->getResponse(theUser,
  927.                 language::set_cmd_syntax_on_off,
  928.                 string("value of %s must be ON or OFF")).c_str(),
  929.             option.c_str());
  930.         return true;
  931.         }
  932.         theChan->commit();
  933.         bot->Notice(theClient,
  934.             bot->getResponse(theUser,
  935.                 language::set_cmd_status,
  936.                 string("%s for %s is %s")).c_str(),
  937.             option.c_str(),
  938.             theChan->getName().c_str(),
  939.             theChan->getFlag(sqlChannel::F_VACATION) ? "ON" : "OFF");
  940.         return true;
  941.     }
  942.     /*
  943.      * Check the "NoForce" status first, so admin's can bypas to turn it OFF :)
  944.      */
  945.  
  946.     if(option == "NOFORCE")
  947.     {
  948.         // Check for admin access
  949.         int admLevel = bot->getAdminAccessLevel(theUser);
  950.         if (admLevel == 0) {
  951.             // No need to tell users about admin commands.
  952.             Usage(theClient);
  953.             return true;
  954.         }
  955.         if (admLevel < level::set::noforce)
  956.         {
  957.         bot->Notice(theClient,
  958.             bot->getResponse(theUser,
  959.                 language::insuf_access,
  960.                 string("Sorry, you have insufficient access to perform that command.")));
  961.         return false;
  962.         }
  963.         if(value == "ON") theChan->setFlag(sqlChannel::F_NOFORCE);
  964.         else if(value == "OFF") theChan->removeFlag(sqlChannel::F_NOFORCE);
  965.         else
  966.         {
  967.         bot->Notice(theClient,
  968.             bot->getResponse(theUser,
  969.                 language::set_cmd_syntax_on_off,
  970.                 string("value of %s must be ON or OFF")).c_str(),
  971.             option.c_str());
  972.         return true;
  973.         }
  974.         theChan->commit();
  975.         bot->Notice(theClient,
  976.             bot->getResponse(theUser,
  977.                 language::set_cmd_status,
  978.                 string("%s for %s is %s")).c_str(),
  979.             option.c_str(),
  980.             theChan->getName().c_str(),
  981.             theChan->getFlag(sqlChannel::F_NOFORCE) ? "ON" : "OFF");
  982.  
  983. //TODO?
  984. //bot->writeChannelLog(theChan, theClient, sqlChannel::EV_NOFORCE, "");
  985.  
  986. if (value == "ON") {
  987.     for(sqlChannel::forceMapType::const_iterator ptr = theChan->forceMap.begin();
  988.         ptr != theChan->forceMap.end(); ++ptr)
  989.     {
  990.         // Look up this username in the cache.
  991.         cservice::sqlUserHashType::iterator ptr2 = bot->sqlUserCache.find(ptr->second.second); 
  992.         sqlUser* AdminUser = ptr2->second;
  993.         int ForceLevel = ptr->second.first;    
  994.  
  995.         //Now Remove force access who is not privileged :)
  996.     if (ForceLevel < level::immune::noforce)
  997.     {  
  998.     bot->noticeAllAuthedClients(AdminUser,
  999.                 bot->getResponse(AdminUser,
  1000.                     language::set_cmd_status,
  1001.                     string("%s for %s is %s")).c_str(),
  1002.                 option.c_str(),
  1003.                 theChan->getName().c_str(),"ON");
  1004.  
  1005.     theChan->forceMap.erase(AdminUser->getID());
  1006.    
  1007.     bot->noticeAllAuthedClients(AdminUser,
  1008.                 bot->getResponse(AdminUser,
  1009.                 language::rem_temp_access,
  1010.                 string("Removed your temporary access of %i from channel %s")).c_str(),
  1011.             ForceLevel, theChan->getName().c_str());
  1012.     }
  1013.     } //for cycle
  1014. }//if (value == ON)
  1015.  
  1016.         return true;
  1017.     }
  1018.         if(option == "MIA")
  1019.         {
  1020.             // Check for admin access
  1021.             int admLevel = bot->getAdminAccessLevel(theUser);
  1022.         if (admLevel == 0) {
  1023.             // No need to tell users about admin commands.
  1024.             Usage(theClient);
  1025.             return true;
  1026.         }
  1027.         if (admLevel < level::set::mia)
  1028.         {
  1029.         bot->Notice(theClient,
  1030.             bot->getResponse(theUser,
  1031.                 language::insuf_access,
  1032.                 string("Sorry, you have insufficient access to perform that command.")));
  1033.         return false;
  1034.         }
  1035.             if(value == "ON") theChan->setFlag(sqlChannel::F_MIA);
  1036.             else if(value == "OFF") theChan->removeFlag(sqlChannel::F_MIA);
  1037.             else
  1038.             {
  1039.                 bot->Notice(theClient,
  1040.                         bot->getResponse(theUser,
  1041.                                 language::set_cmd_syntax_on_off,
  1042.                                 string("value of %s must be ON or OFF")).c_str(),
  1043.                         option.c_str());
  1044.                 return true;
  1045.             }
  1046.             theChan->commit();
  1047.             bot->Notice(theClient,
  1048.                         bot->getResponse(theUser,
  1049.                                 language::set_cmd_status,
  1050.                                 string("%s for %s is %s")).c_str(),
  1051.                         option.c_str(),
  1052.                         theChan->getName().c_str(),
  1053.                         theChan->getFlag(sqlChannel::F_MIA) ? "ON" : "OFF");
  1054.             return true;
  1055.         }
  1056.  
  1057.  
  1058.     if(option == "NOOP")
  1059.     {
  1060.         if(level < level::set::noop)
  1061.         {
  1062.             bot->Notice(theClient,
  1063.                 bot->getResponse(theUser,
  1064.                     language::insuf_access,
  1065.                     string("You do not have enough access!")));
  1066.             return true;
  1067.         }
  1068.         if(value == "ON")
  1069.         {
  1070.             theChan->setFlag(sqlChannel::F_NOOP);
  1071.             if (tmpChan) bot->deopAllOnChan(tmpChan); // Deop everyone. :)
  1072.         }
  1073.         else if(value == "OFF") theChan->removeFlag(sqlChannel::F_NOOP);
  1074.         else
  1075.         {
  1076.         bot->Notice(theClient,
  1077.             bot->getResponse(theUser,
  1078.                 language::set_cmd_syntax_on_off,
  1079.                 string("value of %s must be ON or OFF")).c_str(),
  1080.             option.c_str());
  1081.         return true;
  1082.         }
  1083.         theChan->commit();
  1084.         bot->Notice(theClient,
  1085.             bot->getResponse(theUser,
  1086.                 language::set_cmd_status,
  1087.                 string("%s for %s is %s")).c_str(),
  1088.             option.c_str(),
  1089.             theChan->getName().c_str(),
  1090.             theChan->getFlag(sqlChannel::F_NOOP) ? "ON" : "OFF");
  1091.         return true;
  1092.     }
  1093.  
  1094.     if(option == "NOVOICE")
  1095.     {
  1096.         if(level < level::set::novoice)
  1097.         {
  1098.             bot->Notice(theClient,
  1099.                 bot->getResponse(theUser,
  1100.                     language::insuf_access,
  1101.                     string("You do not have enough access!")));
  1102.             return true;
  1103.         }
  1104.         if(value == "ON")
  1105.         {
  1106.             theChan->setFlag(sqlChannel::F_NOVOICE);
  1107.             if (tmpChan) bot->deVoiceAllOnChan(tmpChan); // DeVoice everyone. :)
  1108.         }
  1109.         else if(value == "OFF") theChan->removeFlag(sqlChannel::F_NOVOICE);
  1110.         else
  1111.         {
  1112.         bot->Notice(theClient,
  1113.             bot->getResponse(theUser,
  1114.                 language::set_cmd_syntax_on_off,
  1115.                 string("value of %s must be ON or OFF")).c_str(),
  1116.             option.c_str());
  1117.         return true;
  1118.         }
  1119.         theChan->commit();
  1120.         bot->Notice(theClient,
  1121.             bot->getResponse(theUser,
  1122.                 language::set_cmd_status,
  1123.                 string("%s for %s is %s")).c_str(),
  1124.             option.c_str(),
  1125.             theChan->getName().c_str(),
  1126.             theChan->getFlag(sqlChannel::F_NOVOICE) ? "ON" : "OFF");
  1127.         return true;
  1128.     }
  1129.  
  1130.     if(option == "STRICTOP")
  1131.     {
  1132.         if(level < level::set::strictop)
  1133.         {
  1134.         bot->Notice(theClient,
  1135.             bot->getResponse(theUser,
  1136.                 language::insuf_access,
  1137.                 string("You do not have enough access!")));
  1138.         return true;
  1139.         }
  1140.         if(value == "ON")
  1141.         {
  1142.             theChan->setFlag(sqlChannel::F_STRICTOP);
  1143.             if (tmpChan) bot->deopAllUnAuthedOnChan(tmpChan);
  1144.         }
  1145.         else if(value == "OFF") theChan->removeFlag(sqlChannel::F_STRICTOP);
  1146.         else
  1147.         {
  1148.         bot->Notice(theClient,
  1149.             bot->getResponse(theUser,
  1150.                 language::set_cmd_syntax_on_off,
  1151.                 string("value of %s must be ON or OFF")).c_str(),
  1152.             option.c_str());
  1153.         return true;
  1154.         }
  1155.         theChan->commit();
  1156.         bot->Notice(theClient,
  1157.             bot->getResponse(theUser,
  1158.                 language::set_cmd_status,
  1159.                 string("%s for %s is %s")).c_str(),
  1160.             option.c_str(),
  1161.             theChan->getName().c_str(),
  1162.             theChan->getFlag(sqlChannel::F_STRICTOP) ? "ON" : "OFF");
  1163.         return true;
  1164.     }
  1165. #ifdef USE_NOTAKE
  1166.     if(option == "NOTAKE")
  1167.     {
  1168.         if(level < level::set::notake)
  1169.         {
  1170.             bot->Notice(theClient,
  1171.                 bot->getResponse(theUser,
  1172.                         language::insuf_access,
  1173.                 string("You do not have enough access!")));
  1174.             return true;
  1175.         }
  1176.         if(value == "ON")
  1177.         {
  1178.             theChan->setFlag(sqlChannel::F_NOTAKE);
  1179.             theChan->setNoTake(2); //default revenge is BAN
  1180.         }
  1181.         else if(value == "OFF") theChan->removeFlag(sqlChannel::F_NOTAKE);
  1182.         else
  1183.         {
  1184.         bot->Notice(theClient,
  1185.             bot->getResponse(theUser,
  1186.                 language::set_cmd_syntax_on_off,
  1187.                     string("value of %s must be ON or OFF")).c_str(),
  1188.                 option.c_str());
  1189.             return true;
  1190.         }
  1191.         theChan->commit();
  1192.         bot->Notice(theClient,
  1193.             bot->getResponse(theUser,
  1194.                 language::set_cmd_status,
  1195.                 string("%s for %s is %s")).c_str(),
  1196.             option.c_str(),
  1197.             theChan->getName().c_str(),
  1198.             theChan->getFlag(sqlChannel::F_NOTAKE) ? "ON" : "OFF");
  1199.         return true;
  1200.     }
  1201.     if(option == "TAKEREVENGE")
  1202.     {
  1203.         if(level < level::set::notake)
  1204.         {
  1205.             bot->Notice(theClient,
  1206.                 bot->getResponse(theUser,
  1207.                         language::insuf_access,
  1208.                         string("You do not have enough access!")));
  1209.             return false;
  1210.         }
  1211.         int setting;
  1212.         if (value != "")
  1213.         {
  1214.             if (!IsNumeric(value))
  1215.             {
  1216.                 if (value=="IGNORE")
  1217.                     setting = 1;
  1218.                 else if (value=="BAN")
  1219.                     setting = 2;
  1220.                 else if (value=="SUSPEND")
  1221.                     setting = 3;
  1222.                 else
  1223.                     setting = 4;        /* dummy value to cause failure */
  1224.             } else {
  1225.                 setting = atoi(value.c_str());
  1226.             }
  1227.             if ( (setting < 1) || (setting > 3))
  1228.             {
  1229.                 bot->Notice(theClient,
  1230.                     bot->getResponse(theUser,
  1231.                             language::userflags_syntax,
  1232.                         string("Invalid TAKEREVENGE setting. Correct values are IGNORE, BAN or SUSPEND.")));
  1233.                 return false;
  1234.             }
  1235.             theChan->setNoTake(setting);
  1236.             theChan->commit();
  1237.         } else {
  1238.             setting = theChan->getNoTake();
  1239.         }
  1240.         /* set value to textual description */
  1241.         switch (setting) {
  1242.             default:    break;
  1243.             case 1:     value = "IGNORE";   break;
  1244.             case 2:     value = "BAN";      break;
  1245.             case 3:     value = "SUSPEND";  break;
  1246.         }
  1247.         bot->Notice(theClient,"TAKEREVENGE for %s is %s",
  1248.             theChan->getName().c_str(), value.c_str());
  1249.         return true;
  1250.     }
  1251. #endif
  1252.     if(option == "AUTOTOPIC")
  1253.     {
  1254.         if(level < level::set::autotopic)
  1255.         {
  1256.         bot->Notice(theClient,
  1257.                 bot->getResponse(theUser,
  1258.                 language::insuf_access,
  1259.                 string("You do not have enough access!")));
  1260.         return true;
  1261.         }
  1262.         if(value == "ON")
  1263.         {
  1264.             theChan->setFlag(sqlChannel::F_AUTOTOPIC);
  1265.             bot->doAutoTopic(theChan);
  1266.         }
  1267.         else if(value == "OFF") theChan->removeFlag(sqlChannel::F_AUTOTOPIC);
  1268.         else
  1269.         {
  1270.         bot->Notice(theClient,
  1271.             bot->getResponse(theUser,
  1272.                 language::set_cmd_syntax_on_off,
  1273.                 string("value of %s must be ON or OFF")).c_str(),
  1274.             option.c_str());
  1275.         return true;
  1276.         }
  1277.         theChan->commit();
  1278.         bot->Notice(theClient,
  1279.             bot->getResponse(theUser,
  1280.                 language::set_cmd_status,
  1281.                 string("%s for %s is %s")).c_str(),
  1282.             option.c_str(),
  1283.             theChan->getName().c_str(),
  1284.             theChan->getFlag(sqlChannel::F_AUTOTOPIC) ? "ON" : "OFF");
  1285.         return true;
  1286.     }
  1287.  
  1288.     if(option == "AUTOJOIN")
  1289.     {
  1290.         if(level < level::set::autojoin)
  1291.         {
  1292.                 bot->Notice(theClient,
  1293.                                 bot->getResponse(theUser,
  1294.                                 language::insuf_access,
  1295.                                 string("You do not have enough access!")));
  1296.  
  1297.         return true;
  1298.         }
  1299.         if(value == "ON")
  1300.         {
  1301.             theChan->setFlag(sqlChannel::F_AUTOJOIN);
  1302.             theChan->setInChan(true);
  1303.             bot->Join(theChan->getName(), "+R",
  1304.                 theChan->getChannelTS(), false);
  1305.             bot->joinCount++;
  1306.             bot->reopQ.insert(cservice::reopQType::value_type(theChan->getName(), bot->currentTime() + 15) );
  1307.         /*if (tmpChan)
  1308.             {
  1309.             if(theChan->getFlag(sqlChannel::F_NOOP)) bot->deopAllOnChan(tmpChan);
  1310.             if(theChan->getFlag(sqlChannel::F_STRICTOP)) bot->deopAllUnAuthedOnChan(tmpChan);
  1311.             }*/
  1312.         }
  1313.         else if(value == "OFF")
  1314.         {
  1315.             theChan->removeFlag(sqlChannel::F_AUTOJOIN);
  1316.             theChan->setInChan(false);
  1317.             bot->joinCount--;
  1318.             bot->Part(theChan->getName());
  1319.         }
  1320.         else
  1321.         {
  1322.         bot->Notice(theClient,
  1323.             bot->getResponse(theUser,
  1324.                 language::set_cmd_status,
  1325.                 string("%s for %s is %s")).c_str(),
  1326.             option.c_str(),
  1327.             theChan->getName().c_str(),
  1328.             theChan->getFlag(sqlChannel::F_AUTOJOIN) ? "ON" : "OFF");
  1329.         return true;
  1330.         }
  1331.         theChan->commit();
  1332.         bot->Notice(theClient,
  1333.             bot->getResponse(theUser,
  1334.                 language::set_cmd_status,
  1335.                 string("%s for %s is %s")).c_str(),
  1336.             option.c_str(),
  1337.             theChan->getName().c_str(),
  1338.             theChan->getFlag(sqlChannel::F_AUTOJOIN) ? "ON" : "OFF");
  1339.         return true;
  1340.     }
  1341.  
  1342.     if(option == "USERFLAGS")
  1343.     {
  1344.         if(level < level::set::userflag)
  1345.         {
  1346.                 bot->Notice(theClient,
  1347.                                 bot->getResponse(theUser,
  1348.                                 language::insuf_access,
  1349.                                 string("You do not have enough access!")));
  1350.         return false;
  1351.         }
  1352.  
  1353.         int setting;
  1354.         if (value != "")
  1355.         {
  1356.             if (!IsNumeric(value))
  1357.             {
  1358.                 if (value=="NONE")
  1359.                     setting = 0;
  1360.                 else if (value=="OP")
  1361.                     setting = 1;
  1362.                 else if (value=="VOICE")
  1363.                     setting = 2;
  1364.                 else
  1365.                     setting = 3;        /* dummy value to cause failure */
  1366.             } else {
  1367.                 setting = atoi(value.c_str());
  1368.             }
  1369.             if ( (setting < 0) || (setting > 2))
  1370.             {
  1371.                 bot->Notice(theClient,
  1372.                     bot->getResponse(theUser,
  1373.                         language::userflags_syntax,
  1374.                         string("Invalid USERFLAGS setting. Correct values are NONE, OP or VOICE.")));
  1375.                 return false;
  1376.             }
  1377.  
  1378.             theChan->setUserFlags(setting);
  1379.             theChan->commit();
  1380.         } else {
  1381.             setting = theChan->getUserFlags();
  1382.         }
  1383.         /* set value to textual description */
  1384.         switch (setting) {
  1385.             default:    break;
  1386.             case 0:     value = "NONE";     break;
  1387.             case 1:     value = "OP";       break;
  1388.             case 2:     value = "VOICE";    break;
  1389.         }
  1390.         bot->Notice(theClient,
  1391.             bot->getResponse(theUser,
  1392.                 language::userflags_status,
  1393.                 string("USERFLAGS for %s is %s")).c_str(),
  1394.             theChan->getName().c_str(), value.c_str());
  1395.         return true;
  1396.     }
  1397.  
  1398.     if(option == "MASSDEOPPRO")
  1399.     {
  1400.         if(level < level::set::massdeoppro)
  1401.         {
  1402.                     bot->Notice(theClient,
  1403.                                     bot->getResponse(theUser,
  1404.                                     language::insuf_access,
  1405.                                     string("You do not have enough access!")));
  1406.             return true;
  1407.         }
  1408.         // Temporary MASSDEOPPRO range! 0-7.. is this correct?
  1409.         if(!IsNumeric(value))
  1410.         {
  1411.             bot->Notice(theClient,
  1412.                 bot->getResponse(theUser,
  1413.                     language::massdeoppro_syntax,
  1414.                     string("value of MASSDEOPPRO has to be 0-7")));
  1415.             return true;
  1416.         }
  1417.         int numValue = atoi(value.c_str());
  1418.         if(numValue > 7 || numValue < 0)
  1419.         {
  1420.             bot->Notice(theClient,
  1421.                 bot->getResponse(theUser,
  1422.                     language::massdeoppro_syntax,
  1423.                     string("value of MASSDEOPPRO has to be 0-7")));
  1424.             return true;
  1425.         }
  1426.         theChan->setMassDeopPro(numValue);
  1427.         theChan->commit();
  1428.         bot->Notice(theClient,
  1429.             bot->getResponse(theUser,
  1430.                 language::massdeoppro_status,
  1431.                 string("MASSDEOPPRO for %s is set to %d")).c_str(),
  1432.             theChan->getName().c_str(), numValue);
  1433.         return true;
  1434.     }
  1435.  
  1436.     if(option == "DESCRIPTION" || option == "DESC")
  1437.     {
  1438.         string desc = st.assemble(3);
  1439.         if(level < level::set::desc)
  1440.         {
  1441.                 bot->Notice(theClient,
  1442.                                   bot->getResponse(theUser,
  1443.                                   language::insuf_access,
  1444.                                   string("You do not have enough access!")));
  1445.         return true;
  1446.         }
  1447.         if(strlen(desc.c_str()) > 384)
  1448.         {
  1449.             bot->Notice(theClient,
  1450.                 bot->getResponse(theUser,
  1451.                     language::desc_max_len,
  1452.                     string("The DESCRIPTION can be a maximum of 384 chars!")));
  1453.             return true;
  1454.         }
  1455.         theChan->setDescription(desc);
  1456.         theChan->commit();
  1457.  
  1458.         if(desc == "")
  1459.         {
  1460.             bot->Notice(theClient,
  1461.                 bot->getResponse(theUser,
  1462.                     language::desc_cleared,
  1463.                     string("DESCRIPTION for %s is cleared.")).c_str(),
  1464.                 theChan->getName().c_str());
  1465.         } else
  1466.         {
  1467.             bot->Notice(theClient,
  1468.             bot->getResponse(theUser,
  1469.                 language::desc_status,
  1470.                 string("DESCRIPTION for %s is: %s")).c_str(),
  1471.             theChan->getName().c_str(),
  1472.             desc.c_str());
  1473.         }
  1474.  
  1475.         if (theChan->getFlag(sqlChannel::F_AUTOTOPIC))
  1476.         {
  1477.             bot->doAutoTopic(theChan);
  1478.         }
  1479.  
  1480.         return true;
  1481.     }
  1482.  
  1483.     if(option == "URL")
  1484.     {
  1485.         string url = st.assemble(3);
  1486.         if(level < level::set::url)
  1487.         {
  1488.                         bot->Notice(theClient,
  1489.                                         bot->getResponse(theUser,
  1490.                                         language::insuf_access,
  1491.                                         string("You do not have enough access!")));
  1492.             return true;
  1493.         }
  1494.         if(strlen(url.c_str()) > 128) // Gator - changed to 75
  1495.         {
  1496.             bot->Notice(theClient,
  1497.                 bot->getResponse(theUser,
  1498.                     language::url_max_len,
  1499.                     string("The URL can be a maximum of 128 chars!")));
  1500.             return true;
  1501.         }
  1502.         theChan->setURL(url);
  1503.         theChan->commit();
  1504.  
  1505.         if(url == "")
  1506.         {
  1507.             bot->Notice(theClient,
  1508.                 bot->getResponse(theUser,
  1509.                     language::url_cleared,
  1510.                     string("URL for %s is cleared.")).c_str(),
  1511.                 theChan->getName().c_str());
  1512.         } else
  1513.         {
  1514.             bot->Notice(theClient,
  1515.             bot->getResponse(theUser,
  1516.                 language::url_status,
  1517.                 string("URL for %s is: %s")).c_str(),
  1518.             theChan->getName().c_str(),
  1519.             url.c_str());
  1520.         }
  1521.  
  1522.         if (theChan->getFlag(sqlChannel::F_AUTOTOPIC))
  1523.         {
  1524.             bot->doAutoTopic(theChan);
  1525.         }
  1526.  
  1527.         return true;
  1528.     }
  1529.  
  1530.     if(option == "KEYWORDS")
  1531.     {
  1532.         /* Keywords are being processed as a long string. */
  1533.         string keywords = st.assemble(3);
  1534.         if(level < level::set::keywords)
  1535.         {
  1536.                 bot->Notice(theClient,
  1537.                                bot->getResponse(theUser,
  1538.                                language::insuf_access,
  1539.                                string("You do not have enough access!")));
  1540.         return true;
  1541.         }
  1542.         if(strlen(value.c_str()) > 80) // is 80 ok as an max keywords length?
  1543.         {
  1544.         bot->Notice(theClient,
  1545.             bot->getResponse(theUser,
  1546.                 language::keywords_max_len,
  1547.                 string("The string of keywords cannot exceed 80 chars!")));
  1548.         return true;
  1549.         }
  1550.         theChan->setKeywords(keywords);
  1551.         theChan->commit();
  1552.         bot->Notice(theClient,
  1553.             bot->getResponse(theUser,
  1554.                 language::keywords_status,
  1555.                 string("KEYWORDS for %s are: %s")).c_str(),
  1556.             theChan->getName().c_str(),
  1557.             keywords.c_str());
  1558.         return true;
  1559.     }
  1560.  
  1561.     if(option == "MODE")
  1562.     {
  1563.         if(level < level::set::mode)
  1564.         {
  1565.                 bot->Notice(theClient,
  1566.                                bot->getResponse(theUser,
  1567.                                language::insuf_access,
  1568.                                string("You do not have enough access!")));
  1569.         return true;
  1570.         }
  1571.         if (!tmpChan)
  1572.         {
  1573.             bot->Notice(theClient,
  1574.                 bot->getResponse(theUser,
  1575.                     language::no_such_chan,
  1576.                     string("Can't locate channel %s on the network!")).c_str(),
  1577.                 st[1].c_str());
  1578.             return false;
  1579.         }
  1580.  
  1581.         theChan->setChannelMode(tmpChan->getModeString());
  1582.         theChan->commit();
  1583.  
  1584.         bot->Notice(theClient,
  1585.             bot->getResponse(theUser,
  1586.                 language::set_cmd_status,
  1587.                 string("%s for %s is %s")).c_str(),
  1588.             option.c_str(),
  1589.             theChan->getName().c_str(),
  1590.             theChan->getChannelMode().c_str());
  1591.         return true;
  1592.     }
  1593.  
  1594.  
  1595.     if(option == "COMMENT")
  1596.     {
  1597.         /* Check for admin access */
  1598.         int admLevel = bot->getAdminAccessLevel(theUser);
  1599.         if(admLevel < level::set::comment)
  1600.             {
  1601.             /* No need to tell users about admin commands. */
  1602.             Usage(theClient);
  1603.             return true;
  1604.             }
  1605.  
  1606.         string comment = st.assemble(3);
  1607.  
  1608.         if(comment.size() > 200)
  1609.         {
  1610.             bot->Notice(theClient, "The COMMENT can be a maximum of 200 chars!");
  1611.             return true;
  1612.         }
  1613.  
  1614.         theChan->setComment(comment);
  1615.         theChan->commit();
  1616.  
  1617.         if(comment.empty())
  1618.         {
  1619.             bot->Notice(theClient, "COMMENT for %s is cleared.",
  1620.                 theChan->getName().c_str());
  1621.         } else
  1622.         {
  1623.             bot->Notice(theClient, "COMMENT for %s is: %s",
  1624.                 theChan->getName().c_str(), comment.c_str());
  1625.         }
  1626.  
  1627.         return true;
  1628.     }
  1629.  
  1630.  
  1631.     if(option == "FLOATLIM")
  1632.     {
  1633.         if(level < level::set::floatlim)
  1634.         {
  1635.         bot->Notice(theClient,
  1636.                 bot->getResponse(theUser,
  1637.                 language::insuf_access,
  1638.                 string("You do not have enough access!")));
  1639.         return true;
  1640.         }
  1641.         if(value == "ON")
  1642.         {
  1643.             theChan->setFlag(sqlChannel::F_FLOATLIM);
  1644.         }
  1645.         else if(value == "OFF") theChan->removeFlag(sqlChannel::F_FLOATLIM);
  1646.         else
  1647.         {
  1648.         bot->Notice(theClient,
  1649.             bot->getResponse(theUser,
  1650.                 language::set_cmd_syntax_on_off,
  1651.                 string("value of %s must be ON or OFF")).c_str(),
  1652.             option.c_str());
  1653.         return true;
  1654.         }
  1655.         theChan->commit();
  1656.         bot->Notice(theClient,
  1657.             bot->getResponse(theUser,
  1658.                 language::set_cmd_status,
  1659.                 string("%s for %s is %s")).c_str(),
  1660.             option.c_str(),
  1661.             theChan->getName().c_str(),
  1662.             theChan->getFlag(sqlChannel::F_FLOATLIM) ? "ON" : "OFF");
  1663.         return true;
  1664.     }
  1665.  
  1666.     if(option == "FLOATMARGIN")
  1667.     {
  1668.         if(level < level::set::floatlim)
  1669.         {
  1670.         bot->Notice(theClient,
  1671.                 bot->getResponse(theUser,
  1672.                 language::insuf_access,
  1673.                 string("You do not have enough access!")));
  1674.         return true;
  1675.         }
  1676.  
  1677.     unsigned int limit_offset = atoi(value.c_str());
  1678.  
  1679.     if ((limit_offset <= 1) | (limit_offset > 20))
  1680.         {
  1681.             bot->Notice(theClient, "Invalid floating-limit Margin (2-20 Allowed).");
  1682.             return true;
  1683.         }
  1684.  
  1685.     if (limit_offset <= theChan->getLimitGrace())
  1686.         {
  1687.             bot->Notice(theClient, "FLOATMARGIN cannot be less than or equal to FLOATGRACE.");
  1688.             return true;
  1689.         }
  1690.  
  1691.     theChan->setLimitOffset(limit_offset);
  1692.     theChan->commit();
  1693.  
  1694.     bot->Notice(theClient, "Floating-limit Margin now set to %i", limit_offset);
  1695.     return true;
  1696.     }
  1697.  
  1698.     if(option == "FLOATPERIOD")
  1699.     {
  1700.         if(level < level::set::floatlim)
  1701.         {
  1702.         bot->Notice(theClient,
  1703.                 bot->getResponse(theUser,
  1704.                 language::insuf_access,
  1705.                 string("You do not have enough access!")));
  1706.         return true;
  1707.         }
  1708.  
  1709.     unsigned int limit_period = atoi(value.c_str());
  1710.  
  1711.     if ((limit_period < 20) | (limit_period > 200))
  1712.         {
  1713.             bot->Notice(theClient, "Invalid floating-limit period (20-200 Allowed).");
  1714.             return true;
  1715.         }
  1716.  
  1717.     theChan->setLimitPeriod(limit_period);
  1718.     theChan->commit();
  1719.  
  1720.     bot->Notice(theClient, "Floating-limit period now set to %i", limit_period);
  1721.     return true;
  1722.     }
  1723.  
  1724.     if(option == "FLOATGRACE")
  1725.     {
  1726.         if(level < level::set::floatlim)
  1727.         {
  1728.         bot->Notice(theClient,
  1729.                 bot->getResponse(theUser,
  1730.                 language::insuf_access,
  1731.                 string("You do not have enough access!")));
  1732.         return true;
  1733.         }
  1734.  
  1735.     unsigned int limit_grace = atoi(value.c_str());
  1736.  
  1737.     if (limit_grace > 19)
  1738.         {
  1739.             bot->Notice(theClient, "Invalid floating-grace setting (0-19 Allowed).");
  1740.             return true;
  1741.         }
  1742.  
  1743.     if (limit_grace > theChan->getLimitOffset())
  1744.         {
  1745.             bot->Notice(theClient, "FLOATGRACE cannot be greater than FLOATMARGIN.");
  1746.             return true;
  1747.         }
  1748.  
  1749.     theChan->setLimitGrace(limit_grace);
  1750.     theChan->commit();
  1751.  
  1752.     bot->Notice(theClient, "Floating-limit grace now set to %i", limit_grace);
  1753.     return true;
  1754.     }
  1755.  
  1756.     if(option == "FLOATMAX")
  1757.     {
  1758.         if(level < level::set::floatlim)
  1759.         {
  1760.         bot->Notice(theClient,
  1761.                 bot->getResponse(theUser,
  1762.                 language::insuf_access,
  1763.                 string("You do not have enough access!")));
  1764.         return true;
  1765.         }
  1766.  
  1767.     unsigned int limit_max = atoi(value.c_str());
  1768.  
  1769.     if (limit_max > 65536)
  1770.         {
  1771.             bot->Notice(theClient, "Invalid floating-limit max (0-65536 Allowed).");
  1772.             return true;
  1773.         }
  1774.  
  1775.  
  1776.     theChan->setLimitMax(limit_max);
  1777.     theChan->commit();
  1778.  
  1779.     if (!limit_max)
  1780.     {
  1781.         bot->Notice(theClient, "Floating-limit MAX setting has now been disabled.");
  1782.     } else {
  1783.         bot->Notice(theClient, "Floating-limit max now set to %i", limit_max);
  1784.     }
  1785.     return true;
  1786.     }
  1787.  
  1788.     bot->Notice(theClient,
  1789.         bot->getResponse(theUser,
  1790.             language::mode_invalid,
  1791.             string("ERROR: Invalid channel setting.")));
  1792.     return true ;
  1793. }
  1794.  
  1795. } // namespace gnuworld.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement