m_helpop.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #include "inspircd.h"
00015
00016
00017 static std::map<irc::string, std::string> helpop_map;
00018
00019
00022 class Helpop : public SimpleUserModeHandler
00023 {
00024 public:
00025 Helpop(InspIRCd* Instance) : SimpleUserModeHandler(Instance, 'h') { }
00026 };
00027
00030 class CommandHelpop : public Command
00031 {
00032 public:
00033 CommandHelpop (InspIRCd* Instance) : Command(Instance, "HELPOP", 0, 0)
00034 {
00035 this->source = "m_helpop.so";
00036 syntax = "<any-text>";
00037 }
00038
00039 CmdResult Handle (const std::vector<std::string> ¶meters, User *user)
00040 {
00041 irc::string parameter("start");
00042 if (parameters.size() > 0)
00043 parameter = parameters[0].c_str();
00044
00045 if (parameter == "index")
00046 {
00047
00048 user->WriteServ("NOTICE %s :HELPOP topic index", user->nick.c_str());
00049 for (std::map<irc::string, std::string>::iterator iter = helpop_map.begin(); iter != helpop_map.end(); iter++)
00050 {
00051 user->WriteServ("NOTICE %s : %s", user->nick.c_str(), iter->first.c_str());
00052 }
00053 user->WriteServ("NOTICE %s :*** End of HELPOP topic index", user->nick.c_str());
00054 }
00055 else
00056 {
00057 user->WriteServ("NOTICE %s :*** HELPOP for %s", user->nick.c_str(), parameter.c_str());
00058
00059 std::map<irc::string, std::string>::iterator iter = helpop_map.find(parameter);
00060
00061 if (iter == helpop_map.end())
00062 {
00063 iter = helpop_map.find("nohelp");
00064 }
00065
00066 std::string value = iter->second;
00067 irc::sepstream stream(value, '\n');
00068 std::string token = "*";
00069
00070 while (stream.GetToken(token))
00071 user->WriteServ("NOTICE %s :%s", user->nick.c_str(), token.c_str());
00072
00073 user->WriteServ("NOTICE %s :*** End of HELPOP", user->nick.c_str());
00074 }
00075
00076
00077
00078
00079 return CMD_FAILURE;
00080 }
00081 };
00082
00083 class ModuleHelpop : public Module
00084 {
00085 private:
00086 std::string h_file;
00087 CommandHelpop* mycommand;
00088 Helpop* ho;
00089
00090 public:
00091 ModuleHelpop(InspIRCd* Me)
00092 : Module(Me)
00093 {
00094 ReadConfig();
00095 ho = new Helpop(ServerInstance);
00096 if (!ServerInstance->Modes->AddMode(ho))
00097 throw ModuleException("Could not add new modes!");
00098 mycommand = new CommandHelpop(ServerInstance);
00099 ServerInstance->AddCommand(mycommand);
00100 Implementation eventlist[] = { I_OnRehash, I_OnWhois };
00101 ServerInstance->Modules->Attach(eventlist, this, 2);
00102 }
00103
00104 virtual void ReadConfig()
00105 {
00106 ConfigReader *MyConf = new ConfigReader(ServerInstance);
00107
00108 helpop_map.clear();
00109
00110 for (int i = 0; i < MyConf->Enumerate("helpop"); i++)
00111 {
00112 irc::string key = assign(MyConf->ReadValue("helpop", "key", i));
00113 std::string value = MyConf->ReadValue("helpop", "value", i, true);
00114
00115 if (key == "index")
00116 {
00117 throw ModuleException("m_helpop: The key 'index' is reserved for internal purposes. Please remove it.");
00118 }
00119
00120 helpop_map[key] = value;
00121 }
00122
00123 if (helpop_map.find("start") == helpop_map.end())
00124 {
00125
00126 throw ModuleException("m_helpop: Helpop file is missing important entries. Please check the example conf.");
00127 }
00128 else if (helpop_map.find("nohelp") == helpop_map.end())
00129 {
00130
00131 throw ModuleException("m_helpop: Helpop file is missing important entries. Please check the example conf.");
00132 }
00133
00134 }
00135
00136
00137 virtual void OnRehash(User* user, const std::string ¶meter)
00138 {
00139 ReadConfig();
00140 }
00141
00142 virtual void OnWhois(User* src, User* dst)
00143 {
00144 if (dst->IsModeSet('h'))
00145 {
00146 ServerInstance->SendWhoisLine(src, dst, 310, std::string(src->nick)+" "+std::string(dst->nick)+" :is available for help.");
00147 }
00148 }
00149
00150 virtual ~ModuleHelpop()
00151 {
00152 ServerInstance->Modes->DelMode(ho);
00153 delete ho;
00154 }
00155
00156 virtual Version GetVersion()
00157 {
00158 return Version("$Id: m_helpop.cpp 10291 2008-08-25 20:35:51Z w00t $", VF_COMMON | VF_VENDOR, API_VERSION);
00159 }
00160 };
00161
00162 MODULE_INIT(ModuleHelpop)