summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2008-03-18 22:56:05 +0000
committerbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2008-03-18 22:56:05 +0000
commit93425ec211be8185fa9a428dcb24bc8b8121f917 (patch)
tree5c9710e2ccfc83a1025242b7512b86a11198de2c /src
parent90c5531101dedb1825bd8192d3b5ea4c810eee06 (diff)
Apply CAP ACK/NAK stuff from nenolod, thanks :)
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@9124 e03df62e-2008-0410-955e-edbf42e46eb7
Diffstat (limited to 'src')
-rw-r--r--src/modules/m_cap.cpp41
-rw-r--r--src/modules/m_cap.h4
2 files changed, 35 insertions, 10 deletions
diff --git a/src/modules/m_cap.cpp b/src/modules/m_cap.cpp
index df11f1d32..5673c7f62 100644
--- a/src/modules/m_cap.cpp
+++ b/src/modules/m_cap.cpp
@@ -48,16 +48,39 @@ class CommandCAP : public Command
if (subcommand == "REQ")
{
CapData Data;
- Data.type = parameters[1];
+
+ Data.type = subcommand;
Data.user = user;
Data.creator = this->Creator;
- Data.parameter = (pcnt > 1 ? parameters[1] : "");
+
+ if (pcnt < 2)
+ return CMD_FAILURE;
+
+ // tokenize the input into a nice list of requested caps
+ std::string param = parameters[1];
+ std::string cap_;
+ irc::spacesepstream cap_stream(param);
+
+ while (cap_stream.GetToken(cap_))
+ {
+ Data.wanted.push_back(cap_);
+ }
user->Extend("CAP_REGHOLD");
Event event((char*) &Data, (Module*)this->Creator, "cap_req");
event.Send(this->ServerInstance);
- user->WriteServ("CAP * ACK :%s", Data.parameter.c_str());
+ if (Data.ack.size() > 0)
+ {
+ std::string AckResult = irc::stringjoiner(" ", Data.ack, 0, Data.ack.size() - 1).GetJoined();
+ user->WriteServ("CAP * ACK :%s", AckResult.c_str());
+ }
+
+ if (Data.nak.size() > 0)
+ {
+ std::string NakResult = irc::stringjoiner(" ", Data.nak, 0, Data.nak.size() - 1).GetJoined();
+ user->WriteServ("CAP * NAK :%s", NakResult.c_str());
+ }
}
else if (subcommand == "END")
{
@@ -70,13 +93,13 @@ class CommandCAP : public Command
Data.type = subcommand;
Data.user = user;
Data.creator = this->Creator;
- Data.parameter.clear();
user->Extend("CAP_REGHOLD");
Event event((char*) &Data, (Module*)this->Creator, subcommand == "LS" ? "cap_ls" : "cap_list");
event.Send(this->ServerInstance);
- user->WriteServ("CAP * LS :%s", Data.parameter.c_str());
+ std::string Result = irc::stringjoiner(" ", Data.wanted, 0, Data.wanted.size() - 1).GetJoined();
+ user->WriteServ("CAP * LS :%s", Result.c_str());
}
else if (subcommand == "CLEAR")
{
@@ -85,13 +108,13 @@ class CommandCAP : public Command
Data.type = subcommand;
Data.user = user;
Data.creator = this->Creator;
- Data.parameter.clear();
user->Extend("CAP_REGHOLD");
Event event((char*) &Data, (Module*)this->Creator, "cap_clear");
event.Send(this->ServerInstance);
- user->WriteServ("CAP * ACK :%s", Data.parameter.c_str());
+ std::string Result = irc::stringjoiner(" ", Data.ack, 0, Data.ack.size() - 1).GetJoined();
+ user->WriteServ("CAP * ACK :%s", Result.c_str());
}
else
{
@@ -113,8 +136,8 @@ class ModuleCAP : public Module
newcommand = new CommandCAP(ServerInstance, this);
ServerInstance->AddCommand(newcommand);
- Implementation eventlist[] = { I_OnCheckReady, I_OnCleanup, I_OnUserDisconnect, I_OnRequest };
- ServerInstance->Modules->Attach(eventlist, this, 5);
+ Implementation eventlist[] = { I_OnCheckReady };
+ ServerInstance->Modules->Attach(eventlist, this, 1);
}
virtual bool OnCheckReady(User* user)
diff --git a/src/modules/m_cap.h b/src/modules/m_cap.h
index 149528934..1c0ea49fc 100644
--- a/src/modules/m_cap.h
+++ b/src/modules/m_cap.h
@@ -21,7 +21,9 @@ class CapData
{
public:
irc::string type;
- irc::string parameter;
+ std::vector<std::string> wanted;
+ std::vector<std::string> ack;
+ std::vector<std::string> nak;
User* user;
Module* creator;
};