2 * IRC - Internet Relay Chat, ircd/m_squit.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.
23 * $Id: m_squit.c 1334 2005-03-20 16:06:30Z entrope $
30 #include "ircd_chattr.h"
32 #include "ircd_reply.h"
33 #include "ircd_string.h"
42 /* #include <assert.h> -- Now using assert in ircd_log.h */
50 * parv[0] = sender prefix
51 * parv[1] = server name
53 * parv[parc-1] = comment
55 * No longer supports wildcards from servers.
56 * No longer squits a server that gave us an malformed squit message.
60 int ms_squit(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
62 const char* server = parv[1];
68 return need_more_params(sptr, "SQUIT");
70 comment = parv[parc-1];
72 if (BadPtr(parv[parc - 1]))
73 comment = cli_name(sptr);
75 acptr = FindServer(server);
78 acptr = FindNServer(server);
81 Debug((DEBUG_NOTICE, "Ignoring SQUIT to an unknown server"));
85 if (IsMaster(acptr)) {
88 /* If they are squitting me, we reverse it */
90 acptr = cptr; /* Bugfix by Prefect */
93 timestamp = atoi(parv[2]);
95 protocol_violation(cptr, "SQUIT with no timestamp/reason");
97 /* If atoi(parv[2]) == 0 we must indeed squit !
98 * It will be our neighbour.
100 if ( timestamp != 0 && timestamp != cli_serv(acptr)->timestamp)
102 Debug((DEBUG_NOTICE, "Ignoring SQUIT with the wrong timestamp"));
106 return exit_client(cptr, acptr, sptr, comment);
112 * parv[0] = sender prefix
113 * parv[1] = server name
114 * parv[2] = comment (optional)
117 int mo_squit(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
120 struct Client *acptr;
121 struct Client *acptr2;
125 return need_more_params(sptr, "SQUIT");
127 if (parc < 3 || BadPtr(parv[2]))
128 comment = cli_name(sptr);
134 * The following allows wild cards in SQUIT. Only useful
135 * when the command is issued by an oper.
137 for (acptr = GlobalClientList; (acptr = next_client(acptr, server));
138 acptr = cli_next(acptr)) {
139 if (IsServer(acptr) || IsMe(acptr))
143 /* Not found? Bugger. */
144 if (!acptr || IsMe(acptr))
145 return send_reply(sptr, ERR_NOSUCHSERVER, server);
148 * Look for a matching server that is closer,
149 * that way we won't accidentally squit two close
150 * servers like davis.* and davis-r.* when typing
153 for (acptr2 = cli_serv(acptr)->up; acptr2 != &me;
154 acptr2 = cli_serv(acptr2)->up)
155 if (!match(server, cli_name(acptr2)))
158 /* Disallow local opers to squit remote servers */
160 if ((IsLocOp(sptr) && !MyConnect(acptr)) || IsMaster(acptr))
161 return send_reply(sptr, ERR_NOPRIVILEGES);
163 return exit_client(cptr, acptr, sptr, comment);