1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2010 InspIRCd Development Team
6 * See: http://wiki.inspircd.org/Credits
8 * This program is free but copyrighted software; see
9 * the file COPYING for details.
11 * ---------------------------------------------------
14 /* $ModDesc: Provides a module for testing the server while linked in a network */
20 virtual void isok(const char* name, int impl, Module* basemod, std::vector<std::string>& allmods) = 0;
23 template<typename T> struct vtable : public vtbase
35 /** member function pointer dereference from vtable; depends on the GCC 4.4 ABI (x86_64) */
36 template<typename E> void* read(E* obj)
40 uint8_t* optr = reinterpret_cast<uint8_t*>(obj);
42 uint8_t* vptr = *reinterpret_cast<uint8_t**>(optr);
43 vptr += u.v.delta - 1;
44 return *reinterpret_cast<void**>(vptr);
47 return reinterpret_cast<void*>(u.v.delta);
49 void isok(const char* name, int impl, Module* basemod, std::vector<std::string>& allmods)
51 void* base = read(basemod);
52 for(unsigned int i=0; i < allmods.size(); ++i)
54 Module* mod = ServerInstance->Modules->Find(allmods[i]);
55 void* fptr = read(mod);
56 for(EventHandlerIter j = ServerInstance->Modules->EventHandlers[impl].begin();
57 j != ServerInstance->Modules->EventHandlers[impl].end(); j++)
63 ServerInstance->SNO->WriteToSnoMask('a', "Module %s implements %s but uses default function",
64 mod->ModuleSourceFile.c_str(), name);
71 ServerInstance->SNO->WriteToSnoMask('a', "Module %s does not implement %s but overrides function",
72 mod->ModuleSourceFile.c_str(), name);
79 template<typename T> vtbase* vtinit(T t)
81 return new vtable<T>(t);
84 static void checkall(Module* noimpl)
86 std::vector<std::string> allmods = ServerInstance->Modules->GetAllModuleNames(0);
87 #define CHK(name) do { \
88 vtbase* vt = vtinit(&Module::name); \
89 vt->isok(#name, I_ ## name, noimpl, allmods); \
94 CHK(OnUserDisconnect);
105 CHK(OnUserPreInvite);
107 CHK(OnUserPreMessage);
108 CHK(OnUserPreNotice);
113 CHK(OnGetServerDescription);
116 CHK(OnDecodeMetaData);
118 CHK(OnAcceptConnection);
131 CHK(OnBackgroundTimer);
139 CHK(OnCheckChannelBan);
142 CHK(OnChangeLocalUserHost);
143 CHK(OnPreTopicChange);
144 CHK(OnPostTopicChange);
150 CHK(OnChangeLocalUserGECOS);
152 CHK(OnChannelPreDelete);
153 CHK(OnChannelDelete);
161 CHK(OnBuildNeighborList);
162 CHK(OnGarbageCollect);
166 CHK(OnNamesListItem);
173 CHK(OnChannelRestrictionApply);
176 class CommandTest : public Command
179 CommandTest(Module* parent) : Command(parent, "TEST", 1)
181 syntax = "<action> <parameters>";
184 CmdResult Handle(const std::vector<std::string> ¶meters, User *user)
186 if (parameters[0] == "flood")
188 unsigned int count = parameters.size() > 1 ? atoi(parameters[1].c_str()) : 100;
189 std::string line = parameters.size() > 2 ? parameters[2] : ":z.z NOTICE !flood :Flood text";
190 for(unsigned int i=0; i < count; i++)
193 else if (parameters[0] == "freeze" && IS_LOCAL(user) && parameters.size() > 1)
195 IS_LOCAL(user)->CommandFloodPenalty += atoi(parameters[1].c_str());
197 else if (parameters[0] == "shutdown" && IS_LOCAL(user))
199 int i = parameters.size() > 1 ? atoi(parameters[1].c_str()) : 2;
200 ServerInstance->SE->Shutdown(IS_LOCAL(user)->GetFd(), i);
202 else if (parameters[0] == "check")
205 ServerInstance->SNO->WriteToSnoMask('a', "Module check complete");
211 class ModuleTest : public Module
215 ModuleTest() : cmd(this)
217 if (!strstr(ServerInstance->Config->ServerName.c_str(), ".test"))
218 throw ModuleException("Don't load modules without reading their descriptions!");
219 ServerInstance->AddCommand(&cmd);
224 return Version("Provides a module for testing the server while linked in a network", VF_VENDOR|VF_OPTCOMMON);
228 MODULE_INIT(ModuleTest)