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_xopen.h"
44 #include "querycmds.h"
51 #include "sprintf_irc.h"
60 unsigned int max_connection_count = 0;
61 unsigned int max_client_count = 0;
63 int exit_new_server(struct Client* cptr, struct Client* sptr,
64 const char* host, time_t timestamp, const char* fmt, ...)
68 (char*) MyMalloc(strlen(me.name) + strlen(host) + 22 + strlen(fmt));
72 return vexit_client_msg(cptr, cptr, &me, fmt, vl);
73 sprintf_irc(buf, ":%s " TOK_SQUIT " %s " TIME_T_FMT " :", me.name, host, timestamp);
75 vsendto_one(cptr, buf, vl);
81 int a_kills_b_too(struct Client *a, struct Client *b)
83 for (; b != a && b != &me; b = b->serv->up);
84 return (a == b ? 1 : 0);
90 * May only be called after a SERVER was received from cptr,
91 * and thus make_server was called, and serv->prot set. --Run
93 int server_estab(struct Client *cptr, struct ConfItem *aconf)
95 struct Client* acptr = 0;
100 assert(0 != cptr->local);
102 split = (0 != ircd_strcmp(cptr->name, cptr->sockhost)
103 && 0 != ircd_strncmp(cptr->info, "JUPE", 4));
106 if (IsUnknown(cptr)) {
107 if (aconf->passwd[0])
108 sendto_one(cptr, "PASS :%s", aconf->passwd);
110 * Pass my info to the new server
112 sendto_one(cptr, "SERVER %s 1 " TIME_T_FMT " " TIME_T_FMT " J%s %s%s :%s",
113 me.name, me.serv->timestamp, cptr->serv->timestamp,
114 MAJOR_PROTOCOL, NumServCap(&me),
115 (me.info[0]) ? (me.info) : "IRCers United");
117 * Don't charge this IP# for connecting
118 * XXX - if this comes from a server port, it will not have been added
119 * to the IP check registry, see add_connection in s_bsd.c
121 IPcheck_connect_fail(cptr->ip);
124 det_confs_butmask(cptr, CONF_LEAF | CONF_HUB | CONF_SERVER | CONF_UWORLD);
126 if (!IsHandshake(cptr))
129 cptr->handler = SERVER_HANDLER;
130 Count_unknownbecomesserver(UserStats);
132 release_dns_reply(cptr);
136 nextping = CurrentTime;
139 * NOTE: check for acptr->user == cptr->serv->user is necessary to insure
140 * that we got the same one... bleah
142 if (cptr->serv->user && *cptr->serv->by &&
143 (acptr = findNUser(cptr->serv->by))) {
144 if (acptr->user == cptr->serv->user) {
145 sendcmdto_one(&me, CMD_NOTICE, acptr, "%C :Link with %s established.",
150 * if not the same client, set by to empty string
153 *cptr->serv->by = '\0';
157 sendto_opmask_butone(acptr, SNO_OLDSNO, "Link with %s established.", inpath);
158 cptr->serv->up = &me;
159 cptr->serv->updown = add_dlink(&me.serv->down, cptr);
160 sendto_opmask_butone(0, SNO_NETWORK, "Net junction: %s %s", me.name,
164 * Old sendto_serv_but_one() call removed because we now
165 * need to send different names to different servers
166 * (domain name matching) Send new server to other servers.
168 for (i = 0; i <= HighestFd; i++)
170 if (!(acptr = LocalClientArray[i]) || !IsServer(acptr) ||
171 acptr == cptr || IsMe(acptr))
173 if (!match(me.name, cptr->name))
175 sendcmdto_one(&me, CMD_SERVER, acptr, "%s 2 0 %Tu J%02u %s%s 0 :%s",
176 cptr->name, cptr->serv->timestamp, Protocol(cptr),
177 NumServCap(cptr), cptr->info);
181 * Pass on my client information to the new server
183 * First, pass only servers (idea is that if the link gets
184 * cancelled beacause the server was already there,
185 * there are no NICK's to be cancelled...). Of course,
186 * if cancellation occurs, all this info is sent anyway,
187 * and I guess the link dies when a read is attempted...? --msa
189 * Note: Link cancellation to occur at this point means
190 * that at least two servers from my fragment are building
191 * up connection this other fragment at the same time, it's
192 * a race condition, not the normal way of operation...
195 for (acptr = &me; acptr; acptr = acptr->prev) {
196 /* acptr->from == acptr for acptr == cptr */
197 if (acptr->from == cptr)
199 if (IsServer(acptr)) {
200 const char* protocol_str;
202 if (Protocol(acptr) > 9)
203 protocol_str = IsBurst(acptr) ? "J" : "P";
205 protocol_str = IsBurst(acptr) ? "J0" : "P0";
207 if (0 == match(me.name, acptr->name))
209 split = (MyConnect(acptr) &&
210 0 != ircd_strcmp(acptr->name, acptr->sockhost) &&
211 0 != ircd_strncmp(acptr->info, "JUPE", 4));
212 sendcmdto_one(&me, CMD_SERVER, cptr, "%s %d 0 %Tu %s%u %s%s 0 :%s",
213 acptr->name, acptr->hopcount + 1, acptr->serv->timestamp,
214 protocol_str, Protocol(acptr), NumServCap(acptr),
219 for (acptr = &me; acptr; acptr = acptr->prev)
221 /* acptr->from == acptr for acptr == cptr */
222 if (acptr->from == cptr)
227 char *s = umode_str(acptr);
228 sendcmdto_one(acptr->user->server, CMD_NICK, cptr, *s ?
229 "%s %d %Tu %s %s +%s %s %s%s :%s" :
230 "%s %d %Tu %s %s %s%s %s%s :%s",
231 acptr->name, acptr->hopcount + 1, acptr->lastnick,
232 acptr->user->username, acptr->user->host, s,
233 inttobase64(xxx_buf, ntohl(acptr->ip.s_addr), 6),
234 NumNick(acptr), acptr->info);
238 * Last, send the BURST.
239 * (Or for 2.9 servers: pass all channels plus statuses)
242 struct Channel *chptr;
243 for (chptr = GlobalChannelList; chptr; chptr = chptr->next)
244 send_channel_modes(cptr, chptr);
248 sendcmdto_one(&me, CMD_END_OF_BURST, cptr, "");