core/ConCmdManager.cpp
author Scott Ehlert <ds@alliedmods.net>
Sun Sep 14 02:58:58 2008 -0500 (2008-09-14)
changeset 2287 017a725c9d17
parent 2245 d8518466c06c
child 2289 44045ead61cd
permissions -rw-r--r--
Eliminated head for dead branch: sourcemod-1.1.0
ds@1952
     1
/**
ds@1952
     2
 * vim: set ts=4 :
ds@1952
     3
 * =============================================================================
ds@1952
     4
 * SourceMod
ds@1952
     5
 * Copyright (C) 2004-2008 AlliedModders LLC.  All rights reserved.
ds@1952
     6
 * =============================================================================
ds@1952
     7
 *
ds@1952
     8
 * This program is free software; you can redistribute it and/or modify it under
ds@1952
     9
 * the terms of the GNU General Public License, version 3.0, as published by the
ds@1952
    10
 * Free Software Foundation.
ds@1952
    11
 * 
ds@1952
    12
 * This program is distributed in the hope that it will be useful, but WITHOUT
ds@1952
    13
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
ds@1952
    14
 * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
ds@1952
    15
 * details.
ds@1952
    16
 *
ds@1952
    17
 * You should have received a copy of the GNU General Public License along with
ds@1952
    18
 * this program.  If not, see <http://www.gnu.org/licenses/>.
ds@1952
    19
 *
ds@1952
    20
 * As a special exception, AlliedModders LLC gives you permission to link the
ds@1952
    21
 * code of this program (as well as its derivative works) to "Half-Life 2," the
ds@1952
    22
 * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
ds@1952
    23
 * by the Valve Corporation.  You must obey the GNU General Public License in
ds@1952
    24
 * all respects for all other code used.  Additionally, AlliedModders LLC grants
ds@1952
    25
 * this exception to all derivative works.  AlliedModders LLC defines further
ds@1952
    26
 * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
ds@1952
    27
 * or <http://www.sourcemod.net/license.php>.
ds@1952
    28
 *
ds@1952
    29
 * Version: $Id$
ds@1952
    30
 */
ds@1952
    31
ds@1952
    32
#include "ConCmdManager.h"
ds@1952
    33
#include "sm_srvcmds.h"
ds@1952
    34
#include "AdminCache.h"
ds@1952
    35
#include "sm_stringutil.h"
ds@1952
    36
#include "PlayerManager.h"
ds@1952
    37
#include "Translator.h"
ds@1952
    38
#include "HalfLife2.h"
ds@1952
    39
#include "ChatTriggers.h"
ds@1952
    40
ds@1952
    41
ConCmdManager g_ConCmds;
ds@1952
    42
ds@1952
    43
#if defined ORANGEBOX_BUILD
ds@1952
    44
	SH_DECL_HOOK1_void(ConCommand, Dispatch, SH_NOATTRIB, false, const CCommand &);
ds@1952
    45
#else
ds@1952
    46
	SH_DECL_HOOK0_void(ConCommand, Dispatch, SH_NOATTRIB, false);
ds@1952
    47
#endif
ds@1952
    48
ds@1952
    49
SH_DECL_HOOK1_void(IServerGameClients, SetCommandClient, SH_NOATTRIB, false, int);
ds@1952
    50
ds@1952
    51
struct PlCmdInfo
ds@1952
    52
{
ds@1952
    53
	ConCmdInfo *pInfo;
ds@1952
    54
	CmdHook *pHook;
ds@1952
    55
	CmdType type;
ds@1952
    56
};
ds@1952
    57
typedef List<PlCmdInfo> CmdList;
ds@1952
    58
ds@1952
    59
void AddToPlCmdList(CmdList *pList, const PlCmdInfo &info);
ds@1952
    60
ds@1952
    61
ConCmdManager::ConCmdManager() : m_Strings(1024)
ds@1952
    62
{
ds@1952
    63
	m_pCmds = sm_trie_create();
ds@1952
    64
	m_pCmdGrps = sm_trie_create();
ds@1952
    65
	m_CmdClient = 0;
ds@1952
    66
}
ds@1952
    67
ds@1952
    68
ConCmdManager::~ConCmdManager()
ds@1952
    69
{
ds@1952
    70
	sm_trie_destroy(m_pCmds);
ds@1952
    71
	sm_trie_destroy(m_pCmdGrps);
ds@1952
    72
}
ds@1952
    73
ds@1952
    74
void ConCmdManager::OnSourceModAllInitialized()
ds@1952
    75
{
ds@1952
    76
	g_PluginSys.AddPluginsListener(this);
ds@1952
    77
	g_RootMenu.AddRootConsoleCommand("cmds", "List console commands", this);
ds@1952
    78
	SH_ADD_HOOK_MEMFUNC(IServerGameClients, SetCommandClient, serverClients, this, &ConCmdManager::SetCommandClient, false);
ds@1952
    79
}
ds@1952
    80
ds@1952
    81
void ConCmdManager::OnSourceModShutdown()
ds@1952
    82
{
ds@1952
    83
	/* All commands should already be removed by the time we're done */
ds@1952
    84
	SH_REMOVE_HOOK_MEMFUNC(IServerGameClients, SetCommandClient, serverClients, this, &ConCmdManager::SetCommandClient, false);
ds@1952
    85
	g_RootMenu.RemoveRootConsoleCommand("cmds", this);
ds@1952
    86
}
ds@1952
    87
ds@1952
    88
void ConCmdManager::OnUnlinkConCommandBase(ConCommandBase *pBase, const char *name, bool is_read_safe)
ds@1952
    89
{
ds@1952
    90
	/* Whoa, first get its information struct */
ds@1952
    91
	ConCmdInfo *pInfo;
ds@1952
    92
ds@1952
    93
	if (!sm_trie_retrieve(m_pCmds, name, (void **)&pInfo))
ds@1952
    94
	{
ds@1952
    95
		return;
ds@1952
    96
	}
ds@1952
    97
ds@1952
    98
	RemoveConCmds(pInfo->srvhooks);
ds@1952
    99
	RemoveConCmds(pInfo->conhooks);
ds@1952
   100
ds@1952
   101
	RemoveConCmd(pInfo, name, is_read_safe, false);
ds@1952
   102
}
ds@1952
   103
ds@1952
   104
