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"
44 #include "querycmds.h"
51 #ifdef HEAD_IN_SAND_MAP
53 static struct Map *MapList = 0;
55 /* Add a server to the map list. */
56 static void map_add(struct Client *server)
58 /* assert(server != 0);
59 assert(!IsHub(server));
60 assert(!IsService(server));
62 struct Map *map = (struct Map *)MyAlloc(sizeof(struct Map));
64 map->lasttime = TStime();
65 strcpy(map->name, cli_name(server));
66 map->maxclients = cli_serv(server)->clients;
77 /* Remove a server from the map list */
78 static void map_remove(struct Map *cptr)
80 /* assert(cptr != 0);*/
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)
99 /* 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 if(map->maxclients < cli_serv(cptr)->clients)
111 map->maxclients = cli_serv(cptr)->clients;
116 /* We do this check after finding a matching map because
117 * a client server can become a hub or service (such as
120 if(IsHub(cptr) || IsService(cptr))
127 /* If we haven't seen it before, add it to the list. */
129 map_add(cli_name(cptr));
132 void map_dump_head_in_sand(struct Client *cptr)
135 struct Map *smap = 0;
136 struct Client *acptr = 0;
139 send_reply(cptr, RPL_MAP, "", "", cli_name(&me), "", UserStats.local_clients);
141 for(map = MapList; map; map = smap)
145 /* Don't show servers we haven't seen in more than a week */
146 if(map->lasttime < TStime() - 604800)
148 acptr = FindServer(map->name);
157 send_reply(cptr, RPL_MAP, "", "|-", map->name, "", map->maxclients);
161 #endif /* HEAD_IN_SAND_MAP */
163 void map_dump(struct Client *cptr, struct Client *server, char *mask, int prompt_length)
165 static char prompt[64];
167 char *p = &prompt[prompt_length];
171 if (prompt_length > 60)
172 send_reply(cptr, RPL_MAPMORE, prompt, cli_name(server));
175 if (cli_serv(server)->lag>10000)
177 else if (cli_serv(server)->lag<0)
180 sprintf(lag,"(%is)",cli_serv(server)->lag);
181 send_reply(cptr, RPL_MAP, prompt, (
182 (IsBurst(server)) ? "*" : (IsBurstAck(server) ? "!" : "")),
183 cli_name(server), lag, (server == &me) ? UserStats.local_clients :
184 cli_serv(server)->clients);
186 if (prompt_length > 0)
192 if (prompt_length > 60)
195 for (lp = cli_serv(server)->down; lp; lp = lp->next)
196 if (match(mask, cli_name(lp->value.cptr)))
197 cli_flags(lp->value.cptr) &= ~FLAGS_MAP;
200 cli_flags(lp->value.cptr) |= FLAGS_MAP;
203 for (lp = cli_serv(server)->down; lp; lp = lp->next)
205 if ((cli_flags(lp->value.cptr) & FLAGS_MAP) == 0)
209 map_dump(cptr, lp->value.cptr, mask, prompt_length + 2);
211 if (prompt_length > 0)