#include "inspircd.h"
#include <stdarg.h>
-#include "configreader.h"
-#include "users.h"
-#include "modules.h"
#include "wildcard.h"
-#include "mode.h"
#include "xline.h"
#include "exitcodes.h"
void InspIRCd::Log(int level, const char* text, ...)
{
/* sanity check, just in case */
- if (!this->Config)
+ if (!this->Config || !this->Logger)
return;
/* Do this check again here so that we save pointless vsnprintf calls */
void InspIRCd::Log(int level, const std::string &text)
{
/* sanity check, just in case */
- if (!this->Config)
+ if (!this->Config || !this->Logger)
return;
/* If we were given -debug we output all messages, regardless of configured loglevel */
void InspIRCd::WriteOpers(const std::string &text)
{
- for (std::vector<userrec*>::iterator i = this->all_opers.begin(); i != this->all_opers.end(); i++)
+ for (std::list<userrec*>::iterator i = this->all_opers.begin(); i != this->all_opers.end(); i++)
{
userrec* a = *i;
if (IS_LOCAL(a) && a->IsModeSet('s'))
/* Find a user record by nickname and return a pointer to it */
userrec* InspIRCd::FindNick(const std::string &nick)
{
+ if (!nick.empty() && isdigit(*nick.begin()))
+ return FindUUID(nick);
+
user_hash::iterator iter = clientlist->find(nick);
if (iter == clientlist->end())
userrec* InspIRCd::FindNick(const char* nick)
{
+ if (isdigit(*nick))
+ return FindUUID(nick);
+
user_hash::iterator iter = clientlist->find(nick);
if (iter == clientlist->end())
return iter->second;
}
+userrec* InspIRCd::FindNickOnly(const std::string &nick)
+{
+ user_hash::iterator iter = clientlist->find(nick);
+
+ if (iter == clientlist->end())
+ return NULL;
+
+ return iter->second;
+}
+
+userrec* InspIRCd::FindNickOnly(const char* nick)
+{
+ user_hash::iterator iter = clientlist->find(nick);
+
+ if (iter == clientlist->end())
+ return NULL;
+
+ return iter->second;
+}
+
+userrec *InspIRCd::FindUUID(const std::string &uid)
+{
+ return FindUUID(uid.c_str());
+}
+
+userrec *InspIRCd::FindUUID(const char *uid)
+{
+ user_hash::iterator finduuid = uuidlist->find(uid);
+
+ if (finduuid == uuidlist->end())
+ return NULL;
+
+ return finduuid->second;
+}
+
/* find a channel record by channel name and return a pointer to it */
chanrec* InspIRCd::FindChan(const char* chan)
{
}
/* true for valid nickname, false else */
-bool InspIRCd::IsNick(const char* n)
+bool IsNickHandler::Call(const char* n)
{
if (!n || !*n)
return false;
}
/* return true for good ident, false else */
-bool InspIRCd::IsIdent(const char* n)
+bool IsIdentHandler::Call(const char* n)
{
if (!n || !*n)
return false;
}
/* open the proper logfile */
-void InspIRCd::OpenLog(char** argv, int argc)
+bool InspIRCd::OpenLog(char** argv, int argc)
{
Config->MyDir = Config->GetFullProgDir();
{
if (Config->logpath.empty())
{
-#ifndef DARWIN
Config->logpath = Config->MyDir + "/ircd.log";
-#else
- Config->logpath = "/var/log/ircd.log";
-#endif
}
Config->log_file = fopen(Config->logpath.c_str(),"a+");
if (!Config->log_file)
{
- printf("ERROR: Could not write to logfile %s: %s\n\n", Config->logpath.c_str(), strerror(errno));
- Exit(EXIT_STATUS_LOG);
+ this->Logger = NULL;
+ return false;
}
this->Logger = new FileLogger(this, Config->log_file);
+ return true;
}
void InspIRCd::CheckRoot()
{
-#ifndef DARWIN
if (geteuid() == 0)
{
printf("WARNING!!! You are running an irc server as ROOT!!! DO NOT DO THIS!!!\n\n");
this->Log(DEFAULT,"Cant start as root");
-#else
- if (geteuid() != 16)
- {
- printf("WARNING!!! You are not running inspircd as the ircdaemon user!!! YOU CAN NOT DO THIS!!!\n\n");
- this->Log(DEFAULT,"Must start as user ircdaemon");
-#endif
Exit(EXIT_STATUS_ROOT);
}
}
}
}
-/* We must load the modules AFTER initializing the socket engine, now */
-void InspIRCd::LoadAllModules()
-{
- char configToken[MAXBUF];
- Config->module_names.clear();
- this->ModCount = -1;
-
- for (int count = 0; count < Config->ConfValueEnum(Config->config_data, "module"); count++)
- {
- Config->ConfValue(Config->config_data, "module", "name", count, configToken, MAXBUF);
- printf_c("[\033[1;32m*\033[0m] Loading module:\t\033[1;32m%s\033[0m\n",configToken);
-
- if (!this->LoadModule(configToken))
- {
- this->Log(DEFAULT,"There was an error loading the module '%s': %s", configToken, this->ModuleError());
- printf_c("\n[\033[1;31m*\033[0m] There was an error loading the module '%s': %s\n\n", configToken, this->ModuleError());
- Exit(EXIT_STATUS_MODULE);
- }
- }
- printf_c("\nA total of \033[1;32m%d\033[0m module%s been loaded.\n", this->ModCount+1, this->ModCount+1 == 1 ? " has" : "s have");
- this->Log(DEFAULT,"Total loaded modules: %d", this->ModCount+1);
-}
-
void InspIRCd::SendWhoisLine(userrec* user, userrec* dest, int numeric, const std::string &text)
{
std::string copy_text = text;
this->SendWhoisLine(user, dest, numeric, std::string(textbuffer));
}
-