sourcemm/concommands.cpp
changeset 205 08964c08d894
parent 194 86c91d09179f
child 207 5c09084ad251
     1.1 --- a/sourcemm/concommands.cpp	Fri May 19 13:57:04 2006 +0000
     1.2 +++ b/sourcemm/concommands.cpp	Thu May 25 04:49:47 2006 +0000
     1.3 @@ -371,6 +371,12 @@
     1.4  				const char *file = e->Cmd_Argv(2);
     1.5  				char full_path[255];
     1.6  
     1.7 +				const char *alias = g_PluginMngr.LookupAlias(file);
     1.8 +				if (alias)
     1.9 +				{
    1.10 +					file = alias;
    1.11 +				}
    1.12 +
    1.13  				if (file[0] == '/' || strcmp(&(file[1]), ":\\") == 0)
    1.14  				{
    1.15  					g_SmmAPI.PathFormat(full_path, sizeof(full_path)-1, "%s", file);
    1.16 @@ -410,12 +416,105 @@
    1.17  
    1.18  				return;
    1.19  			}
    1.20 +		} else if ( (strcmp(command, "alias") == 0) ||
    1.21 +					(strcmp(command, "aliases") == 0) ) {
    1.22 +			if (args >= 4)
    1.23 +			{
    1.24 +				const char *alias = e->Cmd_Argv(2);
    1.25 +				const char *value = e->Cmd_Argv(3);
    1.26 +
    1.27 +				g_PluginMngr.SetAlias(alias, value);
    1.28 +				if (value[0] == '\0')
    1.29 +				{
    1.30 +					CONMSG("Deleted alias: %s.\n", alias);
    1.31 +				} else {
    1.32 +					CONMSG("Set alias \"%s\" to: %s\n", alias, value);
    1.33 +				}
    1.34 +			} else if (args >= 3) {
    1.35 +				const char *alias = e->Cmd_Argv(2);
    1.36 +				const char *value = g_PluginMngr.LookupAlias(alias);
    1.37 +				if (value)
    1.38 +				{
    1.39 +					CONMSG("Alias \"%s\" is set to: %s\n", alias, value);
    1.40 +				} else {
    1.41 +					CONMSG("Alias \"%s\" was not found.\n", alias);
    1.42 +				}
    1.43 +			} else {
    1.44 +				SourceHook::List<SourceMM::CNameAlias *>::iterator iter, end;
    1.45 +				SourceMM::CNameAlias *p;
    1.46 +
    1.47 +				iter = g_PluginMngr._alias_begin();
    1.48 +				end = g_PluginMngr._alias_end();
    1.49 +				size_t total = 0;
    1.50 +				if (iter != end)
    1.51 +				{
    1.52 +					CONMSG("%-10.9s %s\n", "Alias", "File");
    1.53 +					CONMSG(" --- \n");
    1.54 +					for (; iter!=end; iter++)
    1.55 +					{
    1.56 +						p = (*iter);
    1.57 +						CONMSG("%-10.9s %s\n", p->alias.c_str(), p->value.c_str());
    1.58 +						total++;
    1.59 +					}
    1.60 +					CONMSG(" --- \n");
    1.61 +					CONMSG("%d aliases total.\n", total);
    1.62 +				} else {
    1.63 +					CONMSG("No aliases found.\n");
    1.64 +				}
    1.65 +			}
    1.66 +			return;
    1.67  		} else if (strcmp(command, "unload") == 0) {
    1.68  			if (args >= 3)
    1.69  			{
    1.70 -				int id = atoi(e->Cmd_Argv(2));
    1.71 +				const char *file = e->Cmd_Argv(2);
    1.72 +				int id = atoi(file);
    1.73  				char error[255]={0};
    1.74  
    1.75 +				if (id == 0 && isalpha(file[0]))
    1.76 +				{
    1.77 +					char full_path[255];
    1.78 +					const char *alias = g_PluginMngr.LookupAlias(file);
    1.79 +
    1.80 +					if (alias)
    1.81 +					{
    1.82 +						file = alias;
    1.83 +					}
    1.84 +
    1.85 +					/* first check if it's a known filename */
    1.86 +					if (file[0] == '/' || strcmp(&(file[1]), ":\\") == 0)
    1.87 +					{
    1.88 +						g_SmmAPI.PathFormat(full_path, sizeof(full_path)-1, "%s", file);
    1.89 +						snprintf(full_path, sizeof(full_path)-1, "%s", file);
    1.90 +					} else {
    1.91 +						const char *ext = UTIL_GetExtension(file);
    1.92 +#if defined WIN32 || defined _WIN32
    1.93 +						ext = ext ? "" : ".dll";
    1.94 +#else
    1.95 +						ext = ext ? "" : "_i486.so";
    1.96 +#endif
    1.97 +						g_SmmAPI.PathFormat(full_path, sizeof(full_path)-1, "%s/%s%s", g_ModPath.c_str(), file, ext);
    1.98 +					}
    1.99 +
   1.100 +					SourceHook::List<SourceMM::CPluginManager::CPlugin *>::iterator iter, end;
   1.101 +					SourceMM::CPluginManager::CPlugin *pl;
   1.102 +					iter = g_PluginMngr._begin();
   1.103 +					end = g_PluginMngr._end();
   1.104 +					for (; iter!=end; iter++)
   1.105 +					{
   1.106 +						pl = (*iter);
   1.107 +						if (strcmp(pl->m_File.c_str(), full_path) == 0)
   1.108 +						{
   1.109 +							id = pl->m_Id;
   1.110 +							break;
   1.111 +						}
   1.112 +					}
   1.113 +					if (id == 0)
   1.114 +					{
   1.115 +						CONMSG("Plugin \"%s\" not found.\n", full_path);
   1.116 +						return;
   1.117 +					}
   1.118 +				}
   1.119 +
   1.120  				if (!g_PluginMngr.Unload(id, false, error, sizeof(error)-1))
   1.121  				{
   1.122  					CONMSG("Unload failed: %s\n", error);
   1.123 @@ -423,13 +522,10 @@
   1.124  				}
   1.125  
   1.126  				CONMSG("Plugin %d unloaded.\n", id);
   1.127 -
   1.128 -				return;
   1.129  			} else {
   1.130  				CONMSG("Usage: meta unload <id>\n");
   1.131 -
   1.132 -				return;
   1.133  			}
   1.134 +			return;
   1.135  		} else if (strcmp(command, "force_unload") == 0) {
   1.136  			if (args >= 3)
   1.137  			{
   1.138 @@ -485,6 +581,7 @@
   1.139  
   1.140  	CONMSG("Metamod:Source Menu\n");
   1.141  	CONMSG("usage: meta <command> [arguments]\n");
   1.142 +	CONMSG("  alias        - list or set an alias\n");
   1.143  	CONMSG("  clear        - Unload all plugins forcefully\n");
   1.144  	CONMSG("  cmds         - Show plugin commands\n");
   1.145  	CONMSG("  cvars        - Show plugin cvars\n");