time_t startup_time = time(NULL);
int NetBufferSize = 10240; // NetBufferSize used as the buffer size for all read() ops
int MaxConn = SOMAXCONN; // size of accept() backlog (128 by default on *BSD)
+unsigned int SoftLimit = MAXCLIENTS;
extern int MaxWhoResults;
time_t nb_start = 0;
int dns_timeout = 5;
void AddServerName(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)
void ReadConfig(bool bail, userrec* user)
{
char dbg[MAXBUF],pauseval[MAXBUF],Value[MAXBUF],timeout[MAXBUF],NB[MAXBUF],flood[MAXBUF],MW[MAXBUF],MCON[MAXBUF];
- char AH[MAXBUF],AP[MAXBUF],AF[MAXBUF],DNT[MAXBUF],pfreq[MAXBUF],thold[MAXBUF],sqmax[MAXBUF],rqmax[MAXBUF];
+ char AH[MAXBUF],AP[MAXBUF],AF[MAXBUF],DNT[MAXBUF],pfreq[MAXBUF],thold[MAXBUF],sqmax[MAXBUF],rqmax[MAXBUF],SLIMT[MAXBUF];
ConnectClass c;
std::stringstream errstr;
include_stack.clear();
if (!LoadConf(CONFIG_FILE,&config_f,&errstr))
{
errstr.seekg(0);
+ log(DEFAULT,"There were errors in your configuration:\n%s",errstr.str().c_str());
if (bail)
{
printf("There were errors in your configuration:\n%s",errstr.str().c_str());
ConfValue("options","moduledir",0,ModPath,&config_f);
ConfValue("disabled","commands",0,DisabledCommands,&config_f);
ConfValue("options","somaxconn",0,MCON,&config_f);
+ ConfValue("options","softlimit",0,SLIMT,&config_f);
+ SoftLimit = atoi(SLIMT);
+ if ((SoftLimit < 1) || (SoftLimit > MAXCLIENTS))
+ {
+ log(DEFAULT,"WARNING: <options:softlimit> value is greater than %d or less than 0, set to %d.",MAXCLIENTS,MAXCLIENTS);
+ SoftLimit = MAXCLIENTS;
+ }
MaxConn = atoi(MCON);
if (MaxConn > SOMAXCONN)
log(DEFAULT,"WARNING: <options:somaxconn> value may be higher than the system-defined SOMAXCONN value!");
chanlist.erase(iter);
}
}
+
+ return NULL;
}
strlcpy(MyExecutable,argv[0],MAXBUF);
// initialize the lowercase mapping table
- for (int cn = 0; cn < 256; cn++)
+ for (unsigned int cn = 0; cn < 256; cn++)
lowermap[cn] = cn;
// lowercase the uppercase chars
- for (int cn = 65; cn < 91; cn++)
+ for (unsigned int cn = 65; cn < 91; cn++)
lowermap[cn] = tolower(cn);
// now replace the specific chars for scandanavian comparison
- lowermap['['] = '{';
- lowermap[']'] = '}';
- lowermap['\\'] = '|';
+ lowermap[(unsigned)'['] = '{';
+ lowermap[(unsigned)']'] = '}';
+ lowermap[(unsigned)'\\'] = '|';
if (InspIRCd(argv,argc) == ERROR)
{
if (iter == whowas.end())
{
- if (whowas.size() >= WHOWAS_MAX)
+ if (whowas.size() >= (unsigned)WHOWAS_MAX)
{
for (whowas_hash::iterator i = whowas.begin(); i != whowas.end(); i++)
{
clientlist[tempnick]->chans[i].uc_modes = 0;
}
- if (clientlist.size() == MAXCLIENTS)
+ if (clientlist.size() > SoftLimit)
{
- kill_link(clientlist[tempnick],"No more connections allowed in this class");
+ kill_link(clientlist[tempnick],"No more connections allowed");
+ return;
+ }
+
+ if (clientlist.size() >= MAXCLIENTS)
+ {
+ kill_link(clientlist[tempnick],"No more connections allowed");
return;
}
// irc server at once (or the irc server otherwise initiating this many connections, files etc)
// which for the time being is a physical impossibility (even the largest networks dont have more
// than about 10,000 users on ONE server!)
- if (socket > 65534)
+ if ((unsigned)socket > 65534)
{
kill_link(clientlist[tempnick],"Server is full");
return;
std::stringstream v;
v << "MESHED WALLCHOPS MODES=13 CHANTYPES=# PREFIX=(ohv)@%+ MAP SAFELIST MAXCHANNELS=" << MAXCHANS;
v << " MAXBANS=60 NICKLEN=" << NICKMAX;
- v << " TOPICLEN=307 KICKLEN=307 MAXTARGETS=20 AWAYLEN=307 CHANMODES=ohvb,k,l,psmnti NETWORK=";
+ v << " TOPICLEN=" << MAXTOPIC << " KICKLEN=" << MAXKICK << " MAXTARGETS=20 AWAYLEN=" << MAXAWAY << " CHANMODES=ohvb,k,l,psmnti NETWORK=";
v << Network;
std::string data005 = v.str();
FOREACH_MOD On005Numeric(data005);
// fix by brain: these should be AFTER the N token, so other servers know what the HELL we're on about... :)
FOREACH_MOD OnUserConnect(user);
+ FOREACH_MOD OnGlobalConnect(user);
WriteOpers("*** Client connecting on port %lu: %s!%s@%s [%s]",(unsigned long)user->port,user->nick,user->ident,user->host,user->ip);
}
{
if (me[j] != NULL)
{
- for (int x = 0; x < me[j]->connectors.size(); x++)
+ for (unsigned int x = 0; x < me[j]->connectors.size(); x++)
{
WriteServ(user->fd,"351 %s :Server %d:%d (%s): %s",user->nick,j,x,me[j]->connectors[x].GetServerName().c_str(),me[j]->connectors[x].GetVersionString().c_str());
}
{
if (me[j] != NULL)
{
- for (int x = 0; x < me[j]->connectors.size(); x++)
+ for (unsigned int x = 0; x < me[j]->connectors.size(); x++)
{
if (match(me[j]->connectors[x].GetServerName().c_str(),parameters[0]))
{
void call_handler(const char* commandname,char **parameters, int pcnt, userrec *user)
{
- for (int i = 0; i < cmdlist.size(); i++)
+ for (unsigned int i = 0; i < cmdlist.size(); i++)
{
if (!strcasecmp(cmdlist[i].command,commandname))
{
int total_params = 0;
if (strlen(cmd)>2)
{
- for (int q = 0; q < strlen(cmd)-1; q++)
+ for (unsigned int q = 0; q < strlen(cmd)-1; q++)
{
if ((cmd[q] == ' ') && (cmd[q+1] == ':'))
{
items = 0;
command_p[0] = NULL;
parameters = NULL;
- for (int i = 0; i <= strlen(cmd); i++)
+ for (unsigned int i = 0; i <= strlen(cmd); i++)
{
cmd[i] = toupper(cmd[i]);
}
strcpy(cmd,"");
j = 0;
/* strip out extraneous linefeeds through mirc's crappy pasting (thanks Craig) */
- for (int i = 0; i < strlen(temp); i++)
+ for (unsigned int i = 0; i < strlen(temp); i++)
{
if ((temp[i] != 10) && (temp[i] != 13) && (temp[i] != 0) && (temp[i] != 7))
{
command = cmd;
if (strchr(cmd,' '))
{
- for (int i = 0; i <= strlen(cmd); i++)
+ for (unsigned int i = 0; i <= strlen(cmd); i++)
{
/* capitalise the command ONLY, leave params intact */
cmd[i] = toupper(cmd[i]);
}
else
{
- for (int i = 0; i <= strlen(cmd); i++)
+ for (unsigned int i = 0; i <= strlen(cmd); i++)
{
cmd[i] = toupper(cmd[i]);
}
return;
}
- for (int x = 0; x < strlen(command); x++)
+ for (unsigned int x = 0; x < strlen(command); x++)
{
if (((command[x] < 'A') || (command[x] > 'Z')) && (command[x] != '.'))
{
}
}
- for (int i = 0; i != cmdlist.size(); i++)
+ for (unsigned int i = 0; i != cmdlist.size(); i++)
{
if (cmdlist[i].command[0])
{
{
if (me[j] != NULL)
{
- for (int k = 0; k < me[j]->connectors.size(); k++)
+ for (unsigned int k = 0; k < me[j]->connectors.size(); k++)
{
if (is_uline(me[j]->connectors[k].GetServerName().c_str()))
{
for (int i = 0; i <= MODCOUNT; i++)
{
string_list l = modules[i]->OnUserSync(u->second);
- for (int j = 0; j < l.size(); j++)
+ for (unsigned int j = 0; j < l.size(); j++)
{
snprintf(data,MAXBUF,"%s %s",CreateSum().c_str(),l[j].c_str());
serv->SendPacket(data,tcp_host);
for (int i = 0; i <= MODCOUNT; i++)
{
string_list l = modules[i]->OnChannelSync(c->second);
- for (int j = 0; j < l.size(); j++)
+ for (unsigned int j = 0; j < l.size(); j++)
{
snprintf(data,MAXBUF,"%s %s",CreateSum().c_str(),l[j].c_str());
serv->SendPacket(data,tcp_host);
{
if (me[i] != NULL)
{
- for (int j = 0; j < me[i]->connectors.size(); j++)
+ for (unsigned int j = 0; j < me[i]->connectors.size(); j++)
{
if ((me[i]->connectors[j].GetState() != STATE_DISCONNECTED) || (is_uline(me[i]->connectors[j].GetServerName().c_str())))
{
bool UnloadModule(const char* filename)
{
std::string filename_str = filename;
- for (int j = 0; j != module_names.size(); j++)
+ for (unsigned int j = 0; j != module_names.size(); j++)
{
if (module_names[j] == filename_str)
{
snprintf(MODERR,MAXBUF,"Module not unloadable (marked static)");
return false;
}
+ FOREACH_MOD OnUnloadModule(modules[j],module_names[j]);
// found the module
log(DEBUG,"Deleting module...");
erase_module(j);
if (FileExists(modfile))
{
#endif
- for (int j = 0; j < module_names.size(); j++)
+ for (unsigned int j = 0; j < module_names.size(); j++)
{
if (module_names[j] == filename_str)
{
{
Module* m = factory[MODCOUNT+1]->factory->CreateModule();
modules[MODCOUNT+1] = m;
+ FOREACH_MOD OnLoadModule(m,filename_str);
/* save the module and the module's classfactory, if
* this isnt done, random crashes can occur :/ */
module_names.push_back(filename);
{
if (me[j] != NULL)
{
- for (int k = 0; k < me[j]->connectors.size(); k++)
+ for (unsigned int k = 0; k < me[j]->connectors.size(); k++)
{
if (name == me[j]->connectors[k].GetServerName())
{
int incomingSockfd, result = TRUE;
socklen_t length;
int count = 0;
+#ifdef USE_SELECT
int selectResult = 0, selectResult2 = 0;
- char configToken[MAXBUF], Addr[MAXBUF], Type[MAXBUF];
fd_set selectFds;
+#endif
+ char configToken[MAXBUF], Addr[MAXBUF], Type[MAXBUF];
timeval tv;
std::string logpath = GetFullProgDir(argv,argc) + "/ircd.log";
WritePID(PID);
/* setup select call */
-#ifndef USE_KQUEUE
+#ifdef USE_SELECT
FD_ZERO(&selectFds);
#endif
log(DEBUG,"InspIRCd: startup: zero selects");
#ifdef USE_EPOLL
struct epoll_event event[33];
#endif
+#ifdef USE_SELECT
fd_set serverfds;
+ fd_set sfd;
+#endif
timeval tvs;
tvs.tv_usec = 10000L;
tvs.tv_sec = 0;
tv.tv_usec = 10000L;
char data[65536];
timeval tval;
- fd_set sfd;
tval.tv_usec = 10000L;
tval.tv_sec = 0;
int total_in_this_set = 0;
log(DEBUG,"epoll: Listening server socket event, i=%d, event.data.fd=%d",i,event[0].data.fd);
for (int x = 0; x != SERVERportCount; x++)
{
- if ((me[x]) && (event[0].data.fd == me[x]->fd))
+ if ((me[x]) && ((unsigned)event[0].data.fd == (unsigned)me[x]->fd))
{
#endif
#ifdef USE_KQUEUE
log(DEBUG,"kqueue: Listening server socket event, i=%d, ke.ident=%d",i,ke.ident);
for (int x = 0; x != SERVERportCount; x++)
{
- if ((me[x]) && (ke.ident == me[x]->fd))
+ if ((me[x]) && ((unsigned)ke.ident == (unsigned)me[x]->fd))
{
#endif
while ((me[x]) && (me[x]->RecvPacket(msgs, tcp_host, sums))) // returns 0 or more lines (can be multiple lines!)
{
has_been_netsplit = false;
- for (int ctr = 0; ctr < msgs.size(); ctr++)
+ for (unsigned int ctr = 0; ctr < msgs.size(); ctr++)
{
strlcpy(tcp_msg,msgs[ctr].c_str(),MAXBUF);
strlcpy(tcp_sum,sums[ctr].c_str(),MAXBUF);
// registration timeout -- didnt send USER/NICK/HOST in the time specified in
// their connection class.
- if ((TIME > curr->timeout) && (curr->registered != 7))
+ if (((unsigned)TIME > (unsigned)curr->timeout) && (curr->registered != 7))
{
log(DEBUG,"InspIRCd: registration timeout: %s",curr->nick);
kill_link(curr,"Registration timeout");
}
goto label;
}
- if (current->recvq.length() > NetBufferSize)
+ if (current->recvq.length() > (unsigned)NetBufferSize)
{
if (current->registered == 7)
{
// compared to the number of clients (possibly over 2000)
for (count = 0; count < boundPortCount; count++)
{
- if (ke_list[j].ident == openSockfd[count])
+ if ((unsigned)ke_list[j].ident == (unsigned)openSockfd[count])
{
#endif
#ifdef USE_EPOLL
log(DEBUG,"epoll: Listening socket event, i=%d,events[j].data.fd=%d",i,event[j].data.fd);
for (count = 0; count < boundPortCount; count++)
{
- if (event[j].data.fd == openSockfd[count])
+ if ((unsigned)event[j].data.fd == (unsigned)openSockfd[count])
{
#endif
char target[MAXBUF], resolved[MAXBUF];
}
/* not reached */
close (incomingSockfd);
+return 0;
}