The InspIRCd Project
Home | Developers | Wiki | Forums | Bug Tracker | SVN | Download | Blog | Stats
Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

cmd_invite.cpp

Go to the documentation of this file.
00001 /*       +------------------------------------+
00002  *       | Inspire Internet Relay Chat Daemon |
00003  *       +------------------------------------+
00004  *
00005  *  InspIRCd: (C) 2002-2008 InspIRCd Development Team
00006  * See: http://www.inspircd.org/wiki/index.php/Credits
00007  *
00008  * This program is free but copyrighted software; see
00009  *            the file COPYING for details.
00010  *
00011  * ---------------------------------------------------
00012  */
00013 
00014 #include "inspircd.h"
00015 #include "configreader.h"
00016 #include "users.h"
00017 #include "modules.h"
00018 #include "commands/cmd_invite.h"
00019 
00020 extern "C" DllExport command_t* init_command(InspIRCd* Instance)
00021 {
00022         return new cmd_invite(Instance);
00023 }
00024 
00027 CmdResult cmd_invite::Handle (const char** parameters, int pcnt, userrec *user)
00028 {
00029         int MOD_RESULT = 0;
00030 
00031         if (pcnt == 2)
00032         {
00033                 userrec* u = ServerInstance->FindNick(parameters[0]);
00034                 chanrec* c = ServerInstance->FindChan(parameters[1]);
00035 
00036                 if ((!c) || (!u))
00037                 {
00038                         if (!c)
00039                         {
00040                                 user->WriteServ("401 %s %s :No such nick/channel",user->nick, parameters[1]);
00041                         }
00042                         else
00043                         {
00044                                 user->WriteServ("401 %s %s :No such nick/channel",user->nick, parameters[0]);
00045                         }
00046 
00047                         return CMD_FAILURE;
00048                 }
00049 
00050                 if ((c->IsModeSet('i')) && (IS_LOCAL(user)))
00051                 {
00052                         if (c->GetStatus(user) < STATUS_HOP)
00053                         {
00054                                 user->WriteServ("482 %s %s :You must be a channel %soperator", user->nick, c->name, c->GetStatus(u) == STATUS_HOP ? "" : "half-");
00055                                 return CMD_FAILURE;
00056                         }
00057                 }
00058 
00059                 if (c->HasUser(u))
00060                 {
00061                         user->WriteServ("443 %s %s %s :is already on channel",user->nick,u->nick,c->name);
00062                         return CMD_FAILURE;
00063                 }
00064 
00065                 if ((IS_LOCAL(user)) && (!c->HasUser(user)))
00066                 {
00067                         user->WriteServ("442 %s %s :You're not on that channel!",user->nick, c->name);
00068                         return CMD_FAILURE;
00069                 }
00070 
00071                 FOREACH_RESULT(I_OnUserPreInvite,OnUserPreInvite(user,u,c));
00072 
00073                 if (MOD_RESULT == 1)
00074                 {
00075                         return CMD_FAILURE;
00076                 }
00077 
00078                 u->InviteTo(c->name);
00079                 u->WriteFrom(user,"INVITE %s :%s",u->nick,c->name);
00080                 user->WriteServ("341 %s %s %s",user->nick,u->nick,c->name);
00081                 if (ServerInstance->Config->AnnounceInvites)
00082                         c->WriteChannelWithServ(ServerInstance->Config->ServerName, "NOTICE %s :*** %s invited %s into the channel", c->name, user->nick, u->nick);
00083                 FOREACH_MOD(I_OnUserInvite,OnUserInvite(user,u,c));
00084         }
00085         else
00086         {
00087                 // pinched from ircu - invite with not enough parameters shows channels
00088                 // youve been invited to but haven't joined yet.
00089                 InvitedList* il = user->GetInviteList();
00090                 for (InvitedList::iterator i = il->begin(); i != il->end(); i++)
00091                 {
00092                         user->WriteServ("346 %s :%s",user->nick,i->c_str());
00093                 }
00094                 user->WriteServ("347 %s :End of INVITE list",user->nick);
00095         }
00096         return CMD_SUCCESS;
00097 }
00098