#include "inspstring.h"
#include "helperfuncs.h"
#include "hashcomp.h"
+#include "typedefs.h"
extern int MODCOUNT;
extern std::vector<Module*> modules;
-
+extern ServerConfig *Config;
extern time_t TIME;
-extern bool nofork;
extern char lowermap[255];
-extern char ServerName[MAXBUF];
-extern char Network[MAXBUF];
-extern char ServerDesc[MAXBUF];
-extern char list[MAXBUF];
-
-extern int debugging;
-extern int LogLevel;
-
-extern std::stringstream config_f;
-
-
-
-extern FILE *log_file;
+static char list[MAXBUF];
extern userrec* fd_ref_table[65536];
-
-extern int statsAccept, statsRefused, statsUnknown, statsCollisions, statsDns, statsDnsGood, statsDnsBad, statsConnects, statsSent, statsRecv;
-
+extern serverstats* stats;
static char already_sent[65536];
extern std::vector<userrec*> all_opers;
-
extern ClassVector Classes;
-
-typedef nspace::hash_map<std::string, userrec*, nspace::hash<string>, irc::StrHashComp> user_hash;
-typedef nspace::hash_map<std::string, chanrec*, nspace::hash<string>, irc::StrHashComp> chan_hash;
-typedef std::deque<command_t> command_table;
-
extern user_hash clientlist;
extern chan_hash chanlist;
extern command_table cmdlist;
-extern file_cache MOTD;
-extern file_cache RULES;
void log(int level,char *text, ...)
{
va_list argsPtr;
time_t rawtime;
struct tm * timeinfo;
- if (level < LogLevel)
+ if (level < Config->LogLevel)
return;
time(&rawtime);
- timeinfo = localtime (&rawtime);
+ timeinfo = localtime(&rawtime);
- if (log_file)
+ if (Config->log_file)
{
char b[MAXBUF];
va_start (argsPtr, text);
va_end(argsPtr);
strlcpy(b,asctime(timeinfo),MAXBUF);
b[24] = ':'; // we know this is the end of the time string
- fprintf(log_file,"%s %s\n",b,textbuffer);
- if (nofork)
+ if (Config->log_file)
+ fprintf(Config->log_file,"%s %s\n",b,textbuffer);
+ if (Config->nofork)
{
// nofork enabled? display it on terminal too
printf("%s %s\n",b,textbuffer);
{
fgets(linebuf,sizeof(linebuf),file);
linebuf[strlen(linebuf)-1]='\0';
- if (linebuf[0] == 0)
+ if (!*linebuf)
{
strcpy(linebuf," ");
}
int MOD_RESULT = 0;
FOREACH_RESULT(OnRawSocketWrite(sock,tb,bytes));
fd_ref_table[sock]->AddWriteBuf(tb);
- statsSent += bytes;
+ stats->statsSent += bytes;
}
else log(DEFAULT,"ERROR! attempted write to a user with no fd_ref_table entry!!!");
}
vsnprintf(textbuffer, MAXBUF, text, argsPtr);
va_end(argsPtr);
- int bytes = snprintf(tb,MAXBUF,":%s %s\r\n",ServerName,textbuffer);
+ int bytes = snprintf(tb,MAXBUF,":%s %s\r\n",Config->ServerName,textbuffer);
chop(tb);
if (fd_ref_table[sock])
{
int MOD_RESULT = 0;
FOREACH_RESULT(OnRawSocketWrite(sock,tb,bytes));
fd_ref_table[sock]->AddWriteBuf(tb);
- statsSent += bytes;
+ stats->statsSent += bytes;
}
else log(DEFAULT,"ERROR! attempted write to a user with no fd_ref_table entry!!!");
}
int MOD_RESULT = 0;
FOREACH_RESULT(OnRawSocketWrite(sock,tb,bytes));
fd_ref_table[sock]->AddWriteBuf(tb);
- statsSent += bytes;
+ stats->statsSent += bytes;
}
else log(DEFAULT,"ERROR! attempted write to a user with no fd_ref_table entry!!!");
}
// if no source given send it from the server.
if (!source)
{
- WriteServ(dest->fd,":%s %s",ServerName,textbuffer);
+ WriteServ(dest->fd,":%s %s",Config->ServerName,textbuffer);
}
else
{
}
else
{
- return ServerDesc; // not a remote server that can be found, it must be me.
+ return Config->ServerDesc; // not a remote server that can be found, it must be me.
}
}
{
if ((i->second) && (i->second->fd != FD_MAGIC_NUMBER))
{
- WriteServ(i->second->fd,"NOTICE $%s :%s",ServerName,textbuffer);
+ WriteServ(i->second->fd,"NOTICE $%s :%s",Config->ServerName,textbuffer);
}
}
}
{
if ((i->second) && (i->second->fd != FD_MAGIC_NUMBER))
{
- WriteServ(i->second->fd,"PRIVMSG $%s :%s",ServerName,textbuffer);
+ WriteServ(i->second->fd,"PRIVMSG $%s :%s",Config->ServerName,textbuffer);
}
}
}
long GetMaxBans(char* name)
{
char CM[MAXBUF];
- for (int count = 0; count < ConfValueEnum("banlist",&config_f); count++)
+ for (int count = 0; count < ConfValueEnum("banlist",&Config->config_f); count++)
{
- ConfValue("banlist","chan",count,CM,&config_f);
+ ConfValue("banlist","chan",count,CM,&Config->config_f);
if (match(name,CM))
{
- ConfValue("banlist","limit",count,CM,&config_f);
+ ConfValue("banlist","limit",count,CM,&Config->config_f);
return atoi(CM);
}
}
{
strlcat(scratch,"t",MAXMODES);
}
- if (chan->key[0])
+ if (*chan->key)
{
strlcat(scratch,"k",MAXMODES);
}
{
strlcat(scratch,"p",MAXMODES);
}
- if (chan->key[0])
+ if (*chan->key)
{
strlcat(sparam," ",MAXBUF);
strlcat(sparam,chan->key,MAXBUF);
return 0;
}
- strcpy(list,"");
for (user_hash::const_iterator i = clientlist.begin(); i != clientlist.end(); i++)
{
if (i->second)
for (user_hash::const_iterator i = clientlist.begin(); i != clientlist.end(); i++)
{
- if ((i->second->fd) && (i->second->registered != 7))
+ if ((i->second->fd > -1) && (i->second->registered != 7))
c++;
}
return c;
int c = 0;
for (user_hash::const_iterator i = clientlist.begin(); i != clientlist.end(); i++)
{
- if ((i->second->fd) && (isnick(i->second->nick)) && (!strcasecmp(i->second->server,ServerName))) c++;
+ if ((isnick(i->second->nick)) && (i->second->fd > -1)) c++;
}
return c;
}
WriteServ(user->fd,"422 %s :Message of the day file is missing.",user->nick);
return;
}
- snprintf(buf,65535,":%s 375 %s :- %s message of the day\r\n", ServerName, user->nick, ServerName);
+ snprintf(buf,65535,":%s 375 %s :- %s message of the day\r\n", Config->ServerName, user->nick, Config->ServerName);
WholeMOTD = WholeMOTD + buf;
for (unsigned int i = 0; i != MOTD.size(); i++)
{
- snprintf(buf,65535,":%s 372 %s :- %s\r\n", ServerName, user->nick, MOTD[i].c_str());
+ snprintf(buf,65535,":%s 372 %s :- %s\r\n", Config->ServerName, user->nick, MOTD[i].c_str());
WholeMOTD = WholeMOTD + buf;
}
- snprintf(buf,65535,":%s 376 %s :End of message of the day.\r\n", ServerName, user->nick);
+ snprintf(buf,65535,":%s 376 %s :End of message of the day.\r\n", Config->ServerName, user->nick);
WholeMOTD = WholeMOTD + buf;
// only one write operation
user->AddWriteBuf(WholeMOTD);
- statsSent += WholeMOTD.length();
+ stats->statsSent += WholeMOTD.length();
}
void ShowRULES(userrec *user)
WriteServ(user->fd,"NOTICE %s :Rules file is missing.",user->nick);
return;
}
- WriteServ(user->fd,"NOTICE %s :%s rules",user->nick,ServerName);
+ WriteServ(user->fd,"NOTICE %s :%s rules",user->nick,Config->ServerName);
for (unsigned int i = 0; i != RULES.size(); i++)
{
WriteServ(user->fd,"NOTICE %s :%s",user->nick,RULES[i].c_str());
}
- WriteServ(user->fd,"NOTICE %s :End of %s rules.",user->nick,ServerName);
+ WriteServ(user->fd,"NOTICE %s :End of %s rules.",user->nick,Config->ServerName);
}
// this returns 1 when all modules are satisfied that the user should be allowed onto the irc server