diff options
author | brain <brain@e03df62e-2008-0410-955e-edbf42e46eb7> | 2004-04-06 22:52:28 +0000 |
---|---|---|
committer | brain <brain@e03df62e-2008-0410-955e-edbf42e46eb7> | 2004-04-06 22:52:28 +0000 |
commit | 3717c045aabf40d8280d1f8a7a0f33383ecafae4 (patch) | |
tree | da546fa794be2f5947da8f10bcd27f8a1178e66a | |
parent | 59a2c6c2d96a4557cd885fefcbce97f490962692 (diff) |
indentation fixes
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@412 e03df62e-2008-0410-955e-edbf42e46eb7
-rw-r--r-- | include/modules.h | 12 | ||||
-rw-r--r-- | src/InspIRCd.layout | 36 | ||||
-rw-r--r-- | src/inspircd.cpp | 597 |
3 files changed, 325 insertions, 320 deletions
diff --git a/include/modules.h b/include/modules.h index 4e3f5368b..ed947b30a 100644 --- a/include/modules.h +++ b/include/modules.h @@ -410,14 +410,14 @@ class Server : public classbase * On success, the return value is a valid pointer to a chanrec* of the channel the user was joined to. * On failure, the result is NULL. */ - virtual chanrec* Server::JoinUserToChannel(userrec* user, std::string cname, std::string key); + virtual chanrec* JoinUserToChannel(userrec* user, std::string cname, std::string key); /** Forces a user to part a channel. * This is similar to svspart and can be used to implement redirection, etc. * Although the return value of this function is a pointer to a channel record, the returned data is * undefined and should not be read or written to. This behaviour may be changed in a future version. */ - virtual chanrec* Server::PartUserFromChannel(userrec* user, std::string cname, std::string reason); + virtual chanrec* PartUserFromChannel(userrec* user, std::string cname, std::string reason); /** Forces a user nickchange. * This command works similarly to SVSNICK, and can be used to implement Q-lines etc. @@ -499,28 +499,34 @@ class FileReader : public classbase * after constructing the class this way. */ FileReader(); + /** Secondary constructor. * This method initialises the class with a file loaded into it ready for GetLine and * and other methods to be called. If the file could not be loaded, FileReader::FileSize * returns 0. */ FileReader(std::string filename); + /** Default destructor. * This deletes the memory allocated to the file. */ ~FileReader(); + /** Used to load a file. * This method loads a file into the class ready for GetLine and * and other methods to be called. If the file could not be loaded, FileReader::FileSize * returns 0. */ void LoadFile(std::string filename); + + bool Exists(); + /** Retrieve one line from the file. * This method retrieves one line from the text file. If an empty non-NULL string is returned, * the index was out of bounds, or the line had no data on it. */ - bool Exists(); std::string GetLine(int x); + /** Returns the size of the file in lines. * This method returns the number of lines in the read file. If it is 0, no lines have been * read into memory, either because the file is empty or it does not exist, or cannot be diff --git a/src/InspIRCd.layout b/src/InspIRCd.layout index 60f36e9a1..b6c14fd5f 100644 --- a/src/InspIRCd.layout +++ b/src/InspIRCd.layout @@ -1,5 +1,5 @@ [Editors] -Focused=-1 +Focused=1 Order=7,3,2,6,25,24,4,5,0,-1,1 [Editor_0] @@ -12,10 +12,10 @@ LeftChar=1 [Editor_1] Open=1 -Top=0 -CursorCol=1 -CursorRow=123 -TopLine=79 +Top=1 +CursorCol=7 +CursorRow=5232 +TopLine=5208 LeftChar=1 [Editor_2] @@ -61,9 +61,9 @@ LeftChar=1 [Editor_7] Open=1 Top=0 -CursorCol=1 -CursorRow=1 -TopLine=6 +CursorCol=20 +CursorRow=15 +TopLine=15 LeftChar=1 [Editor_8] @@ -123,11 +123,11 @@ TopLine=1 LeftChar=1 [Editor_15] -Open=0 +Open=1 Top=0 CursorCol=1 -CursorRow=1 -TopLine=1 +CursorRow=81 +TopLine=59 LeftChar=1 [Editor_16] @@ -164,10 +164,10 @@ LeftChar=1 [Editor_20] Open=1 -Top=1 -CursorCol=15 -CursorRow=210 -TopLine=176 +Top=0 +CursorCol=2 +CursorRow=494 +TopLine=506 LeftChar=1 [Editor_21] @@ -197,9 +197,9 @@ LeftChar=1 [Editor_24] Open=1 Top=0 -CursorCol=71 -CursorRow=101 -TopLine=84 +CursorCol=1 +CursorRow=1 +TopLine=1 LeftChar=1 [Editor_25] Open=1 diff --git a/src/inspircd.cpp b/src/inspircd.cpp index 3b481bb3e..786cbe4f2 100644 --- a/src/inspircd.cpp +++ b/src/inspircd.cpp @@ -4892,48 +4892,48 @@ void createcommand(char* cmd, handlerfunc f, char flags, int minparams) void SetupCommandTable(void) { - createcommand("USER",handle_user,0,4); - createcommand("NICK",handle_nick,0,1); - createcommand("QUIT",handle_quit,0,0); - createcommand("VERSION",handle_version,0,0); - createcommand("PING",handle_ping,0,1); - createcommand("PONG",handle_pong,0,1); - createcommand("ADMIN",handle_admin,0,0); - createcommand("PRIVMSG",handle_privmsg,0,2); - createcommand("INFO",handle_info,0,0); - createcommand("TIME",handle_time,0,0); - createcommand("WHOIS",handle_whois,0,1); - createcommand("WALLOPS",handle_wallops,'o',1); - createcommand("NOTICE",handle_notice,0,2); - createcommand("JOIN",handle_join,0,1); - createcommand("NAMES",handle_names,0,1); - createcommand("PART",handle_part,0,1); - createcommand("KICK",handle_kick,0,2); - createcommand("MODE",handle_mode,0,1); - createcommand("TOPIC",handle_topic,0,1); - createcommand("WHO",handle_who,0,1); - createcommand("MOTD",handle_motd,0,0); - createcommand("RULES",handle_join,0,0); - createcommand("OPER",handle_oper,0,2); - createcommand("LIST",handle_list,0,0); - createcommand("DIE",handle_die,'o',1); - createcommand("RESTART",handle_restart,'o',1); - createcommand("KILL",handle_kill,'o',2); - createcommand("REHASH",handle_rehash,'o',0); - createcommand("LUSERS",handle_lusers,0,0); - createcommand("STATS",handle_stats,0,1); - createcommand("USERHOST",handle_userhost,0,1); - createcommand("AWAY",handle_away,0,0); - createcommand("ISON",handle_ison,0,0); - createcommand("SUMMON",handle_summon,0,0); - createcommand("USERS",handle_users,0,0); - createcommand("INVITE",handle_invite,0,2); - createcommand("PASS",handle_pass,0,1); - createcommand("TRACE",handle_trace,'o',0); - createcommand("WHOWAS",handle_whowas,0,1); - createcommand("CONNECT",handle_connect,'o',1); - createcommand("SQUIT",handle_squit,'o',1); - createcommand("MODULES",handle_modules,'o',0); + createcommand("USER",handle_user,0,4); + createcommand("NICK",handle_nick,0,1); + createcommand("QUIT",handle_quit,0,0); + createcommand("VERSION",handle_version,0,0); + createcommand("PING",handle_ping,0,1); + createcommand("PONG",handle_pong,0,1); + createcommand("ADMIN",handle_admin,0,0); + createcommand("PRIVMSG",handle_privmsg,0,2); + createcommand("INFO",handle_info,0,0); + createcommand("TIME",handle_time,0,0); + createcommand("WHOIS",handle_whois,0,1); + createcommand("WALLOPS",handle_wallops,'o',1); + createcommand("NOTICE",handle_notice,0,2); + createcommand("JOIN",handle_join,0,1); + createcommand("NAMES",handle_names,0,1); + createcommand("PART",handle_part,0,1); + createcommand("KICK",handle_kick,0,2); + createcommand("MODE",handle_mode,0,1); + createcommand("TOPIC",handle_topic,0,1); + createcommand("WHO",handle_who,0,1); + createcommand("MOTD",handle_motd,0,0); + createcommand("RULES",handle_rules,0,0); + createcommand("OPER",handle_oper,0,2); + createcommand("LIST",handle_list,0,0); + createcommand("DIE",handle_die,'o',1); + createcommand("RESTART",handle_restart,'o',1); + createcommand("KILL",handle_kill,'o',2); + createcommand("REHASH",handle_rehash,'o',0); + createcommand("LUSERS",handle_lusers,0,0); + createcommand("STATS",handle_stats,0,1); + createcommand("USERHOST",handle_userhost,0,1); + createcommand("AWAY",handle_away,0,0); + createcommand("ISON",handle_ison,0,0); + createcommand("SUMMON",handle_summon,0,0); + createcommand("USERS",handle_users,0,0); + createcommand("INVITE",handle_invite,0,2); + createcommand("PASS",handle_pass,0,1); + createcommand("TRACE",handle_trace,'o',0); + createcommand("WHOWAS",handle_whowas,0,1); + createcommand("CONNECT",handle_connect,'o',1); + createcommand("SQUIT",handle_squit,'o',1); + createcommand("MODULES",handle_modules,'o',0); } void process_buffer(userrec *user) @@ -5187,239 +5187,241 @@ int reap_counter = 0; int InspIRCd(void) { - struct sockaddr_in client, server; - char addrs[MAXBUF][255]; - int openSockfd[MAXSOCKS], incomingSockfd, result = TRUE; - socklen_t length; - int count = 0, scanDetectTrigger = TRUE, showBanner = FALSE; - int selectResult = 0; - char *temp, configToken[MAXBUF], stuff[MAXBUF], Addr[MAXBUF], Type[MAXBUF]; - char resolvedHost[MAXBUF]; - fd_set selectFds; - struct timeval tv; - - log_file = fopen("ircd.log","a+"); - if (!log_file) - { - printf("ERROR: Could not write to logfile ircd.log, bailing!\n\n"); - Exit(ERROR); - } - - log(DEBUG,"InspIRCd: startup: begin"); - log(DEBUG,"$Id$"); - if (geteuid() == 0) - { - printf("WARNING!!! You are running an irc server as ROOT!!! DO NOT DO THIS!!!\n\n"); - Exit(ERROR); - log(DEBUG,"InspIRCd: startup: not starting with UID 0!"); - } - SetupCommandTable(); - log(DEBUG,"InspIRCd: startup: default command table set up"); - - ReadConfig(); - if (strcmp(DieValue,"")) - { - printf("WARNING: %s\n\n",DieValue); - exit(0); - } - log(DEBUG,"InspIRCd: startup: read config"); - - int count2 = 0, count3 = 0; - for (count = 0; count < ConfValueEnum("bind"); count++) - { - ConfValue("bind","port",count,configToken); - ConfValue("bind","address",count,Addr); - ConfValue("bind","type",count,Type); - if (!strcmp(Type,"servers")) - { - char Default[MAXBUF]; - strcpy(Default,"no"); - ConfValue("bind","default",count,Default); - if (strchr(Default,'y')) - { - defaultRoute = count3; - log(DEBUG,"InspIRCd: startup: binding '%s:%s' is default server route",Addr,configToken); - } - me[count3] = new serverrec(ServerName,100L,false); - me[count3]->CreateListener(Addr,atoi(configToken)); - count3++; + struct sockaddr_in client, server; + char addrs[MAXBUF][255]; + int openSockfd[MAXSOCKS], incomingSockfd, result = TRUE; + socklen_t length; + int count = 0, scanDetectTrigger = TRUE, showBanner = FALSE; + int selectResult = 0; + char *temp, configToken[MAXBUF], stuff[MAXBUF], Addr[MAXBUF], Type[MAXBUF]; + char resolvedHost[MAXBUF]; + fd_set selectFds; + struct timeval tv; + + log_file = fopen("ircd.log","a+"); + if (!log_file) + { + printf("ERROR: Could not write to logfile ircd.log, bailing!\n\n"); + Exit(ERROR); } - else + + log(DEBUG,"InspIRCd: startup: begin"); + log(DEBUG,"$Id$"); + if (geteuid() == 0) { - ports[count2] = atoi(configToken); - strcpy(addrs[count2],Addr); - count2++; + printf("WARNING!!! You are running an irc server as ROOT!!! DO NOT DO THIS!!!\n\n"); + Exit(ERROR); + log(DEBUG,"InspIRCd: startup: not starting with UID 0!"); } - log(DEBUG,"InspIRCd: startup: read binding %s:%s [%s] from config",Addr,configToken, Type); - } - portCount = count2; - UDPportCount = count3; - - log(DEBUG,"InspIRCd: startup: read %d total client ports and %d total server ports",portCount,UDPportCount); - - log(DEBUG,"InspIRCd: startup: InspIRCd is now running!"); - - printf("\n"); - - /* BugFix By Craig! :p */ - count2 = 0; - for (count = 0; count2 < ConfValueEnum("module"); count2++) - { - char modfile[MAXBUF]; - ConfValue("module","name",count,configToken); - sprintf(modfile,"%s/%s",MOD_PATH,configToken); - printf("Loading module... \033[1;37m%s\033[0;37m\n",modfile); - log(DEBUG,"InspIRCd: startup: Loading module: %s",modfile); - /* If The File Doesnt exist, Trying to load it - * Will Segfault the IRCd.. So, check to see if - * it Exists, Before Proceeding. */ - if (FileExists(modfile)) - { - factory[count] = new ircd_module(modfile); - if (factory[count]->LastError()) - { - log(DEBUG,"Unable to load %s: %s",modfile,factory[count]->LastError()); - sprintf("Unable to load %s: %s\nExiting...\n",modfile,factory[count]->LastError()); - Exit(ERROR); + SetupCommandTable(); + log(DEBUG,"InspIRCd: startup: default command table set up"); + + ReadConfig(); + if (strcmp(DieValue,"")) + { + printf("WARNING: %s\n\n",DieValue); + exit(0); + } + log(DEBUG,"InspIRCd: startup: read config"); + + int count2 = 0, count3 = 0; + + for (count = 0; count < ConfValueEnum("bind"); count++) + { + ConfValue("bind","port",count,configToken); + ConfValue("bind","address",count,Addr); + ConfValue("bind","type",count,Type); + if (!strcmp(Type,"servers")) + { + char Default[MAXBUF]; + strcpy(Default,"no"); + ConfValue("bind","default",count,Default); + if (strchr(Default,'y')) + { + defaultRoute = count3; + log(DEBUG,"InspIRCd: startup: binding '%s:%s' is default server route",Addr,configToken); + } + me[count3] = new serverrec(ServerName,100L,false); + me[count3]->CreateListener(Addr,atoi(configToken)); + count3++; } - if (factory[count]->factory) + else { - modules[count] = factory[count]->factory->CreateModule(); - /* save the module and the module's classfactory, if - * this isnt done, random crashes can occur :/ */ - module_names.push_back(modfile); + ports[count2] = atoi(configToken); + strcpy(addrs[count2],Addr); + count2++; + } + log(DEBUG,"InspIRCd: startup: read binding %s:%s [%s] from config",Addr,configToken, Type); + } + portCount = count2; + UDPportCount = count3; + + log(DEBUG,"InspIRCd: startup: read %d total client ports and %d total server ports",portCount,UDPportCount); + + log(DEBUG,"InspIRCd: startup: InspIRCd is now running!"); + + printf("\n"); + + /* BugFix By Craig! :p */ + count2 = 0; + for (count = 0; count2 < ConfValueEnum("module"); count2++) + { + char modfile[MAXBUF]; + ConfValue("module","name",count,configToken); + sprintf(modfile,"%s/%s",MOD_PATH,configToken); + printf("Loading module... \033[1;37m%s\033[0;37m\n",modfile); + log(DEBUG,"InspIRCd: startup: Loading module: %s",modfile); + /* If The File Doesnt exist, Trying to load it + * Will Segfault the IRCd.. So, check to see if + * it Exists, Before Proceeding. */ + if (FileExists(modfile)) + { + factory[count] = new ircd_module(modfile); + if (factory[count]->LastError()) + { + log(DEBUG,"Unable to load %s: %s",modfile,factory[count]->LastError()); + sprintf("Unable to load %s: %s\nExiting...\n",modfile,factory[count]->LastError()); + Exit(ERROR); + } + if (factory[count]->factory) + { + modules[count] = factory[count]->factory->CreateModule(); + /* save the module and the module's classfactory, if + * this isnt done, random crashes can occur :/ */ + module_names.push_back(modfile); + } + else + { + log(DEBUG,"Unable to load %s",modfile); + sprintf("Unable to load %s\nExiting...\n",modfile); + Exit(ERROR); + } + /* Increase the Count */ + count++; } else { - log(DEBUG,"Unable to load %s",modfile); - sprintf("Unable to load %s\nExiting...\n",modfile); - Exit(ERROR); + log(DEBUG,"InspIRCd: startup: Module Not Found %s",modfile); + printf("Module Not Found: \033[1;37m%s\033[0;37m, Skipping\n",modfile); } - /* Increase the Count */ - count++; + } + MODCOUNT = count - 1; + log(DEBUG,"Total loaded modules: %d",MODCOUNT+1); + + printf("\nInspIRCd is now running!\n"); + + startup_time = time(NULL); + + if (nofork) + { + log(VERBOSE,"Not forking as -nofork was specified"); } else { - log(DEBUG,"InspIRCd: startup: Module Not Found %s",modfile); - printf("Module Not Found: \033[1;37m%s\033[0;37m, Skipping\n",modfile); + if (DaemonSeed() == ERROR) + { + log(DEBUG,"InspIRCd: startup: can't daemonise"); + printf("ERROR: could not go into daemon mode. Shutting down.\n"); + Exit(ERROR); + } + } + + + /* setup select call */ + FD_ZERO(&selectFds); + log(DEBUG,"InspIRCd: startup: zero selects"); + log(VERBOSE,"InspIRCd: startup: portCount = %d", portCount); + + for (count = 0; count < portCount; count++) + { + if ((openSockfd[boundPortCount] = OpenTCPSocket()) == ERROR) + { + log(DEBUG,"InspIRCd: startup: bad fd %d",openSockfd[boundPortCount]); + return(ERROR); + } + if (BindSocket(openSockfd[boundPortCount],client,server,ports[count],addrs[count]) == ERROR) + { + log(DEBUG,"InspIRCd: startup: failed to bind port %d",ports[count]); + } + else /* well we at least bound to one socket so we'll continue */ + { + boundPortCount++; + } } - } - MODCOUNT = count - 1; - log(DEBUG,"Total loaded modules: %d",MODCOUNT+1); - - printf("\nInspIRCd is now running!\n"); - - startup_time = time(NULL); - - if (nofork) - { - log(VERBOSE,"Not forking as -nofork was specified"); - } - else - { - if (DaemonSeed() == ERROR) + + log(DEBUG,"InspIRCd: startup: total bound ports %d",boundPortCount); + + /* if we didn't bind to anything then abort */ + if (boundPortCount == 0) { - log(DEBUG,"InspIRCd: startup: can't daemonise"); - printf("ERROR: could not go into daemon mode. Shutting down.\n"); - Exit(ERROR); - } - } - - - /* setup select call */ - FD_ZERO(&selectFds); - log(DEBUG,"InspIRCd: startup: zero selects"); - log(VERBOSE,"InspIRCd: startup: portCount = %d", portCount); - - for (count = 0; count < portCount; count++) - { - if ((openSockfd[boundPortCount] = OpenTCPSocket()) == ERROR) - { - log(DEBUG,"InspIRCd: startup: bad fd %d",openSockfd[boundPortCount]); - return(ERROR); - } - if (BindSocket(openSockfd[boundPortCount],client,server,ports[count],addrs[count]) == ERROR) - { - log(DEBUG,"InspIRCd: startup: failed to bind port %d",ports[count]); - } - else /* well we at least bound to one socket so we'll continue */ - { - boundPortCount++; - } - } - - log(DEBUG,"InspIRCd: startup: total bound ports %d",boundPortCount); - - /* if we didn't bind to anything then abort */ - if (boundPortCount == 0) - { - log(DEBUG,"InspIRCd: startup: no ports bound, bailing!"); - return (ERROR); - } - - length = sizeof (client); - int flip_flop = 0, udp_port = 0; - char udp_msg[MAXBUF], udp_host[MAXBUF]; - - /* main loop for multiplexing/resetting */ - for (;;) - { - /* set up select call */ - for (count = 0; count < boundPortCount; count++) - { - FD_SET (openSockfd[count], &selectFds); - } + log(DEBUG,"InspIRCd: startup: no ports bound, bailing!"); + return (ERROR); + } - /* added timeout! select was waiting forever... wank... :/ */ - tv.tv_usec = 0; - - flip_flop++; - reap_counter++; - if (flip_flop > 20) - { - tv.tv_usec = 1; - flip_flop = 0; - } + length = sizeof (client); + int flip_flop = 0, udp_port = 0; + char udp_msg[MAXBUF], udp_host[MAXBUF]; + + /* main loop for multiplexing/resetting */ + for (;;) + { + /* set up select call */ + for (count = 0; count < boundPortCount; count++) + { + FD_SET (openSockfd[count], &selectFds); + } + + /* added timeout! select was waiting forever... wank... :/ */ + tv.tv_usec = 0; + + flip_flop++; + reap_counter++; + if (flip_flop > 20) + { + tv.tv_usec = 1; + flip_flop = 0; + } - vector<int>::iterator niterator; + vector<int>::iterator niterator; - // *FIX* Instead of closing sockets in kill_link when they receive the ERROR :blah line, we should queue - // them in a list, then reap the list every second or so. - if (reap_counter>5000) { - if (fd_reap.size() > 0) { - for( int n = 0; n < fd_reap.size(); n++) - { - Blocking(fd_reap[n]); - close(fd_reap[n]); - NonBlocking(fd_reap[n]); + // *FIX* Instead of closing sockets in kill_link when they receive the ERROR :blah line, we should queue + // them in a list, then reap the list every second or so. + if (reap_counter>5000) { + if (fd_reap.size() > 0) { + for( int n = 0; n < fd_reap.size(); n++) + { + Blocking(fd_reap[n]); + close(fd_reap[n]); + NonBlocking(fd_reap[n]); + } } + fd_reap.clear(); + reap_counter=0; } - fd_reap.clear(); - reap_counter=0; - } - tv.tv_sec = 0; - selectResult = select(MAXSOCKS, &selectFds, NULL, NULL, &tv); - - for (int x = 0; x != UDPportCount; x++) - { - long theirkey = 0; - if (me[x]->RecvPacket(udp_msg, udp_host, udp_port, theirkey)) - { - if (strlen(udp_msg)<1) { - log(DEBUG,"Invalid datagram from %s:%d:%d [route%d]",udp_host,udp_port,me[x]->port,x); - } - else { + tv.tv_sec = 0; + selectResult = select(MAXSOCKS, &selectFds, NULL, NULL, &tv); + + for (int x = 0; x != UDPportCount; x++) + { + long theirkey = 0; + if (me[x]->RecvPacket(udp_msg, udp_host, udp_port, theirkey)) + { + if (strlen(udp_msg)<1) { + log(DEBUG,"Invalid datagram from %s:%d:%d [route%d]",udp_host,udp_port,me[x]->port,x); + } + else + { FOREACH_MOD OnPacketReceive(udp_msg); // Packets must go back via the route they arrived on :) handle_link_packet(theirkey, udp_msg, udp_host, udp_port, me[x]); - } - } - } + } + } + } - for (user_hash::iterator count2 = clientlist.begin(); count2 != clientlist.end(); count2++) + for (user_hash::iterator count2 = clientlist.begin(); count2 != clientlist.end(); count2++) { char data[MAXBUF]; @@ -5510,55 +5512,52 @@ int InspIRCd(void) } } } - - /* select is reporting a waiting socket. Poll them all to find out which */ - if (selectResult > 0) - { - char target[MAXBUF], resolved[MAXBUF]; - for (count = 0; count < boundPortCount; count++) - { - if (FD_ISSET (openSockfd[count], &selectFds)) - { - incomingSockfd = accept (openSockfd[count], (struct sockaddr *) &client, &length); - - address_cache::iterator iter = IP.find(client.sin_addr); - bool iscached = false; - if (iter == IP.end()) - { - /* ip isn't in cache, add it */ - strncpy (target, (char *) inet_ntoa (client.sin_addr), MAXBUF); - if(CleanAndResolve(resolved, target) != TRUE) - { - strncpy(resolved,target,MAXBUF); - } - /* hostname now in 'target' */ - IP[client.sin_addr] = new string(resolved); - /* hostname in cache */ - } - else - { - /* found ip (cached) */ - strncpy(resolved, iter->second->c_str(), MAXBUF); - iscached = true; - } - - if (incomingSockfd < 0) - { - WriteOpers("*** WARNING: Accept failed on port %d (%s)", ports[count],target); - log(DEBUG,"InspIRCd: accept failed: %d",ports[count]); - break; - } - - AddClient(incomingSockfd, resolved, ports[count], iscached); - log(DEBUG,"InspIRCd: adding client on port %d fd=%d",ports[count],incomingSockfd); - break; - } - - } - } - } - - /* not reached */ - close (incomingSockfd); + + /* select is reporting a waiting socket. Poll them all to find out which */ + if (selectResult > 0) + { + char target[MAXBUF], resolved[MAXBUF]; + for (count = 0; count < boundPortCount; count++) + { + if (FD_ISSET (openSockfd[count], &selectFds)) + { + incomingSockfd = accept (openSockfd[count], (struct sockaddr *) &client, &length); + + address_cache::iterator iter = IP.find(client.sin_addr); + bool iscached = false; + if (iter == IP.end()) + { + /* ip isn't in cache, add it */ + strncpy (target, (char *) inet_ntoa (client.sin_addr), MAXBUF); + if(CleanAndResolve(resolved, target) != TRUE) + { + strncpy(resolved,target,MAXBUF); + } + /* hostname now in 'target' */ + IP[client.sin_addr] = new string(resolved); + /* hostname in cache */ + } + else + { + /* found ip (cached) */ + strncpy(resolved, iter->second->c_str(), MAXBUF); + iscached = true; + } + + if (incomingSockfd < 0) + { + WriteOpers("*** WARNING: Accept failed on port %d (%s)", ports[count],target); + log(DEBUG,"InspIRCd: accept failed: %d",ports[count]); + break; + } + AddClient(incomingSockfd, resolved, ports[count], iscached); + log(DEBUG,"InspIRCd: adding client on port %d fd=%d",ports[count],incomingSockfd); + break; + } + } + } +} +/* not reached */ +close (incomingSockfd); } |