summaryrefslogtreecommitdiff
path: root/src/modules
diff options
context:
space:
mode:
authorbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2005-12-16 18:48:07 +0000
committerbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2005-12-16 18:48:07 +0000
commit347e25f83d2d8403851e8bdcbf27d987abbd8fd5 (patch)
tree6eff73c25154ac55bfe4167abd79011ac3f06b61 /src/modules
parenta5a8764bfe85e208a622a86295bdf56da575f21c (diff)
Last set of modules converted to new command system
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@2538 e03df62e-2008-0410-955e-edbf42e46eb7
Diffstat (limited to 'src/modules')
-rw-r--r--src/modules/m_testcommand.cpp2
-rw-r--r--src/modules/m_timedbans.cpp99
-rw-r--r--src/modules/m_userip.cpp42
-rw-r--r--src/modules/m_watch.cpp247
4 files changed, 210 insertions, 180 deletions
diff --git a/src/modules/m_testcommand.cpp b/src/modules/m_testcommand.cpp
index 15405d80c..9e1da629a 100644
--- a/src/modules/m_testcommand.cpp
+++ b/src/modules/m_testcommand.cpp
@@ -28,7 +28,7 @@ Server *Srv;
class cmd_woot : public command_t
{
public:
- cmd_woot () : command_t("WOOT", 0, 0);
+ cmd_woot () : command_t("WOOT", 0, 0)
{
this->source = "m_testcommand.so";
}
diff --git a/src/modules/m_timedbans.cpp b/src/modules/m_timedbans.cpp
index 29581054f..e45967dd0 100644
--- a/src/modules/m_timedbans.cpp
+++ b/src/modules/m_timedbans.cpp
@@ -39,70 +39,81 @@ class TimedBan
typedef std::vector<TimedBan> timedbans;
timedbans TimedBanList;
-void handle_tban(char **parameters, int pcnt, userrec *user)
+class cmd_tban : public command_t
{
- chanrec* channel = Srv->FindChannel(parameters[0]);
- if (channel)
+ public:
+ cmd_tban () : command_t("TBAN", 0, 3)
{
- std::string cm = Srv->ChanMode(user,channel);
- if ((cm == "%") || (cm == "@"))
+ this->source = "m_timedbans,cpp";
+ }
+
+ void Handle (char **parameters, int pcnt, userrec *user)
+ {
+ chanrec* channel = Srv->FindChannel(parameters[0]);
+ if (channel)
{
- if (!Srv->IsValidMask(parameters[2]))
- {
- Srv->SendServ(user->fd,"NOTICE "+std::string(user->nick)+" :Invalid ban mask");
- return;
- }
- for (timedbans::iterator i = TimedBanList.begin(); i < TimedBanList.end(); i++)
+ std::string cm = Srv->ChanMode(user,channel);
+ if ((cm == "%") || (cm == "@"))
{
- irc::string listitem = i->mask.c_str();
- irc::string target = parameters[2];
- irc::string listchan = i->channel.c_str();
- irc::string targetchan = parameters[0];
- if ((listitem == target) && (listchan == targetchan))
+ if (!Srv->IsValidMask(parameters[2]))
{
- Srv->SendServ(user->fd,"NOTICE "+std::string(user->nick)+" :The ban "+std::string(parameters[2])+" is already on the banlist of "+std::string(parameters[0]));
+ Srv->SendServ(user->fd,"NOTICE "+std::string(user->nick)+" :Invalid ban mask");
return;
}
- }
- TimedBan T;
- std::string channelname = parameters[0];
- unsigned long expire = Srv->CalcDuration(parameters[1]) + time(NULL);
- if (Srv->CalcDuration(parameters[1]) < 1)
- {
- Srv->SendServ(user->fd,"NOTICE "+std::string(user->nick)+" :Invalid ban time");
+ for (timedbans::iterator i = TimedBanList.begin(); i < TimedBanList.end(); i++)
+ {
+ irc::string listitem = i->mask.c_str();
+ irc::string target = parameters[2];
+ irc::string listchan = i->channel.c_str();
+ irc::string targetchan = parameters[0];
+ if ((listitem == target) && (listchan == targetchan))
+ {
+ Srv->SendServ(user->fd,"NOTICE "+std::string(user->nick)+" :The ban "+std::string(parameters[2])+" is already on the banlist of "+std::string(parameters[0]));
+ return;
+ }
+ }
+ TimedBan T;
+ std::string channelname = parameters[0];
+ unsigned long expire = Srv->CalcDuration(parameters[1]) + time(NULL);
+ if (Srv->CalcDuration(parameters[1]) < 1)
+ {
+ Srv->SendServ(user->fd,"NOTICE "+std::string(user->nick)+" :Invalid ban time");
+ return;
+ }
+ char duration[MAXBUF];
+ snprintf(duration,MAXBUF,"%lu",Srv->CalcDuration(parameters[1]));
+ std::string mask = parameters[2];
+ char *setban[3];
+ setban[0] = parameters[0];
+ setban[1] = "+b";
+ setban[2] = parameters[2];
+ // use CallCommandHandler to make it so that the user sets the mode
+ // themselves
+ Srv->CallCommandHandler("MODE",setban,3,user);
+ T.channel = channelname;
+ T.mask = mask;
+ T.expire = expire;
+ TimedBanList.push_back(T);
+ Srv->SendChannelServerNotice(Srv->GetServerName(),channel,"NOTICE "+std::string(channel->name)+" :"+std::string(user->nick)+" added a timed ban on "+mask+" lasting for "+std::string(duration)+" seconds.");
return;
}
- char duration[MAXBUF];
- snprintf(duration,MAXBUF,"%lu",Srv->CalcDuration(parameters[1]));
- std::string mask = parameters[2];
- char *setban[3];
- setban[0] = parameters[0];
- setban[1] = "+b";
- setban[2] = parameters[2];
- // use CallCommandHandler to make it so that the user sets the mode
- // themselves
- Srv->CallCommandHandler("MODE",setban,3,user);
- T.channel = channelname;
- T.mask = mask;
- T.expire = expire;
- TimedBanList.push_back(T);
- Srv->SendChannelServerNotice(Srv->GetServerName(),channel,"NOTICE "+std::string(channel->name)+" :"+std::string(user->nick)+" added a timed ban on "+mask+" lasting for "+std::string(duration)+" seconds.");
+ else WriteServ(user->fd,"482 %s %s :You must be at least a half-operator to change modes on this channel",user->nick, channel->name);
return;
}
- else WriteServ(user->fd,"482 %s %s :You must be at least a half-operator to change modes on this channel",user->nick, channel->name);
- return;
+ WriteServ(user->fd,"401 %s %s :No such channel",user->nick, parameters[0]);
}
- WriteServ(user->fd,"401 %s %s :No such channel",user->nick, parameters[0]);
-}
+};
class ModuleTimedBans : public Module
{
+ cmd_tban* mycommand;
public:
ModuleTimedBans(Server* Me)
: Module::Module(Me)
{
Srv = Me;
- Srv->AddCommand("TBAN",handle_tban,0,3,"m_timedbans.so");
+ mycommand = new cmd_tban();
+ Srv->AddCommand(mycommand);
TimedBanList.clear();
}
diff --git a/src/modules/m_userip.cpp b/src/modules/m_userip.cpp
index 9e5b33d4e..a5e8b9bef 100644
--- a/src/modules/m_userip.cpp
+++ b/src/modules/m_userip.cpp
@@ -26,32 +26,42 @@ using namespace std;
/* $ModDesc: Provides support for USERIP command */
Server *Srv;
-
-void handle_userip(char **parameters, int pcnt, userrec *user)
+
+class cmd_userip : public command_t
{
- char Return[MAXBUF],junk[MAXBUF];
- snprintf(Return,MAXBUF,"340 %s :",user->nick);
- for (int i = 0; i < pcnt; i++)
- {
- userrec *u = Find(parameters[i]);
- if (u)
- {
- snprintf(junk,MAXBUF,"%s%s=+%s@%s ",u->nick,strchr(u->modes,'o') ? "*" : "",u->ident,u->ip);
- strlcat(Return,junk,MAXBUF);
- }
- }
- WriteServ(user->fd,Return);
-}
+ public:
+ cmd_userip () : command_t("USERIP", 'o', 1)
+ {
+ this->source = "m_userip.so";
+ }
+ void Handle (char **parameters, int pcnt, userrec *user)
+ {
+ char Return[MAXBUF],junk[MAXBUF];
+ snprintf(Return,MAXBUF,"340 %s :",user->nick);
+ for (int i = 0; i < pcnt; i++)
+ {
+ userrec *u = Find(parameters[i]);
+ if (u)
+ {
+ snprintf(junk,MAXBUF,"%s%s=+%s@%s ",u->nick,strchr(u->modes,'o') ? "*" : "",u->ident,u->ip);
+ strlcat(Return,junk,MAXBUF);
+ }
+ }
+ WriteServ(user->fd,Return);
+ }
+};
class ModuleUserIP : public Module
{
+ cmd_userip* myommand;
public:
ModuleUserIP(Server* Me)
: Module::Module(Me)
{
Srv = Me;
- Srv->AddCommand("USERIP",handle_userip,'o',1,"m_userip.so");
+ mycommand = new cmd_userip();
+ Srv->AddCommand(mycommand);
}
virtual void On005Numeric(std::string &output)
diff --git a/src/modules/m_watch.cpp b/src/modules/m_watch.cpp
index bd3a2f707..1a8d6a658 100644
--- a/src/modules/m_watch.cpp
+++ b/src/modules/m_watch.cpp
@@ -39,155 +39,164 @@ class watchentry
typedef std::vector<watchentry> watchlist;
watchlist watches;
-void handle_watch(char **parameters, int pcnt, userrec *user)
+class cmd_watch : public command_t
{
- if (!pcnt)
+ public:
+ cmd_watch() : command_t("WATCH",0,0)
{
- for (watchlist::iterator q = watches.begin(); q != watches.end(); q++)
- {
- if (q->watcher == user)
- {
- userrec* targ = Srv->FindNick(q->target);
- if (targ)
- {
- WriteServ(user->fd,"604 %s %s %s %s %lu :is online",user->nick,targ->nick,targ->ident,targ->dhost,targ->age);
- }
- }
- }
- WriteServ(user->fd,"607 %s :End of WATCH list",user->nick);
+ this->source = "m_watch.so";
}
- else if (pcnt > 0)
+
+ void Handle (char **parameters, int pcnt, userrec *user)
{
- for (int x = 0; x < pcnt; x++)
+ if (!pcnt)
+ {
+ for (watchlist::iterator q = watches.begin(); q != watches.end(); q++)
+ {
+ if (q->watcher == user)
+ {
+ userrec* targ = Srv->FindNick(q->target);
+ if (targ)
+ {
+ WriteServ(user->fd,"604 %s %s %s %s %lu :is online",user->nick,targ->nick,targ->ident,targ->dhost,targ->age);
+ }
+ }
+ }
+ WriteServ(user->fd,"607 %s :End of WATCH list",user->nick);
+ }
+ else if (pcnt > 0)
{
- char *nick = parameters[x];
- if (!strcasecmp(nick,"C"))
+ for (int x = 0; x < pcnt; x++)
{
- // watch clear
- bool done = false;
- while (!done)
- {
- done = true;
+ char *nick = parameters[x];
+ if (!strcasecmp(nick,"C"))
+ {
+ // watch clear
+ bool done = false;
+ while (!done)
+ {
+ done = true;
+ for (watchlist::iterator q = watches.begin(); q != watches.end(); q++)
+ {
+ if (q->watcher == user)
+ {
+ done = false;
+ watches.erase(q);
+ break;
+ }
+ }
+ }
+ }
+ else if (!strcasecmp(nick,"L"))
+ {
+ for (watchlist::iterator q = watches.begin(); q != watches.end(); q++)
+ {
+ if (q->watcher == user)
+ {
+ userrec* targ = Srv->FindNick(q->target);
+ if (targ)
+ {
+ WriteServ(user->fd,"604 %s %s %s %s %lu :is online",user->nick,targ->nick,targ->ident,targ->dhost,targ->age);
+ }
+ }
+ }
+ WriteServ(user->fd,"607 %s :End of WATCH list",user->nick);
+ }
+ else if (!strcasecmp(nick,"S"))
+ {
+ std::string list = "";
+ for (watchlist::iterator q = watches.begin(); q != watches.end(); q++)
+ {
+ if (q->watcher == user)
+ {
+ list = list + " " + q->target;
+ }
+ }
+ char* l = (char*)list.c_str();
+ if (*l == ' ')
+ l++;
+ WriteServ(user->fd,"606 %s :%s",user->nick,l);
+ WriteServ(user->fd,"607 %s :End of WATCH S",user->nick);
+ }
+ else if (nick[0] == '-')
+ {
+ // removing an item from the list
+ nick++;
+ irc::string n1 = nick;
for (watchlist::iterator q = watches.begin(); q != watches.end(); q++)
{
if (q->watcher == user)
{
- done = false;
- watches.erase(q);
- break;
- }
- }
- }
- }
- else if (!strcasecmp(nick,"L"))
- {
- for (watchlist::iterator q = watches.begin(); q != watches.end(); q++)
- {
- if (q->watcher == user)
- {
- userrec* targ = Srv->FindNick(q->target);
- if (targ)
- {
- WriteServ(user->fd,"604 %s %s %s %s %lu :is online",user->nick,targ->nick,targ->ident,targ->dhost,targ->age);
- }
- }
- }
- WriteServ(user->fd,"607 %s :End of WATCH list",user->nick);
- }
- else if (!strcasecmp(nick,"S"))
- {
- std::string list = "";
- for (watchlist::iterator q = watches.begin(); q != watches.end(); q++)
- {
- if (q->watcher == user)
- {
- list = list + " " + q->target;
- }
- }
- char* l = (char*)list.c_str();
- if (*l == ' ')
- l++;
- WriteServ(user->fd,"606 %s :%s",user->nick,l);
- WriteServ(user->fd,"607 %s :End of WATCH S",user->nick);
- }
- else if (nick[0] == '-')
- {
- // removing an item from the list
- nick++;
- irc::string n1 = nick;
- for (watchlist::iterator q = watches.begin(); q != watches.end(); q++)
- {
- if (q->watcher == user)
- {
- irc::string n2 = q->target.c_str();
- userrec* a = Srv->FindNick(q->target);
- if (a)
- {
- WriteServ(user->fd,"602 %s %s %s %s %lu :stopped watching",user->nick,a->nick,a->ident,a->dhost,a->age);
- }
- else
- {
- WriteServ(user->fd,"602 %s %s * * 0 :stopped watching",user->nick,q->target.c_str());
- }
- if (n1 == n2)
- {
- watches.erase(q);
- break;
- }
+ irc::string n2 = q->target.c_str();
+ userrec* a = Srv->FindNick(q->target);
+ if (a)
+ {
+ WriteServ(user->fd,"602 %s %s %s %s %lu :stopped watching",user->nick,a->nick,a->ident,a->dhost,a->age);
+ }
+ else
+ {
+ WriteServ(user->fd,"602 %s %s * * 0 :stopped watching",user->nick,q->target.c_str());
+ }
+ if (n1 == n2)
+ {
+ watches.erase(q);
+ break;
+ }
+ }
}
}
- }
- else if (nick[0] == '+')
- {
- nick++;
- irc::string n1 = nick;
- bool exists = false;
- for (watchlist::iterator q = watches.begin(); q != watches.end(); q++)
+ else if (nick[0] == '+')
{
- if (q->watcher == user)
+ nick++;
+ irc::string n1 = nick;
+ bool exists = false;
+ for (watchlist::iterator q = watches.begin(); q != watches.end(); q++)
{
- irc::string n2 = q->target.c_str();
- if (n1 == n2)
+ if (q->watcher == user)
{
- // already on watch list
- exists = true;
+ irc::string n2 = q->target.c_str();
+ if (n1 == n2)
+ {
+ // already on watch list
+ exists = true;
+ }
}
}
+ if (!exists)
+ {
+ watchentry w;
+ w.watcher = user;
+ w.target = nick;
+ watches.push_back(w);
+ log(DEBUG,"*** Added %s to watchlist of %s",nick,user->nick);
+ }
+ userrec* a = Srv->FindNick(nick);
+ if (a)
+ {
+ WriteServ(user->fd,"604 %s %s %s %s %lu :is online",user->nick,a->nick,a->ident,a->dhost,a->age);
+ }
+ else
+ {
+ WriteServ(user->fd,"605 %s %s * * 0 :is offline",user->nick,nick);
+ }
}
- if (!exists)
- {
- watchentry w;
- w.watcher = user;
- w.target = nick;
- watches.push_back(w);
- log(DEBUG,"*** Added %s to watchlist of %s",nick,user->nick);
- }
- userrec* a = Srv->FindNick(nick);
- if (a)
- {
- WriteServ(user->fd,"604 %s %s %s %s %lu :is online",user->nick,a->nick,a->ident,a->dhost,a->age);
- }
- else
- {
- WriteServ(user->fd,"605 %s %s * * 0 :is offline",user->nick,nick);
- }
}
}
+ return;
}
- return;
-}
-
+};
class Modulewatch : public Module
{
-
+ cmd_watch* mycommand;
public:
Modulewatch(Server* Me)
: Module::Module(Me)
{
Srv = Me;
- Srv->AddCommand("WATCH",handle_watch,0,0,"m_watch.so");
+ mycommand = new cmd_watch();
+ Srv->AddCommand(mycommand);
}
virtual void OnUserQuit(userrec* user, std::string reason)