void ConCmdManager::RemoveConCmds(List<CmdHook *> &cmdlist)
ds@1952
   105
{
ds@1952
   106
	List<CmdHook *>::iterator iter = cmdlist.begin();
ds@1952
   107
ds@1952
   108
	while (iter != cmdlist.end())
ds@1952
   109
	{
ds@1952
   110
		CmdHook *pHook = (*iter);
ds@1952
   111
		IPluginContext *pContext = pHook->pf->GetParentContext();
ds@1952
   112
		IPlugin *pPlugin = g_PluginSys.GetPluginByCtx(pContext->GetContext());
ds@1952
   113
		CmdList *pList = NULL;
ds@1952
   114
		
ds@1952
   115
		//gaben
ds@1952
   116
		if (!pPlugin->GetProperty("CommandList", (void **)&pList, false) || !pList)
ds@1952
   117
		{
ds@1952
   118
			continue;
ds@1952
   119
		}
ds@1952
   120
ds@1952
   121
		CmdList::iterator p_iter = pList->begin();
ds@1952
   122
		while (p_iter != pList->end())
ds@1952
   123
		{
ds@1952
   124
			PlCmdInfo &cmd = (*p_iter);
ds@1952
   125
			if (cmd.pHook == pHook)
ds@1952
   126
			{
ds@1952
   127
				p_iter = pList->erase(p_iter);
ds@1952
   128
			}
ds@1952
   129
			else
ds@1952
   130
			{
ds@1952
   131
				p_iter++;
ds@1952
   132
			}
ds@1952
   133
		}
ds@1952
   134
ds@1952
   135
		delete pHook->pAdmin;
ds@1952
   136
		delete pHook;
ds@1952
   137
		
ds@1952
   138
		iter = cmdlist.erase(iter);
ds@1952
   139
	}
ds@1952
   140
}
ds@1952
   141
ds@1952
   142
void ConCmdManager::RemoveConCmds(List<CmdHook *> &cmdlist, IPluginContext *pContext)
ds@1952
   143
{
ds@1952
   144
	List<CmdHook *>::iterator iter = cmdlist.begin();
ds@1952
   145
	CmdHook *pHook;
ds@1952
   146
ds@1952
   147
	while (iter != cmdlist.end())
ds@1952
   148
	{
ds@1952
   149
		pHook = (*iter);
ds@1952
   150
		if (pHook->pf->GetParentContext() == pContext)
ds@1952
   151
		{
ds@1952
   152
			delete pHook->pAdmin;
ds@1952
   153
			delete pHook;
ds@1952
   154
			iter = cmdlist.erase(iter);
ds@1952
   155
		}
ds@1952
   156
		else
ds@1952
   157
		{
ds@1952
   158
			iter++;
ds@1952
   159
		}
ds@1952
   160
	}
ds@1952
   161
}
ds@1952
   162
ds@1952
   163
void ConCmdManager::OnPluginDestroyed(IPlugin *plugin)
ds@1952
   164
{
ds@1952
   165
	CmdList *pList;
ds@1952
   166
	List<ConCmdInfo *> removed;
ds@1952
   167
	if (plugin->GetProperty("CommandList", (void **)&pList, true))
ds@1952
   168
	{
ds@1952
   169
		IPluginContext *pContext = plugin->GetBaseContext();
ds@1952
   170
		CmdList::iterator iter;
ds@1952
   171
		/* First pass!
ds@1952
   172
	 	 * Only bother if there's an actual command list on this plugin... 
ds@1952
   173
	 	 */
ds@1952
   174
		for (iter=pList->begin();
ds@1952
   175
			iter!=pList->end();
ds@1952
   176
			iter++)
ds@1952
   177
		{
ds@1952
   178
			PlCmdInfo &cmd = (*iter);
ds@1952
   179
			ConCmdInfo *pInfo = cmd.pInfo;
ds@1952
   180
ds@1952
   181
			/* Has this chain already been fully cleaned/removed? */
ds@1952
   182
			if (removed.find(pInfo) != removed.end())
ds@1952
   183
			{
ds@1952
   184
				continue;
ds@1952
   185
			}
ds@1952
   186
ds@1952
   187
			/* Remove any hooks from us on this command */
ds@1952
   188
			RemoveConCmds(pInfo->conhooks, pContext);
ds@1952
   189
			RemoveConCmds(pInfo->srvhooks, pContext);
ds@1952
   190
ds@1952
   191
			/* See if there are still hooks */
ds@1952
   192
			if (pInfo->srvhooks.size())
ds@1952
   193
			{
ds@1952
   194
				continue;
ds@1952
   195
			}
ds@1952
   196
			if (pInfo->conhooks.size())
ds@1952
   197
			{
ds@1952
   198
				continue;
ds@1952
   199
			}
ds@1952
   200
ds@1952
   201
			/* Remove the command, it should be safe now */
ds@1952
   202
			RemoveConCmd(pInfo, pInfo->pCmd->GetName(), true, true);
ds@1952
   203
			removed.push_back(pInfo);
ds@1952
   204
		}
ds@1952
   205
		delete pList;
ds@1952
   206
	}
ds@1952
   207
}
ds@1952
   208
#if defined ORANGEBOX_BUILD
ds@1952
   209
