-/* +------------------------------------+
- * | Inspire Internet Relay Chat Daemon |
- * +------------------------------------+
+/* ---------------------------------------------------------------------
+ *
+ * +------------------------------------+
+ * | Inspire Internet Relay Chat Daemon |
+ * +------------------------------------+
*
- * InspIRCd is copyright (C) 2002-2006 ChatSpike-Dev.
- * E-mail:
- * <brain@chatspike.net>
- * <Craig@chatspike.net>
+ * InspIRCd is copyright (C) 2002-2006 ChatSpike-Dev.
+ * E-mail:
+ * <brain@chatspike.net>
+ * <Craig@chatspike.net>
*
- * Written by Craig Edwards, Craig McLure, and others.
- * This program is free but copyrighted software; see
- * the file COPYING for details.
+ * Written by Craig Edwards, Craig McLure, and others.
+ * This program is free but copyrighted 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, version 2
+ * (two) ONLY.
*
- * ---------------------------------------------------
+ * 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., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ * ---------------------------------------------------------------------
*/
-/* Now with added unF! ;) */
-
+#include <algorithm>
#include "inspircd_config.h"
#include "inspircd.h"
#include "configreader.h"
#include <fcntl.h>
#include <sys/errno.h>
#include <sys/ioctl.h>
+#include <signal.h>
#include <time.h>
#include <string>
#include <exception>
int WHOWAS_STALE = 48; // default WHOWAS Entries last 2 days before they go 'stale'
int WHOWAS_MAX = 100; // default 100 people maximum in the WHOWAS list
-extern std::vector<Module*> modules;
-extern std::vector<ircd_module*> factory;
+extern ModuleList modules;
+extern FactoryList factory;
std::vector<InspSocket*> module_sockets;
std::vector<userrec*> local_users;
servernamelist servernames;
char lowermap[255];
-void AddServerName(std::string servername)
+void AddServerName(const std::string &servername)
{
log(DEBUG,"Adding server name: %s",servername.c_str());
- for (servernamelist::iterator a = servernames.begin(); a < servernames.end(); a++)
- {
- if (*a == servername)
- return;
- }
- servernames.push_back(servername);
+
+ if(find(servernames.begin(), servernames.end(), servername) == servernames.end())
+ servernames.push_back(servername); /* Wasn't already there. */
}
-const char* FindServerNamePtr(std::string servername)
+const char* FindServerNamePtr(const std::string &servername)
{
- for (servernamelist::iterator a = servernames.begin(); a < servernames.end(); a++)
- {
- if (*a == servername)
- return a->c_str();
+ servernamelist::iterator iter = find(servernames.begin(), servernames.end(), servername);
+
+ if(iter == servernames.end())
+ {
+ AddServerName(servername);
+ iter = --servernames.end();
}
- AddServerName(servername);
- return FindServerNamePtr(servername);
+
+ return iter->c_str();
}
-bool FindServerName(std::string servername)
+bool FindServerName(const std::string &servername)
{
- for (servernamelist::iterator a = servernames.begin(); a < servernames.end(); a++)
- {
- if (*a == servername)
- return true;
- }
- return false;
+ return (find(servernames.begin(), servernames.end(), servername) != servernames.end());
}
void Exit(int status)
exit (status);
}
-void Start()
+void InspIRCd::Start()
{
printf("\033[1;32mInspire Internet Relay Chat Server, compiled %s at %s\n",__DATE__,__TIME__);
printf("(C) ChatSpike Development team.\033[0m\n\n");
- printf("Developers:\t\t\033[1;32mBrain, FrostyCoolSlug, w00t, Om\033[0m\n");
+ printf("Developers:\t\t\033[1;32mBrain, FrostyCoolSlug, w00t, Om, Special\033[0m\n");
printf("Others:\t\t\t\033[1;32mSee /INFO Output\033[0m\n");
printf("Name concept:\t\t\033[1;32mLord_Zathras\033[0m\n\n");
}
FOREACH_MOD(I_OnRehash,OnRehash(""));
}
-void SetSignals()
+void InspIRCd::SetSignals()
{
signal (SIGALRM, SIG_IGN);
signal (SIGHUP, Rehash);
signal (SIGSEGV, Error);
}
-bool DaemonSeed()
+bool InspIRCd::DaemonSeed()
{
int childpid;
if ((childpid = fork ()) < 0)
return true;
}
-void WritePID(const std::string &filename)
+void InspIRCd::WritePID(const std::string &filename)
{
std::ofstream outfile(filename.c_str());
if (outfile.is_open())
InspIRCd::InspIRCd(int argc, char** argv)
{
- Start();
+ this->Start();
module_sockets.clear();
this->startup_time = time(NULL);
srand(time(NULL));
memset(&Config->implement_lists,0,sizeof(Config->implement_lists));
printf("\n");
- SetSignals();
+ this->SetSignals();
if (!Config->nofork)
{
- if (!DaemonSeed())
+ if (!this->DaemonSeed())
{
printf("ERROR: could not go into daemon mode. Shutting down.\n");
Exit(ERROR);
return MODERR;
}
-void InspIRCd::erase_factory(int j)
+void InspIRCd::EraseFactory(int j)
{
int v = 0;
for (std::vector<ircd_module*>::iterator t = factory.begin(); t != factory.end(); t++)
}
}
-void InspIRCd::erase_module(int j)
+void InspIRCd::EraseModule(int j)
{
int v1 = 0;
for (std::vector<Module*>::iterator m = modules.begin(); m!= modules.end(); m++)
{
if (v1 == j)
{
- delete *m;
+ DELETE(*m);
modules.erase(m);
modules.push_back(NULL);
break;
// found the module
log(DEBUG,"Deleting module...");
- erase_module(j);
+ this->EraseModule(j);
log(DEBUG,"Erasing module entry...");
- erase_factory(j);
+ this->EraseFactory(j);
log(DEBUG,"Removing dependent commands...");
Parser->RemoveCommands(filename);
log(DEFAULT,"Module %s unloaded",filename);
if ((s) && (!s->Poll()))
{
- log(DEBUG,"inspircd.cpp: Socket poll returned false, close and bail");
+ log(DEBUG,"Socket poll returned false, close and bail");
SE->DelFd(s->GetFd());
socket_ref[activefds[activefd]] = NULL;
for (std::vector<InspSocket*>::iterator a = module_sockets.begin(); a < module_sockets.end(); a++)
{
- s_del = (InspSocket*)*a;
+ s_del = *a;
if ((s_del) && (s_del->GetFd() == activefds[activefd]))
{
module_sockets.erase(a);
}
}
s->Close();
- delete s;
+ DELETE(s);
}
else if (!s)
{
{
try
{
- Config->GetIOHook(in_port)->OnRawSocketAccept(incomingSockfd, (char*)inet_ntoa(client.sin_addr), in_port);
+ Config->GetIOHook(in_port)->OnRawSocketAccept(incomingSockfd, inet_ntoa(client.sin_addr), in_port);
}
catch (ModuleException& modexcept)
{
for (int count = 0; count < stats->BoundPortCount; count++)
SE->AddFd(openSockfd[count],true,X_LISTEN);
- WritePID(Config->PID);
+ this->WritePID(Config->PID);
/* main loop, this never returns */
expire_run = false;
{
ServerInstance = new InspIRCd(argc, argv);
ServerInstance->Run();
- delete ServerInstance;
+ DELETE(ServerInstance);
}
catch (std::bad_alloc)
{