The InspIRCd Project
Home | Developers | Wiki | Forums | Bug Tracker | SVN | Download
Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

m_antibottler.cpp

Go to the documentation of this file.
00001 /*       +------------------------------------+
00002  *       | Inspire Internet Relay Chat Daemon |
00003  *       +------------------------------------+
00004  *
00005  *  InspIRCd: (C) 2002-2008 InspIRCd Development Team
00006  * See: http://www.inspircd.org/wiki/index.php/Credits
00007  *
00008  * This program is free but copyrighted software; see
00009  *            the file COPYING for details.
00010  *
00011  * ---------------------------------------------------
00012  */
00013 
00014 #include "inspircd.h"
00015 
00016 /* $ModDesc: Changes the ident of connecting bottler clients to 'bottler' */
00017 
00018 class ModuleAntiBottler : public Module
00019 {
00020  public:
00021         ModuleAntiBottler(InspIRCd* Me)
00022                 : Module(Me)
00023         {
00024 
00025                 Implementation eventlist[] = { I_OnPreCommand };
00026                 ServerInstance->Modules->Attach(eventlist, this, 1);
00027         }
00028 
00029 
00030 
00031         virtual ~ModuleAntiBottler()
00032         {
00033         }
00034 
00035         virtual Version GetVersion()
00036         {
00037                 return Version("$Id: m_antibottler.cpp 10291 2008-08-25 20:35:51Z w00t $",VF_VENDOR,API_VERSION);
00038         }
00039 
00040         virtual int OnPreCommand(std::string &command, std::vector<std::string> &parameters, User *user, bool validated, const std::string &original_line)
00041         {
00042                 char data[MAXBUF];
00043                 strlcpy(data,original_line.c_str(),MAXBUF);
00044                 bool not_bottler = false;
00045                 if (!strncmp(data,"user ",5))
00046                 {
00047                         for (char* j = data; *j; j++)
00048                         {
00049                                 if (*j == ':')
00050                                         break;
00051 
00052                                 if (*j == '"')
00053                                 {
00054                                         not_bottler = true;
00055                                 }
00056                         }
00057                         // Bug Fix (#14) -- FCS
00058                         if (!*data)
00059                                 return 0;
00060 
00061                         strtok(data," ");
00062                         char *ident = strtok(NULL," ");
00063                         char *local = strtok(NULL," ");
00064                         char *remote = strtok(NULL," :");
00065                         char *gecos = strtok(NULL,"\r\n");
00066 
00067                         if (!ident || !local || !remote || !gecos)
00068                                 return 0;
00069 
00070                         for (char* j = remote; *j; j++)
00071                         {
00072                                 if (((*j < '0') || (*j > '9')) && (*j != '.'))
00073                                 {
00074                                         not_bottler = true;
00075                                 }
00076                         }
00077 
00078                         if (!not_bottler)
00079                         {
00080                                 std::string strgecos = std::string(gecos) + "[Possible bottler, ident: " + std::string(ident) + "]";
00081                                 std::vector<std::string> modified;
00082                                 modified.push_back("bottler");
00083                                 modified.push_back(local);
00084                                 modified.push_back(remote);
00085                                 modified.push_back(strgecos);
00086                                 ServerInstance->Parser->CallHandler("USER", modified, user);
00087                                 return 1;
00088                         }
00089                 }
00090                 return 0;
00091         }
00092 };
00093 
00094 MODULE_INIT(ModuleAntiBottler)