2 * IRC - Internet Relay Chat, ircd/m_proto.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.
25 #include "ircd_reply.h"
28 #include "ircd_snprintf.h"
38 /* Report a protocol violation warning to anyone listening. This can be
39 * easily used to cleanup the last couple of parts of the code up.
42 int protocol_violation(struct Client* cptr, const char* pattern, ...)
49 vd.vd_format = pattern;
50 va_start(vd.vd_args, pattern);
52 sendcmdto_flag_butone(&me, CMD_DESYNCH, NULL, FLAGS_DEBUG,
53 ":Protocol Violation from %C: %v", cptr, &vd);
59 int need_more_params(struct Client* cptr, const char* cmd)
62 protocol_violation(cptr,"Not enough parameters for %s",cmd);
63 send_reply(cptr, ERR_NEEDMOREPARAMS, cmd);
68 * send_error_to_client - send an error message to a client
69 * I don't know if this function is any faster than the other version
70 * but it is a bit easier to use. It's reentrant until it hits vsendto_one
73 int send_error_to_client(struct Client* cptr, int error, ...)
78 const char* src = me.name;
79 const struct Numeric* num = get_error_numeric(error);
87 while ((*dest = *src++))
94 while ((*dest = *src++))
101 while ((*dest = *src++))
107 strcpy(dest, num->format);
110 Debug((DEBUG_INFO, "send_error_to_client: format: ->%s<-", buf));
114 vsendto_one(cptr, buf, vl);
120 int send_reply(struct Client *to, int reply, ...)
123 char sndbuf[IRC_BUFSIZE];
124 const struct Numeric *num;
129 num = get_error_numeric(reply & ~SND_EXPLICIT); /* get reply... */
131 va_start(vd.vd_args, reply);
133 if (reply & SND_EXPLICIT) /* get right pattern */
134 vd.vd_format = (const char *) va_arg(vd.vd_args, char *);
136 vd.vd_format = num->format;
138 assert(0 != vd.vd_format);
141 ircd_snprintf(to->from, sndbuf, sizeof(sndbuf) - 2, "%:#C %s %C %v", &me,
146 /* send it to the user */
147 send_buffer(to, sndbuf);
149 return 0; /* convenience return */
152 int send_admin_info(struct Client* sptr)
154 const struct LocalConf* admin = conf_get_local();
157 send_reply(sptr, RPL_ADMINME, me.name);
158 send_reply(sptr, RPL_ADMINLOC1, admin->location1);
159 send_reply(sptr, RPL_ADMINLOC2, admin->location2);
160 send_reply(sptr, RPL_ADMINEMAIL, admin->contact);