* ---------------------------------------------------
*/
-#include "users.h"
-#include "channels.h"
-#include "modules.h"
#include "inspircd.h"
/* $ModDesc: Provides the SWHOIS command which allows setting of arbitary WHOIS lines */
{
this->source = "m_swhois.so";
syntax = "<nick> <swhois>";
+ TRANSLATE3(TR_NICK, TR_TEXT, TR_END);
}
CmdResult Handle(const char** parameters, int pcnt, userrec* user)
{
userrec* dest = ServerInstance->FindNick(parameters[0]);
- if(dest)
+
+ if (!dest)
{
- std::string line;
- for(int i = 1; i < pcnt; i++)
- {
- if (i != 1)
- line.append(" ");
-
- line.append(parameters[i]);
- }
-
- std::string* text;
- dest->GetExt("swhois", text);
-
- if(text)
- {
- // We already had it set...
-
- if (!ServerInstance->ULine(user->server))
- // Ulines set SWHOISes silently
- ServerInstance->WriteOpers("*** %s used SWHOIS to set %s's extra whois from '%s' to '%s'", user->nick, dest->nick, text->c_str(), line.c_str());
+ user->WriteServ("401 %s %s :No such nick/channel", user->nick, parameters[0]);
+ return CMD_FAILURE;
+ }
+
+ if (!*parameters[1])
+ {
+ user->WriteServ("NOTICE %s :*** SWHOIS: Whois line must be specified", user->nick);
+ return CMD_FAILURE;
+ }
+
+ std::string line;
+ for (int i = 1; i < pcnt; i++)
+ {
+ if (i != 1)
+ line.append(" ");
- dest->Shrink("swhois");
- DELETE(text);
- }
- else if(!ServerInstance->ULine(user->server))
- {
+ line.append(parameters[i]);
+ }
+
+ std::string* text;
+ dest->GetExt("swhois", text);
+
+ if (text)
+ {
+ // We already had it set...
+
+ if (!ServerInstance->ULine(user->server))
// Ulines set SWHOISes silently
- ServerInstance->WriteOpers("*** %s used SWHOIS to set %s's extra whois to '%s'", user->nick, dest->nick, line.c_str());
- }
+ ServerInstance->WriteOpers("*** %s used SWHOIS to set %s's extra whois from '%s' to '%s'", user->nick, dest->nick, text->c_str(), line.c_str());
- text = new std::string(line);
- dest->Extend("swhois", text);
-
- return CMD_SUCCESS;
+ dest->Shrink("swhois");
+ DELETE(text);
+ }
+ else if (!ServerInstance->ULine(user->server))
+ {
+ // Ulines set SWHOISes silently
+ ServerInstance->WriteOpers("*** %s used SWHOIS to set %s's extra whois to '%s'", user->nick, dest->nick, line.c_str());
}
+
+ text = new std::string(line);
+ dest->Extend("swhois", text);
+
+ /* Bug #376 - feature request -
+ * To cut down on the amount of commands services etc have to recognise, this only sends METADATA across the network now
+ * not an actual SWHOIS command. Any SWHOIS command sent from services will be automatically translated to METADATA by this.
+ * Sorry w00t i know this was your fix, but i got bored and wanted to clear down the tracker :)
+ * -- Brain
+ */
+ std::deque<std::string>* metadata = new std::deque<std::string>;
+ metadata->push_back(dest->nick);
+ metadata->push_back("swhois"); // The metadata id
+ metadata->push_back(*text); // The value to send
+ Event event((char*)metadata,(Module*)this,"send_metadata");
+ event.Send(ServerInstance);
+ delete metadata;
- return CMD_FAILURE;
+ return CMD_LOCALONLY;
}
+
};
class ModuleSWhois : public Module
ConfigReader* Conf;
public:
- ModuleSWhois(InspIRCd* Me) : Module::Module(Me)
+ ModuleSWhois(InspIRCd* Me) : Module(Me)
{
Conf = new ConfigReader(ServerInstance);
ServerInstance->AddCommand(mycommand);
}
- void OnRehash(const std::string ¶meter)
+ void OnRehash(userrec* user, const std::string ¶meter)
{
DELETE(Conf);
Conf = new ConfigReader(ServerInstance);
// this method is called. We should use the ProtoSendMetaData function after we've
// corrected decided how the data should look, to send the metadata on its way if
// it is ours.
- virtual void OnSyncUserMetaData(userrec* user, Module* proto, void* opaque, const std::string &extname)
+ virtual void OnSyncUserMetaData(userrec* user, Module* proto, void* opaque, const std::string &extname, bool displayable)
{
// check if the linking module wants to know about OUR metadata
if (extname == "swhois")
}
// when a user quits, tidy up their metadata
- virtual void OnUserQuit(userrec* user, const std::string &message)
+ virtual void OnUserQuit(userrec* user, const std::string &message, const std::string &oper_message)
{
std::string* swhois;
user->GetExt("swhois", swhois);
virtual Version GetVersion()
{
- return Version(1,1,0,0,VF_VENDOR,API_VERSION);
- }
-};
-
-
-class ModuleSWhoisFactory : public ModuleFactory
-{
- public:
- ModuleSWhoisFactory()
- {
- }
-
- ~ModuleSWhoisFactory()
- {
- }
-
- virtual Module * CreateModule(InspIRCd* Me)
- {
- return new ModuleSWhois(Me);
+ return Version(1, 1, 0, 0, VF_COMMON | VF_VENDOR, API_VERSION);
}
-
};
-
-extern "C" void * init_module( void )
-{
- return new ModuleSWhoisFactory;
-}
-
+MODULE_INIT(ModuleSWhois)