2 * IRC - Internet Relay Chat, ircd/map.c
3 * Copyright (C) 1990 Jarkko Oikarinen and
4 * University of Oulu, Computing Center
5 * Copyright (C) 2002 Joseph Bongaarts <foxxe@wtfs.net>
7 * See file AUTHORS in IRC package for additional names of
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 1, or (at your option)
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
31 #include "ircd_defs.h"
32 #include "ircd_policy.h"
33 #include "ircd_reply.h"
34 #include "ircd_snprintf.h"
35 #include "ircd_string.h"
43 #include "querycmds.h"
50 #ifdef HEAD_IN_SAND_MAP
52 static struct Map *MapList = 0;
54 /* Add a server to the map list. */
55 static void map_add(struct Client *server)
58 assert(!IsHub(server));
59 assert(!IsService(server));
61 struct Map *new = (struct Map *)MyAlloc(sizeof(struct Map));
63 new->lasttime = TStime();
64 ircd_strcpy(new->name, cli_name(server));
65 new->maxclients = cli_serv(server)->clients;
76 /* Remove a server from the map list */
77 static void map_remove(struct Map *cptr)
82 cptr->next->prev = cptr->prev;
85 cptr->prev->next = cptr->next;
94 /* Update a server in the list. Called when a server connects
95 * splits, or we haven't checked in more than a week. */
96 void map_update(struct Client *cptr)
98 assert(IsServer(cptr));
102 /* Find the server in the list and update it */
103 for(map = MapList.list; map; map = map->next)
105 /* Show max clients not current, otherwise a split can be detected. */
106 if(!ircd_strcmp(cli_name(cptr), map->name))
108 map->lasttime = TStime();
109 if(map->maxclients < cli_serv(cptr)->clients)
110 map->maxclients = cli_serv(cptr)->clients;
115 /* We do this check after finding a matching map because
116 * a client server can become a hub or service (such as
119 if(IsHub(cptr) || IsService(cptr))
126 /* If we haven't seen it before, add it to the list. */
128 map_add(cli_name(cptr));
131 void dump_map_head_in_sand(struct Client *cptr)
134 struct Map *smap = 0;
135 struct Client *acptr = 0;
138 send_reply(cptr, RPL_MAP, "", "", cli_name(&me), "", UserStats.local_clients);
140 for(map = MapList; map; map = smap)
144 /* Don't show servers we haven't seen in more than a week */
145 if(map->lasttime < TStime() - 604800)
147 acptr = find_match_server(map->name);
156 send_reply(cptr, RPL_MAP, "", "|-", map->name, "", map->maxclients);
160 #endif /* HEAD_IN_SAND_MAP */
162 (void map_dump(struct Client *cptr, struct Client *server, char *mask, int prompt_length)
164 static char prompt[64];
166 char *p = &prompt[prompt_length];
170 if (prompt_length > 60)
171 send_reply(cptr, RPL_MAPMORE, prompt, cli_name(server));
174 if (cli_serv(server)->lag>10000)
176 else if (cli_serv(server)->lag<0)
179 sprintf(lag,"(%is)",cli_serv(server)->lag);
180 send_reply(cptr, RPL_MAP, prompt, (
181 (IsBurst(server)) ? "*" : (IsBurstAck(server) ? "!" : "")),
182 cli_name(server), lag, (server == &me) ? UserStats.local_clients :
183 cli_serv(server)->clients);
185 if (prompt_length > 0)
191 if (prompt_length > 60)
194 for (lp = cli_serv(server)->down; lp; lp = lp->next)
195 if (match(mask, cli_name(lp->value.cptr)))
196 cli_flags(lp->value.cptr) &= ~FLAGS_MAP;
199 cli_flags(lp->value.cptr) |= FLAGS_MAP;
202 for (lp = cli_serv(server)->down; lp; lp = lp->next)
204 if ((cli_flags(lp->value.cptr) & FLAGS_MAP) == 0)
208 map_dump(cptr, lp->value.cptr, mask, prompt_length + 2);
210 if (prompt_length > 0)