]> jfr.im git - irc/rqf/shadowircd.git/blame - modules/m_presence.c
Use full (:n!u@h) prefix for sending ETB from a user to clients.
[irc/rqf/shadowircd.git] / modules / m_presence.c
CommitLineData
0827f524
WP
1/*
2 * charybdis: an advanced ircd.
3 * m_presence.c: IRC presence protocol implementation
4 *
5 * Copyright (C) 1990 Jarkko Oikarinen and University of Oulu, Co Center
6 * Copyright (C) 1996-2002 Hybrid Development Team
7 * Copyright (C) 2002-2005 ircd-ratbox development team
8 * Copyright (c) 2009 William Pitcock <nenolod@dereferenced.org>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
23 * USA
24 *
25 * $Id: m_away.c 3370 2007-04-03 10:15:39Z nenolod $
26 */
27
28#include "stdinc.h"
29#include "client.h"
30#include "match.h"
31#include "ircd.h"
32#include "numeric.h"
33#include "send.h"
34#include "msg.h"
35#include "parse.h"
36#include "modules.h"
37#include "s_conf.h"
38#include "s_serv.h"
39#include "packet.h"
40
41static int m_presence(struct Client *, struct Client *, int, const char **);
42static int me_presence(struct Client *, struct Client *, int, const char **);
43
44struct Message presence_msgtab = {
45 "PRESENCE", 0, 0, 0, MFLG_SLOW,
f62bb077 46 {mg_unreg, {m_presence, 2}, {m_presence, 2}, mg_ignore, {me_presence, 2}, {m_presence, 2}}
0827f524
WP
47};
48
49mapi_clist_av1 presence_clist[] = { &presence_msgtab, NULL };
50DECLARE_MODULE_AV1(presence, NULL, NULL, presence_clist, NULL, NULL, "$Revision$");
51
52/*
53** m_presence
54** parv[1] = key
55** parv[2] = setting
56*/
57static int
58m_presence(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
59{
fa00b4ad 60 const char *val;
0827f524
WP
61
62 if(MyClient(source_p) && !IsFloodDone(source_p))
63 flood_endgrace(source_p);
64
65 if(!IsClient(source_p))
66 return 0;
67
f80e76cf
JT
68 if (!irccmp(parv[1], "away"))
69 {
70 sendto_one_notice(source_p, ":Please use /AWAY to change your away status");
71 return 0;
72 }
73
0827f524
WP
74 if((parc < 3 || EmptyString(parv[2])) && !EmptyString(parv[1]))
75 {
fa00b4ad 76 if ((val = get_metadata(source_p, parv[1])) != NULL)
0827f524
WP
77 {
78 delete_metadata(source_p, parv[1]);
79
80 sendto_server(client_p, NULL, CAP_TS6, NOCAPS,
81 ":%s ENCAP * PRESENCE %s", use_id(source_p), parv[1]);
82 }
83 if (MyConnect(source_p))
84 sendto_one_numeric(source_p, RPL_METADATAREM, form_str(RPL_METADATAREM), parv[1]);
85 return 0;
86 }
87
338dd42d
JT
88 if (strlen(parv[1]) >= METADATAKEYLEN)
89 {
90 sendto_one_notice(source_p, ":Metadata key too long");
91 return 0;
92 }
93
fa00b4ad 94 if ((val = get_metadata(source_p, parv[1])) != NULL)
0827f524
WP
95 {
96 if (!strcmp(parv[2], val))
97 return 0;
0827f524
WP
98 }
99
100 set_metadata(source_p, parv[1], parv[2]);
101 sendto_server(client_p, NULL, CAP_TS6, NOCAPS,
102 ":%s ENCAP * PRESENCE %s :%s", use_id(source_p), parv[1], parv[2]);
103
104 if(MyConnect(source_p))
105 sendto_one_numeric(source_p, RPL_METADATASET, form_str(RPL_METADATASET), parv[1]);
106
107 return 0;
108}
109
110/*
111** me_presence
112** parv[1] = key
113** parv[2] = setting
114*/
115static int
116me_presence(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
117{
fa00b4ad 118 const char *val;
0827f524 119
0827f524
WP
120 if(!IsClient(source_p))
121 return 0;
122
123 if((parc < 3 || EmptyString(parv[2])) && !EmptyString(parv[1]))
124 {
125 delete_metadata(source_p, parv[1]);
126 return 0;
127 }
128
338dd42d
JT
129 if (strlen(parv[1]) >= METADATAKEYLEN)
130 return 0;
131
fa00b4ad 132 if ((val = get_metadata(source_p, parv[1])) != NULL)
0827f524
WP
133 {
134 if (!strcmp(parv[2], val))
135 return 0;
0827f524
WP
136 }
137
138 set_metadata(source_p, parv[1], parv[2]);
139
140 return 0;
141}