From a753fb1bc711e10794e939e424f3cdd703116d82 Mon Sep 17 00:00:00 2001 From: brain Date: Fri, 2 Apr 2004 12:38:41 +0000 Subject: Added support for modules to create commands - this needs a proof-of-concept module yet, do not use unless you like to live dangerously. git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@351 e03df62e-2008-0410-955e-edbf42e46eb7 --- src/InspIRCd.layout | 36 ++++++++++++++-------------- src/inspircd.cpp | 68 +++++++++++++++++++++++++++++++++++++---------------- src/modules.cpp | 16 +++++++------ 3 files changed, 75 insertions(+), 45 deletions(-) (limited to 'src') diff --git a/src/InspIRCd.layout b/src/InspIRCd.layout index b54226867..d2493a3e8 100644 --- a/src/InspIRCd.layout +++ b/src/InspIRCd.layout @@ -1,5 +1,5 @@ [Editors] -Focused=1 +Focused=4 Order=1,7,3,2,0,6,5,4,25,24,-1 [Editor_0] @@ -12,10 +12,10 @@ LeftChar=1 [Editor_1] Open=1 -Top=1 -CursorCol=4 -CursorRow=1129 -TopLine=1078 +Top=0 +CursorCol=1 +CursorRow=2505 +TopLine=2476 LeftChar=1 [Editor_2] @@ -36,10 +36,10 @@ LeftChar=1 [Editor_4] Open=1 -Top=0 -CursorCol=19 -CursorRow=59 -TopLine=1 +Top=1 +CursorCol=5 +CursorRow=47 +TopLine=27 LeftChar=1 [Editor_5] @@ -91,7 +91,7 @@ TopLine=1 LeftChar=1 [Editor_11] -Open=1 +Open=0 Top=0 CursorCol=1 CursorRow=1 @@ -107,7 +107,7 @@ TopLine=120 LeftChar=1 [Editor_13] -Open=1 +Open=0 Top=0 CursorCol=60 CursorRow=64 @@ -115,10 +115,10 @@ TopLine=20 LeftChar=1 [Editor_14] -Open=0 +Open=1 Top=0 CursorCol=1 -CursorRow=1 +CursorRow=23 TopLine=1 LeftChar=1 @@ -163,15 +163,15 @@ TopLine=1 LeftChar=1 [Editor_20] -Open=0 +Open=1 Top=0 -CursorCol=13 -CursorRow=271 -TopLine=232 +CursorCol=21 +CursorRow=23 +TopLine=276 LeftChar=1 [Editor_21] -Open=1 +Open=0 Top=0 CursorCol=1 CursorRow=25 diff --git a/src/inspircd.cpp b/src/inspircd.cpp index bb081f720..082576797 100644 --- a/src/inspircd.cpp +++ b/src/inspircd.cpp @@ -77,6 +77,7 @@ time_t startup_time = time(NULL); extern vector modules; extern vector factory; +vector fd_reap; extern int MODCOUNT; @@ -958,17 +959,20 @@ int usercount_i(chanrec *c) strcpy(list,""); for (user_hash::const_iterator i = clientlist.begin(); i != clientlist.end(); i++) { - if (has_channel(i->second,c)) + if (i->second) { - if (isnick(i->second->nick)) + if (has_channel(i->second,c)) { - if ((!has_channel(i->second,c)) && (strchr(i->second->modes,'i'))) + if (isnick(i->second->nick)) { - /* user is +i, and source not on the channel, does not show - * nick in NAMES list */ - continue; + if ((!has_channel(i->second,c)) && (strchr(i->second->modes,'i'))) + { + /* user is +i, and source not on the channel, does not show + * nick in NAMES list */ + continue; + } + count++; } - count++; } } } @@ -2465,34 +2469,34 @@ void kill_link(userrec *user,char* reason) log(DEBUG,"kill_link: %s '%s'",user->nick,reason); Write(user->fd,"ERROR :Closing link (%s@%s) [%s]",user->ident,user->host,reason); fdatasync(user->fd); - WriteOpers("*** Client exiting: %s!%s@%s [%s]",user->nick,user->ident,user->host,reason); - FOREACH_MOD OnUserQuit(user); log(DEBUG,"closing fd %d",user->fd); + /* bugfix, cant close() a nonblocking socket (sux!) */ - WriteCommonExcept(user,"QUIT :%s",reason); - Blocking(user->fd); - close(user->fd); - NonBlocking(user->fd); + if (user->registered == 7) { + FOREACH_MOD OnUserQuit(user); + WriteCommonExcept(user,"QUIT :%s",reason); + } + + /* push the socket on a stack of sockets due to be closed at the next opportunity */ + fd_reap.push_back(user->fd); bool do_purge = false; if (user->registered == 7) { + WriteOpers("*** Client exiting: %s!%s@%s [%s]",user->nick,user->ident,user->host,reason); AddWhoWas(user); - do_purge = true; } if (iter != clientlist.end()) { log(DEBUG,"deleting user hash value %d",iter->second); - if (iter->second) { + if ((iter->second) && (user->registered == 7)) { delete iter->second; } clientlist.erase(iter); } - - if (do_purge) { - purge_empty_chans(); - } + + purge_empty_chans(); } @@ -2504,6 +2508,8 @@ void handle_kill(char **parameters, int pcnt, userrec *user) log(DEBUG,"kill: %s %s",parameters[0],parameters[1]); if (u) { + WriteTo(user, u, "KILL %s :%s!%s!%s (%s)", u->nick, ServerName,user->dhost,user->nick,parameters[1]); + // :Brain!brain@NetAdmin.chatspike.net KILL [Brain] :homer!NetAdmin.chatspike.net!Brain (test kill) WriteOpers("*** Local Kill by %s: %s!%s@%s (%s)",user->nick,u->nick,u->ident,u->host,parameters[1]); sprintf(killreason,"Killed (%s (%s))",user->nick,parameters[1]); kill_link(u,killreason); @@ -3318,7 +3324,7 @@ void ConnectUser(userrec *user) void handle_version(char **parameters, int pcnt, userrec *user) { - WriteServ(user->fd,"351 %s :%s %s :%s",user->nick,VERSION,ServerName,SYSTEM); + WriteServ(user->fd,"351 %s :%s %s %s :%s",user->nick,VERSION,"$Id$",ServerName,SYSTEM); } void handle_ping(char **parameters, int pcnt, userrec *user) @@ -4290,6 +4296,8 @@ void handle_link_packet(long theirkey, char* udp_msg, char* udp_host, int udp_po } } +int reap_counter = 0; + int InspIRCd(void) { struct sockaddr_in client, server; @@ -4464,12 +4472,32 @@ int InspIRCd(void) tv.tv_usec = 0; flip_flop++; + reap_counter++; if (flip_flop > 20) { tv.tv_usec = 1; flip_flop = 0; } + vector::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]); + } + } + fd_reap.clear(); + reap_counter=0; + } + + tv.tv_sec = 0; selectResult = select(MAXSOCKS, &selectFds, NULL, NULL, &tv); diff --git a/src/modules.cpp b/src/modules.cpp index 389fb60e3..820488c99 100644 --- a/src/modules.cpp +++ b/src/modules.cpp @@ -9,6 +9,7 @@ #include #include "globals.h" #include "modules.h" +#include "ctables.h" #include "inspircd_io.h" // class type for holding an extended mode character - internal to core @@ -43,7 +44,7 @@ bool ModeDefined(char modechar, int type) } // returns number of parameters for a custom mode when it is switched on -int ModeDefinedOn(char modechar, int type) +bool ModeDefinedOn(char modechar, int type) { for (ExtModeListIter i = EMode.begin(); i < EMode.end(); i++) { @@ -56,7 +57,7 @@ int ModeDefinedOn(char modechar, int type) } // returns number of parameters for a custom mode when it is switched on -int ModeDefinedOff(char modechar, int type) +bool ModeDefinedOff(char modechar, int type) { for (ExtModeListIter i = EMode.begin(); i < EMode.end(); i++) { @@ -84,11 +85,6 @@ Version::Version(int major, int minor, int revision, int build) : Major(major), Admin::Admin(std::string name, std::string email, std::string nick) : Name(name), Email(email), Nick(nick) { }; -// -// Announce to the world that the Module base -// class has been created or destroyed -// - Module::Module() { } Module::~Module() { } void Module::OnUserConnect(userrec* user) { } @@ -124,6 +120,12 @@ void Server::Log(int level, std::string s) log(level,"%s",s.c_str()); } +void Server::AddCommand(char* cmd, handlerfunc f, char flags, int minparams) +{ + createcommand(cmd,f,flags,minparams); +} + + void Server::Send(int Socket, std::string s) { Write(Socket,"%s",s.c_str()); -- cgit v1.2.3