From: Joseph Bongaarts Date: Mon, 25 Feb 2002 06:32:02 +0000 (+0000) Subject: Author: Ghostwolf X-Git-Url: http://git.pk910.de/?p=ircu2.10.12-pk.git;a=commitdiff_plain;h=84ba698af2f5d420a276ffe44d2ab010f0af6e54 Author: Ghostwolf Log message: * ircd/m_map.c: Modified to show a useful output to non-opered clients when HEAD_IN_SAND_MAP is defined. Servers are added to the list when first seen (after receiving SERVER) and that list is sent to clients. Servers are excluded from the list if they are hubs, services, or have been missing for more than 1 week. * ircd/map.c: Created file for map_* functions * include/map.h: Created file for map_* functions * ircd/m_server.c: Added calls to map_update() * ircd/s_misc.c: Added call to map_update() * ircd/parse.c: Changed to use m_map() and mo_map() Status: Completely untested. It may compile and work. More commits are on the way. git-svn-id: file:///home/klmitch/undernet-ircu/undernet-ircu-svn/ircu2/trunk@655 c9e4aea6-c8fd-4c43-8297-357d70d61c8c --- diff --git a/ChangeLog b/ChangeLog index 1af5a05..7e21dd9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,21 @@ +2002-02-25 Joseph Bongaarts + + * ircd/m_map.c: Modified to show a useful output to non-opered + clients when HEAD_IN_SAND_MAP is defined. Servers are added to + the list when first seen (after receiving SERVER) and that list + is sent to clients. Servers are excluded from the list if they are + hubs, services, or have been missing for more than 1 week. + + * ircd/map.c: Created file for map_* functions + + * include/map.h: Created file for map_* functions + + * ircd/m_server.c: Added calls to map_update() + + * ircd/s_misc.c: Added call to map_update() + + * ircd/parse.c: Changed to use m_map() and mo_map() + 2002-02-22 Reed Loden * ircd/m_connect.c: Removed an extra : in remote connect message. diff --git a/include/map.h b/include/map.h new file mode 100644 index 0000000..da772ab --- /dev/null +++ b/include/map.h @@ -0,0 +1,52 @@ +#ifndef INCLUDED_map_h +#define INCLUDED_map_h +/* + * IRC - Internet Relay Chat, include/map.h + * Copyright (C) 1990 Jarkko Oikarinen and + * University of Oulu, Computing Center + * Copyright (C) 2002 Joseph Bongaarts + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + * $Id$ + */ +#ifndef INCLUDED_time_h +#include /* struct tm */ +#define INCLUDED_time_h +#endif +#ifndef INCLUDED_sys_types_h +#include +#define INCLUDED_sys_types_h +#endif + +#ifdef HEAD_IN_SAND_MAP + +struct Map { + time_t lasttime; + unsigned int maxclients; + char name[HOSTLEN+1]; + struct Map *next; + struct Map *prev; +} + +extern void map_update(struct Client *server); +extern void map_dump_head_in_sand(struct Client *cptr); + +#endif /* HEAD_IN_SAND_MAP */ + +extern void map_dump(struct Client *cptr, struct Client *server, char *mask, int prompt_length); + +#endif /* INCLUDED_motd_h */ + diff --git a/ircd/m_map.c b/ircd/m_map.c index 589c37f..1e4e48b 100644 --- a/ircd/m_map.c +++ b/ircd/m_map.c @@ -96,64 +96,12 @@ #include "s_serv.h" #include "send.h" #include "querycmds.h" +#include "map.h" #include #include #include -static void dump_map(struct Client *cptr, struct Client *server, char *mask, int prompt_length) -{ - static char prompt[64]; - struct DLink *lp; - char *p = &prompt[prompt_length]; - int cnt = 0; - - *p = '\0'; - if (prompt_length > 60) - send_reply(cptr, RPL_MAPMORE, prompt, cli_name(server)); - else { - char lag[512]; - if (cli_serv(server)->lag>10000) - lag[0]=0; - else if (cli_serv(server)->lag<0) - strcpy(lag,"(0s)"); - else - sprintf(lag,"(%is)",cli_serv(server)->lag); - send_reply(cptr, RPL_MAP, prompt, ( - (IsBurst(server)) ? "*" : (IsBurstAck(server) ? "!" : "")), - cli_name(server), lag, (server == &me) ? UserStats.local_clients : - cli_serv(server)->clients); - } - if (prompt_length > 0) - { - p[-1] = ' '; - if (p[-2] == '`') - p[-2] = ' '; - } - if (prompt_length > 60) - return; - strcpy(p, "|-"); - for (lp = cli_serv(server)->down; lp; lp = lp->next) - if (match(mask, cli_name(lp->value.cptr))) - cli_flags(lp->value.cptr) &= ~FLAGS_MAP; - else - { - cli_flags(lp->value.cptr) |= FLAGS_MAP; - cnt++; - } - for (lp = cli_serv(server)->down; lp; lp = lp->next) - { - if ((cli_flags(lp->value.cptr) & FLAGS_MAP) == 0) - continue; - if (--cnt == 0) - *p = '`'; - dump_map(cptr, lp->value.cptr, mask, prompt_length + 2); - } - if (prompt_length > 0) - p[-1] = '-'; -} - - /* * m_map - generic message handler * -- by Run @@ -163,22 +111,25 @@ static void dump_map(struct Client *cptr, struct Client *server, char *mask, int */ int m_map(struct Client* cptr, struct Client* sptr, int parc, char* parv[]) { - if (parc < 2) +#ifdef HEAD_IN_SAND_MAP + map_dump_head_in_sand(sptr); +#else + if(parc < 2) parv[1] = "*"; - - dump_map(sptr, &me, parv[1], 0); + map_dump(sptr, &me, parv[1], 0); +#endif /* HEAD_IN_SAND_MAP */ send_reply(sptr, RPL_MAPEND); return 0; } -#ifdef HEAD_IN_SAND_MAP -int m_map_redirect(struct Client* cptr, struct Client* sptr, int parc, - char* parv[]) +int mo_map(struct Client* cptr, struct Client* sptr, int parc, char* parv[]) { - sendcmdto_one(&me, CMD_NOTICE, sptr, "%C :%s", sptr, - "/MAP has been disabled, from CFV-165. " - "Visit " URL_SERVERS); + if (parc < 2) + parv[1] = "*"; + + map_dump(sptr, &me, parv[1], 0); + send_reply(sptr, RPL_MAPEND); + return 0; } -#endif diff --git a/ircd/m_server.c b/ircd/m_server.c index 2191a6c..0ea808c 100644 --- a/ircd/m_server.c +++ b/ircd/m_server.c @@ -102,6 +102,7 @@ #include "s_serv.h" #include "send.h" #include "userload.h" +#include "map.h" #include #include @@ -638,6 +639,8 @@ int mr_server(struct Client* cptr, struct Client* sptr, int parc, char* parv[]) else ret = 0; + map_update(cptr); + if (feature_bool(FEAT_RELIABLE_CLOCK) && abs(cli_serv(cptr)->timestamp - recv_time) > 30) { sendto_opmask_butone(0, SNO_OLDSNO, "Connected to a net with a " @@ -1076,6 +1079,7 @@ int ms_server(struct Client* cptr, struct Client* sptr, int parc, char* parv[]) Count_newremoteserver(UserStats); add_client_to_list(acptr); hAddClient(acptr); + map_update(acptr); if (*parv[5] == 'J') { diff --git a/ircd/map.c b/ircd/map.c new file mode 100644 index 0000000..008265e --- /dev/null +++ b/ircd/map.c @@ -0,0 +1,214 @@ +/* + * IRC - Internet Relay Chat, ircd/map.c + * Copyright (C) 1990 Jarkko Oikarinen and + * University of Oulu, Computing Center + * Copyright (C) 2002 Joseph Bongaarts + * + * See file AUTHORS in IRC package for additional names of + * the programmers. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 1, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + * $Id$ + */ + +#include "config.h" + +#include "client.h" +#include "ircd.h" +#include "ircd_defs.h" +#include "ircd_policy.h" +#include "ircd_reply.h" +#include "ircd_snprintf.h" +#include "ircd_string.h" +#include "list.h" +#include "match.h" +#include "msg.h" +#include "numeric.h" +#include "s_user.h" +#include "s_serv.h" +#include "send.h" +#include "querycmds.h" +#include "map.h" + +#include +#include +#include + +#ifdef HEAD_IN_SAND_MAP + +static struct Map *MapList = 0; + +/* Add a server to the map list. */ +static void map_add(struct Client *server) +{ + assert(server != 0); + assert(!IsHub(server)); + assert(!IsService(server)); + + struct Map *new = (struct Map *)MyAlloc(sizeof(struct Map)); + + new->lasttime = TStime(); + ircd_strcpy(new->name, cli_name(server)); + new->maxclients = cli_serv(server)->clients; + + new->prev = 0; + new->next = MapList; + + if(MapList) + MapList->prev = new; + + MapList = new; +} + +/* Remove a server from the map list */ +static void map_remove(struct Map *cptr) +{ + assert(cptr != 0); + + if(cptr->next) + cptr->next->prev = cptr->prev; + + if(cptr->prev) + cptr->prev->next = cptr->next; + + if(MapList == cptr) + MapList = cptr->next; + + MyFree(cptr); + +} + +/* Update a server in the list. Called when a server connects + * splits, or we haven't checked in more than a week. */ +void map_update(struct Client *cptr) +{ + assert(IsServer(cptr)); + + struct Map *map = 0; + + /* Find the server in the list and update it */ + for(map = MapList.list; map; map = map->next) + { + /* Show max clients not current, otherwise a split can be detected. */ + if(!ircd_strcmp(cli_name(cptr), map->name)) + { + map->lasttime = TStime(); + if(map->maxclients < cli_serv(cptr)->clients) + map->maxclients = cli_serv(cptr)->clients; + break; + } + } + + /* We do this check after finding a matching map because + * a client server can become a hub or service (such as + * santaclara) + */ + if(IsHub(cptr) || IsService(cptr)) + { + if(map) + map_remove(map); + return; + } + + /* If we haven't seen it before, add it to the list. */ + if(!map) + map_add(cli_name(cptr)); +} + +void dump_map_head_in_sand(struct Client *cptr) +{ + struct Map *map = 0; + struct Map *smap = 0; + struct Client *acptr = 0; + + /* Send me first */ + send_reply(cptr, RPL_MAP, "", "", cli_name(&me), "", UserStats.local_clients); + + for(map = MapList; map; map = smap) + { + smap = map->next; + + /* Don't show servers we haven't seen in more than a week */ + if(map->lasttime < TStime() - 604800) + { + acptr = find_match_server(map->name); + if(!acptr) + { + map_remove(map); + continue; + } + else + map_update(acptr); + } + send_reply(cptr, RPL_MAP, "", "|-", map->name, "", map->maxclients); + } +} + +#endif /* HEAD_IN_SAND_MAP */ + +(void map_dump(struct Client *cptr, struct Client *server, char *mask, int prompt_length) +{ + static char prompt[64]; + struct DLink *lp; + char *p = &prompt[prompt_length]; + int cnt = 0; + + *p = '\0'; + if (prompt_length > 60) + send_reply(cptr, RPL_MAPMORE, prompt, cli_name(server)); + else { + char lag[512]; + if (cli_serv(server)->lag>10000) + lag[0]=0; + else if (cli_serv(server)->lag<0) + strcpy(lag,"(0s)"); + else + sprintf(lag,"(%is)",cli_serv(server)->lag); + send_reply(cptr, RPL_MAP, prompt, ( + (IsBurst(server)) ? "*" : (IsBurstAck(server) ? "!" : "")), + cli_name(server), lag, (server == &me) ? UserStats.local_clients : + cli_serv(server)->clients); + } + if (prompt_length > 0) + { + p[-1] = ' '; + if (p[-2] == '`') + p[-2] = ' '; + } + if (prompt_length > 60) + return; + strcpy(p, "|-"); + for (lp = cli_serv(server)->down; lp; lp = lp->next) + if (match(mask, cli_name(lp->value.cptr))) + cli_flags(lp->value.cptr) &= ~FLAGS_MAP; + else + { + cli_flags(lp->value.cptr) |= FLAGS_MAP; + cnt++; + } + for (lp = cli_serv(server)->down; lp; lp = lp->next) + { + if ((cli_flags(lp->value.cptr) & FLAGS_MAP) == 0) + continue; + if (--cnt == 0) + *p = '`'; + map_dump(cptr, lp->value.cptr, mask, prompt_length + 2); + } + if (prompt_length > 0) + p[-1] = '-'; +} + + diff --git a/ircd/parse.c b/ircd/parse.c index 9e19f8f..7cde630 100644 --- a/ircd/parse.c +++ b/ircd/parse.c @@ -382,11 +382,7 @@ struct Message msgtab[] = { TOK_MAP, 0, MAXPARA, MFLG_SLOW, 0, /* UNREG, CLIENT, SERVER, OPER, SERVICE */ -#ifdef HEAD_IN_SAND_MAP - { m_unregistered, m_map_redirect, m_ignore, m_map, m_ignore } -#else - { m_unregistered, m_map, m_ignore, m_map, m_ignore } -#endif + { m_unregistered, m_map, m_ignore, mo_map, m_ignore } }, { MSG_VERSION, diff --git a/ircd/s_misc.c b/ircd/s_misc.c index 1ea6d8c..dab42bc 100644 --- a/ircd/s_misc.c +++ b/ircd/s_misc.c @@ -54,6 +54,7 @@ #include "sys.h" #include "uping.h" #include "userload.h" +#include "map.h" #include #include @@ -269,6 +270,8 @@ static void exit_one_client(struct Client* bcptr, const char* comment) Count_serverdisconnects(UserStats); else Count_remoteserverquits(UserStats); + + map_update(bcptr); } else if (IsMe(bcptr)) {