sourcemm/concommands.cpp
changeset 9 01b8b7435e67
parent 7 8ef11f6189e4
child 12 9fd53562f68c
     1.1 --- a/sourcemm/concommands.cpp	Sat Apr 16 20:26:33 2005 +0000
     1.2 +++ b/sourcemm/concommands.cpp	Sat Apr 16 23:33:39 2005 +0000
     1.3 @@ -1,5 +1,5 @@
     1.4  /* ======== SourceMM ========
     1.5 -* Copyright (C) 2004-2005 SourceMM Development Team
     1.6 +* Copyright (C) 2004-2005 Metamod:Source Development Team
     1.7  * No warranties of any kind
     1.8  *
     1.9  * License: zlib/libpng
    1.10 @@ -75,7 +75,7 @@
    1.11  			PluginIter i;
    1.12  			const char *status="";
    1.13  
    1.14 -			Msg("[Id] %-16.15s  %-8.7s  %-12.11s %-8.7s\n", "Name", "Version", "Author", "Status");
    1.15 +			Msg("-Id- %-16.15s  %-8.7s  %-12.11s %-8.7s\n", "Name", "Version", "Author", "Status");
    1.16  			for (i=g_PluginMngr._begin(); i!=g_PluginMngr._end(); i++)
    1.17  			{
    1.18  				pl = (*i);
    1.19 @@ -133,15 +133,181 @@
    1.20  
    1.21  				return;
    1.22  			}
    1.23 +		} else if (strcmp(command, "pause") == 0) {
    1.24 +			if (args >= 3)
    1.25 +			{
    1.26 +				int id = atoi(e->Cmd_Argv(2));
    1.27 +				SourceMM::CPluginManager::CPlugin *pl = g_PluginMngr.FindById(id);
    1.28 +				if (!pl)
    1.29 +				{
    1.30 +					Msg("Plugin %d not found.\n", id);
    1.31 +					return;
    1.32 +				}
    1.33 +				
    1.34 +				if (pl->m_Status != Pl_Running)
    1.35 +				{
    1.36 +					Msg("Plugin %d is not pausable.\n", pl->m_Id);
    1.37 +					return;
    1.38 +				}
    1.39 +
    1.40 +				char error[255]={0};
    1.41 +				if (!pl->m_API->Pause(error, sizeof(error)-1))
    1.42 +				{
    1.43 +					Msg("Plugin %d refused pause: %s\n", pl->m_Id, error);
    1.44 +					return;
    1.45 +				}
    1.46 +
    1.47 +				g_SourceHook.PausePlugin(pl->m_Id);
    1.48 +				Msg("\"%s\" has been paused.\n", pl->m_API->GetName());
    1.49 +
    1.50 +				return;
    1.51 +			} else {
    1.52 +				Msg("Usage: meta pause <id>\n");
    1.53 +
    1.54 +				return;
    1.55 +			}
    1.56 +		} else if (strcmp(command, "unpause") == 0) {
    1.57 +			if (args >= 3)
    1.58 +			{
    1.59 +				int id = atoi(e->Cmd_Argv(2));
    1.60 +				SourceMM::CPluginManager::CPlugin *pl = g_PluginMngr.FindById(id);
    1.61 +				if (!pl)
    1.62 +				{
    1.63 +					Msg("Plugin %d not found.\n", id);
    1.64 +					return;
    1.65 +				}
    1.66 +				
    1.67 +				if (pl->m_Status != Pl_Paused)
    1.68 +				{
    1.69 +					Msg("Plugin %d is not unpausable.\n", pl->m_Id);
    1.70 +					return;
    1.71 +				}
    1.72 +
    1.73 +				char error[255]={0};
    1.74 +				if (!pl->m_API->Pause(error, sizeof(error)-1))
    1.75 +				{
    1.76 +					Msg("Plugin %d refused unpause: %s\n", pl->m_Id, error);
    1.77 +					return;
    1.78 +				}
    1.79 +
    1.80 +				g_SourceHook.UnpausePlugin(pl->m_Id);
    1.81 +				Msg("\"%s\" has been unpaused.\n", pl->m_API->GetName());
    1.82 +
    1.83 +				return;
    1.84 +			} else {
    1.85 +				Msg("Usage: meta unpause <id>\n");
    1.86 +
    1.87 +				return;
    1.88 +			}
    1.89 +		} else if (strcmp(command, "load") == 0) {
    1.90 +			if (args >= 3)
    1.91 +			{
    1.92 +				const char *file = e->Cmd_Argv(2);
    1.93 +				char full_path[255];
    1.94 +
    1.95 +				if (file[0] == '/' || strcmp(&(file[1]), ":\\") == 0)
    1.96 +				{
    1.97 +					snprintf(full_path, sizeof(full_path)-1, "%s", file);
    1.98 +				} else {
    1.99 +					const char *ext = UTIL_GetExtension(file);
   1.100 +#if defined WIN32 || defined _WIN32
   1.101 +					ext ? "" : ".dll";
   1.102 +					snprintf(full_path, sizeof(full_path)-1, "%s\\%s%s", g_ModPath.c_str(), file, ext);
   1.103 +#else
   1.104 +					ext ? "" : "_i486.so";
   1.105 +					snprintf(full_path, sizeof(full_path)-1, "%s/%s%s", g_ModPath.c_str(), file, ext);
   1.106 +#endif
   1.107 +				}
   1.108 +
   1.109 +				char error[255]={0};
   1.110 +				bool already;
   1.111 +				SourceMM::CPluginManager::CPlugin *pl;
   1.112 +
   1.113 +				PluginId id = g_PluginMngr.Load(full_path, Pl_Console, already, error, sizeof(error)-1);
   1.114 +				pl = g_PluginMngr.FindById(id);
   1.115 +				if (!pl || id < Pl_MinId || (pl->m_Status < Pl_Paused))
   1.116 +				{
   1.117 +					Msg("Failed to load plugin %s.  %s\n", file, error);
   1.118 +					return;
   1.119 +				}
   1.120 +
   1.121 +				if (!already)
   1.122 +				{
   1.123 +					Msg("Plugin \"%s\" loaded with id %d.\n", pl->m_API->GetName(), pl->m_Id);
   1.124 +				} else {
   1.125 +					Msg("Plugin \"%s\" is already loaded as %d.\n", pl->m_API->GetName(), pl->m_Id);
   1.126 +				}
   1.127 +				
   1.128 +				return;
   1.129 +			} else {
   1.130 +				Msg("Usage: meta load <path>\n");
   1.131 +
   1.132 +				return;
   1.133 +			}
   1.134 +		} else if (strcmp(command, "unload") == 0) {
   1.135 +			if (args >= 3)
   1.136 +			{
   1.137 +				int id = atoi(e->Cmd_Argv(2));
   1.138 +				char error[255]={0};
   1.139 +
   1.140 +				if (!g_PluginMngr.Unload(id, false, error, sizeof(error)-1))
   1.141 +				{
   1.142 +					Msg("Unload failed: %s\n", error);
   1.143 +					return;
   1.144 +				}
   1.145 +
   1.146 +				Msg("Plugin %d unloaded.\n", id);
   1.147 +
   1.148 +				return;
   1.149 +			} else {
   1.150 +				Msg("Usage: meta unload <id>\n");
   1.151 +
   1.152 +				return;
   1.153 +			}
   1.154 +		} else if (strcmp(command, "force_unload") == 0) {
   1.155 +			if (args >= 3)
   1.156 +			{
   1.157 +				int id = atoi(e->Cmd_Argv(2));
   1.158 +				char error[255]={0};
   1.159 +
   1.160 +				if (!g_PluginMngr.Unload(id, false, error, sizeof(error)-1))
   1.161 +				{
   1.162 +					Msg("Force unload failed: %s\n", error);
   1.163 +					return;
   1.164 +				}
   1.165 +
   1.166 +				Msg("Plugin %d force unloaded.\n", id);
   1.167 +
   1.168 +				return;
   1.169 +			} else {
   1.170 +				Msg("Usage: meta force_unload <id>\n");
   1.171 +
   1.172 +				return;
   1.173 +			}
   1.174 +		} else if (strcmp(command, "clear") == 0) {
   1.175 +			if (!g_PluginMngr.UnloadAll())
   1.176 +			{
   1.177 +				Msg("One or more plugins resisted removal (cleaned anyway).\n");
   1.178 +				return;
   1.179 +			} 
   1.180 +
   1.181 +			Msg("All plugins unloaded.\n");
   1.182 +
   1.183 +			return;
   1.184  		}
   1.185  	}
   1.186  
   1.187  	Msg("Metamod:Source Menu\n");
   1.188  	Msg("usage: meta <command> [arguments]\n");
   1.189 +	Msg("   clear     - Unload all plugins forcefully\n");
   1.190  	Msg("   credits   - About Metamod:Source\n");
   1.191  	Msg("   game      - Information about GameDLL\n");
   1.192  	Msg("   info      - Information about a plugin\n");
   1.193  	Msg("   list      - List plugins\n");
   1.194 +	Msg("   load      - Load a plugin\n");
   1.195 +	Msg("   pause     - Pause a running plugin\n");
   1.196  	Msg("   refresh   - Reparse plugins file\n");
   1.197 +	Msg("   unload    - Unload a loaded plugin\n");
   1.198 +	Msg("   unpause   - Unpause a paused plugin\n");
   1.199  	Msg("   version   - Version information\n");
   1.200  }