2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
6 * This file is part of InspIRCd. InspIRCd is free software: you can
7 * redistribute it and/or modify it under the terms of the GNU General Public
8 * License as published by the Free Software Foundation, version 2.
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
24 virtual void isok(const char* name, int impl, Module* basemod, std::vector<std::string>& allmods) = 0;
28 template<typename T> struct vtable : public vtbase
40 /** member function pointer dereference from vtable; depends on the GCC 4.4 ABI (x86_64) */
41 template<typename E> void* read(E* obj)
45 uint8_t* optr = reinterpret_cast<uint8_t*>(obj);
47 uint8_t* vptr = *reinterpret_cast<uint8_t**>(optr);
48 vptr += u.v.delta - 1;
49 return *reinterpret_cast<void**>(vptr);
52 return reinterpret_cast<void*>(u.v.delta);
54 void isok(const char* name, int impl, Module* basemod, std::vector<std::string>& allmods)
56 void* base = read(basemod);
57 for(unsigned int i=0; i < allmods.size(); ++i)
59 Module* mod = ServerInstance->Modules->Find(allmods[i]);
60 void* fptr = read(mod);
61 for(EventHandlerIter j = ServerInstance->Modules->EventHandlers[impl].begin();
62 j != ServerInstance->Modules->EventHandlers[impl].end(); j++)
68 ServerInstance->SNO->WriteToSnoMask('a', "Module %s implements %s but uses default function",
69 mod->ModuleSourceFile.c_str(), name);
76 ServerInstance->SNO->WriteToSnoMask('a', "Module %s does not implement %s but overrides function",
77 mod->ModuleSourceFile.c_str(), name);
84 template<typename T> vtbase* vtinit(T t)
86 return new vtable<T>(t);
89 static void checkall(Module* noimpl)
91 std::vector<std::string> allmods = ServerInstance->Modules->GetAllModuleNames(0);
92 #define CHK(name) do { \
93 vtbase* vt = vtinit(&Module::name); \
94 vt->isok(#name, I_ ## name, noimpl, allmods); \
99 CHK(OnUserDisconnect);
110 CHK(OnUserPreInvite);
112 CHK(OnUserPreMessage);
116 CHK(OnGetServerDescription);
119 CHK(OnDecodeMetaData);
120 CHK(OnAcceptConnection);
132 CHK(OnBackgroundTimer);
140 CHK(OnCheckChannelBan);
143 CHK(OnChangeLocalUserHost);
144 CHK(OnPreTopicChange);
145 CHK(OnPostTopicChange);
149 CHK(OnChangeLocalUserGECOS);
151 CHK(OnChannelPreDelete);
152 CHK(OnChannelDelete);
159 CHK(OnBuildNeighborList);
160 CHK(OnGarbageCollect);
164 CHK(OnNamesListItem);
173 class CommandTest : public Command
176 CommandTest(Module* parent) : Command(parent, "TEST", 1)
178 syntax = "<action> <parameters>";
181 CmdResult Handle(const std::vector<std::string> ¶meters, User *user)
183 if (parameters[0] == "flood")
185 unsigned int count = parameters.size() > 1 ? atoi(parameters[1].c_str()) : 100;
186 std::string line = parameters.size() > 2 ? parameters[2] : ":z.z NOTICE !flood :Flood text";
187 for(unsigned int i=0; i < count; i++)
190 else if (parameters[0] == "freeze" && IS_LOCAL(user) && parameters.size() > 1)
192 IS_LOCAL(user)->CommandFloodPenalty += atoi(parameters[1].c_str());
194 else if (parameters[0] == "check")
197 ServerInstance->SNO->WriteToSnoMask('a', "Module check complete");
203 class ModuleTest : public Module
207 ModuleTest() : cmd(this)
211 void init() CXX11_OVERRIDE
213 if (!strstr(ServerInstance->Config->ServerName.c_str(), ".test"))
214 throw ModuleException("Don't load modules without reading their descriptions!");
215 ServerInstance->Modules->AddService(cmd);
218 Version GetVersion() CXX11_OVERRIDE
220 return Version("Provides a module for testing the server while linked in a network", VF_VENDOR|VF_OPTCOMMON);
224 MODULE_INIT(ModuleTest)