]>
jfr.im git - irc/quakenet/snircd.git/blob - ircd/m_account.c
2 * IRC - Internet Relay Chat, ircd/m_account.c
3 * Copyright (C) 2002 Kevin L. Mitchell <klmitch@mit.edu>
5 * See file AUTHORS in IRC package for additional names of
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 1, or (at your option)
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 * $Id: m_account.c,v 1.6 2004/12/11 05:13:46 klmitch Exp $
26 * m_functions execute protocol messages on this server:
28 * cptr is always NON-NULL, pointing to a *LOCAL* client
29 * structure (with an open socket connected!). This
30 * identifies the physical socket where the message
31 * originated (or which caused the m_function to be
32 * executed--some m_functions may call others...).
34 * sptr is the source of the message, defined by the
35 * prefix part of the message if present. If not
36 * or prefix not found, then sptr==cptr.
38 * (!IsServer(cptr)) => (cptr == sptr), because
39 * prefixes are taken *only* from servers...
42 * (sptr == cptr) => the message didn't
45 * (sptr != cptr && IsServer(sptr) means
46 * the prefix specified servername. (?)
48 * (sptr != cptr && !IsServer(sptr) means
49 * that message originated from a remote
54 * (!IsServer(sptr)) means that, sptr can safely
55 * taken as defining the target structure of the
56 * message in this server.
58 * *Always* true (if 'parse' and others are working correct):
60 * 1) sptr->from == cptr (note: cptr->from == cptr)
62 * 2) MyConnect(sptr) <=> sptr == cptr (e.g. sptr
63 * *cannot* be a local connection, unless it's
64 * actually cptr!). [MyConnect(x) should probably
65 * be defined as (x == x->from) --msa ]
67 * parc number of variable parameter strings (if zero,
68 * parv is allowed to be NULL)
70 * parv a NULL terminated list of parameter pointers,
72 * parv[0], sender (prefix string), if not present
73 * this points to an empty string.
74 * parv[1]...parv[parc-1]
75 * pointers to additional parameters
76 * parv[parc] == NULL, *always*
78 * note: it is guaranteed that parv[0]..parv[parc-1] are all
86 #include "ircd_reply.h"
87 #include "ircd_string.h"
94 /* #include <assert.h> -- Now using assert in ircd_log.h */
99 * ms_account - server message handler
101 * parv[0] = sender prefix
102 * parv[1] = numeric of client to act on
103 * parv[2] = account name (12 characters or less)
104 * parv[3] = account timestamp (optional)
105 * parv[4] = account id (optional, requires timestamp to be set to use)
107 int ms_account(struct Client
* cptr
, struct Client
* sptr
, int parc
,
110 struct Client
*acptr
;
113 return need_more_params(sptr
, "ACCOUNT");
116 return protocol_violation(cptr
, "ACCOUNT from non-server %s",
119 if (!(acptr
= findNUser(parv
[1])))
120 return 0; /* Ignore ACCOUNT for a user that QUIT; probably crossed */
122 if (IsAccount(acptr
))
123 return protocol_violation(cptr
, "ACCOUNT for already registered user %s "
124 "(%s -> %s)", cli_name(acptr
),
125 cli_user(acptr
)->account
, parv
[2]);
127 assert(0 == cli_user(acptr
)->account
[0]);
129 if (strlen(parv
[2]) > ACCOUNTLEN
)
130 return protocol_violation(cptr
,
131 "Received account (%s) longer than %d for %s; "
133 parv
[2], ACCOUNTLEN
, cli_name(acptr
));
136 cli_user(acptr
)->acc_create
= atoi(parv
[3]);
137 Debug((DEBUG_DEBUG
, "Received timestamped account: account \"%s\", "
138 "timestamp %Tu", parv
[2], cli_user(acptr
)->acc_create
));
140 cli_user(acptr
)->acc_id
= strtoul(parv
[4], NULL
, 10);
141 Debug((DEBUG_DEBUG
, "Received account id for account \"%s\": id %lu", parv
[2], cli_user(acptr
)->acc_id
));
145 ircd_strncpy(cli_user(acptr
)->account
, parv
[2], ACCOUNTLEN
);
146 hide_hostmask(acptr
, FLAG_ACCOUNT
);
148 if (cli_user(acptr
)->acc_id
) {
149 sendcmdto_serv_butone(sptr
, CMD_ACCOUNT
, cptr
, "%C %s %Tu %lu",
150 acptr
, cli_user(acptr
)->account
,
151 cli_user(acptr
)->acc_create
,
152 cli_user(acptr
)->acc_id
);
153 } else if (cli_user(acptr
)->acc_create
) {
154 sendcmdto_serv_butone(sptr
, CMD_ACCOUNT
, cptr
, "%C %s %Tu",
155 acptr
, cli_user(acptr
)->account
,
156 cli_user(acptr
)->acc_create
);
158 sendcmdto_serv_butone(sptr
, CMD_ACCOUNT
, cptr
, "%C %s",
159 acptr
, cli_user(acptr
)->account
);