diff options
author | brain <brain@e03df62e-2008-0410-955e-edbf42e46eb7> | 2005-05-02 17:23:40 +0000 |
---|---|---|
committer | brain <brain@e03df62e-2008-0410-955e-edbf42e46eb7> | 2005-05-02 17:23:40 +0000 |
commit | e06a27ff0c52acbee3299614c2f60d2cb53a9e60 (patch) | |
tree | dc83dc7ca3f28647ad4c317d569176f08f7d96ca | |
parent | e786e52f6a59b5d3041befe59646a48e6dad393b (diff) |
Added /stats T
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@1280 e03df62e-2008-0410-955e-edbf42e46eb7
-rw-r--r-- | src/channels.cpp | 2 | ||||
-rw-r--r-- | src/commands.cpp | 55 | ||||
-rw-r--r-- | src/dns.cpp | 5 | ||||
-rw-r--r-- | src/inspircd.cpp | 14 | ||||
-rw-r--r-- | src/inspircd_io.cpp | 2 |
5 files changed, 55 insertions, 23 deletions
diff --git a/src/channels.cpp b/src/channels.cpp index b586871ea..fcc1c732d 100644 --- a/src/channels.cpp +++ b/src/channels.cpp @@ -125,7 +125,7 @@ chanrec::chanrec() void chanrec::SetCustomMode(char mode,bool mode_on) { if (mode_on) { - char m[3]; + static char m[3]; m[0] = mode; m[1] = '\0'; if (!strchr(this->custom_modes,mode)) diff --git a/src/commands.cpp b/src/commands.cpp index 1f8af3b8a..7a17070c8 100644 --- a/src/commands.cpp +++ b/src/commands.cpp @@ -203,6 +203,8 @@ extern std::vector<userrec*> all_opers; // by an integer, meaning there is no need for a scan/search operation. extern userrec* fd_ref_table[65536]; +extern int statsAccept,statsRefused,statsUnknown,statsCollisions,statsDns,statsDnsGood,statsDnsBad,statsConnects,statsSent,statsRecv; + void handle_join(char **parameters, int pcnt, userrec *user) { @@ -976,11 +978,11 @@ void handle_who(char **parameters, int pcnt, userrec *user) // Bug Fix #29 strcpy(tmp, ""); if (strcmp(i->second->awaymsg, "")) { - strncat(tmp, "G", 9); + strlcat(tmp, "G", 9); } else { - strncat(tmp, "H", 9); + strlcat(tmp, "H", 9); } - if (strchr(i->second->modes,'o')) { strncat(tmp, "*", 9); } + if (strchr(i->second->modes,'o')) { strlcat(tmp, "*", 9); } WriteServ(user->fd,"352 %s %s %s %s %s %s %s :0 %s",user->nick, Ptr ? Ptr->name : "*", i->second->ident, i->second->dhost, i->second->server, i->second->nick, tmp, i->second->fullname); n_list++; if (n_list > MaxWhoResults) @@ -1010,12 +1012,12 @@ void handle_who(char **parameters, int pcnt, userrec *user) // Fix Bug #29 - Part 2.. strcpy(tmp, ""); if (strcmp(i->second->awaymsg, "")) { - strncat(tmp, "G", 9); + strlcat(tmp, "G", 9); } else { - strncat(tmp, "H", 9); + strlcat(tmp, "H", 9); } - if (strchr(i->second->modes,'o')) { strncat(tmp, "*", 9); } - strcat(tmp, cmode(i->second, Ptr)); + if (strchr(i->second->modes,'o')) { strlcat(tmp, "*", 9); } + strlcat(tmp, cmode(i->second, Ptr),5); WriteServ(user->fd,"352 %s %s %s %s %s %s %s :0 %s",user->nick, Ptr->name, i->second->ident, i->second->dhost, i->second->server, i->second->nick, tmp, i->second->fullname); } } @@ -1034,11 +1036,11 @@ void handle_who(char **parameters, int pcnt, userrec *user) // Bug Fix #29 -- Part 29.. strcpy(tmp, ""); if (strcmp(u->awaymsg, "")) { - strncat(tmp, "G" ,9); + strlcat(tmp, "G" ,9); } else { - strncat(tmp, "H" ,9); + strlcat(tmp, "H" ,9); } - if (strchr(u->modes,'o')) { strncat(tmp, "*" ,9); } + if (strchr(u->modes,'o')) { strlcat(tmp, "*" ,9); } WriteServ(user->fd,"352 %s %s %s %s %s %s %s :0 %s",user->nick, u->chans[0].channel ? u->chans[0].channel->name : "*", u->ident, u->dhost, u->server, u->nick, tmp, u->fullname); } @@ -1056,9 +1058,9 @@ void handle_who(char **parameters, int pcnt, userrec *user) userrec* oper = *i; strcpy(tmp, ""); if (strcmp(oper->awaymsg, "")) { - strncat(tmp, "G" ,9); + strlcat(tmp, "G" ,9); } else { - strncat(tmp, "H" ,9); + strlcat(tmp, "H" ,9); } WriteServ(user->fd,"352 %s %s %s %s %s %s %s* :0 %s", user->nick, oper->chans[0].channel ? oper->chans[0].channel->name : "*", oper->ident, oper->dhost, oper->server, oper->nick, tmp, oper->fullname); @@ -1428,6 +1430,16 @@ void handle_stats(char **parameters, int pcnt, userrec *user) WriteServ(user->fd,"249 %s :ClassFactories(VECTOR) %d (%d)",user->nick,factory.size(),factory.size()*sizeof(ircd_module)); WriteServ(user->fd,"249 %s :Ports(STATIC_ARRAY) %d",user->nick,boundPortCount); } + + if (*parameters[0] == 'T') + { + WriteServ(user->fd,"249 Brain :accepts %d refused %d",statsAccept,statsRefused); + WriteServ(user->fd,"249 Brain :unknown commands %d",statsUnknown); + WriteServ(user->fd,"249 Brain :nick collisions %d",statsCollisions); + WriteServ(user->fd,"249 Brain :dns requests %d succeeded %d failed %d",statsDns,statsDnsGood,statsDnsBad); + WriteServ(user->fd,"249 Brain :connections %d",statsConnects); + WriteServ(user->fd,"249 Brain :bytes sent %dK recv %dK",(statsSent / 1024),(statsRecv / 1024)); + } /* stats o */ if (*parameters[0] == 'o') @@ -2160,11 +2172,13 @@ void handle_n(char token,char* params,serverrec* source,serverrec* reply, char* FOREACH_RESULT(OnUserPreNick(user,newnick)); if (MOD_RESULT) { // if a module returns true, the nick change couldnt be allowed + statsCollisions++; kill_link(user,"Nickname collision"); return; } if (matches_qline(newnick)) { + statsCollisions++; kill_link(user,"Nickname collision"); return; } @@ -2265,6 +2279,7 @@ void handle_N(char token,char* params,serverrec* source,serverrec* reply, char* if (iter != clientlist.end()) { // nick collision + statsCollisions++; WriteOpers("Nickname collision: %s@%s != %s@%s",nick,server,iter->second->nick,iter->second->server); char str[MAXBUF]; snprintf(str,MAXBUF,"Killed (Nick Collision (%s@%s < %s@%s))",nick,server,iter->second->nick,iter->second->server); @@ -3112,7 +3127,7 @@ void handle_link_packet(char* udp_msg, char* tcp_host, serverrec *serv) { WriteOpers("CONNECT aborted: Could not link to %s, is an incompatible version %s, our version is %d",servername,revision,GetRevision()); char buffer[MAXBUF]; - sprintf(buffer,"E :Version number mismatch"); + snprintf(buffer,MAXBUF,"E :Version number mismatch"); serv->SendPacket(buffer,tcp_host); RemoveServer(tcp_host); RemoveServer(servername); @@ -3166,7 +3181,7 @@ void handle_link_packet(char* udp_msg, char* tcp_host, serverrec *serv) } } char buffer[MAXBUF]; - sprintf(buffer,"E :Access is denied (no matching link block)"); + snprintf(buffer,MAXBUF,"E :Access is denied (no matching link block)"); serv->SendPacket(buffer,tcp_host); WriteOpers("CONNECT from %s denied, no matching link block",servername); RemoveServer(tcp_host); @@ -3223,7 +3238,7 @@ void handle_link_packet(char* udp_msg, char* tcp_host, serverrec *serv) char buffer[MAXBUF]; me[j]->connectors[k].SetDescription(serverdesc); me[j]->connectors[k].SetState(STATE_CONNECTED); - sprintf(buffer,"X 0"); + snprintf(buffer,MAXBUF,"X 0"); serv->SendPacket(buffer,tcp_host); DoSync(me[j],tcp_host); NetSendMyRoutingTable(); @@ -3238,7 +3253,7 @@ void handle_link_packet(char* udp_msg, char* tcp_host, serverrec *serv) } } char buffer[MAXBUF]; - sprintf(buffer,"E :Access is denied (no matching link block)"); + snprintf(buffer,MAXBUF,"E :Access is denied (no matching link block)"); serv->SendPacket(buffer,tcp_host); WriteOpers("CONNECT from %s denied, no matching link block",servername); RemoveServer(tcp_host); @@ -3273,7 +3288,7 @@ void handle_link_packet(char* udp_msg, char* tcp_host, serverrec *serv) if (!strcasecmp(me[j]->connectors[k].GetServerName().c_str(),servername)) { char buffer[MAXBUF]; - sprintf(buffer,"E :Access is denied (Server exists in the mesh)"); + snprintf(buffer,MAXBUF,"E :Access is denied (Server exists in the mesh)"); serv->SendPacket(buffer,tcp_host); WriteOpers("CONNECT from %s denied, \"%s\" already exists!",tcp_host,servername); RemoveServer(tcp_host); @@ -3311,9 +3326,9 @@ void handle_link_packet(char* udp_msg, char* tcp_host, serverrec *serv) me[j]->connectors[k].SetDescription(serverdesc); me[j]->connectors[k].SetServerName(servername); me[j]->connectors[k].SetState(STATE_SERVICES); - sprintf(buffer,"X 0"); + snprintf(buffer,MAXBUF,"X 0"); serv->SendPacket(buffer,servername); - sprintf(buffer,"s %s %s %lu :%s",ServerName,Link_SendPass,LinkPort,ServerDesc); + snprintf(buffer,MAXBUF,"s %s %s %lu :%s",ServerName,Link_SendPass,LinkPort,ServerDesc); serv->SendPacket(buffer,servername); DoSync(me[j],servername); snprintf(buffer,MAXBUF,"H %s",servername); @@ -3333,7 +3348,7 @@ void handle_link_packet(char* udp_msg, char* tcp_host, serverrec *serv) } log(DEBUG,"No matching link block found"); char buffer[MAXBUF]; - sprintf(buffer,"E :Access is denied (no matching link block)"); + snprintf(buffer,MAXBUF,"E :Access is denied (no matching link block)"); serv->SendPacket(buffer,tcp_host); WriteOpers("CONNECT from %s denied, no matching link block",servername); RemoveServer(tcp_host); diff --git a/src/dns.cpp b/src/dns.cpp index 8e3f4f48d..a9039fcdc 100644 --- a/src/dns.cpp +++ b/src/dns.cpp @@ -31,7 +31,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA #include <poll.h> #include "dns.h" -static const char tagstring[] = "$Id$"; +extern int statsAccept,statsRefused,statsUnknown,statsCollisions,statsDns,statsDnsGood,statsDnsBad,statsConnects,statsSent,statsRecv; #define max(a,b) (a > b ? a : b) #define DNS_MAX 8 /* max number of nameservers used */ @@ -691,6 +691,7 @@ DNS::~DNS() bool DNS::ReverseLookup(std::string ip) { + statsDns++; binip = dns_aton4(ip.c_str()); if (binip == NULL) { return false; @@ -723,9 +724,11 @@ std::string DNS::GetResult() { result = dns_getresult(this->fd); if (result) { + statsDnsGood++; dns_close(this->fd); return result; } else { + statsDnsBad++; return ""; } } diff --git a/src/inspircd.cpp b/src/inspircd.cpp index c3c3acb3a..ba5b9c572 100644 --- a/src/inspircd.cpp +++ b/src/inspircd.cpp @@ -181,6 +181,8 @@ typedef std::deque<command_t> command_table; // by an integer, meaning there is no need for a scan/search operation. userrec* fd_ref_table[65536]; +int statsAccept = 0, statsRefused = 0, statsUnknown = 0, statsCollisions = 0, statsDns = 0, statsDnsGood = 0, statsDnsBad = 0, statsConnects = 0, statsSent= 0, statsRecv = 0; + serverrec* me[32]; FILE *log_file; @@ -598,6 +600,7 @@ void Write(int sock,char *text, ...) fd_ref_table[sock]->bytes_out += (bytes > 512 ? 512 : bytes); fd_ref_table[sock]->cmds_out++; } + statsSent += (bytes > 512 ? 512 : bytes); } } @@ -631,6 +634,7 @@ void WriteServ(int sock, char* text, ...) fd_ref_table[sock]->bytes_out += (bytes > 512 ? 512 : bytes); fd_ref_table[sock]->cmds_out++; } + statsSent += (bytes > 512 ? 512 : bytes); } } @@ -664,6 +668,7 @@ void WriteFrom(int sock, userrec *user,char* text, ...) fd_ref_table[sock]->bytes_out += (bytes > 512 ? 512 : bytes); fd_ref_table[sock]->cmds_out++; } + statsSent += (bytes > 512 ? 512 : bytes); } } @@ -2709,6 +2714,7 @@ void ShowRULES(userrec *user) /* shows the message of the day, and any other on-logon stuff */ void FullConnectUser(userrec* user) { + statsConnects++; user->registered = 7; user->idle_lastmsg = TIME; log(DEBUG,"ConnectUser: %s",user->nick); @@ -2982,11 +2988,13 @@ void force_nickchange(userrec* user,const char* newnick) FOREACH_RESULT(OnUserPreNick(user,newnick)); if (MOD_RESULT) { + statsCollisions++; kill_link(user,"Nickname collision"); return; } if (matches_qline(newnick)) { + statsCollisions++; kill_link(user,"Nickname collision"); return; } @@ -3193,6 +3201,7 @@ void process_command(userrec *user, char* cmd) { if (strchr("@!\"$%^&*(){}[]_=+;:'#~,<>/?\\|`",command[x])) { + statsUnknown++; WriteServ(user->fd,"421 %s %s :Unknown command",user->nick,command); return; } @@ -3315,6 +3324,7 @@ void process_command(userrec *user, char* cmd) } if ((!cmd_found) && (user)) { + statsUnknown++; WriteServ(user->fd,"421 %s %s :Unknown command",user->nick,command); } } @@ -4155,6 +4165,7 @@ int InspIRCd(void) { log(DEBUG,"signon exceed, registered=3, and modules ready, OK"); curr->dns_done = true; + statsDnsBad++; FullConnectUser(curr); goto label; } @@ -4219,6 +4230,7 @@ int InspIRCd(void) if (result) { + statsRecv += result; // perform a check on the raw buffer as an array (not a string!) to remove // characters 0 and 7 which are illegal in the RFC - replace them with spaces. // hopefully this should stop even more people whining about "Unknown command: *" @@ -4391,10 +4403,12 @@ int InspIRCd(void) { WriteOpers("*** WARNING: Accept failed on port %lu (%s)",(unsigned long)ports[count],target); log(DEBUG,"InspIRCd: accept failed: %lu",(unsigned long)ports[count]); + statsRefused++; } else { FOREACH_MOD OnRawSocketAccept(incomingSockfd, resolved, ports[count]); + statsAccept++; AddClient(incomingSockfd, resolved, ports[count], false, inet_ntoa (client.sin_addr)); log(DEBUG,"InspIRCd: adding client on port %lu fd=%lu",(unsigned long)ports[count],(unsigned long)incomingSockfd); } diff --git a/src/inspircd_io.cpp b/src/inspircd_io.cpp index ebd248178..83c302d90 100644 --- a/src/inspircd_io.cpp +++ b/src/inspircd_io.cpp @@ -63,7 +63,7 @@ void Rehash(int status) void Start (void) { - printf("\033[1;32mInspire Internet Relay Chat Server, compiled " __DATE__ " at " __TIME__ "\n"); + printf("\033[1;32mInspire Internet Relay Chat Server, compiled %s at %s\n",__DATE__,__TIME__); printf("(C) ChatSpike Development team.\033[0m\n\n"); printf("Developers:\033[1;32m Brain, FrostyCoolSlug\033[0m\n"); printf("Documentation:\033[1;32m FrostyCoolSlug, w00t\033[0m\n"); |