2005-05-15 04:21:31 +00:00
|
|
|
/* +------------------------------------+
|
|
|
|
* | Inspire Internet Relay Chat Daemon |
|
|
|
|
* +------------------------------------+
|
|
|
|
*
|
2006-12-15 21:45:30 +00:00
|
|
|
* InspIRCd: (C) 2002-2007 InspIRCd Development Team
|
|
|
|
* See: http://www.inspircd.org/wiki/index.php/Credits
|
2005-05-15 04:21:31 +00:00
|
|
|
*
|
|
|
|
* This program is free but copyrighted software; see
|
2006-12-15 21:45:30 +00:00
|
|
|
* the file COPYING for details.
|
2005-05-15 04:21:31 +00:00
|
|
|
*
|
|
|
|
* ---------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
2007-05-21 18:22:16 +00:00
|
|
|
#include "inspircd.h"
|
2006-04-08 17:05:48 +00:00
|
|
|
#include <stdarg.h>
|
|
|
|
#include "configreader.h"
|
2005-05-15 03:03:23 +00:00
|
|
|
#include "users.h"
|
|
|
|
#include "modules.h"
|
|
|
|
#include "wildcard.h"
|
|
|
|
#include "mode.h"
|
|
|
|
#include "xline.h"
|
2006-12-23 16:40:09 +00:00
|
|
|
#include "exitcodes.h"
|
2005-05-15 03:03:23 +00:00
|
|
|
|
2006-03-02 14:57:40 +00:00
|
|
|
static char TIMESTR[26];
|
|
|
|
static time_t LAST = 0;
|
|
|
|
|
2006-08-09 14:20:04 +00:00
|
|
|
/** Log()
|
2006-03-06 03:20:25 +00:00
|
|
|
* Write a line of text `text' to the logfile (and stdout, if in nofork) if the level `level'
|
|
|
|
* is greater than the configured loglevel.
|
|
|
|
*/
|
2006-08-09 13:19:41 +00:00
|
|
|
void InspIRCd::Log(int level, const char* text, ...)
|
2005-05-15 03:03:23 +00:00
|
|
|
{
|
2006-12-12 23:31:13 +00:00
|
|
|
/* Do this check again here so that we save pointless vsnprintf calls */
|
|
|
|
if ((level < Config->LogLevel) && !Config->forcedebug)
|
|
|
|
return;
|
|
|
|
|
2006-03-08 03:35:21 +00:00
|
|
|
va_list argsPtr;
|
2006-12-11 20:55:59 +00:00
|
|
|
char textbuffer[65536];
|
2006-03-02 14:57:40 +00:00
|
|
|
|
2006-08-09 13:19:41 +00:00
|
|
|
va_start(argsPtr, text);
|
2006-12-11 20:55:59 +00:00
|
|
|
vsnprintf(textbuffer, 65536, text, argsPtr);
|
2006-08-09 13:19:41 +00:00
|
|
|
va_end(argsPtr);
|
|
|
|
|
2006-08-11 12:15:03 +00:00
|
|
|
this->Log(level, std::string(textbuffer));
|
2006-08-09 13:19:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void InspIRCd::Log(int level, const std::string &text)
|
|
|
|
{
|
2006-08-11 12:15:03 +00:00
|
|
|
if (!this->Config)
|
2006-08-09 11:33:10 +00:00
|
|
|
return;
|
|
|
|
|
2006-04-07 12:21:11 +00:00
|
|
|
/* If we were given -debug we output all messages, regardless of configured loglevel */
|
2006-08-11 12:15:03 +00:00
|
|
|
if ((level < Config->LogLevel) && !Config->forcedebug)
|
2006-03-08 03:35:21 +00:00
|
|
|
return;
|
2006-03-02 14:57:40 +00:00
|
|
|
|
2006-08-11 12:15:03 +00:00
|
|
|
if (Time() != LAST)
|
2006-03-02 14:57:40 +00:00
|
|
|
{
|
2006-08-11 12:15:03 +00:00
|
|
|
time_t local = Time();
|
2006-08-11 09:23:46 +00:00
|
|
|
struct tm *timeinfo = localtime(&local);
|
2006-03-08 03:35:21 +00:00
|
|
|
|
2006-03-02 14:57:40 +00:00
|
|
|
strlcpy(TIMESTR,asctime(timeinfo),26);
|
|
|
|
TIMESTR[24] = ':';
|
2006-08-11 12:15:03 +00:00
|
|
|
LAST = Time();
|
2006-03-02 14:57:40 +00:00
|
|
|
}
|
2005-05-15 03:03:23 +00:00
|
|
|
|
2006-08-11 12:15:03 +00:00
|
|
|
if (Config->log_file && Config->writelog)
|
2006-03-08 03:35:21 +00:00
|
|
|
{
|
2006-08-18 22:04:09 +00:00
|
|
|
std::string out = std::string(TIMESTR) + " " + text.c_str() + "\n";
|
2006-08-18 22:01:26 +00:00
|
|
|
this->Logger->WriteLogLine(out);
|
2006-04-07 12:21:11 +00:00
|
|
|
}
|
2006-08-09 13:19:41 +00:00
|
|
|
|
2006-08-11 12:15:03 +00:00
|
|
|
if (Config->nofork)
|
2006-04-07 12:21:11 +00:00
|
|
|
{
|
2006-08-09 13:19:41 +00:00
|
|
|
printf("%s %s\n", TIMESTR, text.c_str());
|
2006-03-08 03:35:21 +00:00
|
|
|
}
|
2005-05-15 03:03:23 +00:00
|
|
|
}
|
|
|
|
|
2006-08-10 14:43:29 +00:00
|
|
|
std::string InspIRCd::GetServerDescription(const char* servername)
|
2005-05-15 03:03:23 +00:00
|
|
|
{
|
2006-12-18 18:42:17 +00:00
|
|
|
std::string description;
|
2006-03-08 03:35:21 +00:00
|
|
|
|
2006-08-10 20:27:51 +00:00
|
|
|
FOREACH_MOD_I(this,I_OnGetServerDescription,OnGetServerDescription(servername,description));
|
2006-03-08 03:35:21 +00:00
|
|
|
|
2005-11-30 14:28:22 +00:00
|
|
|
if (description != "")
|
|
|
|
{
|
|
|
|
return description;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-03-08 03:35:21 +00:00
|
|
|
// not a remote server that can be found, it must be me.
|
2006-08-10 14:43:29 +00:00
|
|
|
return Config->ServerDesc;
|
2005-11-30 14:28:22 +00:00
|
|
|
}
|
2005-05-15 03:03:23 +00:00
|
|
|
}
|
|
|
|
|
2006-03-08 10:37:49 +00:00
|
|
|
/* XXX - We don't use WriteMode for this because WriteMode is very slow and
|
|
|
|
* this isnt. Basically WriteMode has to iterate ALL the users 'n' times for
|
|
|
|
* the number of modes provided, e.g. if you send WriteMode 'og' to write to
|
|
|
|
* opers with globops, and you have 2000 users, thats 4000 iterations. WriteOpers
|
|
|
|
* uses the oper list, which means if you have 2000 users but only 5 opers,
|
|
|
|
* it iterates 5 times.
|
|
|
|
*/
|
2006-08-10 14:43:29 +00:00
|
|
|
void InspIRCd::WriteOpers(const char* text, ...)
|
2005-05-15 03:03:23 +00:00
|
|
|
{
|
2006-03-08 03:35:21 +00:00
|
|
|
char textbuffer[MAXBUF];
|
|
|
|
va_list argsPtr;
|
|
|
|
|
|
|
|
va_start(argsPtr, text);
|
|
|
|
vsnprintf(textbuffer, MAXBUF, text, argsPtr);
|
|
|
|
va_end(argsPtr);
|
|
|
|
|
2006-08-10 14:43:29 +00:00
|
|
|
this->WriteOpers(std::string(textbuffer));
|
2006-04-04 06:43:26 +00:00
|
|
|
}
|
|
|
|
|
2006-08-10 14:43:29 +00:00
|
|
|
void InspIRCd::WriteOpers(const std::string &text)
|
2006-04-04 06:43:26 +00:00
|
|
|
{
|
2006-08-10 21:39:57 +00:00
|
|
|
for (std::vector<userrec*>::iterator i = this->all_opers.begin(); i != this->all_opers.end(); i++)
|
2006-03-08 03:35:21 +00:00
|
|
|
{
|
|
|
|
userrec* a = *i;
|
2006-08-10 14:43:29 +00:00
|
|
|
if (IS_LOCAL(a) && a->modes[UM_SERVERNOTICE])
|
2006-03-08 03:35:21 +00:00
|
|
|
{
|
2006-08-10 14:43:29 +00:00
|
|
|
// send server notices to all with +s
|
|
|
|
a->WriteServ("NOTICE %s :%s",a->nick,text.c_str());
|
2006-03-08 03:35:21 +00:00
|
|
|
}
|
|
|
|
}
|
2005-05-15 03:03:23 +00:00
|
|
|
}
|
|
|
|
|
2006-08-09 17:52:10 +00:00
|
|
|
void InspIRCd::ServerNoticeAll(char* text, ...)
|
2005-12-04 17:16:22 +00:00
|
|
|
{
|
|
|
|
if (!text)
|
|
|
|
return;
|
|
|
|
|
2006-03-08 03:35:21 +00:00
|
|
|
char textbuffer[MAXBUF];
|
2006-03-11 14:05:57 +00:00
|
|
|
char formatbuffer[MAXBUF];
|
2006-03-08 03:35:21 +00:00
|
|
|
va_list argsPtr;
|
|
|
|
va_start (argsPtr, text);
|
|
|
|
vsnprintf(textbuffer, MAXBUF, text, argsPtr);
|
|
|
|
va_end(argsPtr);
|
|
|
|
|
2006-08-10 20:27:51 +00:00
|
|
|
snprintf(formatbuffer,MAXBUF,"NOTICE $%s :%s",Config->ServerName,textbuffer);
|
2006-03-11 14:05:57 +00:00
|
|
|
|
2006-03-08 03:35:21 +00:00
|
|
|
for (std::vector<userrec*>::const_iterator i = local_users.begin(); i != local_users.end(); i++)
|
|
|
|
{
|
2006-08-08 18:59:13 +00:00
|
|
|
userrec* t = *i;
|
|
|
|
t->WriteServ(std::string(formatbuffer));
|
2006-03-08 03:35:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-08-09 17:52:10 +00:00
|
|
|
void InspIRCd::ServerPrivmsgAll(char* text, ...)
|
2006-03-08 03:35:21 +00:00
|
|
|
{
|
|
|
|
if (!text)
|
|
|
|
return;
|
|
|
|
|
|
|
|
char textbuffer[MAXBUF];
|
2006-03-11 14:05:57 +00:00
|
|
|
char formatbuffer[MAXBUF];
|
2006-03-08 03:35:21 +00:00
|
|
|
va_list argsPtr;
|
|
|
|
va_start (argsPtr, text);
|
|
|
|
vsnprintf(textbuffer, MAXBUF, text, argsPtr);
|
|
|
|
va_end(argsPtr);
|
|
|
|
|
2006-08-10 20:27:51 +00:00
|
|
|
snprintf(formatbuffer,MAXBUF,"PRIVMSG $%s :%s",Config->ServerName,textbuffer);
|
2006-03-11 14:05:57 +00:00
|
|
|
|
2006-03-08 03:35:21 +00:00
|
|
|
for (std::vector<userrec*>::const_iterator i = local_users.begin(); i != local_users.end(); i++)
|
|
|
|
{
|
2006-08-08 18:59:13 +00:00
|
|
|
userrec* t = *i;
|
|
|
|
t->WriteServ(std::string(formatbuffer));
|
2006-03-08 03:35:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-08-09 17:52:10 +00:00
|
|
|
void InspIRCd::WriteMode(const char* modes, int flags, const char* text, ...)
|
2006-03-08 03:35:21 +00:00
|
|
|
{
|
|
|
|
char textbuffer[MAXBUF];
|
|
|
|
int modelen;
|
|
|
|
va_list argsPtr;
|
|
|
|
|
2006-10-06 08:20:47 +00:00
|
|
|
if (!text || !modes || !flags)
|
2006-03-08 03:35:21 +00:00
|
|
|
{
|
2006-08-11 12:26:07 +00:00
|
|
|
this->Log(DEFAULT,"*** BUG *** WriteMode was given an invalid parameter");
|
2006-03-08 03:35:21 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
va_start(argsPtr, text);
|
2005-12-04 17:16:22 +00:00
|
|
|
vsnprintf(textbuffer, MAXBUF, text, argsPtr);
|
|
|
|
va_end(argsPtr);
|
2006-03-08 03:35:21 +00:00
|
|
|
modelen = strlen(modes);
|
2005-12-04 17:16:22 +00:00
|
|
|
|
2006-10-06 08:20:47 +00:00
|
|
|
if (flags == WM_AND)
|
2005-12-04 17:16:22 +00:00
|
|
|
{
|
2006-10-06 08:20:47 +00:00
|
|
|
for (std::vector<userrec*>::const_iterator i = local_users.begin(); i != local_users.end(); i++)
|
2006-03-08 03:35:21 +00:00
|
|
|
{
|
2006-10-06 08:20:47 +00:00
|
|
|
userrec* t = *i;
|
|
|
|
bool send_to_user = true;
|
2006-03-08 03:35:21 +00:00
|
|
|
|
|
|
|
for (int n = 0; n < modelen; n++)
|
|
|
|
{
|
2006-07-08 18:03:30 +00:00
|
|
|
if (!t->modes[modes[n]-65])
|
2006-03-08 03:35:21 +00:00
|
|
|
{
|
|
|
|
send_to_user = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2006-10-06 08:28:25 +00:00
|
|
|
if (send_to_user)
|
|
|
|
t->WriteServ("NOTICE %s :%s",t->nick,textbuffer);
|
2006-03-08 03:35:21 +00:00
|
|
|
}
|
2006-10-06 08:20:47 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
if (flags == WM_OR)
|
|
|
|
{
|
|
|
|
for (std::vector<userrec*>::const_iterator i = local_users.begin(); i != local_users.end(); i++)
|
2006-03-08 03:35:21 +00:00
|
|
|
{
|
2006-10-06 08:20:47 +00:00
|
|
|
userrec* t = *i;
|
|
|
|
bool send_to_user = false;
|
2006-03-08 03:35:21 +00:00
|
|
|
|
|
|
|
for (int n = 0; n < modelen; n++)
|
|
|
|
{
|
2006-07-08 18:03:30 +00:00
|
|
|
if (t->modes[modes[n]-65])
|
2006-03-08 03:35:21 +00:00
|
|
|
{
|
|
|
|
send_to_user = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2006-10-06 08:28:25 +00:00
|
|
|
if (send_to_user)
|
|
|
|
t->WriteServ("NOTICE %s :%s",t->nick,textbuffer);
|
2006-03-08 03:35:21 +00:00
|
|
|
}
|
2005-12-04 17:16:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-05-15 03:03:23 +00:00
|
|
|
/* Find a user record by nickname and return a pointer to it */
|
|
|
|
|
2006-08-10 14:43:29 +00:00
|
|
|
userrec* InspIRCd::FindNick(const std::string &nick)
|
2005-05-15 03:03:23 +00:00
|
|
|
{
|
2006-12-23 23:06:37 +00:00
|
|
|
user_hash::iterator iter = clientlist->find(nick);
|
2005-05-15 03:03:23 +00:00
|
|
|
|
2006-12-23 23:06:37 +00:00
|
|
|
if (iter == clientlist->end())
|
2006-03-08 03:35:21 +00:00
|
|
|
/* Couldn't find it */
|
|
|
|
return NULL;
|
2005-05-15 03:03:23 +00:00
|
|
|
|
2006-03-08 03:35:21 +00:00
|
|
|
return iter->second;
|
2005-05-15 03:03:23 +00:00
|
|
|
}
|
|
|
|
|
2006-08-10 14:43:29 +00:00
|
|
|
userrec* InspIRCd::FindNick(const char* nick)
|
2006-02-21 19:03:13 +00:00
|
|
|
{
|
2006-12-23 23:06:37 +00:00
|
|
|
user_hash::iterator iter = clientlist->find(nick);
|
2006-02-21 19:03:13 +00:00
|
|
|
|
2006-12-23 23:06:37 +00:00
|
|
|
if (iter == clientlist->end())
|
2006-02-21 19:03:13 +00:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return iter->second;
|
|
|
|
}
|
|
|
|
|
2005-05-15 03:03:23 +00:00
|
|
|
/* find a channel record by channel name and return a pointer to it */
|
|
|
|
|
2006-08-10 14:43:29 +00:00
|
|
|
chanrec* InspIRCd::FindChan(const char* chan)
|
2005-05-15 03:03:23 +00:00
|
|
|
{
|
2006-12-23 23:06:37 +00:00
|
|
|
chan_hash::iterator iter = chanlist->find(chan);
|
2005-05-15 03:03:23 +00:00
|
|
|
|
2006-12-23 23:06:37 +00:00
|
|
|
if (iter == chanlist->end())
|
2006-03-08 03:35:21 +00:00
|
|
|
/* Couldn't find it */
|
|
|
|
return NULL;
|
2005-05-15 03:03:23 +00:00
|
|
|
|
2006-03-08 03:35:21 +00:00
|
|
|
return iter->second;
|
2005-05-15 03:03:23 +00:00
|
|
|
}
|
|
|
|
|
2006-08-10 14:43:29 +00:00
|
|
|
chanrec* InspIRCd::FindChan(const std::string &chan)
|
2005-05-15 03:03:23 +00:00
|
|
|
{
|
2006-12-23 23:06:37 +00:00
|
|
|
chan_hash::iterator iter = chanlist->find(chan);
|
2005-05-15 03:03:23 +00:00
|
|
|
|
2006-12-23 23:06:37 +00:00
|
|
|
if (iter == chanlist->end())
|
2006-08-10 14:43:29 +00:00
|
|
|
/* Couldn't find it */
|
|
|
|
return NULL;
|
2005-05-15 03:03:23 +00:00
|
|
|
|
2006-08-10 14:43:29 +00:00
|
|
|
return iter->second;
|
2006-03-08 03:35:21 +00:00
|
|
|
}
|
2005-05-15 03:03:23 +00:00
|
|
|
|
2006-03-08 03:35:21 +00:00
|
|
|
/*
|
|
|
|
* sends out an error notice to all connected clients (not to be used
|
|
|
|
* lightly!)
|
|
|
|
*/
|
2006-12-23 14:06:57 +00:00
|
|
|
void InspIRCd::SendError(const std::string &s)
|
2005-05-15 03:03:23 +00:00
|
|
|
{
|
2006-08-09 17:52:10 +00:00
|
|
|
for (std::vector<userrec*>::const_iterator i = this->local_users.begin(); i != this->local_users.end(); i++)
|
2006-03-08 03:35:21 +00:00
|
|
|
{
|
2006-12-23 14:06:57 +00:00
|
|
|
if ((*i)->registered == REG_ALL)
|
2006-03-08 03:35:21 +00:00
|
|
|
{
|
2006-12-23 14:06:57 +00:00
|
|
|
(*i)->WriteServ("NOTICE %s :%s",(*i)->nick,s.c_str());
|
2006-03-08 03:35:21 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-12-23 14:06:57 +00:00
|
|
|
/* Unregistered connections receive ERROR, not a NOTICE */
|
|
|
|
(*i)->Write("ERROR :" + s);
|
2006-03-08 03:35:21 +00:00
|
|
|
}
|
2006-12-23 14:06:57 +00:00
|
|
|
/* This might generate a whole load of EAGAIN, but we dont really
|
|
|
|
* care about this, as if we call SendError something catastrophic
|
|
|
|
* has occured anyway, and we wont receive the events for these.
|
|
|
|
*/
|
|
|
|
(*i)->FlushWriteBuf();
|
2006-03-08 03:35:21 +00:00
|
|
|
}
|
2005-05-15 03:03:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// this function counts all users connected, wether they are registered or NOT.
|
2006-08-11 16:14:44 +00:00
|
|
|
int InspIRCd::UserCount()
|
2005-05-15 03:03:23 +00:00
|
|
|
{
|
2006-12-23 23:06:37 +00:00
|
|
|
return clientlist->size();
|
2005-05-15 03:03:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// this counts only registered users, so that the percentages in /MAP don't mess up when users are sitting in an unregistered state
|
2006-08-11 16:14:44 +00:00
|
|
|
int InspIRCd::RegisteredUserCount()
|
2005-05-15 03:03:23 +00:00
|
|
|
{
|
2006-12-23 23:06:37 +00:00
|
|
|
return clientlist->size() - this->UnregisteredUserCount();
|
2005-05-15 03:03:23 +00:00
|
|
|
}
|
|
|
|
|
2006-12-29 23:34:47 +00:00
|
|
|
int InspIRCd::ModeCount(const char mode)
|
2005-05-15 03:03:23 +00:00
|
|
|
{
|
2006-12-29 23:57:38 +00:00
|
|
|
ModeHandler* mh = this->Modes->FindMode(mode, MODETYPE_USER);
|
2006-03-08 03:35:21 +00:00
|
|
|
|
2006-12-29 23:34:47 +00:00
|
|
|
if (mh)
|
|
|
|
return mh->GetCount();
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
2006-03-08 03:35:21 +00:00
|
|
|
|
2006-12-29 23:34:47 +00:00
|
|
|
int InspIRCd::InvisibleUserCount()
|
|
|
|
{
|
|
|
|
return ModeCount('i');
|
2005-05-15 03:03:23 +00:00
|
|
|
}
|
|
|
|
|
2006-08-11 16:14:44 +00:00
|
|
|
int InspIRCd::OperCount()
|
2005-05-15 03:03:23 +00:00
|
|
|
{
|
2007-01-06 15:39:05 +00:00
|
|
|
return this->all_opers.size();
|
2005-05-15 03:03:23 +00:00
|
|
|
}
|
|
|
|
|
2006-08-11 16:14:44 +00:00
|
|
|
int InspIRCd::UnregisteredUserCount()
|
2005-05-15 03:03:23 +00:00
|
|
|
{
|
2006-12-30 14:34:49 +00:00
|
|
|
return this->unregistered_count;
|
2005-05-15 03:03:23 +00:00
|
|
|
}
|
|
|
|
|
2006-08-11 16:14:44 +00:00
|
|
|
long InspIRCd::ChannelCount()
|
2005-05-15 03:03:23 +00:00
|
|
|
{
|
2006-12-23 23:06:37 +00:00
|
|
|
return chanlist->size();
|
2005-05-15 03:03:23 +00:00
|
|
|
}
|
|
|
|
|
2006-08-11 16:14:44 +00:00
|
|
|
long InspIRCd::LocalUserCount()
|
2005-05-15 03:03:23 +00:00
|
|
|
{
|
2006-12-30 14:34:49 +00:00
|
|
|
/* Doesnt count unregistered clients */
|
|
|
|
return (local_users.size() - this->UnregisteredUserCount());
|
2005-05-15 03:03:23 +00:00
|
|
|
}
|
2006-12-30 14:34:49 +00:00
|
|
|
|
2006-08-10 20:27:51 +00:00
|
|
|
bool InspIRCd::IsChannel(const char *chname)
|
2006-02-13 01:01:43 +00:00
|
|
|
{
|
2006-03-08 03:35:21 +00:00
|
|
|
char *c;
|
|
|
|
|
|
|
|
/* check for no name - don't check for !*chname, as if it is empty, it won't be '#'! */
|
|
|
|
if (!chname || *chname != '#')
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2006-02-13 01:01:43 +00:00
|
|
|
|
2006-03-08 03:35:21 +00:00
|
|
|
c = (char *)chname + 1;
|
|
|
|
while (*c)
|
|
|
|
{
|
|
|
|
switch (*c)
|
2006-02-13 01:01:43 +00:00
|
|
|
{
|
2006-03-08 03:35:21 +00:00
|
|
|
case ' ':
|
|
|
|
case ',':
|
|
|
|
case 7:
|
2006-02-13 01:01:43 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2006-03-08 03:35:21 +00:00
|
|
|
c++;
|
|
|
|
}
|
2006-02-13 01:01:43 +00:00
|
|
|
|
2006-03-08 03:35:21 +00:00
|
|
|
/* too long a name - note funky pointer arithmetic here. */
|
|
|
|
if ((c - chname) > CHANMAX)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2006-02-13 01:01:43 +00:00
|
|
|
|
2006-03-08 03:35:21 +00:00
|
|
|
return true;
|
2006-02-13 01:01:43 +00:00
|
|
|
}
|
2006-03-02 11:45:38 +00:00
|
|
|
|
2006-10-02 01:47:47 +00:00
|
|
|
bool InspIRCd::IsNick(const char* n)
|
|
|
|
{
|
|
|
|
if (!n || !*n)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
int p = 0;
|
|
|
|
for (char* i = (char*)n; *i; i++, p++)
|
|
|
|
{
|
|
|
|
if ((*i >= 'A') && (*i <= '}'))
|
|
|
|
{
|
|
|
|
/* "A"-"}" can occur anywhere in a nickname */
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((((*i >= '0') && (*i <= '9')) || (*i == '-')) && (i > n))
|
|
|
|
{
|
|
|
|
/* "0"-"9", "-" can occur anywhere BUT the first char of a nickname */
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* invalid character! abort */
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* too long? or not -- pointer arithmetic rocks */
|
|
|
|
return (p < NICKMAX - 1);
|
|
|
|
}
|
|
|
|
|
2007-05-13 18:08:37 +00:00
|
|
|
|
|
|
|
bool InspIRCd::IsIdent(const char* n)
|
|
|
|
{
|
|
|
|
if (!n || !*n)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
for (char* i = (char*)n; *i; i++)
|
|
|
|
{
|
|
|
|
if ((*i >= 'A') && (*i <= '}'))
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (((*i >= '0') && (*i <= '9')) || (*i == '-') || (*i == '.'))
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2006-08-10 20:27:51 +00:00
|
|
|
void InspIRCd::OpenLog(char** argv, int argc)
|
2006-04-04 00:41:28 +00:00
|
|
|
{
|
2007-05-26 19:58:19 +00:00
|
|
|
Config->MyDir = Config->GetFullProgDir();
|
2006-12-23 14:06:57 +00:00
|
|
|
|
2006-08-10 21:19:19 +00:00
|
|
|
if (!*this->LogFileName)
|
2006-04-04 00:41:28 +00:00
|
|
|
{
|
2006-08-10 20:27:51 +00:00
|
|
|
if (Config->logpath == "")
|
2006-04-04 00:41:28 +00:00
|
|
|
{
|
2006-12-23 14:06:57 +00:00
|
|
|
Config->logpath = Config->MyDir + "/ircd.log";
|
2006-04-04 00:41:28 +00:00
|
|
|
}
|
2006-10-23 09:10:20 +00:00
|
|
|
|
|
|
|
Config->log_file = fopen(Config->logpath.c_str(),"a+");
|
2006-04-04 00:41:28 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-08-10 21:19:19 +00:00
|
|
|
Config->log_file = fopen(this->LogFileName,"a+");
|
2006-04-04 00:41:28 +00:00
|
|
|
}
|
|
|
|
|
2006-08-10 20:27:51 +00:00
|
|
|
if (!Config->log_file)
|
2006-04-04 00:41:28 +00:00
|
|
|
{
|
2006-10-23 09:10:20 +00:00
|
|
|
printf("ERROR: Could not write to logfile %s: %s\n\n", Config->logpath.c_str(), strerror(errno));
|
2006-12-23 16:40:09 +00:00
|
|
|
Exit(EXIT_STATUS_LOG);
|
2006-04-04 00:41:28 +00:00
|
|
|
}
|
2006-08-18 22:01:26 +00:00
|
|
|
|
|
|
|
this->Logger = new FileLogger(this, Config->log_file);
|
2006-04-04 00:41:28 +00:00
|
|
|
}
|
|
|
|
|
2006-08-10 20:27:51 +00:00
|
|
|
void InspIRCd::CheckRoot()
|
2006-04-04 00:41:28 +00:00
|
|
|
{
|
|
|
|
if (geteuid() == 0)
|
|
|
|
{
|
|
|
|
printf("WARNING!!! You are running an irc server as ROOT!!! DO NOT DO THIS!!!\n\n");
|
2006-08-11 12:26:07 +00:00
|
|
|
this->Log(DEFAULT,"Cant start as root");
|
2006-12-23 16:40:09 +00:00
|
|
|
Exit(EXIT_STATUS_ROOT);
|
2006-04-04 00:41:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-08-10 20:27:51 +00:00
|
|
|
void InspIRCd::CheckDie()
|
2006-04-04 00:41:28 +00:00
|
|
|
{
|
2006-08-10 20:27:51 +00:00
|
|
|
if (*Config->DieValue)
|
2006-04-04 00:41:28 +00:00
|
|
|
{
|
2006-08-10 20:27:51 +00:00
|
|
|
printf("WARNING: %s\n\n",Config->DieValue);
|
2006-08-11 12:26:07 +00:00
|
|
|
this->Log(DEFAULT,"Died because of <die> tag: %s",Config->DieValue);
|
2006-12-23 16:40:09 +00:00
|
|
|
Exit(EXIT_STATUS_DIETAG);
|
2006-04-04 00:41:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* We must load the modules AFTER initializing the socket engine, now */
|
2006-08-10 20:27:51 +00:00
|
|
|
void InspIRCd::LoadAllModules()
|
2006-04-04 00:41:28 +00:00
|
|
|
{
|
|
|
|
char configToken[MAXBUF];
|
2006-08-10 20:27:51 +00:00
|
|
|
Config->module_names.clear();
|
2006-08-10 21:19:19 +00:00
|
|
|
this->ModCount = -1;
|
2006-04-06 02:25:20 +00:00
|
|
|
|
2006-08-10 20:27:51 +00:00
|
|
|
for (int count = 0; count < Config->ConfValueEnum(Config->config_data, "module"); count++)
|
2006-04-04 00:41:28 +00:00
|
|
|
{
|
2007-04-06 20:44:46 +00:00
|
|
|
Config->ConfValue(Config->config_data, "module", "name", count, configToken, MAXBUF);
|
2007-05-19 15:56:42 +00:00
|
|
|
printf_c("[\033[1;32m*\033[0m] Loading module:\t\033[1;32m%s\033[0m\n",configToken);
|
2006-04-04 00:41:28 +00:00
|
|
|
|
2006-08-10 20:27:51 +00:00
|
|
|
if (!this->LoadModule(configToken))
|
2006-04-04 00:41:28 +00:00
|
|
|
{
|
2007-04-06 20:44:46 +00:00
|
|
|
this->Log(DEFAULT,"There was an error loading the module '%s': %s", configToken, this->ModuleError());
|
2007-05-19 15:56:42 +00:00
|
|
|
printf_c("\n[\033[1;31m*\033[0m] There was an error loading the module '%s': %s\n\n", configToken, this->ModuleError());
|
2006-12-23 16:40:09 +00:00
|
|
|
Exit(EXIT_STATUS_MODULE);
|
2006-04-04 00:41:28 +00:00
|
|
|
}
|
|
|
|
}
|
2007-05-19 15:56:42 +00:00
|
|
|
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");
|
2006-08-11 12:26:07 +00:00
|
|
|
this->Log(DEFAULT,"Total loaded modules: %d", this->ModCount+1);
|
2006-04-04 00:41:28 +00:00
|
|
|
}
|
2006-08-10 20:27:51 +00:00
|
|
|
|
2006-10-28 18:41:34 +00:00
|
|
|
void InspIRCd::SendWhoisLine(userrec* user, userrec* dest, int numeric, const std::string &text)
|
2006-10-28 18:12:45 +00:00
|
|
|
{
|
|
|
|
std::string copy_text = text;
|
|
|
|
|
|
|
|
int MOD_RESULT = 0;
|
2006-10-28 18:41:34 +00:00
|
|
|
FOREACH_RESULT_I(this, I_OnWhoisLine, OnWhoisLine(user, dest, numeric, copy_text));
|
2006-10-28 18:12:45 +00:00
|
|
|
|
|
|
|
if (!MOD_RESULT)
|
|
|
|
user->WriteServ("%d %s", numeric, copy_text.c_str());
|
|
|
|
}
|
|
|
|
|
2006-10-28 18:41:34 +00:00
|
|
|
void InspIRCd::SendWhoisLine(userrec* user, userrec* dest, int numeric, const char* format, ...)
|
2006-10-28 18:12:45 +00:00
|
|
|
{
|
|
|
|
char textbuffer[MAXBUF];
|
|
|
|
va_list argsPtr;
|
|
|
|
va_start (argsPtr, format);
|
|
|
|
vsnprintf(textbuffer, MAXBUF, format, argsPtr);
|
|
|
|
va_end(argsPtr);
|
|
|
|
|
2006-10-28 18:41:34 +00:00
|
|
|
this->SendWhoisLine(user, dest, numeric, std::string(textbuffer));
|
2006-10-28 18:12:45 +00:00
|
|
|
}
|
|
|
|
|