This commit is contained in:
Nicholas Hastings 2012-11-20 20:57:36 -05:00
commit bd9f126973
5 changed files with 36 additions and 72 deletions

View File

@ -559,44 +559,6 @@ bool ConCmdManager::CheckAccess(int client, const char *cmd, AdminCmdInfo *pAdmi
return false; return false;
} }
bool ConCmdManager::AddConsoleCommand(IPluginFunction *pFunction,
const char *name,
const char *description,
int flags)
{
ConCmdInfo *pInfo = AddOrFindCommand(name, description, flags);
if (!pInfo)
{
return false;
}
CmdHook *pHook = new CmdHook();
pHook->pf = pFunction;
if (description && description[0])
{
pHook->helptext.assign(description);
}
pInfo->conhooks.push_back(pHook);
/* Add to the plugin */
CmdList *pList;
IPlugin *pPlugin = g_PluginSys.GetPluginByCtx(pFunction->GetParentContext()->GetContext());
if (!pPlugin->GetProperty("CommandList", (void **)&pList))
{
pList = new CmdList();
pPlugin->SetProperty("CommandList", pList);
}
PlCmdInfo info;
info.pInfo = pInfo;
info.type = Cmd_Console;
info.pHook = pHook;
AddToPlCmdList(pList, info);
return true;
}
bool ConCmdManager::AddAdminCommand(IPluginFunction *pFunction, bool ConCmdManager::AddAdminCommand(IPluginFunction *pFunction,
const char *name, const char *name,
const char *group, const char *group,
@ -658,7 +620,6 @@ bool ConCmdManager::AddAdminCommand(IPluginFunction *pFunction,
/* Finally, add the hook */ /* Finally, add the hook */
pInfo->conhooks.push_back(pHook); pInfo->conhooks.push_back(pHook);
pInfo->admin = *(pHook->pAdmin); pInfo->admin = *(pHook->pAdmin);
pInfo->is_admin_set = true;
/* Now add to the plugin */ /* Now add to the plugin */
CmdList *pList; CmdList *pList;
@ -803,7 +764,6 @@ void ConCmdManager::UpdateAdminCmdFlags(const char *cmd, OverrideType type, Flag
pInfo->admin = *(pHook->pAdmin); pInfo->admin = *(pHook->pAdmin);
} }
} }
pInfo->is_admin_set = true;
} }
else if (type == Override_CommandGroup) else if (type == Override_CommandGroup)
{ {
@ -837,7 +797,6 @@ void ConCmdManager::UpdateAdminCmdFlags(const char *cmd, OverrideType type, Flag
} }
} }
} }
pInfo->is_admin_set = true;
} }
} }
@ -905,7 +864,7 @@ bool ConCmdManager::LookForCommandAdminFlags(const char *cmd, FlagBits *pFlags)
*pFlags = pInfo->admin.eflags; *pFlags = pInfo->admin.eflags;
return pInfo->is_admin_set; return true;
} }
ConCmdInfo *ConCmdManager::AddOrFindCommand(const char *name, const char *description, int flags) ConCmdInfo *ConCmdManager::AddOrFindCommand(const char *name, const char *description, int flags)
@ -942,7 +901,6 @@ ConCmdInfo *ConCmdManager::AddOrFindCommand(const char *name, const char *descri
} }
pInfo->pCmd = pCmd; pInfo->pCmd = pCmd;
pInfo->is_admin_set = false;
sm_trie_insert(m_pCmds, name, pInfo); sm_trie_insert(m_pCmds, name, pInfo);
AddToCmdList(pInfo); AddToCmdList(pInfo);
@ -995,13 +953,9 @@ void ConCmdManager::OnRootConsoleCommand(const char *cmdname, const CCommand &co
{ {
type = "server"; type = "server";
} }
else if (cmd.type == Cmd_Console)
{
type = "console";
}
else if (cmd.type == Cmd_Admin) else if (cmd.type == Cmd_Admin)
{ {
type = "admin"; type = (cmd.pInfo->admin.eflags == 0)?"console":"admin";
} }
name = cmd.pInfo->pCmd->GetName(); name = cmd.pInfo->pCmd->GetName();
if (cmd.pHook->helptext.size()) if (cmd.pHook->helptext.size())

View File

@ -48,7 +48,6 @@ using namespace SourceHook;
enum CmdType enum CmdType
{ {
Cmd_Server, Cmd_Server,
Cmd_Console,
Cmd_Admin, Cmd_Admin,
}; };
@ -89,7 +88,6 @@ struct ConCmdInfo
List<CmdHook *> srvhooks; /**< Hooks as a server command */ List<CmdHook *> srvhooks; /**< Hooks as a server command */
List<CmdHook *> conhooks; /**< Hooks as a console command */ List<CmdHook *> conhooks; /**< Hooks as a console command */
AdminCmdInfo admin; /**< Admin info, if any */ AdminCmdInfo admin; /**< Admin info, if any */
bool is_admin_set; /**< Whether or not admin info is set */
}; };
typedef List<ConCmdInfo *> ConCmdList; typedef List<ConCmdInfo *> ConCmdList;
@ -119,7 +117,6 @@ public: //IConCommandTracker
void OnUnlinkConCommandBase(ConCommandBase *pBase, const char *name, bool is_read_safe); void OnUnlinkConCommandBase(ConCommandBase *pBase, const char *name, bool is_read_safe);
public: public:
bool AddServerCommand(IPluginFunction *pFunction, const char *name, const char *description, int flags); bool AddServerCommand(IPluginFunction *pFunction, const char *name, const char *description, int flags);
bool AddConsoleCommand(IPluginFunction *pFunction, const char *name, const char *description, int flags);
bool AddAdminCommand(IPluginFunction *pFunction, bool AddAdminCommand(IPluginFunction *pFunction,
const char *name, const char *name,
const char *group, const char *group,

View File

@ -193,17 +193,30 @@ void CoreConfig::OnRootConsoleCommand(const char *cmdname, const CCommand &comma
if (res == ConfigResult_Reject) if (res == ConfigResult_Reject)
{ {
g_RootMenu.ConsolePrint("[SM] Could not set config option \"%s\" to \"%s\" (%s)", option, value, error); g_RootMenu.ConsolePrint("[SM] Could not set config option \"%s\" to \"%s\". (%s)", option, value, error);
} else if (res == ConfigResult_Ignore) { } else if (res == ConfigResult_Ignore) {
g_RootMenu.ConsolePrint("[SM] No such config option \"%s\" exists.", option); g_RootMenu.ConsolePrint("[SM] No such config option \"%s\" exists.", option);
} else { } else {
g_RootMenu.ConsolePrint("Config option \"%s\" successfully set to \"%s.\"", option, value); g_RootMenu.ConsolePrint("[SM] Config option \"%s\" successfully set to \"%s\".", option, value);
}
return;
} else if (argcount >= 3) {
const char *option = command.Arg(2);
const char *value = GetCoreConfigValue(option);
if (value == NULL)
{
g_RootMenu.ConsolePrint("[SM] No such config option \"%s\" exists.", option);
} else {
g_RootMenu.ConsolePrint("[SM] Config option \"%s\" is set to \"%s\".", option, value);
} }
return; return;
} }
g_RootMenu.ConsolePrint("[SM] Usage: sm config <option> <value>"); g_RootMenu.ConsolePrint("[SM] Usage: sm config <option> [value]");
} }
void CoreConfig::Initialize() void CoreConfig::Initialize()

