1
0
mirror of https://github.com/unrealircd/unrealircd.git synced 2026-07-07 13:43:12 +02:00
Files
unrealircd/u4modules/Velcro.module
T
stskeeps 77317ec9f7 - Added HookAddCfg as a more typesafe way to add
HOOKTYPE_CONFIGRUN/CONFIGTEST. Was needed for Velcro and possibly other
  situations
- Some more Velcro changes to make it fit into 3.3
2007-06-06 15:36:40 +00:00

188 lines
4.6 KiB
Plaintext

/*
* Velcro Module Language
* Copyright (c) 2006, Carsten Valdemar Munk
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* The name of Carsten Valdemar Munk may not be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* $Id$
*/
@version $Id$
@copyright (C) Copyright 2006 Carsten Valdemar Munk
#include <list>
#include <map>
#include <string>
typedef void *(VoidFunctionPointer) (void);
typedef void *(VoidIntParaFunctionPointer) (int value);
typedef void *(VoidIntPointerParaFunctionPointer) (int *ret);
class Velcro
{
public:
bool dependsOnModule(const char *who, const char *module);
@hook initialStartup();
static Velcro& instanceOf()
{
static Velcro modules;
return modules;
}
std::list<const char *> modulesToLoad;
};
implementation:
// Glue for Unreal3
extern "C"
{
#include "config.h"
#include "struct.h"
#include "common.h"
#include "sys.h"
#include "numeric.h"
#include "msg.h"
#include "proto.h"
#include "channel.h"
#include <time.h>
#include <sys/stat.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifdef _WIN32
#include <io.h>
#endif
#include <fcntl.h>
#include "h.h"
#ifdef STRIPBADWORDS
#include "badwords.h"
#endif
#ifdef _WIN32
#include "version.h"
#endif
}
ModuleHeader MOD_HEADER(Velcro)
= {
"Velcro",
"$Id$",
"Velcro module system",
"3.2-b8-1",
NULL
};
static Hook *HookConfTest = NULL;
static Hook *HookConfRun = NULL;
static Hook *HookConfRehash = NULL;
DLLFUNC int h_velcro_configtest(ConfigFile *cf, ConfigEntry *ce, int type, int *errs) {
ConfigEntry *cep;
int errors = 0;
if(type != CONFIG_MAIN)
return 0;
if(!strcmp(ce->ce_varname, "loadmodule4")) {
if (!ce->ce_vardata)
{
config_status("%s:%i: loadmodule4 without filename",
ce->ce_fileptr->cf_filename, ce->ce_varlinenum);
errors=1;
*errs=errors;
return -1;
}
}
return 0;
}
DLLFUNC int h_velcro_configrun(ConfigFile *cf, ConfigEntry *ce, int type, int *errs) {
ConfigEntry *cep;
int errors = 0;
if(type != CONFIG_MAIN)
return 0;
if(!strcmp(ce->ce_varname, "loadmodule4")) {
return 1;
}
return 0;
}
DLLFUNC int h_velcro_configrehash() {
return 0;
}
extern "C" DLLFUNC int MOD_INIT(Velcro)(ModuleInfo *modinfo)
{
MARK_AS_OFFICIAL_MODULE(modinfo);
ModuleSetOptions(modinfo->handle, MOD_OPT_PERM);
HookConfRun = HookAddCfg(modinfo->handle, HOOKTYPE_CONFIGRUN, h_velcro_configrun);
HookConfRehash = HookAddEx(modinfo->handle, HOOKTYPE_REHASH, h_velcro_configrehash);
return MOD_SUCCESS;
}
extern "C" DLLFUNC int MOD_TEST(Velcro)(ModuleInfo *modinfo)
{
HookConfTest = HookAddCfg(modinfo->handle, HOOKTYPE_CONFIGTEST, h_velcro_configtest);
return MOD_SUCCESS;
}
extern "C" DLLFUNC int MOD_LOAD(Velcro)(int module_load)
{
Velcro_init(false);
return MOD_SUCCESS;
}
extern "C" DLLFUNC int MOD_UNLOAD(Velcro)(int module_unload)
{
// does not happen
return MOD_FAILED;
}
// Actual Velcro
@on this_Module::onInit(bool reloading)
{
@yield;
}
@on this_Module::onUnload()
{
@yield;
}
@on this_Module::onReload()
{
@yield;
}