From 60efaaa1377a6696a9f6977347721a2ab03168ef Mon Sep 17 00:00:00 2001 From: Rick Bird Date: Sat, 2 Apr 2011 17:00:06 -0400 Subject: [PATCH] Added some module hooks in places that local_ calls were from local.c --- hdrs/modules.h | 6 +++++- src/bsd.c | 10 ++++++++++ src/game.c | 21 +++++++++++++++++++++ src/modules.c | 5 ++++- src/player.c | 8 ++++++++ src/timer.c | 9 +++++++++ 6 files changed, 57 insertions(+), 2 deletions(-) diff --git a/hdrs/modules.h b/hdrs/modules.h index 8664dc5..5b1c30f 100644 --- a/hdrs/modules.h +++ b/hdrs/modules.h @@ -28,7 +28,11 @@ int modules_shutdown(void); /* Retrieve Module Function */ #define MODULE_FUNC(h, m, func, ...) \ if((h = lt_dlsym(m, func))) { \ - h(__VAR_ARGS__) \ + h(__VA_ARGS__); \ + } +#define MODULE_FUNC_NOARGS(h, m, func) \ + if((h = lt_dlsym(m, func))) { \ + h(); \ } #define MODULE_FUNCRET(m, func) lt_dlsym(m, func); diff --git a/src/bsd.c b/src/bsd.c index 12ada57..11350bc 100644 --- a/src/bsd.c +++ b/src/bsd.c @@ -82,6 +82,7 @@ #define AUTORESTART #endif #include +#include #include "conf.h" @@ -128,6 +129,7 @@ #include "modules.h" #include "lua.h" #include "mushlua.h" +#include "modules.h" #ifdef HAS_WAITPID /** What does wait*() return? */ #define WAIT_TYPE int @@ -154,6 +156,8 @@ #define FD_ISSET(n,p) (*p & (1<<(n))) #endif /* defines for BSD 4.2 */ + +extern struct module_entry_t *module_list; #ifdef HAS_GETRUSAGE void rusage_stats(void); #endif @@ -2857,6 +2861,9 @@ parse_puebloclient(DESC *d, char *command) static int dump_messages(DESC *d, dbref player, int isnew) { + struct module_entry_t *m; + void (*handle)(dbref, int, int); + int is_hidden; int num = 0; DESC *tmpd; @@ -2934,6 +2941,9 @@ dump_messages(DESC *d, dbref player, int isnew) if (Haven(player)) notify(player, T("Your HAVEN flag is set. You cannot receive pages.")); local_connect(player, isnew, num); + MODULE_ITER(m) + MODULE_FUNC(handle, m->handle, "module_connect", player, isnew, num); + return 1; } diff --git a/src/game.c b/src/game.c index 6f27b77..c516547 100644 --- a/src/game.c +++ b/src/game.c @@ -42,6 +42,7 @@ void Win32MUSH_setup(void); #include #endif #include +#include #include "conf.h" #include "externs.h" @@ -73,6 +74,7 @@ void Win32MUSH_setup(void); #include "help.h" #include "dbio.h" #include "pcre.h" +#include "modules.h" #ifdef hpux #include @@ -100,6 +102,7 @@ static dbref *errdblist = NULL; /**< List of dbrefs to return errors from */ static dbref *errdbtail; /**< Pointer to end of errdblist */ static int errdbsize = 4; /**< Current size of errdblist array */ extern int use_flagfile; +extern struct module_entry_t *module_list; static void errdb_grow(void); @@ -332,6 +335,9 @@ dump_database_internal(void) char realtmpfl[2048]; char tmpfl[2048]; FILE *f = NULL; + struct module_entry_t *m; + void (*handle)(); + #ifndef PROFILING #ifndef WIN32 @@ -351,6 +357,8 @@ dump_database_internal(void) return 1; } else { local_dump_database(); + MODULE_ITER(m) + MODULE_FUNC_NOARGS(handle, m->handle, "module_dump_database"); #ifdef ALWAYS_PARANOID paranoid_checkpt = db_top / 5; @@ -751,6 +759,9 @@ extern struct db_stat_info current_state; void init_game_config(const char *conf) { + struct module_entry_t *m; + void (*handler)(); + int a; global_eval_context.process_command_port = 0; @@ -794,6 +805,9 @@ init_game_config(const char *conf) /* Load all the config file stuff except restrict_* */ local_configs(); + MODULE_ITER(m) + MODULE_FUNC_NOARGS(handler, m->handle, "module_configs"); + conf_default_set(); config_file_startup(conf, 0); start_all_logs(); @@ -817,6 +831,9 @@ init_game_config(const char *conf) void init_game_postdb(const char *conf) { + struct module_entry_t *m; + void (*handle)(); + /* access file stuff */ read_access_file(); /* initialize random number generator */ @@ -839,6 +856,10 @@ init_game_postdb(const char *conf) #endif /* CRON */ /* Call Local Startup */ local_startup(); + MODULE_ITER(m) + MODULE_FUNC_NOARGS(handle, m->handle, "module_startup"); + + /* everything else ok. Restart all objects. */ do_restart(); #ifdef HAS_OPENSSL diff --git a/src/modules.c b/src/modules.c index 210ce58..b805816 100644 --- a/src/modules.c +++ b/src/modules.c @@ -42,8 +42,11 @@ struct module_entry_t *module_entry_add(char *name) { int module_entry_del(struct module_entry_t *entry) { struct module_entry_t *m, *e = NULL; - if(module_list == entry) + if(module_list == entry) { e = module_list; + module_list = NULL; + } + else MODULE_ITER(m) if(m->next != NULL && m->next == entry) { e = m; diff --git a/src/player.c b/src/player.c index b7ca914..72fc8dc 100644 --- a/src/player.c +++ b/src/player.c @@ -23,6 +23,7 @@ #include #endif #include +#include #include "conf.h" #include "externs.h" @@ -36,6 +37,7 @@ #include "flags.h" #include "lock.h" #include "parse.h" +#include "modules.h" #ifdef HAS_CRYPT #ifdef I_CRYPT @@ -44,6 +46,7 @@ extern char *crypt(const char *, const char *); #endif #endif +extern struct module_entry_t *module_list; #include "extmail.h" #include "confmagic.h" @@ -414,6 +417,8 @@ make_player(const char *name, const char *password, const char *host, dbref player; char temp[SBUF_LEN]; object_flag_type flags; + struct module_entry_t *m; + void (*handle)(dbref player); player = new_object(); @@ -460,6 +465,9 @@ make_player(const char *name, const char *password, const char *host, current_state.players++; local_data_create(player); + MODULE_ITER(m) + MODULE_FUNC(handle, m->handle, "module_data_create", player); + return player; } diff --git a/src/timer.c b/src/timer.c index 15b0a5a..f661c76 100644 --- a/src/timer.c +++ b/src/timer.c @@ -25,6 +25,7 @@ #ifdef I_UNISTD #include #endif +#include #include "conf.h" #include "externs.h" @@ -40,7 +41,10 @@ #include "help.h" #include "parse.h" #include "confmagic.h" +#include "modules.h" +/* Module extern */ +extern struct module_entry_t *module_list; static sig_atomic_t hup_triggered = 0; static sig_atomic_t usr1_triggered = 0; @@ -205,6 +209,8 @@ void dispatch(void) { static int idle_counter = 0; + struct module_entry_t *m; + void (*handle)(void); /* A HUP reloads configuration and reopens logs */ if (hup_triggered) { @@ -295,6 +301,9 @@ dispatch(void) #endif local_timer(); + + MODULE_ITER(m) + MODULE_FUNC_NOARGS(handle, m->handle, "module_timer"); } sig_atomic_t cpu_time_limit_hit = 0; /** Was the cpu time limit hit? */ -- 2.30.2