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;
24 template<typename T> struct vtable : public vtbase
36 /** member function pointer dereference from vtable; depends on the GCC 4.4 ABI (x86_64) */
37 template<typename E> void* read(E* obj)
41 uint8_t* optr = reinterpret_cast<uint8_t*>(obj);
43 uint8_t* vptr = *reinterpret_cast<uint8_t**>(optr);
44 vptr += u.v.delta - 1;
45 return *reinterpret_cast<void**>(vptr);
48 return reinterpret_cast<void*>(u.v.delta);
50 void isok(const char* name, int impl, Module* basemod, std::vector<std::string>& allmods)
52 void* base = read(basemod);
53 for(unsigned int i=0; i < allmods.size(); ++i)
55 Module* mod = ServerInstance->Modules->Find(allmods[i]);
56 void* fptr = read(mod);
57 for(EventHandlerIter j = ServerInstance->Modules->EventHandlers[impl].begin();
58 j != ServerInstance->Modules->EventHandlers[impl].end(); j++)
64 ServerInstance->SNO->WriteToSnoMask('a', "Module %s implements %s but uses default function",
65 mod->ModuleSourceFile.c_str(), name);
72 ServerInstance->SNO->WriteToSnoMask('a', "Module %s does not implement %s but overrides function",
73 mod->ModuleSourceFile.c_str(), name);
80 template<typename T> vtbase* vtinit(T t)
82 return new vtable<T>(t);
85 static void checkall(Module* noimpl)
87 std::vector<std::string> allmods = ServerInstance->Modules->GetAllModuleNames(0);
88 #define CHK(name) do { \
89 vtbase* vt = vtinit(&Module::name); \
90 vt->isok(#name, I_ ## name, noimpl, allmods); \
95 CHK(OnUserDisconnect);
106 CHK(OnUserPreInvite);
108 CHK(OnUserPreMessage);
109 CHK(OnUserPreNotice);
114 CHK(OnGetServerDescription);
117 CHK(OnDecodeMetaData);
119 CHK(OnAcceptConnection);
132 CHK(OnBackgroundTimer);
140 CHK(OnCheckChannelBan);
143 CHK(OnChangeLocalUserHost);
144 CHK(OnPreTopicChange);
145 CHK(OnPostTopicChange);
151 CHK(OnChangeLocalUserGECOS);
153 CHK(OnChannelPreDelete);
154 CHK(OnChannelDelete);
161 CHK(OnBuildNeighborList);
162 CHK(OnGarbageCollect);
166 CHK(OnNamesListItem);
175 class CommandTest : public Command
178 CommandTest(Module* parent) : Command(parent, "TEST", 1)
180 syntax = "<action> <parameters>";
183 CmdResult Handle(const std::vector<std::string> ¶meters, User *user)
185 if (parameters[0] == "flood")
187 unsigned int count = parameters.size() > 1 ? atoi(parameters[1].c_str()) : 100;
188 std::string line = parameters.size() > 2 ? parameters[2] : ":z.z NOTICE !flood :Flood text";
189 for(unsigned int i=0; i < count; i++)
192 else if (parameters[0] == "freeze" && IS_LOCAL(user) && parameters.size() > 1)
194 IS_LOCAL(user)->CommandFloodPenalty += atoi(parameters[1].c_str());
196 else if (parameters[0] == "check")
199 ServerInstance->SNO->WriteToSnoMask('a', "Module check complete");
205 class ModuleTest : public Module
209 ModuleTest() : cmd(this)
211 if (!strstr(ServerInstance->Config->ServerName.c_str(), ".test"))
212 throw ModuleException("Don't load modules without reading their descriptions!");
213 ServerInstance->AddCommand(&cmd);
218 return Version("Provides a module for testing the server while linked in a network", VF_VENDOR|VF_OPTCOMMON);
222 MODULE_INIT(ModuleTest)