3 * =============================================================================
5 * Copyright (C) 2004-2007 AlliedModders LLC. All rights reserved.
6 * =============================================================================
8 * This program is free software; you can redistribute it and/or modify it under
9 * the terms of the GNU General Public License, version 3.0, as published by the
10 * Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
17 * You should have received a copy of the GNU General Public License along with
18 * this program. If not, see <http://www.gnu.org/licenses/>.
20 * As a special exception, AlliedModders LLC gives you permission to link the
21 * code of this program (as well as its derivative works) to "Half-Life 2," the
22 * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
23 * by the Valve Corporation. You must obey the GNU General Public License in
24 * all respects for all other code used. Additionally, AlliedModders LLC grants
25 * this exception to all derivative works. AlliedModders LLC defines further
26 * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
27 * or <http://www.sourcemod.net/license.php>.
32 #include "sm_globals.h"
33 #include "HalfLife2.h"
34 #include "sourcemm_api.h"
35 #include "HandleSys.h"
36 #include "ConVarManager.h"
37 #include "ConCmdManager.h"
38 #include "PluginSys.h"
39 #include "sm_stringutil.h"
40 #include "PlayerManager.h"
41 #include "ChatTriggers.h"
42 #include <inetchannel.h>
45 #define NET_SETCONVAR 5
49 ConVarBound_Upper = 0,
53 HandleType_t hCmdIterType = 0;
58 List<ConCmdInfo *>::iterator iter;
61 class ConsoleHelpers :
63 public IHandleTypeDispatch
66 virtual void OnSourceModAllInitialized()
69 g_HandleSys.InitAccessDefaults(NULL, &access);
70 access.access[HandleAccess_Clone] = HANDLE_RESTRICT_OWNER | HANDLE_RESTRICT_IDENTITY;
72 hCmdIterType = g_HandleSys.CreateType(NULL, this, 0, NULL, &access, g_pCoreIdent, NULL);
74 virtual void OnHandleDestroy(HandleType_t type, void *object)
76 GlobCmdIter *iter = (GlobCmdIter *)object;
81 static void ReplicateConVar(ConVar *pConVar)
83 int maxClients = g_Players.GetMaxClients();
86 bf_write buffer(data, sizeof(data));
88 buffer.WriteUBitLong(NET_SETCONVAR, 5);
90 buffer.WriteString(pConVar->GetName());
91 buffer.WriteString(pConVar->GetString());
93 for (int i = 1; i <= maxClients; i++)
95 CPlayer *pPlayer = g_Players.GetPlayerByIndex(i);
97 if (pPlayer && pPlayer->IsInGame() && !pPlayer->IsFakeClient())
99 INetChannel *netchan = static_cast<INetChannel *>(engine->GetPlayerNetInfo(i));
100 netchan->SendData(buffer);
105 static void NotifyConVar(ConVar *pConVar)
107 IGameEvent *pEvent = gameevents->CreateEvent("server_cvar");
108 pEvent->SetString("cvarname", pConVar->GetName());
109 if (pConVar->IsBitSet(FCVAR_PROTECTED))
111 pEvent->SetString("cvarvalue", "***PROTECTED***");
113 pEvent->SetString("cvarvalue", pConVar->GetString());
116 gameevents->FireEvent(pEvent);
119 static cell_t sm_CreateConVar(IPluginContext *pContext, const cell_t *params)
121 char *name, *defaultVal, *helpText;
123 pContext->LocalToString(params[1], &name);
125 // While the engine seems to accept a blank convar name, it causes a crash upon server quit
126 if (name == NULL || strcmp(name, "") == 0)
128 return pContext->ThrowNativeError("Convar with blank name is not permitted");
131 pContext->LocalToString(params[2], &defaultVal);
132 pContext->LocalToString(params[3], &helpText);
134 bool hasMin = params[5] ? true : false;
135 bool hasMax = params[7] ? true : false;
136 float min = sp_ctof(params[6]);
137 float max = sp_ctof(params[8]);
139 Handle_t hndl = g_ConVarManager.CreateConVar(pContext, name, defaultVal, helpText, params[4], hasMin, min, hasMax, max);
141 if (hndl == BAD_HANDLE)
143 return pContext->ThrowNativeError("Convar \"%s\" was not created. A console command with the same name already exists.", name);
149 static cell_t sm_FindConVar(IPluginContext *pContext, const cell_t *params)
153 pContext->LocalToString(params[1], &name);
155 return g_ConVarManager.FindConVar(name);
158 static cell_t sm_HookConVarChange(IPluginContext *pContext, const cell_t *params)
160 Handle_t hndl = static_cast<Handle_t>(params[1]);
164 if ((err=g_HandleSys.ReadHandle(hndl, g_ConVarManager.GetHandleType(), NULL, (void **)&pConVar))
167 return pContext->ThrowNativeError("Invalid convar handle %x (error %d)", hndl, err);
170 IPluginFunction *pFunction = pContext->GetFunctionById(params[2]);
174 return pContext->ThrowNativeError("Invalid function id (%X)", params[2]);
177 g_ConVarManager.HookConVarChange(pConVar, pFunction);
182 static cell_t sm_UnhookConVarChange(IPluginContext *pContext, const cell_t *params)
184 Handle_t hndl = static_cast<Handle_t>(params[1]);
188 if ((err=g_HandleSys.ReadHandle(hndl, g_ConVarManager.GetHandleType(), NULL, (void **)&pConVar))
191 return pContext->ThrowNativeError("Invalid convar handle %x (error %d)", hndl, err);
194 IPluginFunction *pFunction = pContext->GetFunctionById(params[2]);
198 return pContext->ThrowNativeError("Invalid function id (%X)", params[2]);
201 g_ConVarManager.UnhookConVarChange(pConVar, pFunction);
206 static cell_t sm_GetConVarBool(IPluginContext *pContext, const cell_t *params)
208 Handle_t hndl = static_cast<Handle_t>(params[1]);
212 if ((err=g_HandleSys.ReadHandle(hndl, g_ConVarManager.GetHandleType(), NULL, (void **)&pConVar))
215 return pContext->ThrowNativeError("Invalid convar handle %x (error %d)", hndl, err);
218 return pConVar->GetBool();
221 static cell_t sm_GetConVarInt(IPluginContext *pContext, const cell_t *params)
223 Handle_t hndl = static_cast<Handle_t>(params[1]);
227 if ((err=g_HandleSys.ReadHandle(hndl, g_ConVarManager.GetHandleType(), NULL, (void **)&pConVar))
230 return pContext->ThrowNativeError("Invalid convar handle %x (error %d)", hndl, err);
233 return pConVar->GetInt();
236 /* This handles both SetConVarBool() and SetConVarInt() */
237 static cell_t sm_SetConVarNum(IPluginContext *pContext, const cell_t *params)
239 Handle_t hndl = static_cast<Handle_t>(params[1]);
243 if ((err=g_HandleSys.ReadHandle(hndl, g_ConVarManager.GetHandleType(), NULL, (void **)&pConVar))
246 return pContext->ThrowNativeError("Invalid convar handle %x (error %d)", hndl, err);
249 pConVar->SetValue(params[2]);
251 /* Should we replicate it? */
252 if (params[3] && pConVar->IsBitSet(FCVAR_REPLICATED))
254 ReplicateConVar(pConVar);
257 /* Should we notify clients? */
258 if (params[4] && pConVar->IsBitSet(FCVAR_NOTIFY))
260 NotifyConVar(pConVar);
266 static cell_t sm_GetConVarFloat(IPluginContext *pContext, const cell_t *params)
268 Handle_t hndl = static_cast<Handle_t>(params[1]);
272 if ((err=g_HandleSys.ReadHandle(hndl, g_ConVarManager.GetHandleType(), NULL, (void **)&pConVar))
275 return pContext->ThrowNativeError("Invalid convar handle %x (error %d)", hndl, err);
278 float value = pConVar->GetFloat();
280 return sp_ftoc(value);
283 static cell_t sm_SetConVarFloat(IPluginContext *pContext, const cell_t *params)
285 Handle_t hndl = static_cast<Handle_t>(params[1]);
289 if ((err=g_HandleSys.ReadHandle(hndl, g_ConVarManager.GetHandleType(), NULL, (void **)&pConVar))
292 return pContext->ThrowNativeError("Invalid convar handle %x (error %d)", hndl, err);
295 float value = sp_ctof(params[2]);
296 pConVar->SetValue(value);
298 /* Should we replicate it? */
299 if (params[3] && pConVar->IsBitSet(FCVAR_REPLICATED))
301 ReplicateConVar(pConVar);
304 /* Should we notify clients? */
305 if (params[4] && pConVar->IsBitSet(FCVAR_NOTIFY))
307 NotifyConVar(pConVar);
313 static cell_t sm_GetConVarString(IPluginContext *pContext, const cell_t *params)
315 Handle_t hndl = static_cast<Handle_t>(params[1]);
319 if ((err=g_HandleSys.ReadHandle(hndl, g_ConVarManager.GetHandleType(), NULL, (void **)&pConVar))
322 return pContext->ThrowNativeError("Invalid convar handle %x (error %d)", hndl, err);
325 pContext->StringToLocalUTF8(params[2], params[3], pConVar->GetString(), NULL);
330 static cell_t sm_SetConVarString(IPluginContext *pContext, const cell_t *params)
332 Handle_t hndl = static_cast<Handle_t>(params[1]);
336 if ((err=g_HandleSys.ReadHandle(hndl, g_ConVarManager.GetHandleType(), NULL, (void **)&pConVar))
339 return pContext->ThrowNativeError("Invalid convar handle %x (error %d)", hndl, err);
343 pContext->LocalToString(params[2], &value);
345 pConVar->SetValue(value);
347 /* Should we replicate it? */
348 if (params[3] && pConVar->IsBitSet(FCVAR_REPLICATED))
350 ReplicateConVar(pConVar);
353 /* Should we notify clients? */
354 if (params[4] && pConVar->IsBitSet(FCVAR_NOTIFY))
356 NotifyConVar(pConVar);
362 static cell_t sm_ResetConVar(IPluginContext *pContext, const cell_t *params)
364 Handle_t hndl = static_cast<Handle_t>(params[1]);
368 if ((err=g_HandleSys.ReadHandle(hndl, g_ConVarManager.GetHandleType(), NULL, (void **)&pConVar))
371 return pContext->ThrowNativeError("Invalid convar handle %x (error %d)", hndl, err);
376 /* Should we replicate it? */
377 if (params[2] && pConVar->IsBitSet(FCVAR_REPLICATED))
379 ReplicateConVar(pConVar);
382 /* Should we notify clients? */
383 if (params[3] && pConVar->IsBitSet(FCVAR_NOTIFY))
385 NotifyConVar(pConVar);
391 static cell_t sm_GetConVarFlags(IPluginContext *pContext, const cell_t *params)
393 Handle_t hndl = static_cast<Handle_t>(params[1]);
397 if ((err=g_HandleSys.ReadHandle(hndl, g_ConVarManager.GetHandleType(), NULL, (void **)&pConVar))
400 return pContext->ThrowNativeError("Invalid convar handle %x (error %d)", hndl, err);
403 return pConVar->GetFlags();
406 static cell_t sm_SetConVarFlags(IPluginContext *pContext, const cell_t *params)
408 Handle_t hndl = static_cast<Handle_t>(params[1]);
412 if ((err=g_HandleSys.ReadHandle(hndl, g_ConVarManager.GetHandleType(), NULL, (void **)&pConVar))
415 return pContext->ThrowNativeError("Invalid convar handle %x (error %d)", hndl, err);
418 pConVar->SetFlags(params[2]);
423 static cell_t sm_GetConVarBounds(IPluginContext *pContext, const cell_t *params)
425 Handle_t hndl = static_cast<Handle_t>(params[1]);
429 if ((err=g_HandleSys.ReadHandle(hndl, g_ConVarManager.GetHandleType(), NULL, (void **)&pConVar))
432 return pContext->ThrowNativeError("Invalid convar handle %x (error %d)", hndl, err);
441 case ConVarBound_Upper:
442 hasBound = pConVar->GetMax(bound);
444 case ConVarBound_Lower:
445 hasBound = pConVar->GetMin(bound);
448 return pContext->ThrowNativeError("Invalid ConVarBounds value %d");
451 pContext->LocalToPhysAddr(params[3], &addr);
452 *addr = sp_ftoc(bound);
457 static cell_t sm_SetConVarBounds(IPluginContext *pContext, const cell_t *params)
459 Handle_t hndl = static_cast<Handle_t>(params[1]);
463 if ((err=g_HandleSys.ReadHandle(hndl, g_ConVarManager.GetHandleType(), NULL, (void **)&pConVar))
466 return pContext->ThrowNativeError("Invalid convar handle %x (error %d)", hndl, err);
471 case ConVarBound_Upper:
472 pConVar->SetMax(params[3] ? true : false, sp_ctof(params[4]));
474 case ConVarBound_Lower:
475 pConVar->SetMin(params[3] ? true : false, sp_ctof(params[4]));
478 return pContext->ThrowNativeError("Invalid ConVarBounds value %d");
484 static cell_t sm_GetConVarName(IPluginContext *pContext, const cell_t *params)
486 Handle_t hndl = static_cast<Handle_t>(params[1]);
490 if ((err=g_HandleSys.ReadHandle(hndl, g_ConVarManager.GetHandleType(), NULL, (void **)&pConVar))
493 return pContext->ThrowNativeError("Invalid convar handle %x (error %d)", hndl, err);
496 pContext->StringToLocalUTF8(params[2], params[3], pConVar->GetName(), NULL);
501 static bool s_QueryAlreadyWarned = false;
503 static cell_t sm_QueryClientConVar(IPluginContext *pContext, const cell_t *params)
507 IPluginFunction *pCallback;
509 if (g_IsOriginalEngine)
511 if (!s_QueryAlreadyWarned)
513 s_QueryAlreadyWarned = true;
514 return pContext->ThrowNativeError("Game does not support client convar querying (one time warning)");
520 pPlayer = g_Players.GetPlayerByIndex(params[1]);
524 return pContext->ThrowNativeError("Client index %d is invalid", params[1]);
527 if (!pPlayer->IsConnected())
529 return pContext->ThrowNativeError("Client %d is not connected", params[1]);
532 /* Trying a query on a bot results in callback not be fired, so don't bother */
533 if (pPlayer->IsFakeClient())
538 pContext->LocalToString(params[2], &name);
539 pCallback = pContext->GetFunctionById(params[3]);
543 return pContext->ThrowNativeError("Invalid function id (%X)", params[3]);
546 return g_ConVarManager.QueryClientConVar(pPlayer->GetEdict(), name, pCallback, params[4]);
549 static cell_t sm_RegServerCmd(IPluginContext *pContext, const cell_t *params)
552 IPluginFunction *pFunction;
554 pContext->LocalToString(params[1], &name);
555 pContext->LocalToString(params[3], &help);
556 pFunction = pContext->GetFunctionById(params[2]);
560 return pContext->ThrowNativeError("Invalid function id (%X)", params[2]);
563 if (!g_ConCmds.AddServerCommand(pFunction, name, help, params[4]))
565 return pContext->ThrowNativeError("Command \"%s\" could not be created. A convar with the same name already exists.", name);
571 static cell_t sm_RegConsoleCmd(IPluginContext *pContext, const cell_t *params)
574 IPluginFunction *pFunction;
576 pContext->LocalToString(params[1], &name);
577 pContext->LocalToString(params[3], &help);
578 pFunction = pContext->GetFunctionById(params[2]);
582 return pContext->ThrowNativeError("Invalid function id (%X)", params[2]);
585 if (!g_ConCmds.AddConsoleCommand(pFunction, name, help, params[4]))
587 return pContext->ThrowNativeError("Command \"%s\" could not be created. A convar with the same name already exists.", name);
593 static cell_t sm_RegAdminCmd(IPluginContext *pContext, const cell_t *params)
597 IPluginFunction *pFunction;
598 FlagBits flags = params[3];
599 int cmdflags = params[6];
601 pContext->LocalToString(params[1], &name);
602 pContext->LocalToString(params[4], &help);
603 pContext->LocalToString(params[5], (char **)&group);
604 pFunction = pContext->GetFunctionById(params[2]);
606 if (group[0] == '\0')
608 CPlugin *pPlugin = g_PluginSys.GetPluginByCtx(pContext->GetContext());
609 group = pPlugin->GetFilename();
614 return pContext->ThrowNativeError("Invalid function id (%X)", params[2]);
617 if (!g_ConCmds.AddAdminCommand(pFunction, name, group, flags, help, cmdflags))
619 return pContext->ThrowNativeError("Command \"%s\" could not be created. A convar with the same name already exists.", name);
625 static cell_t sm_GetCmdArgs(IPluginContext *pContext, const cell_t *params)
627 return engine->Cmd_Argc() - 1;
630 static cell_t sm_GetCmdArg(IPluginContext *pContext, const cell_t *params)
632 const char *arg = engine->Cmd_Argv(params[1]);
634 pContext->StringToLocalUTF8(params[2], params[3], arg, NULL);
639 static cell_t sm_GetCmdArgString(IPluginContext *pContext, const cell_t *params)
641 const char *args = engine->Cmd_Args();
648 pContext->StringToLocalUTF8(params[1], params[2], args, NULL);
653 static cell_t sm_PrintToServer(IPluginContext *pCtx, const cell_t *params)
659 pCtx->LocalToString(params[1], &fmt);
660 size_t res = atcprintf(buffer, sizeof(buffer)-2, fmt, pCtx, params, &arg);
662 buffer[res++] = '\n';
665 META_CONPRINT(buffer);
670 static cell_t sm_PrintToConsole(IPluginContext *pCtx, const cell_t *params)
672 int index = params[1];
673 if ((index < 0) || (index > g_Players.GetMaxClients()))
675 return pCtx->ThrowNativeError("Client index %d is invalid", index);
678 CPlayer *pPlayer = NULL;
681 pPlayer = g_Players.GetPlayerByIndex(index);
682 if (!pPlayer->IsInGame())
684 return pCtx->ThrowNativeError("Client %d is not in game", index);
687 /* Silent fail on bots, engine will crash */
688 if (pPlayer->IsFakeClient())
698 pCtx->LocalToString(params[2], &fmt);
699 size_t res = atcprintf(buffer, sizeof(buffer)-2, fmt, pCtx, params, &arg);
701 buffer[res++] = '\n';
706 engine->ClientPrintf(pPlayer->GetEdict(), buffer);
708 META_CONPRINT(buffer);
714 static cell_t sm_ServerCommand(IPluginContext *pContext, const cell_t *params)
716 g_SourceMod.SetGlobalTarget(LANG_SERVER);
719 size_t len = g_SourceMod.FormatString(buffer, sizeof(buffer)-2, pContext, params, 1);
721 if (pContext->GetContext()->n_err != SP_ERROR_NONE)
726 /* One byte for null terminator, one for newline */
727 buffer[len++] = '\n';
730 engine->ServerCommand(buffer);
735 static cell_t sm_InsertServerCommand(IPluginContext *pContext, const cell_t *params)
737 g_SourceMod.SetGlobalTarget(LANG_SERVER);
740 size_t len = g_SourceMod.FormatString(buffer, sizeof(buffer)-2, pContext, params, 1);
742 if (pContext->GetContext()->n_err != SP_ERROR_NONE)
747 /* One byte for null terminator, one for newline */
748 buffer[len++] = '\n';
751 engine->InsertServerCommand(buffer);
756 static cell_t sm_ServerExecute(IPluginContext *pContext, const cell_t *params)
758 engine->ServerExecute();
763 static cell_t sm_ClientCommand(IPluginContext *pContext, const cell_t *params)
765 CPlayer *pPlayer = g_Players.GetPlayerByIndex(params[1]);
769 return pContext->ThrowNativeError("Client index %d is invalid", params[1]);
772 if (!pPlayer->IsConnected())
774 return pContext->ThrowNativeError("Client %d is not connected", params[1]);
777 g_SourceMod.SetGlobalTarget(params[1]);
780 g_SourceMod.FormatString(buffer, sizeof(buffer), pContext, params, 2);
782 if (pContext->GetContext()->n_err != SP_ERROR_NONE)
787 engine->ClientCommand(pPlayer->GetEdict(), "%s", buffer);
792 static cell_t FakeClientCommand(IPluginContext *pContext, const cell_t *params)
794 CPlayer *pPlayer = g_Players.GetPlayerByIndex(params[1]);
798 return pContext->ThrowNativeError("Client index %d is invalid", params[1]);
801 if (!pPlayer->IsConnected())
803 return pContext->ThrowNativeError("Client %d is not connected", params[1]);
807 g_SourceMod.FormatString(buffer, sizeof(buffer), pContext, params, 2);
809 if (pContext->GetContext()->n_err != SP_ERROR_NONE)
814 serverpluginhelpers->ClientCommand(pPlayer->GetEdict(), buffer);
819 static cell_t FakeClientCommandEx(IPluginContext *pContext, const cell_t *params)
821 CPlayer *pPlayer = g_Players.GetPlayerByIndex(params[1]);
825 return pContext->ThrowNativeError("Client index %d is invalid", params[1]);
828 if (!pPlayer->IsConnected())
830 return pContext->ThrowNativeError("Client %d is not connected", params[1]);
834 g_SourceMod.FormatString(buffer, sizeof(buffer), pContext, params, 2);
836 if (pContext->GetContext()->n_err != SP_ERROR_NONE)
841 g_HL2.AddToFakeCliCmdQueue(params[1], engine->GetPlayerUserId(pPlayer->GetEdict()), buffer);
846 static cell_t ReplyToCommand(IPluginContext *pContext, const cell_t *params)
848 g_SourceMod.SetGlobalTarget(params[1]);
850 /* Build the format string */
852 size_t len = g_SourceMod.FormatString(buffer, sizeof(buffer)-2, pContext, params, 2);
854 if (pContext->GetContext()->n_err != SP_ERROR_NONE)
859 /* If we're printing to the server, shortcut out */
863 buffer[len++] = '\n';
865 META_CONPRINT(buffer);
869 CPlayer *pPlayer = g_Players.GetPlayerByIndex(params[1]);
873 return pContext->ThrowNativeError("Client index %d is invalid", params[1]);
876 if (!pPlayer->IsConnected())
878 return pContext->ThrowNativeError("Client %d is not connected", params[1]);
881 g_SourceMod.SetGlobalTarget(params[1]);
883 unsigned int replyto = g_ChatTriggers.GetReplyTo();
884 if (replyto == SM_REPLY_CONSOLE)
886 buffer[len++] = '\n';
888 engine->ClientPrintf(pPlayer->GetEdict(), buffer);
889 } else if (replyto == SM_REPLY_CHAT) {
895 g_HL2.TextMsg(params[1], HUD_PRINTTALK, buffer);
901 static cell_t GetCmdReplyTarget(IPluginContext *pContext, const cell_t *params)
903 return g_ChatTriggers.GetReplyTo();
906 static cell_t SetCmdReplyTarget(IPluginContext *pContext, const cell_t *params)
908 return g_ChatTriggers.SetReplyTo(params[1]);
911 static cell_t GetCommandIterator(IPluginContext *pContext, const cell_t *params)
913 GlobCmdIter *iter = new GlobCmdIter;
914 iter->started = false;
916 Handle_t hndl = g_HandleSys.CreateHandle(hCmdIterType, iter, pContext->GetIdentity(), g_pCoreIdent, NULL);
917 if (hndl == BAD_HANDLE)
925 static cell_t ReadCommandIterator(IPluginContext *pContext, const cell_t *params)
929 HandleSecurity sec(pContext->GetIdentity(), g_pCoreIdent);
931 if ((err = g_HandleSys.ReadHandle(params[1], hCmdIterType, &sec, (void **)&iter))
934 return pContext->ThrowNativeError("Invalid GlobCmdIter Handle %x", params[1]);
937 const List<ConCmdInfo *> &cmds = g_ConCmds.GetCommandList();
941 iter->iter = cmds.begin();
942 iter->started = true;
945 while (iter->iter != cmds.end()
946 && !(*(iter->iter))->sourceMod)
951 if (iter->iter == cmds.end())
956 ConCmdInfo *pInfo = (*(iter->iter));
958 pContext->StringToLocalUTF8(params[2], params[3], pInfo->pCmd->GetName(), NULL);
959 pContext->StringToLocalUTF8(params[5], params[6], pInfo->pCmd->GetHelpText(), NULL);
962 pContext->LocalToPhysAddr(params[4], &addr);
963 *addr = pInfo->admin.eflags;
970 static cell_t CheckCommandAccess(IPluginContext *pContext, const cell_t *params)
978 pContext->LocalToString(params[2], &cmd);
980 /* Support the newer version which will auto-check for an existing command. */
981 FlagBits bits = params[3];
982 if (params[0] == 4 && params[4])
984 g_ConCmds.LookForCommandAdminFlags(cmd, &bits);
987 return g_ConCmds.CheckCommandAccess(params[1], cmd, bits) ? 1 : 0;
990 REGISTER_NATIVES(consoleNatives)
992 {"CreateConVar", sm_CreateConVar},
993 {"FindConVar", sm_FindConVar},
994 {"HookConVarChange", sm_HookConVarChange},
995 {"UnhookConVarChange", sm_UnhookConVarChange},
996 {"GetConVarBool", sm_GetConVarBool},
997 {"SetConVarBool", sm_SetConVarNum},
998 {"GetConVarInt", sm_GetConVarInt},
999 {"SetConVarInt", sm_SetConVarNum},
1000 {"GetConVarFloat", sm_GetConVarFloat},
1001 {"SetConVarFloat", sm_SetConVarFloat},
1002 {"GetConVarString", sm_GetConVarString},
1003 {"SetConVarString", sm_SetConVarString},
1004 {"GetConVarFlags", sm_GetConVarFlags},
1005 {"SetConVarFlags", sm_SetConVarFlags},
1006 {"ResetConVar", sm_ResetConVar},
1007 {"GetConVarName", sm_GetConVarName},
1008 {"GetConVarBounds", sm_GetConVarBounds},
1009 {"SetConVarBounds", sm_SetConVarBounds},
1010 {"QueryClientConVar", sm_QueryClientConVar},
1011 {"RegServerCmd", sm_RegServerCmd},
1012 {"RegConsoleCmd", sm_RegConsoleCmd},
1013 {"GetCmdArgString", sm_GetCmdArgString},
1014 {"GetCmdArgs", sm_GetCmdArgs},
1015 {"GetCmdArg", sm_GetCmdArg},
1016 {"PrintToServer", sm_PrintToServer},
1017 {"PrintToConsole", sm_PrintToConsole},
1018 {"RegAdminCmd", sm_RegAdminCmd},
1019 {"ServerCommand", sm_ServerCommand},
1020 {"InsertServerCommand", sm_InsertServerCommand},
1021 {"ServerExecute", sm_ServerExecute},
1022 {"ClientCommand", sm_ClientCommand},
1023 {"FakeClientCommand", FakeClientCommand},
1024 {"ReplyToCommand", ReplyToCommand},
1025 {"GetCmdReplySource", GetCmdReplyTarget},
1026 {"SetCmdReplySource", SetCmdReplyTarget},
1027 {"GetCommandIterator", GetCommandIterator},
1028 {"ReadCommandIterator", ReadCommandIterator},
1029 {"CheckCommandAccess", CheckCommandAccess},
1030 {"FakeClientCommandEx", FakeClientCommandEx},