Author: Bleep <tomh@inxpress.net>
[ircu2.10.12-pk.git] / ircd / ircd_reply.c
1 /*
2  * IRC - Internet Relay Chat, ircd/m_proto.c
3  * Copyright (C) 1990 Jarkko Oikarinen and
4  *                    University of Oulu, Computing Center
5  *
6  * See file AUTHORS in IRC package for additional names of
7  * the programmers.
8  *
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)
12  * any later version.
13  *
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.
18  *
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.
22  *
23  * $Id$
24  */
25 #include "ircd_reply.h"
26 #include "client.h"
27 #include "ircd.h"
28 #include "numeric.h"
29 #include "s_conf.h"
30 #include "s_debug.h"
31 #include "send.h"
32
33 #include <assert.h>
34
35 int need_more_params(struct Client* cptr, const char* cmd)
36 {
37   sendto_one(cptr, err_str(ERR_NEEDMOREPARAMS), 
38              me.name, (*cptr->name) ? cptr->name : "*", cmd);
39   return 0;
40 }
41
42 /*
43  * send_error_to_client - send an error message to a client
44  * I don't know if this function is any faster than the other version
45  * but it is a bit easier to use. It's reentrant until it hits vsendto_one
46  * at least :) --Bleep
47  */
48 int send_error_to_client(struct Client* cptr, int error, ...)
49 {
50   va_list               vl;
51   char                  buf[BUFSIZE];
52   char*                 dest = buf;
53   const char*           src  = me.name;
54   const struct Numeric* num  = get_error_numeric(error);
55
56   assert(0 != cptr);
57   assert(0 != num);
58   /*
59    * prefix
60    */
61   *dest++ = ':';
62   while ((*dest = *src++))
63     ++dest;
64   *dest++ = ' ';
65   /*
66    * numeric
67    */
68   src = num->str;
69   while ((*dest = *src++))
70     ++dest;
71   *dest++ = ' ';
72   /*
73    * client name (nick)
74    */
75   src = cptr->name;
76   while ((*dest = *src++))
77     ++dest;
78   *dest++ = ' ';
79   /*
80    * reply format
81    */
82   strcpy(dest, num->format);
83
84 #if 0
85   Debug((DEBUG_INFO, "send_error_to_client: format: ->%s<-", buf));
86 #endif
87
88   va_start(vl, error);
89   vsendto_one(cptr, buf, vl);
90   va_end(vl);
91   return 0;
92 }
93
94 int send_admin_info(struct Client* sptr, const struct ConfItem* admin)
95 {
96   assert(0 != sptr);
97   if (admin) {
98     sendto_one(sptr, rpl_str(RPL_ADMINME),    me.name, sptr->name, me.name);
99     sendto_one(sptr, rpl_str(RPL_ADMINLOC1),  me.name, sptr->name, admin->host);
100     sendto_one(sptr, rpl_str(RPL_ADMINLOC2),  me.name, sptr->name, admin->passwd);
101     sendto_one(sptr, rpl_str(RPL_ADMINEMAIL), me.name, sptr->name, admin->name);
102   }
103   else
104     send_error_to_client(sptr, ERR_NOADMININFO, me.name);
105   return 0;
106 }
107
108