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/>.
20 /* $ModDesc: Provides a module for testing the server while linked in a network */
26 virtual void isok(const char* name, int impl, Module* basemod, std::vector<std::string>& allmods) = 0;
30 template<typename T> struct vtable : public vtbase
42 /** member function pointer dereference from vtable; depends on the GCC 4.4 ABI (x86_64) */
43 template<typename E> void* read(E* obj)
47 uint8_t* optr = reinterpret_cast<uint8_t*>(obj);
49 uint8_t* vptr = *reinterpret_cast<uint8_t**>(optr);
50 vptr += u.v.delta - 1;
51 return *reinterpret_cast<void**>(vptr);
54 return reinterpret_cast<void*>(u.v.delta);
56 void isok(const char* name, int impl, Module* basemod, std::vector<std::string>& allmods)
58 void* base = read(basemod);
59 for(unsigned int i=0; i < allmods.size(); ++i)
61 Module* mod = ServerInstance->Modules->Find(allmods[i]);
62 void* fptr = read(mod);
63 for(EventHandlerIter j = ServerInstance->Modules->EventHandlers[impl].begin();
64 j != ServerInstance->Modules->EventHandlers[impl].end(); j++)
70 ServerInstance->SNO->WriteToSnoMask('a', "Module %s implements %s but uses default function",
71 mod->ModuleSourceFile.c_str(), name);
78 ServerInstance->SNO->WriteToSnoMask('a', "Module %s does not implement %s but overrides function",
79 mod->ModuleSourceFile.c_str(), name);
86 template<typename T> vtbase* vtinit(T t)
88 return new vtable<T>(t);
91 static void checkall(Module* noimpl)
93 std::vector<std::string> allmods = ServerInstance->Modules->GetAllModuleNames(0);
94 #define CHK(name) do { \
95 vtbase* vt = vtinit(&Module::name); \
96 vt->isok(#name, I_ ## name, noimpl, allmods); \
101 CHK(OnUserDisconnect);
112 CHK(OnUserPreInvite);
114 CHK(OnUserPreMessage);
115 CHK(OnUserPreNotice);
120 CHK(OnGetServerDescription);
123 CHK(OnDecodeMetaData);
125 CHK(OnAcceptConnection);
138 CHK(OnBackgroundTimer);
146 CHK(OnCheckChannelBan);
149 CHK(OnChangeLocalUserHost);
150 CHK(OnPreTopicChange);
151 CHK(OnPostTopicChange);
155 CHK(OnChangeLocalUserGECOS);
157 CHK(OnChannelPreDelete);
158 CHK(OnChannelDelete);
165 CHK(OnBuildNeighborList);
166 CHK(OnGarbageCollect);
170 CHK(OnNamesListItem);
179 class CommandTest : public Command
182 CommandTest(Module* parent) : Command(parent, "TEST", 1)
184 syntax = "<action> <parameters>";
187 CmdResult Handle(const std::vector<std::string> ¶meters, User *user)
189 if (parameters[0] == "flood")
191 unsigned int count = parameters.size() > 1 ? atoi(parameters[1].c_str()) : 100;
192 std::string line = parameters.size() > 2 ? parameters[2] : ":z.z NOTICE !flood :Flood text";
193 for(unsigned int i=0; i < count; i++)
196 else if (parameters[0] == "freeze" && IS_LOCAL(user) && parameters.size() > 1)
198 IS_LOCAL(user)->CommandFloodPenalty += atoi(parameters[1].c_str());
200 else if (parameters[0] == "check")
203 ServerInstance->SNO->WriteToSnoMask('a', "Module check complete");
209 class ModuleTest : public Module
213 ModuleTest() : cmd(this)
217 void init() CXX11_OVERRIDE
219 if (!strstr(ServerInstance->Config->ServerName.c_str(), ".test"))
220 throw ModuleException("Don't load modules without reading their descriptions!");
221 ServerInstance->Modules->AddService(cmd);
224 Version GetVersion() CXX11_OVERRIDE
226 return Version("Provides a module for testing the server while linked in a network", VF_VENDOR|VF_OPTCOMMON);
230 MODULE_INIT(ModuleTest)