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