void CommandCallback(const CCommand &command)
ds@1952
   210
{
ds@1952
   211
#else
ds@1952
   212
void CommandCallback()
ds@1952
   213
{
ds@1952
   214
	CCommand command;
ds@1952
   215
#endif
ds@1952
   216
ds@1952
   217
	g_HL2.PushCommandStack(&command);
ds@1952
   218
ds@1952
   219
	g_ConCmds.InternalDispatch(command);
ds@1952
   220
ds@1952
   221
	g_HL2.PopCommandStack();
ds@1952
   222
}
ds@1952
   223
ds@1952
   224
void ConCmdManager::SetCommandClient(int client)
ds@1952
   225
{
ds@1952
   226
	m_CmdClient = client + 1;
ds@1952
   227
}
ds@1952
   228
ds@1952
   229
ResultType ConCmdManager::DispatchClientCommand(int client, const char *cmd, int args, ResultType type)
ds@1952
   230
{
ds@1952
   231
	ConCmdInfo *pInfo;
ds@1952
   232
	if (sm_trie_retrieve(m_pCmds, cmd, (void **)&pInfo))
ds@1952
   233
	{
ds@1952
   234
		cell_t result = type;
ds@1952
   235
		cell_t tempres = result;
ds@1952
   236
		List<CmdHook *>::iterator iter;
ds@1952
   237
		CmdHook *pHook;
ds@1952
   238
		for (iter=pInfo->conhooks.begin();
ds@1952
   239
			 iter!=pInfo->conhooks.end();
ds@1952
   240
			 iter++)
ds@1952
   241
		{
ds@1952
   242
			pHook = (*iter);
ds@1952
   243
			if (!pHook->pf->IsRunnable())
ds@1952
   244
			{
ds@1952
   245
				continue;
ds@1952
   246
			}
ds@1952
   247
			if (pHook->pAdmin && !CheckAccess(client, cmd, pHook->pAdmin))
ds@1952
   248
			{
ds@1952
   249
				if (result < Pl_Handled)
ds@1952
   250
				{
ds@1952
   251
					result = Pl_Handled;
ds@1952
   252
				}
ds@1952
   253
				continue;
ds@1952
   254
			}
ds@1952
   255
			pHook->pf->PushCell(client);
ds@1952
   256
			pHook->pf->PushCell(args);
ds@1952
   257
			if (pHook->pf->Execute(&tempres) == SP_ERROR_NONE)
ds@1952
   258
			{
ds@1952
   259
				if (tempres > result)
ds@1952
   260
				{
ds@1952
   261
					result = tempres;
ds@1952
   262
				}
ds@1952
   263
				if (result == Pl_Stop)
ds@1952
   264
				{
ds@1952
   265
					break;
ds@1952
   266
				}
ds@1952
   267
			}
ds@1952
   268
		}
ds@1952
   269
		type = (ResultType)result;
ds@1952
   270
	}
ds@1952
   271
ds@1952
   272
	return type;
ds@1952
   273
}
ds@1952
   274
ds@1952
   275
void ConCmdManager::InternalDispatch(const CCommand &command)
ds@1952
   276
{
ds@1952
   277
	int client = m_CmdClient;
ds@1952
   278
ds@1952
   279
	if (client)
ds@1952
   280
	{
ds@1952
   281
		CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
ds@1952
   282
		if (!pPlayer || !pPlayer->IsConnected())
ds@1952
   283
		{
ds@1952
   284
			return;
ds@1952
   285
		}
ds@1952
   286
	}
ds@1952
   287
ds@1952
   288
	/**
ds@1952
   289
	 * Note: Console commands will EITHER go through IServerGameDLL::ClientCommand,
ds@1952
   290
	 * OR this dispatch.  They will NEVER go through both.
ds@1952
   291
	 * -- 
ds@1952
   292
	 * Whether or not it goes through the callback is determined by FCVAR_GAMEDLL
ds@1952
   293
	 */
ds@1952
   294
	const char *cmd = g_HL2.CurrentCommandName();
ds@1952
   295
ds@1952
   296
	ConCmdInfo *pInfo;
ds@1952
   297
	if (!sm_trie_retrieve(m_pCmds, cmd, (void **)&pInfo))
ds@1952
   298
	{
dvander@2245
   299
        /* Unfortunately, we now have to do a slow lookup because Valve made client commands 
dvander@2245
   300
         * case-insensitive.  We can't even use our sortedness.
dvander@2245
   301
         */
dvander@2245
   302
        if (client == 0 && !engine->IsDedicatedServer())
dvander@2245
   303
        {
dvander@2245
   304
            return;
dvander@2245
   305
        }
dvander@2245
   306
dvander@2245
   307
        List<ConCmdInfo *>::iterator iter;
dvander@2245
   308
dvander@2245
   309
        pInfo = NULL;
dvander@2245
   310
        iter = m_CmdList.begin();
dvander@2245
   311
        while (iter != m_CmdList.end())
dvander@2245
   312
        {
dvander@2245
   313
            if (strcasecmp((*iter)->pCmd->GetName(), cmd) == 0)
dvander@2245
   314
            {
dvander@2245
   315
                pInfo = (*iter);
dvander@2245
   316
                break;
dvander@2245
   317
            }
dvander@2245
   318
            iter++;
dvander@2245
   319
        }
dvander@2245
   320
        
dvander@2245
   321
		if (pInfo == NULL)
dvander@2245
   322
        {
dvander@2245
   323
            return;
dvander@2245
   324
        }
ds@1952
   325
	}
ds@1952
   326
ds@1952
   327
	/* This is a hack to prevent say triggers from firing on messages that were 
ds@1952
   328
	 * blocked because of flooding.  We won't remove this, but the hack will get 
ds@1952
   329
	 * "nicer" when we expose explicit say hooks.
ds@1952
   330
	 */
ds@1952
   331
	if (g_ChatTriggers.WasFloodedMessage())
ds@1952
   332
	{
ds@1952
   333
		return;
ds@1952
   334
	}
ds@1952
   335
ds@1952
   336
	cell_t result = Pl_Continue;
ds@1952
   337
	int args = command.ArgC() - 1;
ds@1952
   338
ds@1952
   339
	List<CmdHook *>::iterator iter;
ds@1952
   340
	CmdHook *pHook;
ds@1952
   341
ds@1952
   342
	/* Execute server-only commands if viable */
ds@1952
   343
	if (client == 0 && pInfo->srvhooks.size())
ds@1952
   344
	{
ds@1952
   345
		cell_t tempres = result;
ds@1952
   346
		for (iter=pInfo->srvhooks.begin();
ds@1952
   347
			 iter!=pInfo->srvhooks.end();
ds@1952
   348
			 iter++)
ds@1952
   349
		{
ds@1952
   350
			pHook = (*iter);
ds@1952
   351
			if (!pHook->pf->IsRunnable())
ds@1952
   352
			{
ds@1952
   353
				continue;
ds@1952
   354
			}
ds@1952
   355
			pHook->pf->PushCell(args);
ds@1952
   356
			if (pHook->pf->Execute(&tempres) == SP_ERROR_NONE)
ds@1952
   357
			{
ds@1952
   358
				if (tempres > result)
ds@1952
   359
				{
ds@1952
   360
					result = tempres;
ds@1952
   361
				}
ds@1952
   362
				if (result == Pl_Stop)
ds@1952
   363
				{
ds@1952
   364
					break;
ds@1952
   365
				}
ds@1952
   366
			}
ds@1952
   367
		}
ds@1952
   368
	
ds@1952
   369
		/* Check if there's an early stop */
ds@1952
   370
		if (result >= Pl_Stop)
ds@1952
   371
		{
ds@1952
   372
			if (!pInfo->sourceMod)
ds@1952
   373
			{
ds@1952
   374
				RETURN_META(MRES_SUPERCEDE);
ds@1952
   375
			}
ds@1952
   376
			return;
ds@1952
   377
		}
ds@1952
   378
	}
ds@1952
   379
ds@1952
   380
	/* Execute console commands */
ds@1952
   381
	if (pInfo->conhooks.size())
ds@1952
   382
	{
ds@1952
   383
		cell_t tempres = result;
ds@1952
   384
		for (iter=pInfo->conhooks.begin();
ds@1952
   385
			iter!=pInfo->conhooks.end();
ds@1952
   386
			iter++)
ds@1952
   387
		{
ds@1952
   388
			pHook = (*iter);
ds@1952
   389
			if (!pHook->pf->IsRunnable())
ds@1952
   390
			{
ds@1952
   391
				continue;
ds@1952
   392
			}
ds@1952
   393
			if (client 
ds@1952
   394
				&& pHook->pAdmin
ds@1952
   395
				&& !CheckAccess(client, cmd, pHook->pAdmin))
ds@1952
   396
			{
ds@1952
   397
				if (result < Pl_Handled)
ds@1952
   398
				{
ds@1952
   399
					result = Pl_Handled;
ds@1952
   400
				}
ds@1952
   401
				continue;
ds@1952
   402
			}
ds@1952
   403
ds@1952
   404
			/* On a listen server, sometimes the server host's client index can be set as 0.
ds@1952
   405
			 * So index 1 is passed to the command callback to correct this potential problem.
ds@1952
   406
			 */
dvander@1996
   407
			if (!engine->IsDedicatedServer())
ds@1952
   408
			{
dvander@1996
   409
				client = g_Players.ListenClient();
ds@1952
   410
			}
ds@1952
   411
dvander@1996
   412
			pHook->pf->PushCell(client);
ds@1952
   413
			pHook->pf->PushCell(args);
dvander@1996
   414
ds@1952
   415
			if (pHook->pf->Execute(&tempres) == SP_ERROR_NONE)
ds@1952
   416
			{
ds@1952
   417
				if (tempres > result)
ds@1952
   418
				{
ds@1952
   419
					result = tempres;
ds@1952
   420
				}
ds@1952
   421
				if (result == Pl_Stop)
ds@1952
   422
				{
ds@1952
   423
					break;
ds@1952
   424
				}
ds@1952
   425
			}
ds@1952
   426
		}
ds@1952
   427
	}
ds@1952
   428
ds@1952
   429
	if (result >= Pl_Handled)
ds@1952
   430
	{
ds@1952
   431
		if (!pInfo->sourceMod)
ds@1952
   432
		{
ds@1952
   433
			RETURN_META(MRES_SUPERCEDE);
ds@1952
   434
		}
ds@1952
   435
		return;
ds@1952
   436
	}
ds@1952
   437
}
ds@1952
   438
ds@1952
   439
bool ConCmdManager::CheckCommandAccess(int client, const char *cmd, FlagBits cmdflags)
ds@1952
   440
{
ds@1952
   441
	if (cmdflags == 0 || client == 0)
ds@1952
   442
	{
ds@1952
   443
		return true;
ds@1952
   444
	}
ds@1952
   445
ds@1952
   446
	/* If running listen server, then client 1 is the server host and should have 'root' access */
ds@1952
   447
	if (client == 1 && !engine->IsDedicatedServer())
ds@1952
   448
	{
ds@1952
   449
		return true;
ds@1952
   450
	}
ds@1952
   451
ds@1952
   452
	CPlayer *player = g_Players.GetPlayerByIndex(client);
ds@1952
   453
	if (!player 
ds@1952
   454
		|| player->GetEdict() == NULL
ds@1952
   455
		|| player->IsFakeClient())
ds@1952
   456
	{
ds@1952
   457
		return false;
ds@1952
   458
	}
ds@1952
   459
ds@1952
   460
	AdminId adm = player->GetAdminId();
ds@1952
   461
	if (adm != INVALID_ADMIN_ID)
ds@1952
   462
	{
ds@1952
   463
		FlagBits bits = g_Admins.GetAdminFlags(adm, Access_Effective);
ds@1952
   464
ds@1952
   465
		/* root knows all, WHOA */
ds@1952
   466
		if ((bits & ADMFLAG_ROOT) == ADMFLAG_ROOT)
ds@1952
   467
		{
ds@1952
   468
			return true;
ds@1952
   469
		}
ds@1952
   470
ds@1952
   471
		/* Check for overrides
ds@1952
   472
		 * :TODO: is it worth optimizing this?
ds@1952
   473
		 */
ds@1952
   474
		unsigned int groups = g_Admins.GetAdminGroupCount(adm);
ds@1952
   475
		GroupId gid;
ds@1952
   476
		OverrideRule rule;
ds@1952
   477
		bool override = false;
ds@1952
   478
		for (unsigned int i=0; i<groups; i++)
ds@1952
   479
		{
ds@1952
   480
			gid = g_Admins.GetAdminGroup(adm, i, NULL);
ds@1952
   481
			/* First get group-level override */
ds@1952
   482
			override = g_Admins.GetGroupCommandOverride(gid, cmd, Override_CommandGroup, &rule);
ds@1952
   483
			/* Now get the specific command override */
ds@1952
   484
			if (g_Admins.GetGroupCommandOverride(gid, cmd, Override_Command, &rule))
ds@1952
   485
			{
ds@1952
   486
				override = true;
ds@1952
   487
			}
ds@1952
   488
			if (override)
ds@1952
   489
			{
ds@1952
   490
				if (rule == Command_Allow)
ds@1952
   491
				{
ds@1952
   492
					return true;
ds@1952
   493
				}
ds@1952
   494
				else if (rule == Command_Deny)
ds@1952
   495
				{
ds@1952
   496
					return false;
ds@1952
   497
				}
ds@1952
   498
			}
ds@1952
   499
		}
ds@1952
   500
ds@1952
   501
		/* See if our other flags match */
ds@1952
   502
		if ((bits & cmdflags) == cmdflags)
ds@1952
   503
		{
ds@1952
   504
			return true;
ds@1952
   505
		}
ds@1952
   506
	}
ds@1952
   507
ds@1952
   508
	return false;
ds@1952
   509
}
ds@1952
   510
ds@1952
   511
bool ConCmdManager::CheckAccess(int client, const char *cmd, AdminCmdInfo *pAdmin)
ds@1952
   512
{
ds@1952
   513
	if (CheckCommandAccess(client, cmd, pAdmin->eflags))
ds@1952
   514
	{
ds@1952
   515
		return true;
ds@1952
   516
	}
ds@1952
   517
ds@1952
   518
	edict_t *pEdict = engine->PEntityOfEntIndex(client);
ds@1952
   519
	
ds@1952
   520
	/* If we got here, the command failed... */
ds@1952
   521
	char buffer[128];
dvander@2055
   522
	if (!CoreTranslate(buffer, sizeof(buffer), "%T", 2, NULL, "No Access", &client))
ds@1952
   523
	{
ds@1952
   524
		UTIL_Format(buffer, sizeof(buffer), "You do not have access to this command");
ds@1952
   525
	}
ds@1952
   526
ds@1952
   527
	unsigned int replyto = g_ChatTriggers.GetReplyTo();
ds@1952
   528
	if (replyto == SM_REPLY_CONSOLE)
ds@1952
   529
	{
ds@1952
   530
		char fullbuffer[192];
ds@1952
   531
		UTIL_Format(fullbuffer, sizeof(fullbuffer), "[SM] %s.\n", buffer);
ds@1952
   532
		engine->ClientPrintf(pEdict, fullbuffer);
ds@1952
   533
	}
ds@1952
   534
	else if (replyto == SM_REPLY_CHAT)
ds@1952
   535
	{
ds@1952
   536
		char fullbuffer[192];
ds@1952
   537
		UTIL_Format(fullbuffer, sizeof(fullbuffer), "[SM] %s.", buffer);
ds@1952
   538
		g_HL2.TextMsg(client, HUD_PRINTTALK, fullbuffer);
ds@1952
   539
	}
ds@1952
   540
	
ds@1952
   541
	return false;
ds@1952
   542
}
ds@1952
   543
ds@1952
   544
bool ConCmdManager::AddConsoleCommand(IPluginFunction *pFunction, 
ds@1952
   545
									   const char *name, 
ds@1952
   546
									   const char *description, 
ds@1952
   547
									   int flags)
ds@1952
   548
{
ds@1952
   549
	ConCmdInfo *pInfo = AddOrFindCommand(name, description, flags);
ds@1952
   550
ds@1952
   551
	if (!pInfo)
ds@1952
   552
	{
ds@1952
   553
		return false;
ds@1952
   554
	}
ds@1952
   555
ds@1952
   556
	CmdHook *pHook = new CmdHook();
ds@1952
   557
ds@1952
   558
	pHook->pf = pFunction;
ds@1952
   559
	if (description && description[0])
ds@1952
   560
	{
ds@1952
   561
		pHook->helptext.assign(description);
ds@1952
   562
	}
ds@1952
   563
	pInfo->conhooks.push_back(pHook);
ds@1952
   564
ds@1952
   565
	/* Add to the plugin */
ds@1952
   566
	CmdList *pList;
ds@1952
   567
	IPlugin *pPlugin = g_PluginSys.GetPluginByCtx(pFunction->GetParentContext()->GetContext());
ds@1952
   568
	if (!pPlugin->GetProperty("CommandList", (void **)&pList))
ds@1952
   569
	{
ds@1952
   570
		pList = new CmdList();
ds@1952
   571
		pPlugin->SetProperty("CommandList", pList);
ds@1952
   572
	}
ds@1952
   573
	PlCmdInfo info;
ds@1952
   574
	info.pInfo = pInfo;
ds@1952
   575
	info.type = Cmd_Console;
ds@1952
   576
	info.pHook = pHook;
ds@1952
   577
	AddToPlCmdList(pList, info);
ds@1952
   578
ds@1952
   579
	return true;
ds@1952
   580
}
ds@1952
   581
ds@1952
   582
bool ConCmdManager::AddAdminCommand(IPluginFunction *pFunction, 
ds@1952
   583
									 const char *name, 
ds@1952
   584
									 const char *group,
ds@1952
   585
									 int adminflags,
ds@1952
   586
									 const char *description, 
ds@1952
   587
									 int flags)
ds@1952
   588
{
ds@1952
   589
	ConCmdInfo *pInfo = AddOrFindCommand(name, description, flags);
ds@1952
   590
ds@1952
   591
	if (!pInfo)
ds@1952
   592
	{
ds@1952
   593
		return false;
ds@1952
   594
	}
ds@1952
   595
ds@1952
   596
	CmdHook *pHook = new CmdHook();
ds@1952
   597
	AdminCmdInfo *pAdmin = new AdminCmdInfo();
ds@1952
   598
ds@1952
   599
	pHook->pf = pFunction;
ds@1952
   600
	if (description && description[0])
ds@1952
   601
	{
ds@1952
   602
		pHook->helptext.assign(description);
ds@1952
   603
	}
ds@1952
   604
	pHook->pAdmin = pAdmin;
ds@1952
   605
ds@1952
   606
	void *object;
ds@1952
   607
	int grpid;
ds@1952
   608
	if (!sm_trie_retrieve(m_pCmdGrps, group, (void **)&object))
ds@1952
   609
	{
ds@1952
   610
		grpid = m_Strings.AddString(group);
ds@1952
   611
		sm_trie_insert(m_pCmdGrps, group, (void *)grpid);
ds@1952
   612
	}
ds@1952
   613
	else
ds@1952
   614
	{
ds@1952
   615
		grpid = (int)object;
ds@1952
   616
	}
ds@1952
   617
ds@1952
   618
	pAdmin->cmdGrpId = grpid;
ds@1952
   619
	pAdmin->flags = adminflags;
ds@1952
   620
ds@1952
   621
	/* First get the command group override, if any */
ds@1952
   622
	bool override = g_Admins.GetCommandOverride(group, 
ds@1952
   623
		Override_CommandGroup,
ds@1952
   624
		&(pAdmin->eflags));
ds@1952
   625
ds@1952
   626
	/* Next get the command override, if any */
ds@1952
   627
	if (g_Admins.GetCommandOverride(name,
ds@1952
   628
		Override_Command,
ds@1952
   629
		&(pAdmin->eflags)))
ds@1952
   630
	{
ds@1952
   631
		override = true;
ds@1952
   632
	}
ds@1952
   633
ds@1952
   634
	/* Assign normal flags if there were no overrides */
ds@1952
   635
	if (!override)
ds@1952
   636
	{
ds@1952
   637
		pAdmin->eflags = pAdmin->flags;
ds@1952
   638
	}
ds@1952
   639
ds@1952
   640
	/* Finally, add the hook */
ds@1952
   641
	pInfo->conhooks.push_back(pHook);
ds@1952
   642
	pInfo->admin = *(pHook->pAdmin);
ds@1952
   643
	pInfo->is_admin_set = true;
ds@1952
   644
ds@1952
   645
	/* Now add to the plugin */
ds@1952
   646
	CmdList *pList;
ds@1952
   647
	IPlugin *pPlugin = g_PluginSys.GetPluginByCtx(pFunction->GetParentContext()->GetContext());
ds@1952
   648
	if (!pPlugin->GetProperty("CommandList", (void **)&pList))
ds@1952
   649
	{
ds@1952
   650
		pList = new CmdList();
ds@1952
   651
		pPlugin->SetProperty("CommandList", pList);
ds@1952
   652
	}
ds@1952
   653
	PlCmdInfo info;
ds@1952
   654
	info.pInfo = pInfo;
ds@1952
   655
	info.type = Cmd_Admin;
ds@1952
   656
	info.pHook = pHook;
ds@1952
   657
	AddToPlCmdList(pList, info);
ds@1952
   658
ds@1952
   659
	return true;
ds@1952
   660
}
ds@1952
   661
ds@1952
   662
bool ConCmdManager::AddServerCommand(IPluginFunction *pFunction, 
ds@1952
   663
									  const char *name, 
ds@1952
   664
									  const char *description, 
ds@1952
   665
									  int flags)
ds@1952
   666
ds@1952
   667
{
ds@1952
   668
	ConCmdInfo *pInfo = AddOrFindCommand(name, description, flags);
ds@1952
   669
ds@1952
   670
	if (!pInfo)
ds@1952
   671
	{
ds@1952
   672
		return false;
ds@1952
   673
	}
ds@1952
   674
ds@1952
   675
	CmdHook *pHook = new CmdHook();
ds@1952
   676
ds@1952
   677
	pHook->pf = pFunction;
ds@1952
   678
	if (description && description[0])
ds@1952
   679
	{
ds@1952
   680
		pHook->helptext.assign(description);
ds@1952
   681
	}
ds@1952
   682
ds@1952
   683
	pInfo->srvhooks.push_back(pHook);
ds@1952
   684
ds@1952
   685
	/* Add to the plugin */
ds@1952
   686
	CmdList *pList;
ds@1952
   687
	IPlugin *pPlugin = g_PluginSys.GetPluginByCtx(pFunction->GetParentContext()->GetContext());
ds@1952
   688
	if (!pPlugin->GetProperty("CommandList", (void **)&pList))
ds@1952
   689
	{
ds@1952
   690
		pList = new CmdList();
ds@1952
   691
		pPlugin->SetProperty("CommandList", pList);
ds@1952
   692
	}
ds@1952
   693
	PlCmdInfo info;
ds@1952
   694
	info.pInfo = pInfo;
ds@1952
   695
	info.type = Cmd_Server;
ds@1952
   696
	info.pHook = pHook;
ds@1952
   697
	AddToPlCmdList(pList, info);
ds@1952
   698
ds@1952
   699
	return true;
ds@1952
   700
}
ds@1952
   701
ds@1952
   702
void AddToPlCmdList(CmdList *pList, const PlCmdInfo &info)
ds@1952
   703
{
ds@1952
   704
	CmdList::iterator iter = pList->begin();
ds@1952
   705
	bool inserted = false;
ds@1952
   706
	const char *orig = NULL;
ds@1952
   707
ds@1952
   708
	orig = info.pInfo->pCmd->GetName();
ds@1952
   709
ds@1952
   710
	/* Insert this into the help list, SORTED alphabetically. */
ds@1952
   711
	while (iter != pList->end())
ds@1952
   712
	{
ds@1952
   713
		PlCmdInfo &obj = (*iter);
ds@1952
   714
		const char *cmd = obj.pInfo->pCmd->GetName();
ds@1952
   715
		if (strcmp(orig, cmd) < 0)
ds@1952
   716
		{
ds@1952
   717
			pList->insert(iter, info);
ds@1952
   718
			inserted = true;
ds@1952
   719
			break;
ds@1952
   720
		}
ds@1952
   721
		iter++;
ds@1952
   722
	}
ds@1952
   723
ds@1952
   724
	if (!inserted)
ds@1952
   725
	{
ds@1952
   726
		pList->push_back(info);
ds@1952
   727
	}
ds@1952
   728
}
ds@1952
   729
ds@1952
   730
void ConCmdManager::AddToCmdList(ConCmdInfo *info)
ds@1952
   731
{
ds@1952
   732
	List<ConCmdInfo *>::iterator iter = m_CmdList.begin();
ds@1952
   733
	ConCmdInfo *pInfo;
ds@1952
   734
	bool inserted = false;
ds@1952
   735
	const char *orig = NULL;
ds@1952
   736
ds@1952
   737
	orig = info->pCmd->GetName();
ds@1952
   738
ds@1952
   739
	/* Insert this into the help list, SORTED alphabetically. */
ds@1952
   740
	while (iter != m_CmdList.end())
ds@1952
   741
	{
ds@1952
   742
		const char *cmd = NULL;
ds@1952
   743
		pInfo = (*iter);
ds@1952
   744
		cmd = pInfo->pCmd->GetName();
ds@1952
   745
		if (strcmp(orig, cmd) < 0)
ds@1952
   746
		{
ds@1952
   747
			m_CmdList.insert(iter, info);
ds@1952
   748
			inserted = true;
ds@1952
   749
			break;
ds@1952
   750
		}
ds@1952
   751
		iter++;
ds@1952
   752
	}
ds@1952
   753
ds@1952
   754
	if (!inserted)
ds@1952
   755
	{
ds@1952
   756
		m_CmdList.push_back(info);
ds@1952
   757
	}
ds@1952
   758
}
ds@1952
   759
ds@1952
   760
void ConCmdManager::UpdateAdminCmdFlags(const char *cmd, OverrideType type, FlagBits bits, bool remove)
ds@1952
   761
{
ds@1952
   762
	ConCmdInfo *pInfo;
ds@1952
   763
ds@1952
   764
	if (type == Override_Command)
ds@1952
   765
	{
ds@1952
   766
		if (!sm_trie_retrieve(m_pCmds, cmd, (void **)&pInfo))
ds@1952
   767
		{
ds@1952
   768
			return;
ds@1952
   769
		}
ds@1952
   770
ds@1952
   771
		List<CmdHook *>::iterator iter;
ds@1952
   772
		CmdHook *pHook;
ds@1952
   773
ds@1952
   774
		for (iter=pInfo->conhooks.begin(); iter!=pInfo->conhooks.end(); iter++)
ds@1952
   775
		{
ds@1952
   776
			pHook = (*iter);
ds@1952
   777
			if (pHook->pAdmin)
ds@1952
   778
			{
ds@1952
   779
				if (!remove)
ds@1952
   780
				{
ds@1952
   781
					pHook->pAdmin->eflags = bits;
ds@1952
   782
				} else {
ds@1952
   783
					pHook->pAdmin->eflags = pHook->pAdmin->flags;
ds@1952
   784
				}
ds@1952
   785
				pInfo->admin = *(pHook->pAdmin);
ds@1952
   786
			}
ds@1952
   787
		}
ds@1952
   788
		pInfo->is_admin_set = true;
ds@1952
   789
	}
ds@1952
   790
	else if (type == Override_CommandGroup)
ds@1952
   791
	{
ds@1952
   792
		void *object;
ds@1952
   793
		if (!sm_trie_retrieve(m_pCmdGrps, cmd, &object))
ds@1952
   794
		{
ds@1952
   795
			return;
ds@1952
   796
		}
ds@1952
   797
		int grpid = (int)object;
ds@1952
   798
ds@1952
   799
		/* This is bad :( loop through all commands */
ds@1952
   800
		List<ConCmdInfo *>::iterator iter;
ds@1952
   801
		CmdHook *pHook;
ds@1952
   802
		for (iter=m_CmdList.begin(); iter!=m_CmdList.end(); iter++)
ds@1952
   803
		{
ds@1952
   804
			pInfo = (*iter);
ds@1952
   805
			for (List<CmdHook *>::iterator citer=pInfo->conhooks.begin();
ds@1952
   806
				 citer!=pInfo->conhooks.end();
ds@1952
   807
				 citer++)
ds@1952
   808
			{
ds@1952
   809
				pHook = (*citer);
ds@1952
   810
				if (pHook->pAdmin && pHook->pAdmin->cmdGrpId == grpid)
ds@1952
   811
				{
ds@1952
   812
					if (remove)
ds@1952
   813
					{
ds@1952
   814
						pHook->pAdmin->eflags = bits;
ds@1952
   815
					} else {
ds@1952
   816
						pHook->pAdmin->eflags = pHook->pAdmin->flags;
ds@1952
   817
					}
ds@1952
   818
					pInfo->admin = *(pHook->pAdmin);
ds@1952
   819
				}
ds@1952
   820
			}
ds@1952
   821
		}
ds@1952
   822
		pInfo->is_admin_set = true;
ds@1952
   823
	}
ds@1952
   824
}
ds@1952
   825
ds@1952
   826
void ConCmdManager::RemoveConCmd(ConCmdInfo *info, const char *name, bool is_read_safe, bool untrack)
ds@1952
   827
{
ds@1952
   828
	/* Remove from the trie */
ds@1952
   829
	sm_trie_delete(m_pCmds, name);
ds@1952
   830
ds@1952
   831
	/* Remove console-specific information
ds@1952
   832
	 * This should always be true as of right now
ds@1952
   833
	 */
ds@1952
   834
	if (info->pCmd)
ds@1952
   835
	{
ds@1952
   836
		if (info->sourceMod)
ds@1952
   837
		{
ds@1952
   838
			/* Unlink from SourceMM */
ds@1952
   839
			g_SMAPI->UnregisterConCommandBase(g_PLAPI, info->pCmd);
ds@1952
   840
			/* Delete the command's memory */
ds@1952
   841
			char *new_help = const_cast<char *>(info->pCmd->GetHelpText());
ds@1952
   842
			char *new_name = const_cast<char *>(info->pCmd->GetName());
ds@1952
   843
			delete [] new_help;
ds@1952
   844
			delete [] new_name;
ds@1952
   845
			delete info->pCmd;
ds@1952
   846
		}
ds@1952
   847
		else
ds@1952
   848
		{
ds@1952
   849
			if (is_read_safe)
ds@1952
   850
			{
ds@1952
   851
				/* Remove the external hook */
ds@1952
   852
				SH_REMOVE_HOOK_STATICFUNC(ConCommand, Dispatch, info->pCmd, CommandCallback, false);
ds@1952
   853
			}
ds@1952
   854
			if (untrack)
ds@1952
   855
			{
ds@1952
   856
				UntrackConCommandBase(info->pCmd, this);
ds@1952
   857
			}
ds@1952
   858
		}
ds@1952
   859
	}
ds@1952
   860
	
ds@1952
   861
	/* Remove from list */
ds@1952
   862
	m_CmdList.remove(info);
ds@1952
   863
ds@1952
   864
	delete info;
ds@1952
   865
}
ds@1952
   866
ds@1952
   867
bool ConCmdManager::LookForSourceModCommand(const char *cmd)
ds@1952
   868
{
ds@1952
   869
	ConCmdInfo *pInfo;
ds@1952
   870
ds@1952
   871
	if (!sm_trie_retrieve(m_pCmds, cmd, (void **)&pInfo))
ds@1952
   872
	{
ds@1952
   873
		return false;
ds@1952
   874
	}
ds@1952
   875
ds@1952
   876
	return pInfo->sourceMod && (pInfo->conhooks.size() > 0);
ds@1952
   877
}
ds@1952
   878
ds@1952
   879
bool ConCmdManager::LookForCommandAdminFlags(const char *cmd, FlagBits *pFlags)
ds@1952
   880
{
ds@1952
   881
	ConCmdInfo *pInfo;
ds@1952
   882
ds@1952
   883
	if (!sm_trie_retrieve(m_pCmds, cmd, (void **)&pInfo))
ds@1952
   884
	{
ds@1952
   885
		return false;
ds@1952
   886
	}
ds@1952
   887
ds@1952
   888
	*pFlags = pInfo->admin.eflags;
ds@1952
   889
ds@1952
   890
	return pInfo->is_admin_set;
ds@1952
   891
}
ds@1952
   892
ds@1952
   893
ConCmdInfo *ConCmdManager::AddOrFindCommand(const char *name, const char *description, int flags)
ds@1952
   894
{
ds@1952
   895
	ConCmdInfo *pInfo;
ds@1952
   896
	if (!sm_trie_retrieve(m_pCmds, name, (void **)&pInfo))
ds@1952
   897
	{
ds@1952
   898
		pInfo = new ConCmdInfo();
ds@1952
   899
		/* Find the commandopan */
ds@1952
   900
		ConCommandBase *pBase = icvar->GetCommands();
ds@1952
   901
		ConCommand *pCmd = NULL;
ds@1952
   902
		while (pBase)
ds@1952
   903
		{
ds@1952
   904
			if (strcmp(pBase->GetName(), name) == 0)
ds@1952
   905
			{
ds@1952
   906
				/* Don't want to return convar with same name */
ds@1952
   907
				if (!pBase->IsCommand())
ds@1952
   908
				{
ds@1952
   909
					return NULL;
ds@1952
   910
				}
ds@1952
   911
ds@1952
   912
				pCmd = (ConCommand *)pBase;
ds@1952
   913
				break;
ds@1952
   914
			}
ds@1952
   915
			pBase = const_cast<ConCommandBase *>(pBase->GetNext());
ds@1952
   916
		}
ds@1952
   917
ds@1952
   918
		if (!pCmd)
ds@1952
   919
		{
ds@1952
   920
			/* Note that we have to duplicate because the source might not be 
ds@1952
   921
			 * a static string, and these expect static memory.
ds@1952
   922
			 */
ds@1952
   923
			if (!description)
ds@1952
   924
			{
ds@1952
   925
				description = "";
ds@1952
   926
			}
ds@1952
   927
			char *new_name = sm_strdup(name);
ds@1952
   928
			char *new_help = sm_strdup(description);
ds@1952
   929
			pCmd = new ConCommand(new_name, CommandCallback, new_help, flags);
ds@1952
   930
			pInfo->sourceMod = true;
ds@1952
   931
		}
ds@1952
   932
		else
ds@1952
   933
		{
ds@1952
   934
			TrackConCommandBase(pCmd, this);
ds@1952
   935
			SH_ADD_HOOK_STATICFUNC(ConCommand, Dispatch, pCmd, CommandCallback, false);
ds@1952
   936
		}
ds@1952
   937
ds@1952
   938
		pInfo->pCmd = pCmd;
ds@1952
   939
		pInfo->is_admin_set = false;
ds@1952
   940
ds@1952
   941
		sm_trie_insert(m_pCmds, name, pInfo);
ds@1952
   942
		AddToCmdList(pInfo);
ds@1952
   943
	}
ds@1952
   944
ds@1952
   945
	return pInfo;
ds@1952
   946
}
ds@1952
   947
ds@1952
   948
void ConCmdManager::OnRootConsoleCommand(const char *cmdname, const CCommand &command)
ds@1952
   949
{
ds@1952
   950
	if (command.ArgC() >= 3)
ds@1952
   951
	{
ds@1952
   952
		const char *text = command.Arg(2);
ds@1952
   953
ds@1952
   954
		CPlugin *pPlugin = g_PluginSys.FindPluginByConsoleArg(text);
ds@1952
   955
ds@1952
   956
		if (!pPlugin)
ds@1952
   957
		{
ds@1952
   958
			g_RootMenu.ConsolePrint("[SM] Plugin \"%s\" was not found.", text);
ds@1952
   959
			return;
ds@1952
   960
		}
ds@1952
   961
ds@1952
   962
		const sm_plugininfo_t *plinfo = pPlugin->GetPublicInfo();
ds@1952
   963
		const char *plname = IS_STR_FILLED(plinfo->name) ? plinfo->name : pPlugin->GetFilename();
ds@1952
   964
ds@1952
   965
		CmdList *pList;
ds@1952
   966
		if (!pPlugin->GetProperty("CommandList", (void **)&pList))
ds@1952
   967
		{
ds@1952
   968
			g_RootMenu.ConsolePrint("[SM] No commands found for: %s", plname);
ds@1952
   969
			return;
ds@1952
   970
		}
ds@1952
   971
		if (!pList->size())
ds@1952
   972
		{
ds@1952
   973
			g_RootMenu.ConsolePrint("[SM] No commands found for: %s", plname);
ds@1952
   974
			return;
ds@1952
   975
		}
ds@1952
   976
ds@1952
   977
		CmdList::iterator iter;
ds@1952
   978
		const char *type = NULL;
ds@1952
   979
		const char *name;
ds@1952
   980
		const char *help;
ds@1952
   981
		g_RootMenu.ConsolePrint("[SM] Listing %d commands for: %s", pList->size(), plname);
ds@1952
   982
		g_RootMenu.ConsolePrint("  %-17.16s %-8.7s %s", "[Name]", "[Type]", "[Help]");
ds@1952
   983
		for (iter=pList->begin();
ds@1952
   984
			 iter!=pList->end();
ds@1952
   985
			 iter++)
ds@1952
   986
		{
ds@1952
   987
			PlCmdInfo &cmd = (*iter);
ds@1952
   988
			if (cmd.type == Cmd_Server)
ds@1952
   989
			{
ds@1952
   990
				type = "server";
ds@1952
   991
			}
ds@1952
   992
			else if (cmd.type == Cmd_Console)
ds@1952
   993
			{
ds@1952
   994
				type = "console";
ds@1952
   995
			}
ds@1952
   996
			else if (cmd.type == Cmd_Admin)
ds@1952
   997
			{
ds@1952
   998
				type = "admin";
ds@1952
   999
			}
ds@1952
  1000
			name = cmd.pInfo->pCmd->GetName();
ds@1952
  1001
			if (cmd.pHook->helptext.size())
ds@1952
  1002
			{
ds@1952
  1003
				help = cmd.pHook->helptext.c_str();
ds@1952
  1004
			}
ds@1952
  1005
			else
ds@1952
  1006
			{
ds@1952
  1007
				help = cmd.pInfo->pCmd->GetHelpText();
ds@1952
  1008
			}
ds@1952
  1009
			g_RootMenu.ConsolePrint("  %-17.16s %-12.11s %s", name, type, help);		
ds@1952
  1010
		}
ds@1952
  1011
ds@1952
  1012
		return;
ds@1952
  1013
	}
ds@1952
  1014
ds@1952
  1015
	g_RootMenu.ConsolePrint("[SM] Usage: sm cmds <plugin #>");
ds@1952
  1016
}