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.
32 #include "ircd_defs.h"
33 #include "ircd_reply.h"
34 #include "ircd_snprintf.h"
35 #include "ircd_string.h"
36 #include "ircd_alloc.h"
45 #include "querycmds.h"
51 static struct Map *MapList = 0;
53 /* Add a server to the map list. */
54 static void map_add(struct Client *server)
56 struct Map *map = (struct Map *)MyMalloc(sizeof(struct Map));
58 assert(IsServer(server));
59 assert(!IsHub(server));
60 assert(!IsService(server));
62 map->lasttime = TStime();
63 strcpy(map->name, cli_name(server));
64 strcpy(map->info, cli_info(server));
65 map->prot = Protocol(server);
66 map->maxclients = cli_serv(server)->clients;
77 /* Remove a server from the map list */
78 static void map_remove(struct Map *cptr)
83 cptr->next->prev = cptr->prev;
86 cptr->prev->next = cptr->next;
95 /* Update a server in the list. Called when a server connects
96 * splits, or we haven't checked in more than a week. */
97 void map_update(struct Client *cptr)
101 assert(IsServer(cptr));
103 /* Find the server in the list and update it */
104 for(map = MapList; map; map = map->next)
106 /* Show max clients not current, otherwise a split can be detected. */
107 if(!ircd_strcmp(cli_name(cptr), map->name))
109 map->lasttime = TStime();
110 map->prot = Protocol(cptr);
111 strcpy(map->info, cli_info(cptr));
112 if(map->maxclients < cli_serv(cptr)->clients)
113 map->maxclients = cli_serv(cptr)->clients;
118 /* We do this check after finding a matching map because
119 * a client server can become a hub or service (such as
122 if(IsHub(cptr) || IsService(cptr))
129 /* If we haven't seen it before, add it to the list. */
134 #ifdef HEAD_IN_SAND_MAP
136 void map_dump_head_in_sand(struct Client *cptr)
139 struct Map *smap = 0;
140 struct Client *acptr = 0;
143 send_reply(cptr, RPL_MAP, "", "", cli_name(&me), "", UserStats.local_clients);
145 for(map = MapList; map; map = smap)
149 /* Don't show servers we haven't seen in more than a week */
150 if(map->lasttime < TStime() - MAP_CACHE_TIME)
152 acptr = FindServer(map->name);
161 send_reply(cptr, RPL_MAP, smap ? "|" : "`", "-", map->name, "", map->maxclients);
165 #endif /* HEAD_IN_SAND_MAP */
167 #ifdef HEAD_IN_SAND_LINKS
168 void map_dump_links_head_in_sand(struct Client *sptr, char *mask)
170 struct Map *link = 0;
171 struct Map *slink = 0;
172 struct Client *acptr = 0;
176 for(link = MapList; link; link = slink)
180 if(link->lasttime < TStime() - MAP_CACHE_TIME)
182 acptr = FindServer(link->name);
191 if (!BadPtr(mask) && match(mask, link->name))
193 send_reply(sptr, RPL_LINKS, link->name, cli_name(&me), 1, link->prot,
196 /* don't forget to send me */
197 send_reply(sptr, RPL_LINKS, cli_name(&me), cli_name(&me), 0, Protocol(&me),
200 #endif /* HEAD_IN_SAND_LINKS */
202 void map_dump(struct Client *cptr, struct Client *server, char *mask, int prompt_length)
204 static char prompt[64];
206 char *p = &prompt[prompt_length];
210 if (prompt_length > 60)
211 send_reply(cptr, RPL_MAPMORE, prompt, cli_name(server));
214 if (cli_serv(server)->lag>10000)
216 else if (cli_serv(server)->lag<0)
219 sprintf(lag,"(%is)",cli_serv(server)->lag);
220 send_reply(cptr, RPL_MAP, prompt, (
221 (IsBurst(server)) ? "*" : (IsBurstAck(server) ? "!" : "")),
222 cli_name(server), lag, (server == &me) ? UserStats.local_clients :
223 cli_serv(server)->clients);
225 if (prompt_length > 0)
231 if (prompt_length > 60)
234 for (lp = cli_serv(server)->down; lp; lp = lp->next)
235 if (match(mask, cli_name(lp->value.cptr)))
236 ClrFlag(lp->value.cptr, FLAG_MAP);
239 SetFlag(lp->value.cptr, FLAG_MAP);
242 for (lp = cli_serv(server)->down; lp; lp = lp->next)
244 if (!HasFlag(lp->value.cptr, FLAG_MAP))
248 map_dump(cptr, lp->value.cptr, mask, prompt_length + 2);
250 if (prompt_length > 0)