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"
36 #include "ircd_alloc.h"
45 #include "querycmds.h"
52 #ifdef HEAD_IN_SAND_MAP
54 static struct Map *MapList = 0;
56 /* Add a server to the map list. */
57 static void map_add(struct Client *server)
59 struct Map *map = (struct Map *)MyMalloc(sizeof(struct Map));
61 assert(IsServer(server));
62 assert(!IsHub(server));
63 assert(!IsService(server));
65 map->lasttime = TStime();
66 strcpy(map->name, cli_name(server));
67 map->maxclients = cli_serv(server)->clients;
78 /* Remove a server from the map list */
79 static void map_remove(struct Map *cptr)
84 cptr->next->prev = cptr->prev;
87 cptr->prev->next = cptr->next;
96 /* Update a server in the list. Called when a server connects
97 * splits, or we haven't checked in more than a week. */
98 void map_update(struct Client *cptr)
102 assert(IsServer(cptr));
104 /* Find the server in the list and update it */
105 for(map = MapList; map; map = map->next)
107 /* Show max clients not current, otherwise a split can be detected. */
108 if(!ircd_strcmp(cli_name(cptr), map->name))
110 map->lasttime = TStime();
111 if(map->maxclients < cli_serv(cptr)->clients)
112 map->maxclients = cli_serv(cptr)->clients;
117 /* We do this check after finding a matching map because
118 * a client server can become a hub or service (such as
121 if(IsHub(cptr) || IsService(cptr))
128 /* If we haven't seen it before, add it to the list. */
133 void map_dump_head_in_sand(struct Client *cptr)
136 struct Map *smap = 0;
137 struct Client *acptr = 0;
140 send_reply(cptr, RPL_MAP, "", "", cli_name(&me), "", UserStats.local_clients);
142 for(map = MapList; map; map = smap)
146 /* Don't show servers we haven't seen in more than a week */
147 if(map->lasttime < TStime() - 604800)
149 acptr = FindServer(map->name);
158 send_reply(cptr, RPL_MAP, smap ? "|" : "`", "-", map->name, "", map->maxclients);
162 #endif /* HEAD_IN_SAND_MAP */
164 void map_dump(struct Client *cptr, struct Client *server, char *mask, int prompt_length)
166 static char prompt[64];
168 char *p = &prompt[prompt_length];
172 if (prompt_length > 60)
173 send_reply(cptr, RPL_MAPMORE, prompt, cli_name(server));
176 if (cli_serv(server)->lag>10000)
178 else if (cli_serv(server)->lag<0)
181 sprintf(lag,"(%is)",cli_serv(server)->lag);
182 send_reply(cptr, RPL_MAP, prompt, (
183 (IsBurst(server)) ? "*" : (IsBurstAck(server) ? "!" : "")),
184 cli_name(server), lag, (server == &me) ? UserStats.local_clients :
185 cli_serv(server)->clients);
187 if (prompt_length > 0)
193 if (prompt_length > 60)
196 for (lp = cli_serv(server)->down; lp; lp = lp->next)
197 if (match(mask, cli_name(lp->value.cptr)))
198 cli_flags(lp->value.cptr) &= ~FLAGS_MAP;
201 cli_flags(lp->value.cptr) |= FLAGS_MAP;
204 for (lp = cli_serv(server)->down; lp; lp = lp->next)
206 if ((cli_flags(lp->value.cptr) & FLAGS_MAP) == 0)
210 map_dump(cptr, lp->value.cptr, mask, prompt_length + 2);
212 if (prompt_length > 0)