2 * IRC - Internet Relay Chat, ircd/s_serv.c (formerly ircd/s_msg.c)
3 * Copyright (C) 1990 Jarkko Oikarinen and
4 * University of Oulu, Computing Center
6 * See file AUTHORS in IRC package for additional names of
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 1, or (at your option)
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
33 #include "ircd_alloc.h"
34 #include "ircd_reply.h"
35 #include "ircd_string.h"
36 #include "ircd_snprintf.h"
37 #include "ircd_xopen.h"
45 #include "querycmds.h"
52 #include "sprintf_irc.h"
61 unsigned int max_connection_count = 0;
62 unsigned int max_client_count = 0;
64 int exit_new_server(struct Client* cptr, struct Client* sptr,
65 const char* host, time_t timestamp, const char* fmt, ...)
69 (char*) MyMalloc(strlen(me.name) + strlen(host) + 22 + strlen(fmt));
73 return vexit_client_msg(cptr, cptr, &me, fmt, vl);
74 sprintf_irc(buf, ":%s " TOK_SQUIT " %s " TIME_T_FMT " :", me.name, host, timestamp);
76 vsendto_one(cptr, buf, vl); /* XXX DEAD */
83 int exit_new_server(struct Client *cptr, struct Client *sptr, const char *host,
84 time_t timestamp, const char *pattern, ...)
89 vd.vd_format = pattern;
90 va_start(vd.vd_args, pattern);
93 retval = vexit_client_msg(cptr, cptr, &me, pattern, vd.vd_args);
95 sendcmdto_one(&me, CMD_SQUIT, cptr, "%s %Tu :%v", host, timestamp, &vd);
102 int a_kills_b_too(struct Client *a, struct Client *b)
104 for (; b != a && b != &me; b = b->serv->up);
105 return (a == b ? 1 : 0);
111 * May only be called after a SERVER was received from cptr,
112 * and thus make_server was called, and serv->prot set. --Run
114 int server_estab(struct Client *cptr, struct ConfItem *aconf,
117 struct Client* acptr = 0;
122 assert(0 != cptr->local);
124 split = (0 != ircd_strcmp(cptr->name, cptr->sockhost)
125 && 0 != ircd_strncmp(cptr->info, "JUPE", 4));
128 if (IsUnknown(cptr)) {
129 if (aconf->passwd[0])
130 sendrawto_one(cptr, MSG_PASS " :%s", aconf->passwd);
132 * Pass my info to the new server
134 sendrawto_one(cptr, MSG_SERVER " %s 1 %Tu %Tu J%s %s%s :%s", me.name,
135 me.serv->timestamp, cptr->serv->timestamp, MAJOR_PROTOCOL,
136 NumServCap(&me), *me.info ? me.info : "IRCers United");
138 * Don't charge this IP# for connecting
139 * XXX - if this comes from a server port, it will not have been added
140 * to the IP check registry, see add_connection in s_bsd.c
142 ip_registry_connect_fail(cptr->ip.s_addr);
145 det_confs_butmask(cptr, CONF_LEAF | CONF_HUB | CONF_SERVER | CONF_UWORLD);
147 if (!IsHandshake(cptr))
150 cptr->handler = SERVER_HANDLER;
151 Count_unknownbecomesserver(UserStats);
153 release_dns_reply(cptr);
157 nextping = CurrentTime;
160 * NOTE: check for acptr->user == cptr->serv->user is necessary to insure
161 * that we got the same one... bleah
163 if (cptr->serv->user && *cptr->serv->by &&
164 (acptr = findNUser(cptr->serv->by))) {
165 if (acptr->user == cptr->serv->user) {
166 sendcmdto_one(&me, CMD_NOTICE, acptr, "%C :Link with %s established.",
171 * if not the same client, set by to empty string
174 *cptr->serv->by = '\0';
178 sendto_opmask_butone(acptr, SNO_OLDSNO, "Link with %s established.", inpath);
179 cptr->serv->up = &me;
180 cptr->serv->updown = add_dlink(&me.serv->down, cptr);
181 sendto_opmask_butone(0, SNO_NETWORK, "Net junction: %s %s", me.name,
185 * Old sendto_serv_but_one() call removed because we now
186 * need to send different names to different servers
187 * (domain name matching) Send new server to other servers.
189 for (i = 0; i <= HighestFd; i++)
191 if (!(acptr = LocalClientArray[i]) || !IsServer(acptr) ||
192 acptr == cptr || IsMe(acptr))
194 if (!match(me.name, cptr->name))
197 sendcmdto_one(&me, CMD_SERVER, acptr,
198 "%s 2 0 %Tu J%02u %s%s 0 %%%Tu :%s", cptr->name,
199 cptr->serv->timestamp, Protocol(cptr), NumServCap(cptr),
200 JupeLastMod(ajupe), cptr->info);
202 sendcmdto_one(&me, CMD_SERVER, acptr,
203 "%s 2 0 %Tu J%02u %s%s 0 :%s", cptr->name,
204 cptr->serv->timestamp, Protocol(cptr), NumServCap(cptr),
209 * Pass on my client information to the new server
211 * First, pass only servers (idea is that if the link gets
212 * cancelled beacause the server was already there,
213 * there are no NICK's to be cancelled...). Of course,
214 * if cancellation occurs, all this info is sent anyway,
215 * and I guess the link dies when a read is attempted...? --msa
217 * Note: Link cancellation to occur at this point means
218 * that at least two servers from my fragment are building
219 * up connection this other fragment at the same time, it's
220 * a race condition, not the normal way of operation...
223 for (acptr = &me; acptr; acptr = acptr->prev) {
224 /* acptr->from == acptr for acptr == cptr */
225 if (acptr->from == cptr)
227 if (IsServer(acptr)) {
228 const char* protocol_str;
230 if (Protocol(acptr) > 9)
231 protocol_str = IsBurst(acptr) ? "J" : "P";
233 protocol_str = IsBurst(acptr) ? "J0" : "P0";
235 if (0 == match(me.name, acptr->name))
237 split = (MyConnect(acptr) &&
238 0 != ircd_strcmp(acptr->name, acptr->sockhost) &&
239 0 != ircd_strncmp(acptr->info, "JUPE", 4));
240 if ((ajupe = jupe_find(acptr->name)) && !JupeIsLocal(ajupe))
241 sendcmdto_one(acptr->serv->up, CMD_SERVER, cptr,
242 "%s %d 0 %Tu %s%u %s%s 0 %%%Tu :%s", acptr->name,
243 acptr->hopcount + 1, acptr->serv->timestamp,
244 protocol_str, Protocol(acptr), NumServCap(acptr),
245 JupeLastMod(ajupe), acptr->info);
247 sendcmdto_one(acptr->serv->up, CMD_SERVER, cptr,
248 "%s %d 0 %Tu %s%u %s%s 0 :%s", acptr->name,
249 acptr->hopcount + 1, acptr->serv->timestamp,
250 protocol_str, Protocol(acptr), NumServCap(acptr),
255 for (acptr = &me; acptr; acptr = acptr->prev)
257 /* acptr->from == acptr for acptr == cptr */
258 if (acptr->from == cptr)
263 char *s = umode_str(acptr);
264 struct Gline *agline = 0;
265 if ((agline = gline_lookup(acptr, GLINE_GLOBAL | GLINE_LASTMOD)))
266 sendcmdto_one(acptr->user->server, CMD_NICK, cptr,
267 "%s %d %Tu %s %s %s%s%s%%%Tu:%s@%s %s %s%s :%s",
268 acptr->name, acptr->hopcount + 1, acptr->lastnick,
269 acptr->user->username, acptr->user->host,
270 *s ? "+" : "", s, *s ? " " : "",
271 GlineLastMod(agline), GlineUser(agline),
273 inttobase64(xxx_buf, ntohl(acptr->ip.s_addr), 6),
274 NumNick(acptr), acptr->info);
276 sendcmdto_one(acptr->user->server, CMD_NICK, cptr,
277 "%s %d %Tu %s %s %s%s%s%s %s%s :%s",
278 acptr->name, acptr->hopcount + 1, acptr->lastnick,
279 acptr->user->username, acptr->user->host,
280 *s ? "+" : "", s, *s ? " " : "",
281 inttobase64(xxx_buf, ntohl(acptr->ip.s_addr), 6),
282 NumNick(acptr), acptr->info);
286 * Last, send the BURST.
287 * (Or for 2.9 servers: pass all channels plus statuses)
290 struct Channel *chptr;
291 for (chptr = GlobalChannelList; chptr; chptr = chptr->next)
292 send_channel_modes(cptr, chptr);
296 sendcmdto_one(&me, CMD_END_OF_BURST, cptr, "");