]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/commands/cmd_invite.cpp
438aa37d0fe53ca5cfcbb5f8c46a2217b1cddda2
[user/henk/code/inspircd.git] / src / commands / cmd_invite.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2010 InspIRCd Development Team
6  * See: http://wiki.inspircd.org/Credits
7  *
8  * This program is free but copyrighted software; see
9  *            the file COPYING for details.
10  *
11  * ---------------------------------------------------
12  */
13
14 #include "inspircd.h"
15
16 /** Handle /INVITE. These command handlers can be reloaded by the core,
17  * and handle basic RFC1459 commands. Commands within modules work
18  * the same way, however, they can be fully unloaded, where these
19  * may not.
20  */
21 class CommandInvite : public Command
22 {
23  public:
24         /** Constructor for invite.
25          */
26         CommandInvite ( Module* parent) : Command(parent,"INVITE", 0, 0) { Penalty = 4; syntax = "[<nick> <channel>]"; }
27         /** Handle command.
28          * @param parameters The parameters to the comamnd
29          * @param pcnt The number of parameters passed to teh command
30          * @param user The user issuing the command
31          * @return A value from CmdResult to indicate command success or failure.
32          */
33         CmdResult Handle(const std::vector<std::string>& parameters, User *user);
34 };
35
36 /** Handle /INVITE
37  */
38 CmdResult CommandInvite::Handle (const std::vector<std::string>& parameters, User *user)
39 {
40         ModResult MOD_RESULT;
41
42         if (parameters.size() == 2 || parameters.size() == 3)
43         {
44                 User* u;
45                 if (IS_LOCAL(user))
46                         u = ServerInstance->FindNickOnly(parameters[0]);
47                 else
48                         u = ServerInstance->FindNick(parameters[0]);
49
50                 Channel* c = ServerInstance->FindChan(parameters[1]);
51                 time_t timeout = 0;
52                 if (parameters.size() == 3)
53                 {
54                         if (IS_LOCAL(user))
55                                 timeout = ServerInstance->Time() + ServerInstance->Duration(parameters[2]);
56                         else
57                                 timeout = ConvToInt(parameters[2]);
58                 }
59
60                 if ((!c) || (!u))
61                 {
62                         user->WriteNumeric(ERR_NOSUCHNICK, "%s %s :No such nick/channel",user->nick.c_str(), c ? parameters[0].c_str() : parameters[1].c_str());
63                         return CMD_FAILURE;
64                 }
65
66                 if (c->HasUser(u))
67                 {
68                         user->WriteNumeric(ERR_USERONCHANNEL, "%s %s %s :is already on channel",user->nick.c_str(),u->nick.c_str(),c->name.c_str());
69                         return CMD_FAILURE;
70                 }
71
72                 if ((IS_LOCAL(user)) && (!c->HasUser(user)))
73                 {
74                         user->WriteNumeric(ERR_NOTONCHANNEL, "%s %s :You're not on that channel!",user->nick.c_str(), c->name.c_str());
75                         return CMD_FAILURE;
76                 }
77
78                 FIRST_MOD_RESULT(OnUserPreInvite, MOD_RESULT, (user,u,c,timeout));
79
80                 if (MOD_RESULT == MOD_RES_DENY)
81                 {
82                         return CMD_FAILURE;
83                 }
84                 else if (MOD_RESULT == MOD_RES_PASSTHRU)
85                 {
86                         if (IS_LOCAL(user))
87                         {
88                                 int rank = c->GetPrefixValue(user);
89                                 if (rank < HALFOP_VALUE)
90                                 {
91                                         user->WriteNumeric(ERR_CHANOPRIVSNEEDED, "%s %s :You must be a channel %soperator",
92                                                 user->nick.c_str(), c->name.c_str(), rank >= HALFOP_VALUE ? "" : "half-");
93                                         return CMD_FAILURE;
94                                 }
95                         }
96                 }
97
98                 if (IS_LOCAL(u))
99                         IS_LOCAL(u)->InviteTo(c->name.c_str(), timeout);
100                 u->WriteFrom(user,"INVITE %s :%s",u->nick.c_str(),c->name.c_str());
101                 user->WriteNumeric(RPL_INVITING, "%s %s %s",user->nick.c_str(),u->nick.c_str(),c->name.c_str());
102                 switch (ServerInstance->Config->AnnounceInvites)
103                 {
104                         case ServerConfig::INVITE_ANNOUNCE_ALL:
105                                 c->WriteChannelWithServ(ServerInstance->Config->ServerName, "NOTICE %s :*** %s invited %s into the channel", c->name.c_str(), user->nick.c_str(), u->nick.c_str());
106                         break;
107                         case ServerConfig::INVITE_ANNOUNCE_OPS:
108                                 c->WriteAllExceptSender(user, true, '@', "NOTICE %s :*** %s invited %s into the channel", c->name.c_str(), user->nick.c_str(), u->nick.c_str());
109                         break;
110                         case ServerConfig::INVITE_ANNOUNCE_DYNAMIC:
111                                 if (c->IsModeSet('i'))
112                                         c->WriteAllExceptSender(user, true, '@', "NOTICE %s :*** %s invited %s into the channel", c->name.c_str(), user->nick.c_str(), u->nick.c_str());
113                                 else
114                                         c->WriteChannelWithServ(ServerInstance->Config->ServerName, "NOTICE %s :*** %s invited %s into the channel", c->name.c_str(), user->nick.c_str(), u->nick.c_str());
115                         break;
116                         default:
117                                 /* Nobody */
118                         break;
119                 }
120                 FOREACH_MOD(I_OnUserInvite,OnUserInvite(user,u,c,timeout));
121         }
122         else if (IS_LOCAL(user))
123         {
124                 // pinched from ircu - invite with not enough parameters shows channels
125                 // youve been invited to but haven't joined yet.
126                 InvitedList* il = IS_LOCAL(user)->GetInviteList();
127                 for (InvitedList::iterator i = il->begin(); i != il->end(); i++)
128                 {
129                         user->WriteNumeric(RPL_INVITELIST, "%s :%s",user->nick.c_str(),i->first.c_str());
130                 }
131                 user->WriteNumeric(RPL_ENDOFINVITELIST, "%s :End of INVITE list",user->nick.c_str());
132         }
133         return CMD_SUCCESS;
134 }
135
136
137 COMMAND_INIT(CommandInvite)