]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/commands/cmd_invite.cpp
89437e25217352f37aa0b3aa2dc1c675669087f1
[user/henk/code/inspircd.git] / src / commands / cmd_invite.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2009 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 = ServerInstance->FindNick(parameters[0]);
45                 Channel* c = ServerInstance->FindChan(parameters[1]);
46                 time_t timeout = 0;
47                 if (parameters.size() == 3)
48                 {
49                         if (IS_LOCAL(user))
50                                 timeout = ServerInstance->Time() + ServerInstance->Duration(parameters[2]);
51                         else
52                                 timeout = ConvToInt(parameters[2]);
53                 }
54
55                 if ((!c) || (!u))
56                 {
57                         user->WriteNumeric(ERR_NOSUCHNICK, "%s %s :No such nick/channel",user->nick.c_str(), c ? parameters[0].c_str() : parameters[1].c_str());
58                         return CMD_FAILURE;
59                 }
60
61                 if (c->HasUser(u))
62                 {
63                         user->WriteNumeric(ERR_USERONCHANNEL, "%s %s %s :is already on channel",user->nick.c_str(),u->nick.c_str(),c->name.c_str());
64                         return CMD_FAILURE;
65                 }
66
67                 if ((IS_LOCAL(user)) && (!c->HasUser(user)))
68                 {
69                         user->WriteNumeric(ERR_NOTONCHANNEL, "%s %s :You're not on that channel!",user->nick.c_str(), c->name.c_str());
70                         return CMD_FAILURE;
71                 }
72
73                 FIRST_MOD_RESULT(ServerInstance, OnUserPreInvite, MOD_RESULT, (user,u,c,timeout));
74
75                 if (MOD_RESULT == MOD_RES_DENY)
76                 {
77                         return CMD_FAILURE;
78                 }
79                 else if (MOD_RESULT == MOD_RES_PASSTHRU)
80                 {
81                         if (IS_LOCAL(user))
82                         {
83                                 int rank = c->GetPrefixValue(user);
84                                 if (rank < HALFOP_VALUE)
85                                 {
86                                         user->WriteNumeric(ERR_CHANOPRIVSNEEDED, "%s %s :You must be a channel %soperator",
87                                                 user->nick.c_str(), c->name.c_str(), rank >= HALFOP_VALUE ? "" : "half-");
88                                         return CMD_FAILURE;
89                                 }
90                         }
91                 }
92
93                 u->InviteTo(c->name.c_str(), timeout);
94                 u->WriteFrom(user,"INVITE %s :%s",u->nick.c_str(),c->name.c_str());
95                 user->WriteNumeric(RPL_INVITING, "%s %s %s",user->nick.c_str(),u->nick.c_str(),c->name.c_str());
96                 switch (ServerInstance->Config->AnnounceInvites)
97                 {
98                         case ServerConfig::INVITE_ANNOUNCE_ALL:
99                                 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());
100                         break;
101                         case ServerConfig::INVITE_ANNOUNCE_OPS:
102                                 c->WriteAllExceptSender(user, true, '@', "NOTICE %s :*** %s invited %s into the channel", c->name.c_str(), user->nick.c_str(), u->nick.c_str());
103                         break;
104                         case ServerConfig::INVITE_ANNOUNCE_DYNAMIC:
105                                 if (c->IsModeSet('i'))
106                                         c->WriteAllExceptSender(user, true, '@', "NOTICE %s :*** %s invited %s into the channel", c->name.c_str(), user->nick.c_str(), u->nick.c_str());
107                                 else
108                                         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());
109                         break;
110                         default:
111                                 /* Nobody */
112                         break;
113                 }
114                 FOREACH_MOD(I_OnUserInvite,OnUserInvite(user,u,c,timeout));
115         }
116         else
117         {
118                 // pinched from ircu - invite with not enough parameters shows channels
119                 // youve been invited to but haven't joined yet.
120                 InvitedList* il = user->GetInviteList();
121                 for (InvitedList::iterator i = il->begin(); i != il->end(); i++)
122                 {
123                         user->WriteNumeric(RPL_INVITELIST, "%s :%s",user->nick.c_str(),i->first.c_str());
124                 }
125                 user->WriteNumeric(RPL_ENDOFINVITELIST, "%s :End of INVITE list",user->nick.c_str());
126         }
127         return CMD_SUCCESS;
128 }
129
130
131 COMMAND_INIT(CommandInvite)