View File

@ -722,7 +722,9 @@ static cell_t sm_RegConsoleCmd(IPluginContext *pContext, const cell_t *params)
return pContext->ThrowNativeError("Invalid function id (%X)", params[2]); return pContext->ThrowNativeError("Invalid function id (%X)", params[2]);
} }
if (!g_ConCmds.AddConsoleCommand(pFunction, name, help, params[4])) CPlugin *pPlugin = g_PluginSys.GetPluginByCtx(pContext->GetContext());
const char *group = pPlugin->GetFilename();
if (!g_ConCmds.AddAdminCommand(pFunction, name, group, 0, help, params[4]))
{ {
return pContext->ThrowNativeError("Command \"%s\" could not be created. A convar with the same name already exists.", name); return pContext->ThrowNativeError("Command \"%s\" could not be created. A convar with the same name already exists.", name);
} }

View File

@ -329,24 +329,22 @@ void UTIL_DrawServerClass_XML(FILE *fp, ServerClass *sc)
fprintf(fp, "</serverclass>\n"); fprintf(fp, "</serverclass>\n");
} }
void UTIL_DrawSendTable(FILE *fp, SendTable *pTable, int level) void UTIL_DrawSendTable(FILE *fp, SendTable *pTable, int level = 1)
{ {
char spaces[255];
for (int i=0; i<level; i++)
spaces[i] = ' ';
spaces[level] = '\0';
const char *name, *type;
SendProp *pProp; SendProp *pProp;
const char *type;
fprintf(fp, "%sSub-Class Table (%d Deep): %s\n", spaces, level, pTable->GetName()); for (int i = 0; i < pTable->GetNumProps(); i++)
for (int i=0; i<pTable->GetNumProps(); i++)
{ {
pProp = pTable->GetProp(i); pProp = pTable->GetProp(i);
name = pProp->GetName();
if (pProp->GetDataTable()) if (pProp->GetDataTable())
{ {
fprintf(fp, "%*sTable: %s (offset %d) (type %s)\n",
level, "",
pProp->GetName(),
pProp->GetOffset(),
pProp->GetDataTable()->GetName());
UTIL_DrawSendTable(fp, pProp->GetDataTable(), level + 1); UTIL_DrawSendTable(fp, pProp->GetDataTable(), level + 1);
} }
else else
@ -356,8 +354,8 @@ void UTIL_DrawSendTable(FILE *fp, SendTable *pTable, int level)
if (type != NULL) if (type != NULL)
{ {
fprintf(fp, fprintf(fp,
"%s-Member: %s (offset %d) (type %s) (bits %d)\n", "%*sMember: %s (offset %d) (type %s) (bits %d)\n",
spaces, level, "",
pProp->GetName(), pProp->GetName(),
pProp->GetOffset(), pProp->GetOffset(),
type, type,
@ -366,8 +364,8 @@ void UTIL_DrawSendTable(FILE *fp, SendTable *pTable, int level)
else else
{ {
fprintf(fp, fprintf(fp,
"%s-Member: %s (offset %d) (type %d) (bits %d)\n", "%*sMember: %s (offset %d) (type %d) (bits %d)\n",
spaces, level, "",
pProp->GetName(), pProp->GetName(),
pProp->GetOffset(), pProp->GetOffset(),
pProp->GetType(), pProp->GetType(),
@ -453,8 +451,8 @@ CON_COMMAND(sm_dump_netprops, "Dumps the networkable property table as a text fi
ServerClass *pBase = gamedll->GetAllServerClasses(); ServerClass *pBase = gamedll->GetAllServerClasses();
while (pBase != NULL) while (pBase != NULL)
{ {
fprintf(fp, "%s:\n", pBase->GetName()); fprintf(fp, "%s (type %s)\n", pBase->GetName(), pBase->m_pTable->GetName());
UTIL_DrawSendTable(fp, pBase->m_pTable, 1); UTIL_DrawSendTable(fp, pBase->m_pTable);
pBase = pBase->m_pNext; pBase = pBase->m_pNext;
} }