]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_uninvite.cpp
*NEEDS TESTING* changed binarymodes to use the custom_modes entries
[user/henk/code/inspircd.git] / src / modules / m_uninvite.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd is copyright (C) 2002-2006 ChatSpike-Dev.
6  *                       E-mail:
7  *                <brain@chatspike.net>
8  *                <Craig@chatspike.net>
9  *     
10  * Written by Craig Edwards, Craig McLure, and others.
11  * This program is free but copyrighted software; see
12  *            the file COPYING for details.
13  *
14  * ---------------------------------------------------
15  */
16
17 using namespace std;
18
19 /* $ModDesc: Provides the UNINVITE command which lets users un-invite other users from channels (!) */
20
21 #include <stdio.h>
22 #include "users.h"
23 #include "channels.h"
24 #include "modules.h"
25 #include "helperfuncs.h"
26 #include "message.h"
27
28 static Server *Srv;
29          
30 class cmd_uninvite : public command_t
31 {
32  public:
33         cmd_uninvite () : command_t("UNINVITE", 0, 2)
34         {
35                 this->source = "m_uninvite.so";
36         }
37
38         void Handle (char **parameters, int pcnt, userrec *user)
39         {
40                 userrec* u = Find(parameters[0]);
41                 chanrec* c = FindChan(parameters[1]);
42                          
43                 if ((!c) || (!u))
44                 {        
45                         if (!c)
46                         {
47                                 WriteServ(user->fd,"401 %s %s :No such nick/channel",user->nick, parameters[1]);
48                         }
49                         else
50                         {
51                                 WriteServ(user->fd,"401 %s %s :No such nick/channel",user->nick, parameters[0]);
52                         }
53                                 
54                         return; 
55                 }        
56
57                 if (c->custom_modes[CM_INVITEONLY])
58                 {
59                         if (cstatus(user,c) < STATUS_HOP)
60                         {
61                                 WriteServ(user->fd,"482 %s %s :You must be at least a half-operator to change modes on this channel",user->nick, c->name);
62                                 return;
63                         }
64                 }
65
66                 irc::string xname(c->name);
67
68                 if (!u->IsInvited(xname))
69                 {
70                         WriteServ(user->fd,"491 %s %s %s :Is not invited to channel %s",user->nick,u->nick,c->name,c->name);
71                         return;
72                 }
73                 if (!c->HasUser(user))
74                 {
75                         WriteServ(user->fd,"492 %s %s :You're not on that channel!",user->nick, c->name);
76                         return;
77                 }
78
79                 u->RemoveInvite(xname);
80                 WriteServ(user->fd,"494 %s %s %s :Uninvited",user->nick,c->name,u->nick);
81                 WriteServ(u->fd,"493 %s :You were uninvited from %s by %s",u->nick,c->name,user->nick);
82                 WriteChannel(c,user,"NOTICE %s :*** %s uninvited %s.",c->name,user->nick,u->nick);
83         }
84 };
85
86 class ModuleUninvite : public Module
87 {
88         cmd_uninvite *mycommand;
89
90  public:
91
92         ModuleUninvite(Server* Me) : Module::Module(Me)
93         {
94                 Srv = Me;
95                 mycommand = new cmd_uninvite();
96                 Srv->AddCommand(mycommand);
97         }
98         
99         virtual ~ModuleUninvite()
100         {
101         }
102         
103         virtual Version GetVersion()
104         {
105                 /* Must be static, because we dont want to desync invite lists */
106                 return Version(1, 0, 0, 0, VF_VENDOR|VF_STATIC);
107         }
108 };
109
110
111 class ModuleUninviteFactory : public ModuleFactory
112 {
113  public:
114         ModuleUninviteFactory()
115         {
116         }
117         
118         ~ModuleUninviteFactory()
119         {
120         }
121         
122         virtual Module * CreateModule(Server* Me)
123         {
124                 return new ModuleUninvite(Me);
125         }
126         
127 };
128
129
130 extern "C" void * init_module( void )
131 {
132         return new ModuleUninviteFactory;
133 }