| 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 INVITE command. |
| 6 |
* |
| 7 |
*/ |
| 8 |
|
| 9 |
/* TODO: |
| 10 |
* We should probably add a way for the target user to remove pending invites |
| 11 |
*/ |
| 12 |
|
| 13 |
#include "atheme.h" |
| 14 |
#include "groupserv.h" |
| 15 |
|
| 16 |
DECLARE_MODULE_V1 |
| 17 |
( |
| 18 |
"groupserv/invite", false, _modinit, _moddeinit, |
| 19 |
PACKAGE_STRING, |
| 20 |
VENDOR_STRING |
| 21 |
); |
| 22 |
|
| 23 |
static void gs_cmd_invite(sourceinfo_t *si, int parc, char *parv[]); |
| 24 |
|
| 25 |
command_t gs_invite = { "INVITE", N_("Invites a user to a group."), AC_AUTHENTICATED, 2, gs_cmd_invite, { .path = "groupserv/invite" } }; |
| 26 |
|
| 27 |
static void gs_cmd_invite(sourceinfo_t *si, int parc, char *parv[]) |
| 28 |
{ |
| 29 |
mygroup_t *mg; |
| 30 |
myuser_t *mu; |
| 31 |
groupacs_t *ga; |
| 32 |
char *group = parv[0]; |
| 33 |
char *user = parv[1]; |
| 34 |
char buf[BUFSIZE]; |
| 35 |
service_t *svs; |
| 36 |
|
| 37 |
if (!group || !user) |
| 38 |
{ |
| 39 |
command_fail(si, fault_needmoreparams, STR_INSUFFICIENT_PARAMS, "INVITE"); |
| 40 |
command_fail(si, fault_needmoreparams, _("Syntax: INVITE <!group> <user>")); |
| 41 |
return; |
| 42 |
} |
| 43 |
|
| 44 |
if ((mg = mygroup_find(group)) == NULL) |
| 45 |
{ |
| 46 |
command_fail(si, fault_nosuch_target, _("The group \2%s\2 does not exist."), group); |
| 47 |
return; |
| 48 |
} |
| 49 |
|
| 50 |
if (!groupacs_sourceinfo_has_flag(mg, si, GA_INVITE)) |
| 51 |
{ |
| 52 |
command_fail(si, fault_noprivs, _("You are not authorized to perform this operation.")); |
| 53 |
return; |
| 54 |
} |
| 55 |
|
| 56 |
if ((mu = myuser_find_ext(user)) == NULL) |
| 57 |
{ |
| 58 |
command_fail(si, fault_nosuch_target, _("\2%s\2 is not a registered account."), user); |
| 59 |
return; |
| 60 |
} |
| 61 |
|
| 62 |
if ((ga = groupacs_find(mg, entity(mu), 0, false)) != NULL) |
| 63 |
{ |
| 64 |
command_fail(si, fault_badparams, _("\2%s\2 is already a member of \2%s\2."), user, group); |
| 65 |
return; |
| 66 |
} |
| 67 |
|
| 68 |
if (metadata_find(mu, "private:groupinvite")) |
| 69 |
{ |
| 70 |
command_fail(si, fault_badparams, _("\2%s\2 can not be invited to a group currently because they already \ |
| 71 |
have another invitation pending."), user); |
| 72 |
return; |
| 73 |
} |
| 74 |
|
| 75 |
if (MU_NEVERGROUP & mu->flags) |
| 76 |
{ |
| 77 |
command_fail(si, fault_noprivs, _("\2%s\2 does not wish to belong to any groups."), user); |
| 78 |
return; |
| 79 |
} |
| 80 |
|
| 81 |
metadata_add(mu, "private:groupinvite", group); |
| 82 |
|
| 83 |
if ((svs = service_find("memoserv")) != NULL) |
| 84 |
{ |
| 85 |
snprintf(buf, BUFSIZE, "%s [auto memo] You have been invited to the group \2%s\2.", user, group); |
| 86 |
|
| 87 |
command_exec_split(svs, si, "SEND", buf, svs->commands); |
| 88 |
} |
| 89 |
else |
| 90 |
{ |
| 91 |
myuser_notice(si->service->nick, mu, "You have been invited to the group \2%s\2.", group); |
| 92 |
} |
| 93 |
|
| 94 |
logcommand(si, CMDLOG_SET, "INVITE: \2%s\2 \2%s\2", group, user); |
| 95 |
command_success_nodata(si, _("\2%s\2 has been invited to \2%s\2"), user, group); |
| 96 |
} |
| 97 |
|
| 98 |
void _modinit(module_t *m) |
| 99 |
{ |
| 100 |
use_groupserv_main_symbols(m); |
| 101 |
|
| 102 |
service_named_bind_command("groupserv", &gs_invite); |
| 103 |
} |
| 104 |
|
| 105 |
void _moddeinit(module_unload_intent_t intent) |
| 106 |
{ |
| 107 |
service_named_unbind_command("groupserv", &gs_invite); |
| 108 |
} |
| 109 |
|