ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/contrib/m_change.c
Revision: 33
Committed: Sun Oct 2 20:50:00 2005 UTC (18 years, 6 months ago) by knight
Content type: text/x-csrc
File size: 6721 byte(s)
Log Message:
- svn:keywords

File Contents

# Content
1 /*
2 * ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd).
3 * m_change.c: Allows changing user/host/real of connected clients.
4 *
5 * Copyright (C) 2002 by the past and present ircd coders, and others.
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 * $Id$
23 */
24
25 /* List of ircd includes from ../include/ */
26 #include "stdinc.h"
27 #include "handlers.h"
28 #include "client.h"
29 #include "common.h" /* FALSE bleah */
30 #include "ircd.h"
31 #include "irc_string.h"
32 #include "numeric.h"
33 #include "fdlist.h"
34 #include "s_bsd.h"
35 #include "s_conf.h"
36 #include "s_log.h"
37 #include "s_serv.h"
38 #include "send.h"
39 #include "msg.h"
40 #include "parse.h"
41 #include "modules.h"
42 #include "s_user.h"
43 #include "hash.h"
44
45 static void mo_chgident(struct Client *, struct Client *, int, char *[]);
46 static void mo_chghost(struct Client *, struct Client *, int, char *[]);
47 static void mo_chgname(struct Client *, struct Client *, int, char *[]);
48
49 struct Message chgident_msgtab = {
50 "CHGIDENT", 0, 0, 2, 0, MFLG_SLOW, 0,
51 {m_unregistered, m_not_oper, mo_chgident, mo_chgident, mo_chgident, m_ignore}
52 };
53
54 struct Message chghost_msgtab = {
55 "CHGHOST", 0, 0, 2, 0, MFLG_SLOW, 0,
56 {m_unregistered, m_not_oper, mo_chghost, mo_chghost, mo_chghost, m_ignore}
57 };
58
59 struct Message chgname_msgtab = {
60 "CHGNAME", 0, 0, 2, 0, MFLG_SLOW, 0,
61 {m_unregistered, m_not_oper, mo_chgname, mo_chgname, mo_chgname, m_ignore}
62 };
63
64 #ifndef STATIC_MODULES
65 void
66 _modinit(void)
67 {
68 mod_add_cmd(&chgident_msgtab);
69 mod_add_cmd(&chghost_msgtab);
70 mod_add_cmd(&chgname_msgtab);
71 }
72
73 void
74 _moddeinit(void)
75 {
76 mod_del_cmd(&chgname_msgtab);
77 mod_del_cmd(&chghost_msgtab);
78 mod_del_cmd(&chgident_msgtab);
79 }
80
81 const char *_version = "$Revision$";
82 #endif
83
84 static void
85 mo_chgident(struct Client *client_p, struct Client *source_p,
86 int parc, char *parv[])
87 {
88 struct Client *target_p = NULL;
89
90 if (MyConnect(source_p) && !IsOperAdmin(source_p))
91 {
92 sendto_one(source_p, form_str(ERR_NOPRIVS),
93 me.name, parv[0], "CHGIDENT");
94 return;
95 }
96
97 if (EmptyString(parv[2]))
98 {
99 parv[2] = parv[1];
100
101 target_p = source_p;
102 if (!IsClient(target_p))
103 return;
104 }
105 else {
106 target_p = find_client(parv[1]);
107
108 if (target_p == NULL || !IsClient(target_p))
109 {
110 sendto_one(source_p, form_str(ERR_NOSUCHNICK), me.name, parv[0], parv[1]);
111 return;
112 }
113 }
114
115 if (strlen(parv[2]) > USERLEN || !*parv[2] || !valid_username(parv[2]))
116 {
117 sendto_one(source_p, ":%s NOTICE %s :Invalid username", me.name, parv[0]);
118 return;
119 }
120
121 strcpy(target_p->username, parv[2]);
122
123 if (MyClient(source_p))
124 {
125 sendto_server(client_p, source_p, NULL, NOCAPS, NOCAPS, LL_ICLIENT,
126 ":%s ENCAP * CHGIDENT %s %s",
127 parv[0], target_p->name, parv[2]);
128 sendto_one(source_p, ":%s NOTICE %s :%s changed to %s@%s",
129 me.name, parv[0], target_p->name, target_p->username,
130 target_p->host);
131 }
132
133 if (MyConnect(target_p) && IsClient(source_p))
134 sendto_one(target_p, ":%s NOTICE %s :You are now %s@%s",
135 me.name, target_p->name, target_p->username, target_p->host);
136 }
137
138 static void
139 mo_chghost(struct Client *client_p, struct Client *source_p,
140 int parc, char *parv[])
141 {
142 struct Client *target_p = NULL;
143
144 if (MyConnect(source_p) && !IsOperAdmin(source_p))
145 {
146 sendto_one(source_p, form_str(ERR_NOPRIVS),
147 me.name, parv[0], "CHGHOST");
148 return;
149 }
150
151 if (EmptyString(parv[2]))
152 {
153 parv[2] = parv[1];
154
155 target_p = source_p;
156 if (!IsClient(target_p))
157 return;
158 }
159 else {
160 target_p = find_client(parv[1]);
161 if (target_p == NULL || !IsClient(target_p))
162 {
163 sendto_one(source_p, form_str(ERR_NOSUCHNICK), me.name, parv[0], parv[1]);
164 return;
165 }
166 }
167
168 if (strlen(parv[2]) > HOSTLEN || !*parv[2] || !valid_hostname(parv[2]))
169 {
170 sendto_one(source_p, ":%s NOTICE %s :Invalid hostname", me.name, parv[0]);
171 return;
172 }
173
174 strcpy(target_p->host, parv[2]);
175
176 if (MyClient(source_p))
177 {
178 sendto_server(client_p, source_p, NULL, NOCAPS, NOCAPS, LL_ICLIENT,
179 ":%s ENCAP * CHGHOST %s %s",
180 parv[0], target_p->name, parv[2]);
181 sendto_one(source_p, ":%s NOTICE %s :%s changed to %s@%s",
182 me.name, parv[0], target_p->name, target_p->username,
183 target_p->host);
184 }
185
186 if (MyConnect(target_p) && IsClient(source_p))
187 sendto_one(target_p, ":%s NOTICE %s :You are now %s@%s",
188 me.name, target_p->name, target_p->username, target_p->host);
189 }
190
191 static void
192 mo_chgname(struct Client *client_p, struct Client *source_p,
193 int parc, char *parv[])
194 {
195 struct Client *target_p = NULL;
196
197 if (MyConnect(source_p) && !IsOperAdmin(source_p))
198 {
199 sendto_one(source_p, form_str(ERR_NOPRIVS),
200 me.name, parv[0], "CHGNAME");
201 return;
202 }
203
204 if (EmptyString(parv[2]))
205 {
206 parv[2] = parv[1];
207 target_p = source_p;
208 }
209 else if ((target_p = find_client(parv[1])) == NULL)
210 {
211 sendto_one(source_p, form_str(ERR_NOSUCHNICK), me.name, parv[0], parv[1]);
212 return;
213 }
214
215 if (strlen(parv[2]) > REALLEN || !*parv[2])
216 {
217 sendto_one(source_p, ":%s NOTICE %s :Invalid realname", me.name, parv[0]);
218 return;
219 }
220
221 if (parc > 3 && MyClient(source_p))
222 sendto_one(source_p, ":%s NOTICE %s :Warning -- too many parameters "
223 "for CHGNAME. You are probably missing a : before the new "
224 "IRC name.", me.name, parv[0]);
225
226 strcpy(target_p->info, parv[2]);
227
228 if (MyClient(source_p))
229 {
230 sendto_server(client_p, source_p, NULL, NOCAPS, NOCAPS, LL_ICLIENT,
231 ":%s ENCAP * CHGNAME %s :%s",
232 parv[0], target_p->name, parv[2]);
233 sendto_one(source_p, ":%s NOTICE %s :%s realname changed to [%s]",
234 me.name, parv[0], target_p->name, target_p->info);
235 }
236
237 if (MyClient(target_p) && IsClient(source_p))
238 sendto_one(target_p, ":%s NOTICE %s :Your realname is now [%s]",
239 me.name, target_p->name, target_p->info);
240 }

Properties

Name Value
svn:eol-style native
svn:keywords Id Revision