darope@0: // vi: set ts=4 sw=4 : darope@0: // vim: set tw=75 : darope@0: darope@0: // mlist.cpp - functions for list of plugins (class MPluginList) darope@0: darope@0: /* darope@0: * Copyright (c) 2001-2003 Will Day darope@0: * darope@0: * This file is part of Metamod. darope@0: * darope@0: * Metamod is free software; you can redistribute it and/or modify it darope@0: * under the terms of the GNU General Public License as published by the darope@0: * Free Software Foundation; either version 2 of the License, or (at darope@0: * your option) any later version. darope@0: * darope@0: * Metamod is distributed in the hope that it will be useful, but darope@0: * WITHOUT ANY WARRANTY; without even the implied warranty of darope@0: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU darope@0: * General Public License for more details. darope@0: * darope@0: * You should have received a copy of the GNU General Public License darope@0: * along with Metamod; if not, write to the Free Software Foundation, darope@0: * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA darope@0: * darope@0: * In addition, as a special exception, the author gives permission to darope@0: * link the code of this program with the Half-Life Game Engine ("HL darope@0: * Engine") and Modified Game Libraries ("MODs") developed by Valve, darope@0: * L.L.C ("Valve"). You must obey the GNU General Public License in all darope@0: * respects for all of the code used other than the HL Engine and MODs darope@0: * from Valve. If you modify this file, you may extend this exception darope@0: * to your version of the file, but you are not obligated to do so. If darope@0: * you do not wish to do so, delete this exception statement from your darope@0: * version. darope@0: * darope@0: */ darope@0: darope@0: #include // errno, etc darope@0: darope@0: #include // always darope@0: darope@0: #include "mlist.h" // me darope@0: #include "mplugin.h" // class MPlugin darope@0: #include "plinfo.h" // plid_t, etc darope@0: #include "commands_meta.h" // cmd_meta_pluginlist, etc darope@0: #include "metamod.h" // GameDLL, etc darope@0: #include "types_meta.h" // mBOOL darope@0: #include "log_meta.h" // META_LOG, etc darope@0: #include "osdep.h" // win32 snprintf, normalize_pathname, darope@0: darope@0: // Constructor darope@0: MPluginList::MPluginList(const char *ifile) darope@0: : size(MAX_PLUGINS), endlist(0) darope@0: { darope@0: int i; darope@0: // store filename of ini file darope@0: STRNCPY(inifile, ifile, sizeof(inifile)); darope@0: // initialize array darope@0: memset(plist, 0, sizeof(plist)); darope@0: for(i=0; i< size; i++) { darope@0: plist[i].index=i+1; // 1-based darope@0: } darope@0: endlist=0; darope@0: } darope@0: darope@0: // Find a plugin based on the plugin index #. darope@0: // meta_errno values: darope@0: // - ME_ARGUMENT invalid pindex darope@0: // - ME_NOTFOUND couldn't find a matching plugin darope@0: MPlugin *MPluginList::find(int pindex) { darope@0: MPlugin *pfound; darope@0: if(pindex <= 0) darope@0: RETURN_ERRNO(NULL, ME_ARGUMENT); darope@0: pfound=&plist[pindex-1]; darope@0: if(pfound->status < PL_VALID) darope@0: RETURN_ERRNO(NULL, ME_NOTFOUND); darope@0: else darope@0: return(pfound); darope@0: } darope@0: darope@0: // Find a plugin with the given plid. darope@0: // meta_errno values: darope@0: // - ME_ARGUMENT null plid_t darope@0: // - ME_NOTFOUND couldn't find a matching plugin darope@0: MPlugin *MPluginList::find(plid_t id) { darope@0: int i; darope@0: darope@0: if(!id) darope@0: RETURN_ERRNO(NULL, ME_ARGUMENT); darope@0: for(i=0; i < endlist; i++) { darope@0: if(plist[i].status < PL_VALID) darope@0: continue; darope@0: if(plist[i].info == id) darope@0: return(&plist[i]); darope@0: } darope@0: RETURN_ERRNO(NULL, ME_NOTFOUND); darope@0: } darope@0: darope@0: // Find a plugin with the given pathname. darope@0: // meta_errno values: darope@0: // - ME_ARGUMENT null path darope@0: // - ME_NOTFOUND couldn't find a matching plugin darope@0: MPlugin *MPluginList::find(const char *findpath) { darope@0: int i; darope@0: darope@0: if(!findpath) darope@0: RETURN_ERRNO(NULL, ME_ARGUMENT); darope@0: META_DEBUG(8, ("Looking for loaded plugin with dlfnamepath: %s", findpath)); darope@0: for(i=0; i < endlist; i++) { darope@0: META_DEBUG(9, ("Looking at: plugin %s loadedpath: %s", plist[i].file, plist[i].pathname)); darope@0: if(plist[i].status < PL_VALID) darope@0: continue; darope@0: if(strmatch(plist[i].pathname, findpath)) { darope@0: META_DEBUG(8, ("Found loaded plugin %s", plist[i].file)); darope@0: return(&plist[i]); darope@0: } darope@0: } darope@0: META_DEBUG(8, ("No loaded plugin found with path: %s", findpath)); darope@0: RETURN_ERRNO(NULL, ME_NOTFOUND); darope@0: } darope@0: darope@0: // Find a plugin that uses the given memory location. darope@0: // meta_errno values: darope@0: // - ME_ARGUMENT null memptr darope@0: // - ME_NOTFOUND couldn't find a matching plugin darope@0: // - errno's from DLFNAME() darope@0: MPlugin *MPluginList::find_memloc(void *memptr) { darope@0: const char *dlfile; darope@0: darope@0: if(!memptr) darope@0: RETURN_ERRNO(NULL, ME_ARGUMENT); darope@0: if(!(dlfile=DLFNAME(memptr))) { darope@0: META_DEBUG(8, ("DLFNAME failed to find memloc %d", memptr)); darope@0: // meta_errno should be already set in DLFNAME darope@0: return(NULL); darope@0: } darope@0: return(find(dlfile)); darope@0: } darope@0: darope@0: // Find a plugin with non-ambiguous prefix string matching desc, file, darope@0: // name, or logtag. darope@0: // meta_errno values: darope@0: // - ME_ARGUMENT null prefix darope@0: // - ME_NOTFOUND couldn't find a matching plugin darope@0: // - ME_NOTUNIQ found multiple matches; no unique match darope@0: MPlugin *MPluginList::find_match(const char *prefix) { darope@0: int i, len; darope@0: MPlugin *iplug, *pfound; darope@0: char buf[NAME_MAX]; darope@0: darope@0: if(!prefix) darope@0: RETURN_ERRNO(NULL, ME_ARGUMENT); darope@0: pfound=NULL; darope@0: len=strlen(prefix); darope@0: snprintf(buf, sizeof(buf), "mm_%s", prefix); darope@0: for(i=0; i < endlist; i++) { darope@0: iplug=&plist[i]; darope@0: if(iplug->status < PL_VALID) darope@0: continue; darope@0: if(iplug->info && strncasecmp(iplug->info->name, prefix, len) == 0) { darope@0: if(pfound) darope@0: RETURN_ERRNO(NULL, ME_NOTUNIQ); darope@0: pfound=iplug; darope@0: continue; darope@0: } darope@0: else if(strncasecmp(iplug->desc, prefix, len) == 0) { darope@0: if(pfound) darope@0: RETURN_ERRNO(NULL, ME_NOTUNIQ); darope@0: pfound=iplug; darope@0: continue; darope@0: } darope@0: else if(strncasecmp(iplug->file, prefix, len) == 0) { darope@0: if(pfound) darope@0: RETURN_ERRNO(NULL, ME_NOTUNIQ); darope@0: pfound=iplug; darope@0: continue; darope@0: } darope@0: else if(strncasecmp(iplug->file, buf, strlen(buf)) == 0) { darope@0: if(pfound) darope@0: RETURN_ERRNO(NULL, ME_NOTUNIQ); darope@0: pfound=iplug; darope@0: continue; darope@0: } darope@0: else if(iplug->info darope@0: && strncasecmp(iplug->info->logtag, prefix, len) == 0) darope@0: { darope@0: if(pfound) darope@0: RETURN_ERRNO(NULL, ME_NOTUNIQ); darope@0: pfound=iplug; darope@0: continue; darope@0: } darope@0: } darope@0: if(pfound) darope@0: return(pfound); darope@0: else darope@0: RETURN_ERRNO(NULL, ME_NOTFOUND); darope@0: } darope@0: darope@244: darope@244: // Find a plugin with same file, logtag, desc or significant darope@244: // prefix of file. Uses the platform_match() method of MPlugin. darope@244: // meta_errno values: darope@244: // - ME_ARGUMENT null prefix darope@244: // - ME_NOTFOUND couldn't find a matching plugin darope@244: MPlugin *MPluginList::find_match(MPlugin *pmatch) { darope@244: int i; darope@244: MPlugin *iplug, *pfound; darope@244: if(!pmatch) darope@244: RETURN_ERRNO(NULL, ME_ARGUMENT); darope@244: pfound=NULL; darope@244: for(i=0; i < endlist; i++) { darope@244: iplug=&plist[i]; darope@244: if(pmatch->platform_match(iplug)) { darope@244: pfound=iplug; darope@244: break; darope@244: } darope@244: } darope@244: darope@244: if(pfound) darope@244: return(pfound); darope@244: else darope@244: RETURN_ERRNO(NULL, ME_NOTFOUND); darope@244: } darope@244: darope@244: darope@0: // Add a plugin to the list. darope@0: // meta_errno values: darope@0: // - ME_MAXREACHED reached max plugins darope@0: MPlugin *MPluginList::add(MPlugin *padd) { darope@0: int i; darope@0: MPlugin *iplug; darope@0: darope@0: // Find either: darope@0: // - a slot in the list that's not being used darope@0: // - the end of the list darope@0: for(i=0; i < endlist && plist[i].status != PL_EMPTY; i++); darope@0: darope@0: // couldn't find a slot to use darope@0: if(i==size) { darope@0: META_ERROR("Couldn't add plugin '%s' to list; reached max plugins (%d)", darope@0: padd->file, i); darope@0: RETURN_ERRNO(NULL, ME_MAXREACHED); darope@0: } darope@0: darope@0: // if we found the end of the list, advance end marker darope@0: if(i==endlist) darope@0: endlist++; darope@0: iplug = &plist[i]; darope@0: darope@0: // copy filename into this free slot darope@0: STRNCPY(iplug->filename, padd->filename, sizeof(iplug->filename)); darope@0: // Copy file offset ptr. darope@0: // Can't just copy ptr, as it points to offset in padd, which will go darope@0: // away; need to point to corresponding offset in iplug. darope@0: iplug->file = iplug->filename + (padd->file - padd->filename); darope@0: // copy description darope@0: STRNCPY(iplug->desc, padd->desc, sizeof(iplug->desc)); darope@0: // copy pathname darope@0: STRNCPY(iplug->pathname, padd->pathname, sizeof(iplug->pathname)); darope@0: // copy source darope@0: iplug->source=padd->source; darope@0: // copy status darope@0: iplug->status=padd->status; darope@0: darope@0: return(iplug); darope@0: } darope@0: darope@0: darope@0: // Read plugins.ini at server startup. darope@0: // meta_errno values: darope@0: // - ME_NOFILE ini file missing or empty darope@0: mBOOL MPluginList::ini_startup() { darope@0: FILE *fp; darope@0: char line[MAX_STRBUF_LEN]; darope@0: int n, ln; darope@244: MPlugin *pmatch; darope@0: darope@0: if(!valid_gamedir_file(inifile)) { darope@0: META_ERROR("ini: Metamod plugins file empty or missing: %s", inifile); darope@0: RETURN_ERRNO(mFALSE, ME_NOFILE); darope@0: } darope@0: full_gamedir_path(inifile, inifile); darope@0: darope@0: fp=fopen(inifile, "r"); darope@0: if(!fp) { darope@0: META_ERROR("ini: Unable to open plugins file '%s': %s", inifile, darope@0: strerror(errno)); darope@0: RETURN_ERRNO(mFALSE, ME_NOFILE); darope@0: } darope@0: darope@0: META_LOG("ini: Begin reading plugins list: %s", inifile); darope@0: for(n=0, ln=1; darope@0: !feof(fp) && fgets(line, sizeof(line), fp) && n < size; darope@0: ln++) darope@0: { darope@0: // Remove line terminations. darope@0: char *cp; darope@0: if((cp=strrchr(line, '\r'))) darope@0: *cp='\0'; darope@0: if((cp=strrchr(line, '\n'))) darope@0: *cp='\0'; darope@0: // Parse directly into next entry in array darope@0: if(!plist[n].ini_parseline(line)) { darope@0: if(meta_errno==ME_FORMAT) darope@0: META_ERROR("ini: Skipping malformed line %d of %s", ln, darope@0: inifile); darope@0: continue; darope@0: } darope@0: // Check for a duplicate - an existing entry with this pathname. darope@0: if(find(plist[n].pathname)) { darope@244: // Should we check platform specific level here? darope@0: META_ERROR("ini: Skipping duplicate plugin, line %d of %s: %s", darope@0: ln, inifile, plist[n].pathname); darope@0: continue; darope@0: } darope@244: // Check for a matching platform with different platform specifics darope@244: // level. darope@244: if(NULL != (pmatch=find_match(&plist[n]))) { darope@244: if(pmatch->pfspecific >= plist[n].pfspecific) { darope@244: META_DEBUG(1, ("ini: Skipping plugin, line %d of %s: plugin with higher platform specific level already exists. (%d >= %d)", darope@244: n, inifile, pmatch->pfspecific, plist[n].pfspecific)); darope@244: continue; darope@244: } darope@244: META_DEBUG(1, ("ini: Plugin in line %d overrides existing plugin with lower platform specific level %d, ours %d", darope@244: n, pmatch->pfspecific, plist[n].pfspecific)); darope@244: memset(pmatch, 0, sizeof(MPlugin)); darope@244: } darope@0: plist[n].action=PA_LOAD; darope@0: META_LOG("ini: Read plugin config for: %s", plist[n].desc); darope@0: n++; darope@0: endlist=n; // mark end of list darope@0: } darope@0: META_LOG("ini: Finished reading plugins list: %s; Found %d plugins to load", darope@0: inifile, n); darope@0: darope@0: fclose(fp); darope@0: if(!n) { darope@0: META_ERROR("ini: Warning; no plugins found to load?"); darope@0: } darope@0: return(mTRUE); darope@0: } darope@0: darope@0: // Re-read plugins.ini looking for added/deleted/changed plugins. darope@0: // meta_errno values: darope@0: // - ME_NOFILE ini file missing or empty darope@0: mBOOL MPluginList::ini_refresh() { darope@0: FILE *fp; darope@0: char line[MAX_STRBUF_LEN]; darope@0: int n, ln; darope@0: MPlugin pl_temp; darope@0: MPlugin *pl_found, *pl_added; darope@0: darope@0: fp=fopen(inifile, "r"); darope@0: if(!fp) { darope@0: META_ERROR("ini: Unable to open plugins file '%s': %s", inifile, darope@0: strerror(errno)); darope@0: RETURN_ERRNO(mFALSE, ME_NOFILE); darope@0: } darope@0: darope@0: META_LOG("ini: Begin re-reading plugins list: %s", inifile); darope@0: for(n=0, ln=1; darope@0: !feof(fp) && fgets(line, sizeof(line), fp) && n < size; darope@0: ln++) darope@0: { darope@0: // Remove line terminations. darope@0: char *cp; darope@0: if((cp=strrchr(line, '\r'))) darope@0: *cp='\0'; darope@0: if((cp=strrchr(line, '\n'))) darope@0: *cp='\0'; darope@0: // Parse into a temp plugin darope@0: memset(&pl_temp, 0, sizeof(pl_temp)); darope@0: if(!pl_temp.ini_parseline(line)) { darope@0: if(meta_errno==ME_FORMAT) darope@0: META_ERROR("ini: Skipping malformed line %d of %s", darope@0: ln, inifile); darope@0: continue; darope@0: } darope@0: // Try to find plugin with this pathname in the current list of darope@0: // plugins. darope@0: if(!(pl_found=find(pl_temp.pathname))) { darope@244: // Check for a matching platform with higher platform specifics darope@244: // level. darope@244: if(NULL != (pl_found=find_match(&pl_temp))) { darope@244: if(pl_found->pfspecific >= pl_temp.pfspecific) { darope@244: META_DEBUG(1, ("ini: Skipping plugin, line %d of %s: plugin with higher platform specific level already exists. (%d >= %d)", darope@244: ln, inifile, pl_found->pfspecific, pl_temp.pfspecific)); darope@244: continue; darope@244: } darope@244: META_DEBUG(1, ("ini: Plugin in line %d should override existing plugin with lower platform specific level %d, ours %d", darope@244: ln, pl_found->pfspecific, pl_temp.pfspecific)); darope@244: continue; darope@244: } darope@0: // new plugin; add to list darope@0: if((pl_added=add(&pl_temp))) { darope@0: // try to load this plugin at the next opportunity darope@0: pl_added->action=PA_LOAD; darope@0: } darope@0: else darope@0: // error details logged in add() darope@0: continue; darope@0: } darope@0: else { darope@0: // This plugin is already in the current list of plugins. darope@0: // Pathname already matches. Recopy desc, if specified in darope@0: // plugins.ini. darope@0: if(pl_temp.desc[0] != '<') darope@0: STRNCPY(pl_found->desc, pl_temp.desc, sizeof(pl_found->desc)); darope@0: darope@0: // Check the file to see if it looks like it's been modified darope@0: // since we last loaded it. darope@0: if(!pl_found->newer_file()) { darope@0: if(meta_errno==ME_NOFILE) { darope@0: META_ERROR("ini: Skipping plugin, couldn't stat file '%s': %s", darope@0: pl_found->pathname, strerror(errno)); darope@0: continue; darope@0: } darope@0: else { darope@0: // File hasn't been updated. darope@0: // Keep plugin (don't let refresh() unload it). darope@0: pl_found->action=PA_KEEP; darope@0: } darope@0: } darope@0: // Newer file on disk. darope@0: else if(pl_found->status >= PL_OPENED) { darope@0: META_DEBUG(2, ("ini: Plugin '%s' has newer file on disk", pl_found->desc)); darope@0: pl_found->action=PA_RELOAD; darope@0: } darope@0: else darope@0: META_ERROR("ini: Plugin '%s' has newer file, but unexpected status (%s)", darope@0: pl_found->desc, pl_found->str_status()); darope@0: } darope@0: META_LOG("ini: Read plugin config for: %s", plist[n].desc); darope@0: n++; darope@0: } darope@0: META_LOG("ini: Finished reading plugins list: %s; Found %d plugins", inifile, n); darope@0: darope@0: fclose(fp); darope@0: if(!n) { darope@0: META_ERROR("ini: Warning; no plugins found to load?"); darope@0: } darope@0: return(mTRUE); darope@0: } darope@0: darope@0: // Load a plugin from a console command. darope@0: // meta_errno values: darope@0: // - errno's from cmd_parseline() darope@0: // - errno's from resolve() darope@0: // - ME_ALREADY this plugin already loaded darope@0: // - errno's from add() darope@0: // - errno's from load() darope@0: mBOOL MPluginList::cmd_addload(const char *args) { darope@0: MPlugin pl_temp; darope@0: MPlugin *pl_found, *pl_added; darope@0: darope@0: // XXX move back to comands_meta ? darope@0: darope@0: // parse into a temp plugin darope@0: memset(&pl_temp, 0, sizeof(pl_temp)); darope@0: if(pl_temp.cmd_parseline(args) != mTRUE) { darope@0: META_CONS("Couldn't parse 'meta load' arguments: %s", args); darope@0: // meta_errno should be already set in cmd_parseline() darope@0: return(mFALSE); darope@0: } darope@0: darope@0: // resolve given path into a file; accepts various "shortcut" darope@0: // pathnames. darope@0: if(pl_temp.resolve() != mTRUE) { darope@0: // Couldn't find a matching file on disk darope@0: META_CONS("Couldn't resolve given path into a file: %s", darope@0: pl_temp.file); darope@0: // meta_errno should be already set in resolve() darope@0: return(mFALSE); darope@0: } darope@0: darope@0: // Try to find plugin with this pathname in the current list of darope@0: // plugins. darope@0: if((pl_found=find(pl_temp.pathname))) { darope@0: // Already in list darope@0: META_CONS("Plugin '%s' already in current list; file=%s desc='%s'", darope@0: pl_temp.file, pl_found->file, pl_found->desc); darope@0: RETURN_ERRNO(mFALSE, ME_ALREADY); darope@0: } darope@0: // new plugin; add to list darope@0: if(!(pl_added=add(&pl_temp))) { darope@0: META_CONS("Couldn't add plugin '%s' to list; see log", pl_temp.desc); darope@0: // meta_errno should be already set in add() darope@0: return(mFALSE); darope@0: } darope@0: darope@0: // try to load new plugin darope@0: pl_added->action=PA_LOAD; darope@0: if(!pl_added->load(PT_ANYTIME)) { darope@0: // load failed darope@0: if(meta_errno==ME_DELAYED) darope@0: META_CONS("Loaded plugin '%s', but will wait to become active, %s", darope@0: pl_added->desc, pl_added->str_loadable(SL_ALLOWED)); darope@0: else if(meta_errno==ME_NOTALLOWED) { darope@0: META_CONS("Plugin '%s' couldn't attach; only allowed %s", darope@0: pl_added->desc, pl_added->str_loadable(SL_ALLOWED)); darope@0: pl_added->clear(); darope@0: } darope@0: else if(pl_added->status == PL_OPENED) darope@0: META_CONS("Opened plugin '%s', but failed to attach; see log", pl_added->desc); darope@0: else darope@0: META_CONS("Couldn't load plugin '%s'; see log", pl_added->desc); darope@0: show(); darope@0: // meta_errno should be already set in load() darope@0: return(mFALSE); darope@0: } darope@0: META_CONS("Loaded plugin '%s' successfully", pl_added->desc); darope@0: show(); darope@0: return(mTRUE); darope@0: } darope@0: darope@0: // Load plugins at startup. darope@0: // meta_errno values: darope@0: // - errno's from ini_startup() darope@0: mBOOL MPluginList::load() { darope@0: int i, n; darope@0: darope@0: if (!ini_startup()) { darope@0: META_ERROR("Problem loading plugins.ini: %s", inifile); darope@0: // meta_errno should be already set in ini_startup() darope@0: return(mFALSE); darope@0: } darope@0: darope@0: META_LOG("dll: Loading plugins..."); darope@0: for(i=0, n=0; i < endlist; i++) { darope@0: if(plist[i].status < PL_VALID) darope@0: continue; darope@0: if(plist[i].load(PT_STARTUP) == mTRUE) darope@0: n++; darope@0: else darope@0: // all plugins should be loadable at startup... darope@0: META_ERROR("dll: Failed to load plugin '%s'", plist[i].file); darope@0: } darope@0: META_LOG("dll: Finished loading %d plugins", n); darope@0: return(mTRUE); darope@0: } darope@0: darope@0: // Update list of loaded plugins from ini file, and load any new/changed plugins. darope@0: // meta_errno values: darope@0: // - errno's from ini_refresh() darope@0: mBOOL MPluginList::refresh(PLUG_LOADTIME now) { darope@0: int i, ndone=0, nkept=0, nloaded=0, nunloaded=0, nreloaded=0, ndelayed=0; darope@0: MPlugin *iplug; darope@0: darope@0: if (!ini_refresh()) { darope@0: META_ERROR("dll: Problem reloading plugins.ini: %s", inifile); darope@0: // meta_errno should be already set in ini_refresh() darope@0: return(mFALSE); darope@0: } darope@0: darope@0: META_LOG("dll: Updating plugins..."); darope@0: for(i=0; i < endlist; i++) { darope@0: iplug=&plist[i]; darope@0: if(iplug->status < PL_VALID) darope@0: continue; darope@0: switch(iplug->action) { darope@0: case PA_KEEP: darope@0: META_DEBUG(1, ("Keeping plugin '%s'", iplug->desc)); darope@0: iplug->action=PA_NONE; darope@0: nkept++; darope@0: break; darope@0: case PA_LOAD: darope@0: META_DEBUG(1, ("Loading plugin '%s'", iplug->desc)); darope@0: if(iplug->load(now)) darope@0: nloaded++; darope@0: else if(meta_errno==ME_DELAYED) darope@0: ndelayed++; darope@0: break; darope@0: case PA_RELOAD: darope@0: META_DEBUG(1, ("Reloading plugin '%s'", iplug->desc)); darope@0: if(iplug->reload(now, PNL_FILE_NEWER)) darope@0: nreloaded++; darope@0: else if(meta_errno==ME_DELAYED) darope@0: ndelayed++; darope@0: break; darope@0: case PA_NONE: darope@0: // If previously loaded from ini, but apparently removed from new ini. darope@0: if(iplug->source==PS_INI && iplug->status >= PL_RUNNING) { darope@0: META_DEBUG(1, ("Unloading plugin '%s'", iplug->desc)); darope@0: iplug->action=PA_UNLOAD; darope@0: if(iplug->unload(now, PNL_INI_DELETED)) darope@0: nunloaded++; darope@0: else if(meta_errno==ME_DELAYED) darope@0: ndelayed++; darope@0: } darope@0: break; darope@0: case PA_ATTACH: darope@0: // Previously requested attach, but was delayed? darope@0: META_DEBUG(1, ("Retrying attach plugin '%s'", iplug->desc)); darope@0: if(iplug->retry(now, PNL_DELAYED)) darope@0: nloaded++; darope@0: else if(meta_errno==ME_DELAYED) darope@0: ndelayed++; darope@0: break; darope@0: case PA_UNLOAD: darope@0: // Previously requested unload, but was delayed? darope@0: META_DEBUG(1, ("Retrying unload plugin '%s'", iplug->desc)); darope@0: if(iplug->retry(now, PNL_DELAYED)) darope@0: nunloaded++; darope@0: else if(meta_errno==ME_DELAYED) darope@0: ndelayed++; darope@0: break; darope@0: case PA_NULL: darope@0: META_ERROR("dll: Unexpected action for plugin '%s': '%s'", iplug->desc, iplug->str_action()); darope@0: break; darope@0: default: darope@0: META_ERROR("dll: Unrecognized action for plugin '%s': '%s'", iplug->desc, iplug->str_action()); darope@0: break; darope@0: } darope@0: ndone++; darope@0: } darope@0: META_LOG("dll: Finished updating %d plugins; kept %d, loaded %d, unloaded %d, reloaded %d, delayed %d", darope@0: ndone, nkept, nloaded, nunloaded, nreloaded, ndelayed); darope@0: return(mTRUE); darope@0: } darope@0: darope@0: // Re-enable any plugins currently paused. darope@0: // meta_errno values: darope@0: // - none darope@0: void MPluginList::unpause_all(void) { darope@0: int i; darope@0: MPlugin *iplug; darope@0: for(i=0; i < endlist; i++) { darope@0: iplug=&plist[i]; darope@0: if(iplug->status==PL_PAUSED) darope@0: iplug->unpause(); darope@0: } darope@0: } darope@0: darope@0: // Retry any pending actions on plugins, for instance load/unload delayed darope@0: // until changelevel. darope@0: // meta_errno values: darope@0: // - none darope@0: void MPluginList::retry_all(PLUG_LOADTIME now) { darope@0: int i; darope@0: MPlugin *iplug; darope@0: for(i=0; i < endlist; i++) { darope@0: iplug=&plist[i]; darope@0: if(iplug->action != PA_NONE) darope@0: iplug->retry(now, PNL_DELAYED); darope@0: } darope@0: } darope@0: darope@0: // List plugins and information about them in a formatted table. darope@0: // meta_errno values: darope@0: // - none darope@0: void MPluginList::show() { darope@0: int i, n=0, r=0; darope@0: MPlugin *pl; darope@0: char desc[15+1], file[16+1], vers[7+1]; // plus 1 for term null darope@0: darope@0: META_CONS("Currently loaded plugins:"); darope@0: META_CONS(" %*s %-*s %-4s %-4s %-*s v%-*s %-3s %-5s %-5s", darope@0: WIDTH_MAX_PLUGINS, "", darope@0: sizeof(desc)-1, "description", darope@0: "stat", "pend", darope@0: sizeof(file)-1, "file", sizeof(vers)-1, "ers", darope@0: "src", "load ", "unlod"); darope@0: for(i=0; i < endlist; i++) { darope@0: pl=&plist[i]; darope@0: if(pl->status < PL_VALID) darope@0: continue; darope@0: STRNCPY(desc, pl->desc, sizeof(desc)); darope@0: STRNCPY(file, pl->file, sizeof(file)); darope@0: if(pl->info && pl->info->version) STRNCPY(vers, pl->info->version, sizeof(vers)); darope@0: else STRNCPY(vers, " -", sizeof(vers)); darope@0: META_CONS(" [%*d] %-*s %-4s %-4s %-*s v%-*s %-3s %-5s %-5s", darope@0: WIDTH_MAX_PLUGINS, pl->index, darope@0: sizeof(desc)-1, desc, darope@0: pl->str_status(ST_SHOW), pl->str_action(SA_SHOW), darope@0: sizeof(file)-1, file, sizeof(vers)-1, vers, darope@0: pl->str_source(SO_SHOW), darope@0: pl->str_loadable(SL_SHOW), pl->str_unloadable(SL_SHOW)); darope@0: if(pl->status == PL_RUNNING) darope@0: r++; darope@0: n++; darope@0: } darope@0: META_CONS("%d plugins, %d running", n, r); darope@0: } darope@0: darope@0: // List plugins and information to Player/client entity. Differs from the darope@0: // "meta list" console command in that: darope@0: // - Shows only "running" plugins, skipping any failed or paused plugins. darope@0: // - Limited info about each plugin, mostly the "public" info (name, author, darope@0: // etc). darope@0: // meta_errno values: darope@0: // - none darope@0: void MPluginList::show_client(edict_t *pEntity) { darope@0: int i, n=0; darope@0: MPlugin *pl; darope@0: META_CLIENT(pEntity, "Currently running plugins:"); darope@0: for(i=0; i < endlist; i++) { darope@0: pl=&plist[i]; darope@0: if(pl->status != PL_RUNNING) darope@0: continue; darope@0: n++; darope@0: META_CLIENT(pEntity, " [%3d] %s, v%s, %s, by %s, see %s", darope@0: n, darope@0: pl->info->name ? pl->info->name : "", darope@0: pl->info->version ? pl->info->version : "", darope@0: pl->info->date ? pl->info->date : "<../../..>", darope@0: pl->info->author ? pl->info->author : "", darope@0: pl->info->url ? pl->info->url : ""); darope@0: } darope@0: META_CLIENT(pEntity, "%d plugins", n); darope@0: }