/** * chanfix.cc * * Copyright (C) 2003 Reed Loden * Matthias Crauwels * Jimmy Lipham * Neil Spierling * * Automatically and manually fix opless and taken over channels * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, * USA. * * $Id: chanfix.cc,v 1.16 2010/03/04 04:24:11 hidden1 Exp $ */ #include #include #include #include #include #include #include #include #include #include #include #include #include "dbHandle.h" #include "gnuworld_config.h" #include "client.h" #include "EConfig.h" #include "Network.h" #include "server.h" #include "StringTokenizer.h" #include "chanfix.h" #include "defs.h" #include "chanfix_misc.h" #include "chanfixCommands.h" #include "responses.h" #include "sqlChanOp.h" #include "sqlChannel.h" #include "sqlcfUser.h" #ifdef CHANFIX_HAVE_BOOST_THREAD #include #endif /* CHANFIX_HAVE_BOOST_THREAD */ RCSTAG("$Id: chanfix.cc,v 1.16 2010/03/04 04:24:11 hidden1 Exp $"); namespace gnuworld { namespace cf { short currentDay; /* * Exported function used by moduleLoader to gain an * instance of this module. */ extern "C" { xClient* _gnuwinit(const std::string& args) { return new chanfix( args ); } } /** * This constructor calls the base class constructor. The xClient * constructor will open the configuration file given and retrieve * basic client info (nick/user/host/etc). * Any additional processing must be done here. */ chanfix::chanfix( const std::string& configFileName ) : xClient( configFileName ) { /* Load the config file */ readConfigFile(configFileName); /* Initial state */ currentState = INIT; /* Initial finding of the channel service */ chanServLinked = false; /* Initial update status */ updateInProgress = false; std::string dbString = "host=" + sqlHost + " dbname=" + sqlDB + " port=" + sqlPort + " user=" + sqlcfUsername + " password=" + sqlPass; theManager = sqlManager::getInstance(dbString); /* Open our logfiles for writing */ adminLog.open(adminLogFile.c_str(), std::ios::out | std::ios::app); debugLog.open(debugLogFile.c_str(), std::ios::out | std::ios::app); /* Register the commands we want to use */ RegisterCommand(new ADDFLAGCommand(this, "ADDFLAG", " ", 3, sqlcfUser::F_USERMANAGER | sqlcfUser::F_SERVERADMIN )); RegisterCommand(new ADDHOSTCommand(this, "ADDHOST", " ", 3, sqlcfUser::F_USERMANAGER | sqlcfUser::F_SERVERADMIN )); RegisterCommand(new ADDNOTECommand(this, "ADDNOTE", "<#channel> ", 3, sqlcfUser::F_COMMENT )); RegisterCommand(new ADDUSERCommand(this, "ADDUSER", " [host]", 2, sqlcfUser::F_USERMANAGER | sqlcfUser::F_SERVERADMIN )); RegisterCommand(new ALERTCommand(this, "ALERT", "<#channel> ", 3, sqlcfUser::F_COMMENT )); RegisterCommand(new BLOCKCommand(this, "BLOCK", "<#channel> ", 3, sqlcfUser::F_BLOCK )); RegisterCommand(new CANFIXCommand(this, "CANFIX", "<#channel>", 2, 0 )); RegisterCommand(new CHANFIXCommand(this, "CHANFIX", "<#channel> [override] [contact]", 2, 0 /* Set to 0 to allow all opers to access it, otherwise this should be sqlcfUser::F_CHANFIX */ )); RegisterCommand(new CHECKCommand(this, "CHECK", "<#channel>", 2, 0 )); #ifdef CHANFIX_DEBUG RegisterCommand(new DEBUGCommand(this, "DEBUG", "", 2, sqlcfUser::F_OWNER )); #endif /* CHANFIX_DEBUG */ RegisterCommand(new DELFLAGCommand(this, "DELFLAG", " ", 3, sqlcfUser::F_USERMANAGER | sqlcfUser::F_SERVERADMIN )); RegisterCommand(new DELHOSTCommand(this, "DELHOST", " ", 3, sqlcfUser::F_USERMANAGER | sqlcfUser::F_SERVERADMIN )); RegisterCommand(new DELNOTECommand(this, "DELNOTE", "<#channel> ", 3, sqlcfUser::F_COMMENT )); RegisterCommand(new DELUSERCommand(this, "DELUSER", "", 2, sqlcfUser::F_USERMANAGER | sqlcfUser::F_SERVERADMIN )); RegisterCommand(new HELPCommand(this, "HELP", "[command]", 1, 0 )); RegisterCommand(new HISTORYCommand(this, "HISTORY", "<#channel>", 2, 0 )); RegisterCommand(new INFOCommand(this, "INFO", "<#channel>", 2, 0 )); RegisterCommand(new INVITECommand(this, "INVITE", "", 1, sqlcfUser::F_OWNER )); RegisterCommand(new LASTCOMCommand(this, "LASTCOM", "[amount of commands] [days from]", 1, sqlcfUser::F_OWNER )); RegisterCommand(new LISTBLOCKEDCommand(this, "LISTBLOCKED", "", 1, sqlcfUser::F_BLOCK )); RegisterCommand(new LISTHOSTSCommand(this, "LISTHOSTS", "[username]", 1, sqlcfUser::F_LOGGEDIN )); RegisterCommand(new OPLISTCommand(this, "OPLIST", "<#channel> [-all] [-days]", 2, 0 )); RegisterCommand(new OPNICKSCommand(this, "OPNICKS", "<#channel>", 2, 0 )); #ifdef ENABLE_QUOTE RegisterCommand(new QUOTECommand(this, "QUOTE", "", 2, sqlcfUser::F_OWNER )); #endif /* ENABLE_QUOTE */ RegisterCommand(new REHASHCommand(this, "REHASH", "", 1, sqlcfUser::F_OWNER )); RegisterCommand(new RELOADCommand(this, "RELOAD", "[reason]", 1, sqlcfUser::F_OWNER )); RegisterCommand(new REQUESTOPCommand(this, "REQUESTOP", isAllowingTopOpAlert() ? "<#channel> [contact]" : "<#channel>", 2, 0 )); RegisterCommand(new SCORECommand(this, "SCORE", "<#channel> [account|=nick]", 2, 0 )); RegisterCommand(new SCORECommand(this, "CSCORE", "<#channel> [account|=nick]", 2, 0 )); RegisterCommand(new SAYCommand(this, "SAY", "<#channel> ", 3, sqlcfUser::F_OWNER )); RegisterCommand(new SETCommand(this, "SET", "