]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/commands/cmd_invite.cpp
Invite timeout on server-to-server is already a unix timestamp
[user/henk/code/inspircd.git] / src / commands / cmd_invite.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2008 InspIRCd Development Team
6  * See: http://www.inspircd.org/wiki/index.php/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 #include "commands/cmd_invite.h"
16
17 extern "C" DllExport Command* init_command(InspIRCd* Instance)
18 {
19         return new CommandInvite(Instance);
20 }
21
22 /** Handle /INVITE
23  */
24 CmdResult CommandInvite::Handle (const std::vector<std::string>& parameters, User *user)
25 {
26         int MOD_RESULT = 0;
27
28         if (parameters.size() == 2 || parameters.size() == 3)
29         {
30                 User* u = ServerInstance->FindNick(parameters[0]);
31                 Channel* c = ServerInstance->FindChan(parameters[1]);
32                 time_t timeout = 0;
33                 if (parameters.size() == 3)
34                 {
35                         if (IS_LOCAL(user))
36                                 timeout = time(NULL) + ServerInstance->Duration(parameters[2]);
37                         else
38                                 timeout = ConvToInt(parameters[2]);
39                 }
40
41                 if ((!c) || (!u))
42                 {
43                         user->WriteNumeric(ERR_NOSUCHNICK, "%s %s :No such nick/channel",user->nick.c_str(), c ? parameters[0].c_str() : parameters[1].c_str());
44                         return CMD_FAILURE;
45                 }
46
47                 if (c->HasUser(u))
48                 {
49                         user->WriteNumeric(ERR_USERONCHANNEL, "%s %s %s :is already on channel",user->nick.c_str(),u->nick.c_str(),c->name.c_str());
50                         return CMD_FAILURE;
51                 }
52
53                 if ((IS_LOCAL(user)) && (!c->HasUser(user)))
54                 {
55                         user->WriteNumeric(ERR_NOTONCHANNEL, "%s %s :You're not on that channel!",user->nick.c_str(), c->name.c_str());
56                         return CMD_FAILURE;
57                 }
58
59                 FOREACH_RESULT(I_OnUserPreInvite,OnUserPreInvite(user,u,c,timeout));
60
61                 if (MOD_RESULT == 1)
62                 {
63                         return CMD_FAILURE;
64                 }
65                 else if (MOD_RESULT == 0)
66                 {
67                         if (IS_LOCAL(user))
68                         {
69                                 if (c->GetStatus(user) < STATUS_HOP)
70                                 {
71                                         user->WriteNumeric(ERR_CHANOPRIVSNEEDED, "%s %s :You must be a channel %soperator", user->nick.c_str(), c->name.c_str(), c->GetStatus(u) == STATUS_HOP ? "" : "half-");
72                                         return CMD_FAILURE;
73                                 }
74                         }
75                 }
76
77                 u->InviteTo(c->name.c_str(), timeout);
78                 u->WriteFrom(user,"INVITE %s :%s",u->nick.c_str(),c->name.c_str());
79                 user->WriteNumeric(RPL_INVITING, "%s %s %s",user->nick.c_str(),u->nick.c_str(),c->name.c_str());
80                 switch (ServerInstance->Config->AnnounceInvites)
81                 {
82                         case ServerConfig::INVITE_ANNOUNCE_ALL:
83                                 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());
84                         break;
85                         case ServerConfig::INVITE_ANNOUNCE_OPS:
86                                 c->WriteAllExceptSender(user, true, '@', "NOTICE %s :*** %s invited %s into the channel", c->name.c_str(), user->nick.c_str(), u->nick.c_str());
87                         break;
88                         case ServerConfig::INVITE_ANNOUNCE_DYNAMIC:
89                                 if (c->IsModeSet('i'))
90                                         c->WriteAllExceptSender(user, true, '@', "NOTICE %s :*** %s invited %s into the channel", c->name.c_str(), user->nick.c_str(), u->nick.c_str());
91                                 else
92                                         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());
93                         break;
94                         default:
95                                 /* Nobody */
96                         break;
97                 }
98                 FOREACH_MOD(I_OnUserInvite,OnUserInvite(user,u,c,timeout));
99         }
100         else
101         {
102                 // pinched from ircu - invite with not enough parameters shows channels
103                 // youve been invited to but haven't joined yet.
104                 InvitedList* il = user->GetInviteList();
105                 for (InvitedList::iterator i = il->begin(); i != il->end(); i++)
106                 {
107                         user->WriteNumeric(RPL_INVITELIST, "%s :%s",user->nick.c_str(),i->first.c_str());
108                 }
109                 user->WriteNumeric(RPL_ENDOFINVITELIST, "%s :End of INVITE list",user->nick.c_str());
110         }
111         return CMD_SUCCESS;
112 }
113