]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_uninvite.cpp
cmode(), cflags(), cstatus() -> chanrec::GetStatusChar(), chanrec::GetStatusFlags...
[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 #include "inspircd.h"
28
29 static Server *Srv;
30 extern InspIRCd* ServerInstance;
31          
32 class cmd_uninvite : public command_t
33 {
34  public:
35         cmd_uninvite () : command_t("UNINVITE", 0, 2)
36         {
37                 this->source = "m_uninvite.so";
38                 syntax = "<nick> <channel>";
39         }
40
41         void Handle (const char** parameters, int pcnt, userrec *user)
42         {
43                 userrec* u = ServerInstance->FindNick(parameters[0]);
44                 chanrec* c = ServerInstance->FindChan(parameters[1]);
45                          
46                 if ((!c) || (!u))
47                 {       
48                         if (!c)
49                         {
50                                 user->WriteServ("401 %s %s :No such nick/channel",user->nick, parameters[1]);
51                         }
52                         else
53                         {
54                                 user->WriteServ("401 %s %s :No such nick/channel",user->nick, parameters[0]);
55                         }
56                                 
57                         return; 
58                 }       
59
60                 if (c->modes[CM_INVITEONLY])
61                 {
62                         if (c->GetStatus(user) < STATUS_HOP)
63                         {
64                                 user->WriteServ("482 %s %s :You must be at least a half-operator to change modes on this channel",user->nick, c->name);
65                                 return;
66                         }
67                 }
68
69                 irc::string xname(c->name);
70
71                 if (!u->IsInvited(xname))
72                 {
73                         user->WriteServ("491 %s %s %s :Is not invited to channel %s",user->nick,u->nick,c->name,c->name);
74                         return;
75                 }
76                 if (!c->HasUser(user))
77                 {
78                         user->WriteServ("492 %s %s :You're not on that channel!",user->nick, c->name);
79                         return;
80                 }
81
82                 u->RemoveInvite(xname);
83                 user->WriteServ("494 %s %s %s :Uninvited",user->nick,c->name,u->nick);
84                 u->WriteServ("493 %s :You were uninvited from %s by %s",u->nick,c->name,user->nick);
85                 c->WriteChannelWithServ(Srv->GetServerName().c_str(), "NOTICE %s :*** %s uninvited %s.", c->name, user->nick, u->nick);
86         }
87 };
88
89 class ModuleUninvite : public Module
90 {
91         cmd_uninvite *mycommand;
92
93  public:
94
95         ModuleUninvite(Server* Me) : Module::Module(Me)
96         {
97                 Srv = Me;
98                 mycommand = new cmd_uninvite();
99                 Srv->AddCommand(mycommand);
100         }
101         
102         virtual ~ModuleUninvite()
103         {
104         }
105         
106         virtual Version GetVersion()
107         {
108                 /* Must be static, because we dont want to desync invite lists */
109                 return Version(1, 0, 0, 0, VF_VENDOR|VF_STATIC);
110         }
111 };
112
113
114 class ModuleUninviteFactory : public ModuleFactory
115 {
116  public:
117         ModuleUninviteFactory()
118         {
119         }
120         
121         ~ModuleUninviteFactory()
122         {
123         }
124         
125         virtual Module * CreateModule(Server* Me)
126         {
127                 return new ModuleUninvite(Me);
128         }
129         
130 };
131
132
133 extern "C" void * init_module( void )
134 {
135         return new ModuleUninviteFactory;
136 }