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.
34 #include "ircd_alloc.h"
35 #include "ircd_reply.h"
36 #include "ircd_string.h"
37 #include "ircd_snprintf.h"
38 #include "ircd_xopen.h"
47 #include "querycmds.h"
62 unsigned int max_connection_count = 0;
63 unsigned int max_client_count = 0;
65 int exit_new_server(struct Client *cptr, struct Client *sptr, const char *host,
66 time_t timestamp, const char *pattern, ...)
71 vd.vd_format = pattern;
72 va_start(vd.vd_args, pattern);
75 retval = vexit_client_msg(cptr, cptr, &me, pattern, vd.vd_args);
77 sendcmdto_one(&me, CMD_SQUIT, cptr, "%s %Tu :%v", host, timestamp, &vd);
84 int a_kills_b_too(struct Client *a, struct Client *b)
86 for (; b != a && b != &me; b = cli_serv(b)->up);
87 return (a == b ? 1 : 0);
93 * May only be called after a SERVER was received from cptr,
94 * and thus make_server was called, and serv->prot set. --Run
96 int server_estab(struct Client *cptr, struct ConfItem *aconf)
98 struct Client* acptr = 0;
103 assert(0 != cli_local(cptr));
105 inpath = cli_name(cptr);
107 if (IsUnknown(cptr)) {
108 if (aconf->passwd[0])
109 sendrawto_one(cptr, MSG_PASS " :%s", aconf->passwd);
111 * Pass my info to the new server
113 sendrawto_one(cptr, MSG_SERVER " %s 1 %Tu %Tu J%s %s%s +%s :%s",
114 cli_name(&me), cli_serv(&me)->timestamp,
115 cli_serv(cptr)->timestamp, MAJOR_PROTOCOL, NumServCap(&me),
116 feature_bool(FEAT_HUB) ? "h" : "",
117 *(cli_info(&me)) ? cli_info(&me) : "IRCers United");
119 * Don't charge this IP# for connecting
120 * XXX - if this comes from a server port, it will not have been added
121 * to the IP check registry, see add_connection in s_bsd.c
123 IPcheck_connect_fail(cli_ip(cptr));
126 det_confs_butmask(cptr, CONF_LEAF | CONF_HUB | CONF_SERVER | CONF_UWORLD);
128 if (!IsHandshake(cptr))
131 cli_handler(cptr) = SERVER_HANDLER;
132 Count_unknownbecomesserver(UserStats);
134 release_dns_reply(cptr);
138 /* nextping = CurrentTime; */
141 * NOTE: check for acptr->user == cptr->serv->user is necessary to insure
142 * that we got the same one... bleah
144 if (cli_serv(cptr)->user && *(cli_serv(cptr))->by &&
145 (acptr = findNUser(cli_serv(cptr)->by))) {
146 if (cli_user(acptr) == cli_serv(cptr)->user) {
147 sendcmdto_one(&me, CMD_NOTICE, acptr, "%C :Link with %s established.",
152 * if not the same client, set by to empty string
155 *(cli_serv(cptr))->by = '\0';
159 sendto_opmask_butone(acptr, SNO_OLDSNO, "Link with %s established.", inpath);
160 cli_serv(cptr)->up = &me;
161 cli_serv(cptr)->updown = add_dlink(&(cli_serv(&me))->down, cptr);
162 sendto_opmask_butone(0, SNO_NETWORK, "Net junction: %s %s", cli_name(&me),
166 * Old sendto_serv_but_one() call removed because we now
167 * need to send different names to different servers
168 * (domain name matching) Send new server to other servers.
170 for (i = 0; i <= HighestFd; i++)
172 if (!(acptr = LocalClientArray[i]) || !IsServer(acptr) ||
173 acptr == cptr || IsMe(acptr))
175 if (!match(cli_name(&me), cli_name(cptr)))
177 sendcmdto_one(&me, CMD_SERVER, acptr,
178 "%s 2 0 %Tu J%02u %s%s +%s%s :%s", cli_name(cptr),
179 cli_serv(cptr)->timestamp, Protocol(cptr), NumServCap(cptr),
180 IsHub(cptr) ? "h" : "", IsService(cptr) ? "s" : "",
185 * Pass on my client information to the new server
187 * First, pass only servers (idea is that if the link gets
188 * cancelled beacause the server was already there,
189 * there are no NICK's to be cancelled...). Of course,
190 * if cancellation occurs, all this info is sent anyway,
191 * and I guess the link dies when a read is attempted...? --msa
193 * Note: Link cancellation to occur at this point means
194 * that at least two servers from my fragment are building
195 * up connection this other fragment at the same time, it's
196 * a race condition, not the normal way of operation...
199 for (acptr = &me; acptr; acptr = cli_prev(acptr)) {
200 /* acptr->from == acptr for acptr == cptr */
201 if (cli_from(acptr) == cptr)
203 if (IsServer(acptr)) {
204 const char* protocol_str;
206 if (Protocol(acptr) > 9)
207 protocol_str = IsBurst(acptr) ? "J" : "P";
209 protocol_str = IsBurst(acptr) ? "J0" : "P0";
211 if (0 == match(cli_name(&me), cli_name(acptr)))
213 sendcmdto_one(cli_serv(acptr)->up, CMD_SERVER, cptr,
214 "%s %d 0 %Tu %s%u %s%s +%s%s :%s", cli_name(acptr),
215 cli_hopcount(acptr) + 1, cli_serv(acptr)->timestamp,
216 protocol_str, Protocol(acptr), NumServCap(acptr),
217 IsHub(acptr) ? "h" : "", IsService(acptr) ? "s" : "",
222 for (acptr = &me; acptr; acptr = cli_prev(acptr))
224 /* acptr->from == acptr for acptr == cptr */
225 if (cli_from(acptr) == cptr)
230 char *s = umode_str(acptr);
231 sendcmdto_one(cli_user(acptr)->server, CMD_NICK, cptr,
232 "%s %d %Tu %s %s %s%s%s%s %s%s :%s",
233 cli_name(acptr), cli_hopcount(acptr) + 1, cli_lastnick(acptr),
234 cli_user(acptr)->username, cli_user(acptr)->host,
235 *s ? "+" : "", s, *s ? " " : "",
236 inttobase64(xxx_buf, ntohl(cli_ip(acptr).s_addr), 6),
237 NumNick(acptr), cli_info(acptr));
241 * Last, send the BURST.
242 * (Or for 2.9 servers: pass all channels plus statuses)
245 struct Channel *chptr;
246 for (chptr = GlobalChannelList; chptr; chptr = chptr->next)
247 send_channel_modes(cptr, chptr);
251 sendcmdto_one(&me, CMD_END_OF_BURST, cptr, "");