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)
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)
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 nspace::hash_map<in_addr,string*, nspace::hash<in_addr>, irc::InAddr_HashComp> address_cache;
typedef nspace::hash_map<std::string, WhoWasUser*, nspace::hash<string>, irc::StrHashComp> whowas_hash;
typedef std::deque<command_t> command_table;
typedef std::map<std::string,time_t> autoconnects;
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 nspace::hash_map<in_addr,string*, nspace::hash<in_addr>, irc::InAddr_HashComp> address_cache;
typedef nspace::hash_map<std::string, WhoWasUser*, nspace::hash<string>, irc::StrHashComp> whowas_hash;
typedef std::deque<command_t> command_table;
typedef std::map<std::string,time_t> autoconnects;
// This table references users by file descriptor.
// its an array to make it VERY fast, as all lookups are referenced
// This table references users by file descriptor.
// its an array to make it VERY fast, as all lookups are referenced
+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)
+ return;
+ }
+ servernames.push_back(servername);
+}
+
+const char* FindServerNamePtr(std::string servername)
+{
+ for (servernamelist::iterator a = servernames.begin(); a < servernames.end(); a++)
+ {
+ if (*a == servername)
+ return a->c_str();
+ }
+ return "";
+}
+
void DeleteOper(userrec* user)
{
for (std::vector<userrec*>::iterator a = all_opers.begin(); a < all_opers.end(); a++)
void DeleteOper(userrec* user)
{
for (std::vector<userrec*>::iterator a = all_opers.begin(); a < all_opers.end(); a++)
void ReadConfig(bool bail, userrec* user)
{
char dbg[MAXBUF],pauseval[MAXBUF],Value[MAXBUF],timeout[MAXBUF],NB[MAXBUF],flood[MAXBUF],MW[MAXBUF],MCON[MAXBUF];
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];
ConfValue("options","moduledir",0,ModPath,&config_f);
ConfValue("disabled","commands",0,DisabledCommands,&config_f);
ConfValue("options","somaxconn",0,MCON,&config_f);
ConfValue("options","moduledir",0,ModPath,&config_f);
ConfValue("disabled","commands",0,DisabledCommands,&config_f);
ConfValue("options","somaxconn",0,MCON,&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;
+ }
}
log(DEBUG,"add_channel: %s %s",user->nick,cname);
}
log(DEBUG,"add_channel: %s %s",user->nick,cname);
- WriteOpers("*** Client exiting: %s!%s@%s [%s]",user->nick,user->ident,user->host,reason);
+ // fix by brain: only show local quits because we only show local connects (it just makes SENSE)
+ if (!strcmp(user->server,ServerName))
+ WriteOpers("*** Client exiting: %s!%s@%s [%s]",user->nick,user->ident,user->host,reason);
strlcpy(MyExecutable,argv[0],MAXBUF);
// initialize the lowercase mapping table
strlcpy(MyExecutable,argv[0],MAXBUF);
// initialize the lowercase mapping table
whowas_hash::iterator iter = whowas.find(u->nick);
WhoWasUser *a = new WhoWasUser();
strlcpy(a->nick,u->nick,NICKMAX);
whowas_hash::iterator iter = whowas.find(u->nick);
WhoWasUser *a = new WhoWasUser();
strlcpy(a->nick,u->nick,NICKMAX);
strlcpy(a->dhost,u->dhost,160);
strlcpy(a->host,u->host,160);
strlcpy(a->dhost,u->dhost,160);
strlcpy(a->host,u->host,160);
log(DEBUG,"AddClient: %lu %s %d %s",(unsigned long)socket,host,port,ip);
clientlist[tempnick]->fd = socket;
log(DEBUG,"AddClient: %lu %s %d %s",(unsigned long)socket,host,port,ip);
clientlist[tempnick]->fd = socket;
- strncpy(clientlist[tempnick]->nick, tn2,NICKMAX);
- strncpy(clientlist[tempnick]->host, host,160);
- strncpy(clientlist[tempnick]->dhost, host,160);
- strncpy(clientlist[tempnick]->server, ServerName,256);
- strncpy(clientlist[tempnick]->ident, "unknown",15);
+ strlcpy(clientlist[tempnick]->nick, tn2,NICKMAX);
+ strlcpy(clientlist[tempnick]->host, host,160);
+ strlcpy(clientlist[tempnick]->dhost, host,160);
+ clientlist[tempnick]->server = (char*)FindServerNamePtr(ServerName);
+ strlcpy(clientlist[tempnick]->ident, "unknown",IDENTMAX);
clientlist[tempnick]->registered = 0;
clientlist[tempnick]->signon = TIME+dns_timeout;
clientlist[tempnick]->lastping = 1;
clientlist[tempnick]->port = port;
clientlist[tempnick]->registered = 0;
clientlist[tempnick]->signon = TIME+dns_timeout;
clientlist[tempnick]->lastping = 1;
clientlist[tempnick]->port = port;
- if (clientlist.size() == MAXCLIENTS)
+ if (clientlist.size() > SoftLimit)
+ {
+ kill_link(clientlist[tempnick],"No more connections allowed");
+ return;
+ }
+
+ if (clientlist.size() >= MAXCLIENTS)
// 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!)
// 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!)
std::stringstream v;
v << "MESHED WALLCHOPS MODES=13 CHANTYPES=# PREFIX=(ohv)@%+ MAP SAFELIST MAXCHANNELS=" << MAXCHANS;
v << " MAXBANS=60 NICKLEN=" << NICKMAX;
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=";
// 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);
// 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);
WriteOpers("*** Client connecting on port %lu: %s!%s@%s [%s]",(unsigned long)user->port,user->nick,user->ident,user->host,user->ip);
}
WriteOpers("*** Client connecting on port %lu: %s!%s@%s [%s]",(unsigned long)user->port,user->nick,user->ident,user->host,user->ip);
}
{
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());
}
{
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());
}
void call_handler(const char* commandname,char **parameters, int pcnt, userrec *user)
{
void call_handler(const char* commandname,char **parameters, int pcnt, userrec *user)
{
{
/* capitalise the command ONLY, leave params intact */
cmd[i] = toupper(cmd[i]);
{
/* capitalise the command ONLY, leave params intact */
cmd[i] = toupper(cmd[i]);
{
// command is disabled!
WriteServ(user->fd,"421 %s %s :This command has been disabled.",user->nick,command);
return;
}
{
// command is disabled!
WriteServ(user->fd,"421 %s %s :This command has been disabled.",user->nick,command);
return;
}
}
if ((user->registered == 7) || (!strncmp(command,"USER",4)) || (!strncmp(command,"NICK",4)) || (!strncmp(command,"PASS",4)))
{
}
if ((user->registered == 7) || (!strncmp(command,"USER",4)) || (!strncmp(command,"NICK",4)) || (!strncmp(command,"PASS",4)))
{
{
snprintf(data,MAXBUF,"%s %s",CreateSum().c_str(),l[j].c_str());
serv->SendPacket(data,tcp_host);
{
snprintf(data,MAXBUF,"%s %s",CreateSum().c_str(),l[j].c_str());
serv->SendPacket(data,tcp_host);
{
snprintf(data,MAXBUF,"%s %s",CreateSum().c_str(),l[j].c_str());
serv->SendPacket(data,tcp_host);
{
snprintf(data,MAXBUF,"%s %s",CreateSum().c_str(),l[j].c_str());
serv->SendPacket(data,tcp_host);
/* save the module and the module's classfactory, if
* this isnt done, random crashes can occur :/ */
module_names.push_back(filename);
/* save the module and the module's classfactory, if
* this isnt done, random crashes can occur :/ */
module_names.push_back(filename);
int clientportcount = 0, serverportcount = 0;
for (count = 0; count < ConfValueEnum("bind",&config_f); count++)
int clientportcount = 0, serverportcount = 0;
for (count = 0; count < ConfValueEnum("bind",&config_f); count++)
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++)
{
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++)
{
log(DEBUG,"kqueue: Listening server socket event, i=%d, ke.ident=%d",i,ke.ident);
for (int x = 0; x != SERVERportCount; x++)
{
log(DEBUG,"kqueue: Listening server socket event, i=%d, ke.ident=%d",i,ke.ident);
for (int x = 0; x != SERVERportCount; x++)
{
msgs.clear();
while ((me[x]) && (me[x]->RecvPacket(msgs, tcp_host, sums))) // returns 0 or more lines (can be multiple lines!)
{
msgs.clear();
while ((me[x]) && (me[x]->RecvPacket(msgs, tcp_host, sums))) // returns 0 or more lines (can be multiple lines!)
{
// registration timeout -- didnt send USER/NICK/HOST in the time specified in
// their connection class.
// registration timeout -- didnt send USER/NICK/HOST in the time specified in
// their connection class.
{
log(DEBUG,"InspIRCd: registration timeout: %s",curr->nick);
kill_link(curr,"Registration timeout");
{
log(DEBUG,"InspIRCd: registration timeout: %s",curr->nick);
kill_link(curr,"Registration timeout");
// compared to the number of clients (possibly over 2000)
for (count = 0; count < boundPortCount; count++)
{
// compared to the number of clients (possibly over 2000)
for (count = 0; count < boundPortCount; count++)
{
log(DEBUG,"epoll: Listening socket event, i=%d,events[j].data.fd=%d",i,event[j].data.fd);
for (count = 0; count < boundPortCount; count++)
{
log(DEBUG,"epoll: Listening socket event, i=%d,events[j].data.fd=%d",i,event[j].data.fd);
for (count = 0; count < boundPortCount; count++)
{