Debian Codegraph @

modules/groupserv/join.c

raw
1 /*
2 * Copyright (c) 2005 Atheme Development Group
3 * Rights to this code are documented in doc/LICENSE.
4 *
5 * This file contains routines to handle the GroupServ HELP command.
6 *
7 */
8
9 #include "atheme.h"
10 #include "groupserv.h"
11
12 DECLARE_MODULE_V1
13 (
14 "groupserv/join", false, _modinit, _moddeinit,
15 PACKAGE_STRING,
16 VENDOR_STRING
17 );
18
19 static void gs_cmd_join(sourceinfo_t *si, int parc, char *parv[]);
20
21 command_t gs_join = { "JOIN", N_("Join a open group."), AC_AUTHENTICATED, 2, gs_cmd_join, { .path = "groupserv/join" } };
22
23 static void gs_cmd_join(sourceinfo_t *si, int parc, char *parv[])
24 {
25 mygroup_t *mg;
26 groupacs_t *ga;
27 metadata_t *md, *md2;
28 unsigned int flags = 0;
29 bool invited = false;
30
31 if (!parv[0])
32 {
33 command_fail(si, fault_needmoreparams, STR_INSUFFICIENT_PARAMS, "JOIN");
34 command_fail(si, fault_needmoreparams, _("Syntax: JOIN <!groupname>"));
35 return;
36 }
37
38 if (!(mg = mygroup_find(parv[0])))
39 {
40 command_fail(si, fault_alreadyexists, _("Group \2%s\2 does not exist."), parv[0]);
41 return;
42 }
43
44 if ((md2 = metadata_find(si->smu, "private:groupinvite")))
45 {
46 if (!strcasecmp(md2->value, parv[0]))
47 invited = true;
48 else
49 invited = false;
50 }
51
52 if (!(mg->flags & MG_OPEN) && !invited)
53 {
54 command_fail(si, fault_noprivs, _("Group \2%s\2 is not open to anyone joining."), parv[0]);
55 return;
56 }
57
58 if (groupacs_sourceinfo_has_flag(mg, si, GA_BAN))
59 {
60 command_fail(si, fault_noprivs, _("You are not authorized to execute this command."));
61 return;
62 }
63
64 if (groupacs_sourceinfo_has_flag(mg, si, 0))
65 {
66 command_fail(si, fault_nochange, _("You are already a member of group \2%s\2."), parv[0]);
67 return;
68 }
69
70 if (MOWGLI_LIST_LENGTH(&mg->acs) > gs_config->maxgroupacs && (!(mg->flags & MG_ACSNOLIMIT)) && !invited)
71 {
72 command_fail(si, fault_toomany, _("Group \2%s\2 access list is full."), entity(mg)->name);
73 return;
74 }
75
76 if ((md = metadata_find(mg, "joinflags")))
77 flags = atoi(md->value);
78 else
79 flags = gs_flags_parser(gs_config->join_flags, 0, flags);
80
81 ga = groupacs_add(mg, entity(si->smu), flags);
82
83 if (invited)
84 metadata_delete(si->smu, "private:groupinvite");
85
86 command_success_nodata(si, _("You are now a member of \2%s\2."), entity(mg)->name);
87 }
88
89 void _modinit(module_t *m)
90 {
91 use_groupserv_main_symbols(m);
92
93 service_named_bind_command("groupserv", &gs_join);
94 }
95
96 void _moddeinit(module_unload_intent_t intent)
97 {
98 service_named_unbind_command("groupserv", &gs_join);
99 }
100