ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/m_svsmode.c
Revision: 1159
Committed: Wed Aug 10 21:08:18 2011 UTC (14 years ago) by michael
Content type: text/x-csrc
Original Path: ircd-hybrid-8/modules/m_svsmode.c
File size: 5337 byte(s)
Log Message:
- Implemented SVSMODE

File Contents

# User Rev Content
1 michael 1159 /*
2     * ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd).
3     *
4     * Copyright (C) 1999 by the Bahamut Development Team.
5     * Copyright (C) 2011 by the Hybrid Development Team.
6     *
7     * This program is free software; you can redistribute it and/or modify
8     * it under the terms of the GNU General Public License as published by
9     * the Free Software Foundation; either version 2 of the License, or
10     * (at your option) any later version.
11     *
12     * This program is distributed in the hope that it will be useful,
13     * but WITHOUT ANY WARRANTY; without even the implied warranty of
14     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15     * GNU General Public License for more details.
16     *
17     * You should have received a copy of the GNU General Public License
18     * along with this program; if not, write to the Free Software
19     * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20     * USA
21     */
22    
23     /*! \file m_svsmode.c
24     * \brief Includes required functions for processing the SVSMODE command.
25     * \version $Id: m_admin.c 1144 2011-07-26 19:33:54Z michael $
26     */
27    
28     #include "stdinc.h"
29     #include "handlers.h"
30     #include "client.h"
31     #include "ircd.h"
32     #include "numeric.h"
33     #include "s_conf.h"
34     #include "s_serv.h"
35     #include "send.h"
36     #include "channel_mode.h"
37     #include "msg.h"
38     #include "parse.h"
39     #include "modules.h"
40     #include "irc_string.h"
41     #include "s_user.h"
42    
43     static void ms_svsmode(struct Client *, struct Client *, int, char *[]);
44    
45     struct Message svsmode_msgtab = {
46     "SVSMODE", 0, 0, 0, 0, MFLG_SLOW | MFLG_UNREG, 0,
47     {m_ignore, m_ignore, ms_svsmode, m_ignore, m_ignore, m_ignore}
48     };
49    
50     const char *_version = "$Revision: 1144 $";
51    
52     void
53     _modinit(void)
54     {
55     mod_add_cmd(&svsmode_msgtab);
56     }
57    
58     void
59     _moddeinit(void)
60     {
61     mod_del_cmd(&svsmode_msgtab);
62     }
63    
64    
65     /*! \brief SVSMODE command handler (called by servers or services)
66     *
67     * \param client_p Pointer to allocated Client struct with physical connection
68     * to this server, i.e. with an open socket connected.
69     * \param source_p Pointer to allocated Client struct from which the message
70     * originally comes from. This can be a local or remote client.
71     * \param parc Integer holding the number of supplied arguments.
72     * \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL
73     * pointers.
74     * \note Valid arguments for this command are:
75     * - parv[0] = sender prefix
76     * - parv[1] = nickname
77     * - parv[2] = TS (or mode, depending on svs version)
78     * - parv[3] = mode (or services id if old svs version)
79     * - parv[4] = optional arguement (services id)
80     */
81     static void
82     ms_svsmode(struct Client *client_p, struct Client *source_p,
83     int parc, char *parv[])
84     {
85     struct Client *target_p = NULL;
86     int what = MODE_ADD;
87     unsigned int flag = 0, setflags = 0;
88     char *m = NULL, *modes = NULL, *extarg = NULL;
89     time_t ts = 0;
90    
91     if (!IsService(source_p) || (parc < 3))
92     return;
93    
94     if ((parc >= 4) && ((*parv[3] == '+') || (*parv[3] == '-')))
95     {
96     ts = atol(parv[2]);
97     modes = parv[3];
98     extarg = (parc > 4) ? parv[4] : NULL;
99     }
100     else
101     {
102     modes = parv[2];
103     extarg = (parc > 3) ? parv[3] : NULL;
104     }
105    
106     if ((target_p = find_person(client_p, parv[1])) == NULL)
107     return;
108    
109     if (ts && (ts != target_p->tsinfo))
110     return;
111    
112     setflags = target_p->umodes;
113    
114     for (m = modes; *m; ++m)
115     {
116     switch (*m)
117     {
118     case '+':
119     what = MODE_ADD;
120     break;
121     case '-':
122     what = MODE_DEL;
123     break;
124     case 'o':
125     if (what == MODE_DEL && IsOper(target_p))
126     {
127     ClearOper(target_p);
128     Count.oper--;
129    
130     if (MyConnect(target_p))
131     {
132     dlink_node *dm = NULL;
133    
134     detach_conf(target_p, OPER_TYPE);
135     ClearOperFlags(target_p);
136     DelUMode(target_p, ConfigFileEntry.oper_only_umodes);
137    
138     if ((dm = dlinkFindDelete(&oper_list, target_p)) != NULL)
139     free_dlink_node(dm);
140     }
141     }
142    
143     break;
144    
145     case ' ':
146     case '\n':
147     case '\r':
148     case '\t':
149     break;
150     case 'd':
151     if (extarg && IsDigit(*extarg))
152     target_p->servicestamp = strtoul(extarg, NULL, 0);
153     break;
154     default:
155     if ((flag = user_modes[(unsigned char)*m]))
156     execute_callback(umode_cb, client_p, target_p, what, flag);
157     break;
158     }
159     }
160    
161     if (extarg)
162     {
163     sendto_server(client_p, NULL, CAP_TS6, NOCAPS,
164     ":%s SVSMODE %s %lu %s %s", ID(source_p),
165     ID(target_p), (unsigned long)target_p->tsinfo, modes, extarg);
166     sendto_server(client_p, NULL, NOCAPS, CAP_TS6,
167     ":%s SVSMODE %s %lu %s %s", source_p->name,
168     target_p->name, (unsigned long)target_p->tsinfo, modes, extarg);
169     }
170     else
171     {
172     sendto_server(client_p, NULL, CAP_TS6, NOCAPS,
173     ":%s SVSMODE %s %lu %s", ID(source_p),
174     ID(target_p), (unsigned long)target_p->tsinfo, modes);
175     sendto_server(client_p, NULL, NOCAPS, CAP_TS6,
176     ":%s SVSMODE %s %lu %s", source_p->name,
177     target_p->name, (unsigned long)target_p->tsinfo, modes);
178     }
179    
180     if (MyClient(target_p) && (setflags != target_p->umodes))
181     {
182     char modebuf[IRCD_BUFSIZE];
183    
184     send_umode(target_p, target_p, setflags, 0xffffffff, modebuf);
185     }
186     }