extensions can now be built for multiple engines, and will autoload from auto.X.Y folders
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 "AdminCache.h"
43 #include <inetchannel.h>
46 #define NET_SETCONVAR 5
50 ConVarBound_Upper = 0,
54 HandleType_t hCmdIterType = 0;
59 List<ConCmdInfo *>::iterator iter;
62 class ConsoleHelpers :
64 public IHandleTypeDispatch
67 virtual void OnSourceModAllInitialized()
70 g_HandleSys.InitAccessDefaults(NULL, &access);
71 access.access[HandleAccess_Clone] = HANDLE_RESTRICT_OWNER | HANDLE_RESTRICT_IDENTITY;
73 hCmdIterType = g_HandleSys.CreateType(NULL, this, 0, NULL, &access, g_pCoreIdent, NULL);
75 virtual void OnHandleDestroy(HandleType_t type, void *object)
77 GlobCmdIter *iter = (GlobCmdIter *)object;
82 static void ReplicateConVar(ConVar *pConVar)
84 int maxClients = g_Players.GetMaxClients();
87 bf_write buffer(data, sizeof(data));
89 buffer.WriteUBitLong(NET_SETCONVAR, 5);
91 buffer.WriteString(pConVar->GetName());
92 buffer.WriteString(pConVar->GetString());
94 for (int i = 1; i <= maxClients; i++)
96 CPlayer *pPlayer = g_Players.GetPlayerByIndex(i);
98 if (pPlayer && pPlayer->IsInGame() && !pPlayer->IsFakeClient())
100 INetChannel *netchan = static_cast<INetChannel *>(engine->GetPlayerNetInfo(i));
101 netchan->SendData(buffer);
106 static void NotifyConVar(ConVar *pConVar)
108 IGameEvent *pEvent = gameevents->CreateEvent("server_cvar");
109 pEvent->SetString("cvarname", pConVar->GetName());
110 if (IsFlagSet(pConVar, FCVAR_PROTECTED))
112 pEvent->SetString("cvarvalue", "***PROTECTED***");
114 pEvent->SetString("cvarvalue", pConVar->GetString());
117 gameevents->FireEvent(pEvent);
120 static cell_t sm_CreateConVar(IPluginContext *pContext, const cell_t *params)
122 char *name, *defaultVal, *helpText;
124 pContext->LocalToString(params[1], &name);
126 // While the engine seems to accept a blank convar name, it causes a crash upon server quit
127 if (name == NULL || strcmp(name, "") == 0)
129 return pContext->ThrowNativeError("Convar with blank name is not permitted");
132 pContext->LocalToString(params[2], &defaultVal);
133 pContext->LocalToString(params[3], &helpText);
135 bool hasMin = params[5] ? true : false;
136 bool hasMax = params[7] ? true : false;
137 float min = sp_ctof(params[6]);
138 float max = sp_ctof(params[8]);
140 Handle_t hndl = g_ConVarManager.CreateConVar(pContext, name, defaultVal, helpText, params[4], hasMin, min, hasMax, max);
142 if (hndl == BAD_HANDLE)
144 return pContext->ThrowNativeError("Convar \"%s\" was not created. A console command with the same name already exists.", name);
150 static cell_t sm_FindConVar(IPluginContext *pContext, const cell_t *params)
154 pContext->LocalToString(params[1], &name);
156 return g_ConVarManager.FindConVar(name);
159 static cell_t sm_HookConVarChange(IPluginContext *pContext, const cell_t *params)
161 Handle_t hndl = static_cast<Handle_t>(params[1]);
165 if ((err=g_HandleSys.ReadHandle(hndl, g_ConVarManager.GetHandleType(), NULL, (void **)&pConVar))
168 return pContext->ThrowNativeError("Invalid convar handle %x (error %d)", hndl, err);
171 IPluginFunction *pFunction = pContext->GetFunctionById(params[2]);
175 return pContext->ThrowNativeError("Invalid function id (%X)", params[2]);
178 g_ConVarManager.HookConVarChange(pConVar, pFunction);
183 static cell_t sm_UnhookConVarChange(IPluginContext *pContext, const cell_t *params)
185 Handle_t hndl = static_cast<Handle_t>(params[1]);
189 if ((err=g_HandleSys.ReadHandle(hndl, g_ConVarManager.GetHandleType(), NULL, (void **)&pConVar))
192 return pContext->ThrowNativeError("Invalid convar handle %x (error %d)", hndl, err);
195 IPluginFunction *pFunction = pContext->GetFunctionById(params[2]);
199 return pContext->ThrowNativeError("Invalid function id (%X)", params[2]);
202 g_ConVarManager.UnhookConVarChange(pConVar, pFunction);
207 static cell_t sm_GetConVarBool(IPluginContext *pContext, const cell_t *params)
209 Handle_t hndl = static_cast<Handle_t>(params[1]);
213 if ((err=g_HandleSys.ReadHandle(hndl, g_ConVarManager.GetHandleType(), NULL, (void **)&pConVar))
216 return pContext->ThrowNativeError("Invalid convar handle %x (error %d)", hndl, err);
219 return pConVar->GetBool();
222 static cell_t sm_GetConVarInt(IPluginContext *pContext, const cell_t *params)
224 Handle_t hndl = static_cast<Handle_t>(params[1]);
228 if ((err=g_HandleSys.ReadHandle(hndl, g_ConVarManager.GetHandleType(), NULL, (void **)&pConVar))
231 return pContext->ThrowNativeError("Invalid convar handle %x (error %d)", hndl, err);
234 return pConVar->GetInt();
237 /* This handles both SetConVarBool() and SetConVarInt() */
238 static cell_t sm_SetConVarNum(IPluginContext *pContext, const cell_t *params)
240 Handle_t hndl = static_cast<Handle_t>(params[1]);
244 if ((err=g_HandleSys.ReadHandle(hndl, g_ConVarManager.GetHandleType(), NULL, (void **)&pConVar))
247 return pContext->ThrowNativeError("Invalid convar handle %x (error %d)", hndl, err);
250 pConVar->SetValue(params[2]);
252 /* Should we replicate it? */
253 if (params[3] && IsFlagSet(pConVar, FCVAR_REPLICATED))
255 ReplicateConVar(pConVar);
258 /* Should we notify clients? */
259 if (params[4] && IsFlagSet(pConVar, FCVAR_NOTIFY))
261 NotifyConVar(pConVar);
267 static cell_t sm_GetConVarFloat(IPluginContext *pContext, const cell_t *params)
269 Handle_t hndl = static_cast<Handle_t>(params[1]);
273 if ((err=g_HandleSys.ReadHandle(hndl, g_ConVarManager.GetHandleType(), NULL, (void **)&pConVar))
276 return pContext->ThrowNativeError("Invalid convar handle %x (error %d)", hndl, err);
279 float value = pConVar->GetFloat();
281 return sp_ftoc(value);
284 static cell_t sm_SetConVarFloat(IPluginContext *pContext, const cell_t *params)
286 Handle_t hndl = static_cast<Handle_t>(params[1]);
290 if ((err=g_HandleSys.ReadHandle(hndl, g_ConVarManager.GetHandleType(), NULL, (void **)&pConVar))
293 return pContext->ThrowNativeError("Invalid convar handle %x (error %d)", hndl, err);
296 float value = sp_ctof(params[2]);
297 pConVar->SetValue(value);
299 /* Should we replicate it? */
300 if (params[3] && IsFlagSet(pConVar, FCVAR_REPLICATED))
302 ReplicateConVar(pConVar);
305 /* Should we notify clients? */
306 if (params[4] && IsFlagSet(pConVar, FCVAR_NOTIFY))
308 NotifyConVar(pConVar);
314 static cell_t sm_GetConVarString(IPluginContext *pContext, const cell_t *params)
316 Handle_t hndl = static_cast<Handle_t>(params[1]);
320 if ((err=g_HandleSys.ReadHandle(hndl, g_ConVarManager.GetHandleType(), NULL, (void **)&pConVar))
323 return pContext->ThrowNativeError("Invalid convar handle %x (error %d)", hndl, err);
326 pContext->StringToLocalUTF8(params[2], params[3], pConVar->GetString(), NULL);
331 static cell_t sm_SetConVarString(IPluginContext *pContext, const cell_t *params)
333 Handle_t hndl = static_cast<Handle_t>(params[1]);
337 if ((err=g_HandleSys.ReadHandle(hndl, g_ConVarManager.GetHandleType(), NULL, (void **)&pConVar))
340 return pContext->ThrowNativeError("Invalid convar handle %x (error %d)", hndl, err);
344 pContext->LocalToString(params[2], &value);
346 pConVar->SetValue(value);
348 /* Should we replicate it? */
349 if (params[3] && IsFlagSet(pConVar, FCVAR_REPLICATED))
351 ReplicateConVar(pConVar);
354 /* Should we notify clients? */
355 if (params[4] && IsFlagSet(pConVar, FCVAR_NOTIFY))
357 NotifyConVar(pConVar);
363 static cell_t sm_ResetConVar(IPluginContext *pContext, const cell_t *params)
365 Handle_t hndl = static_cast<Handle_t>(params[1]);
369 if ((err=g_HandleSys.ReadHandle(hndl, g_ConVarManager.GetHandleType(), NULL, (void **)&pConVar))
372 return pContext->ThrowNativeError("Invalid convar handle %x (error %d)", hndl, err);
377 /* Should we replicate it? */
378 if (params[2] && IsFlagSet(pConVar, FCVAR_REPLICATED))
380 ReplicateConVar(pConVar);
383 /* Should we notify clients? */
384 if (params[3] && IsFlagSet(pConVar, FCVAR_NOTIFY))
386 NotifyConVar(pConVar);
392 static cell_t sm_GetConVarFlags(IPluginContext *pContext, const cell_t *params)
394 Handle_t hndl = static_cast<Handle_t>(params[1]);
398 if ((err=g_HandleSys.ReadHandle(hndl, g_ConVarManager.GetHandleType(), NULL, (void **)&pConVar))
401 return pContext->ThrowNativeError("Invalid convar handle %x (error %d)", hndl, err);
404 return pConVar->GetFlags();
407 static cell_t sm_SetConVarFlags(IPluginContext *pContext, const cell_t *params)
409 Handle_t hndl = static_cast<Handle_t>(params[1]);
413 if ((err=g_HandleSys.ReadHandle(hndl, g_ConVarManager.GetHandleType(), NULL, (void **)&pConVar))
416 return pContext->ThrowNativeError("Invalid convar handle %x (error %d)", hndl, err);
419 pConVar->SetFlags(params[2]);
424 static cell_t sm_GetConVarBounds(IPluginContext *pContext, const cell_t *params)
426 Handle_t hndl = static_cast<Handle_t>(params[1]);
430 if ((err=g_HandleSys.ReadHandle(hndl, g_ConVarManager.GetHandleType(), NULL, (void **)&pConVar))
433 return pContext->ThrowNativeError("Invalid convar handle %x (error %d)", hndl, err);
442 case ConVarBound_Upper:
443 hasBound = pConVar->GetMax(bound);
445 case ConVarBound_Lower:
446 hasBound = pConVar->GetMin(bound);
449 return pContext->ThrowNativeError("Invalid ConVarBounds value %d");
452 pContext->LocalToPhysAddr(params[3], &addr);
453 *addr = sp_ftoc(bound);
458 static cell_t sm_SetConVarBounds(IPluginContext *pContext, const cell_t *params)
460 Handle_t hndl = static_cast<Handle_t>(params[1]);
464 if ((err=g_HandleSys.ReadHandle(hndl, g_ConVarManager.GetHandleType(), NULL, (void **)&pConVar))
467 return pContext->ThrowNativeError("Invalid convar handle %x (error %d)", hndl, err);
472 case ConVarBound_Upper:
473 pConVar->SetMax(params[3] ? true : false, sp_ctof(params[4]));
475 case ConVarBound_Lower:
476 pConVar->SetMin(params[3] ? true : false, sp_ctof(params[4]));
479 return pContext->ThrowNativeError("Invalid ConVarBounds value %d");
485 static cell_t sm_GetConVarName(IPluginContext *pContext, const cell_t *params)
487 Handle_t hndl = static_cast<Handle_t>(params[1]);
491 if ((err=g_HandleSys.ReadHandle(hndl, g_ConVarManager.GetHandleType(), NULL, (void **)&pConVar))
494 return pContext->ThrowNativeError("Invalid convar handle %x (error %d)", hndl, err);
497 pContext->StringToLocalUTF8(params[2], params[3], pConVar->GetName(), NULL);
502 static bool s_QueryAlreadyWarned = false;
504 static cell_t sm_QueryClientConVar(IPluginContext *pContext, const cell_t *params)
508 IPluginFunction *pCallback;
510 if (g_IsOriginalEngine)
512 if (!s_QueryAlreadyWarned)
514 s_QueryAlreadyWarned = true;
515 return pContext->ThrowNativeError("Game does not support client convar querying (one time warning)");
521 pPlayer = g_Players.GetPlayerByIndex(params[1]);
525 return pContext->ThrowNativeError("Client index %d is invalid", params[1]);
528 if (!pPlayer->IsConnected())
530 return pContext->ThrowNativeError("Client %d is not connected", params[1]);
533 /* Trying a query on a bot results in callback not be fired, so don't bother */
534 if (pPlayer->IsFakeClient())
539 pContext->LocalToString(params[2], &name);
540 pCallback = pContext->GetFunctionById(params[3]);
544 return pContext->ThrowNativeError("Invalid function id (%X)", params[3]);
547 return g_ConVarManager.QueryClientConVar(pPlayer->GetEdict(), name, pCallback, params[4]);
550 static cell_t sm_RegServerCmd(IPluginContext *pContext, const cell_t *params)
553 IPluginFunction *pFunction;
555 pContext->LocalToString(params[1], &name);
556 pContext->LocalToString(params[3], &help);
557 pFunction = pContext->GetFunctionById(params[2]);
561 return pContext->ThrowNativeError("Invalid function id (%X)", params[2]);
564 if (!g_ConCmds.AddServerCommand(pFunction, name, help, params[4]))
566 return pContext->ThrowNativeError("Command \"%s\" could not be created. A convar with the same name already exists.", name);
572 static cell_t sm_RegConsoleCmd(IPluginContext *pContext, const cell_t *params)
575 IPluginFunction *pFunction;
577 pContext->LocalToString(params[1], &name);
578 pContext->LocalToString(params[3], &help);
579 pFunction = pContext->GetFunctionById(params[2]);
583 return pContext->ThrowNativeError("Invalid function id (%X)", params[2]);
586 if (!g_ConCmds.AddConsoleCommand(pFunction, name, help, params[4]))
588 return pContext->ThrowNativeError("Command \"%s\" could not be created. A convar with the same name already exists.", name);
594 static cell_t sm_RegAdminCmd(IPluginContext *pContext, const cell_t *params)
598 IPluginFunction *pFunction;
599 FlagBits flags = params[3];
600 int cmdflags = params[6];
602 pContext->LocalToString(params[1], &name);
603 pContext->LocalToString(params[4], &help);
604 pContext->LocalToString(params[5], (char **)&group);
605 pFunction = pContext->GetFunctionById(params[2]);
607 if (group[0] == '\0')
609 CPlugin *pPlugin = g_PluginSys.GetPluginByCtx(pContext->GetContext());
610 group = pPlugin->GetFilename();
615 return pContext->ThrowNativeError("Invalid function id (%X)", params[2]);
618 if (!g_ConCmds.AddAdminCommand(pFunction, name, group, flags, help, cmdflags))
620 return pContext->ThrowNativeError("Command \"%s\" could not be created. A convar with the same name already exists.", name);
626 static cell_t sm_GetCmdArgs(IPluginContext *pContext, const cell_t *params)
628 const CCommand *pCmd = g_HL2.PeekCommandStack();
632 return pContext->ThrowNativeError("No command callback available");
635 return pCmd->ArgC() - 1;
638 static cell_t sm_GetCmdArg(IPluginContext *pContext, const cell_t *params)
640 const CCommand *pCmd = g_HL2.PeekCommandStack();
644 return pContext->ThrowNativeError("No command callback available");
649 const char *arg = pCmd->Arg(params[1]);
651 pContext->StringToLocalUTF8(params[2], params[3], arg ? arg : "", &length);
653 return (cell_t)length;
656 static cell_t sm_GetCmdArgString(IPluginContext *pContext, const cell_t *params)
658 const CCommand *pCmd = g_HL2.PeekCommandStack();
662 return pContext->ThrowNativeError("No command callback available");
665 const char *args = pCmd->ArgS();
673 pContext->StringToLocalUTF8(params[1], params[2], args, &length);
675 return (cell_t)length;
678 static cell_t sm_PrintToServer(IPluginContext *pCtx, const cell_t *params)
684 pCtx->LocalToString(params[1], &fmt);
685 size_t res = atcprintf(buffer, sizeof(buffer)-2, fmt, pCtx, params, &arg);
687 buffer[res++] = '\n';
690 META_CONPRINT(buffer);
695 static cell_t sm_PrintToConsole(IPluginContext *pCtx, const cell_t *params)
697 int index = params[1];
698 if ((index < 0) || (index > g_Players.GetMaxClients()))
700 return pCtx->ThrowNativeError("Client index %d is invalid", index);
703 CPlayer *pPlayer = NULL;
706 pPlayer = g_Players.GetPlayerByIndex(index);
707 if (!pPlayer->IsInGame())
709 return pCtx->ThrowNativeError("Client %d is not in game", index);
712 /* Silent fail on bots, engine will crash */
713 if (pPlayer->IsFakeClient())
723 pCtx->LocalToString(params[2], &fmt);
724 size_t res = atcprintf(buffer, sizeof(buffer)-2, fmt, pCtx, params, &arg);
726 buffer[res++] = '\n';
731 engine->ClientPrintf(pPlayer->GetEdict(), buffer);
733 META_CONPRINT(buffer);
739 static cell_t sm_ServerCommand(IPluginContext *pContext, const cell_t *params)
741 g_SourceMod.SetGlobalTarget(LANG_SERVER);
744 size_t len = g_SourceMod.FormatString(buffer, sizeof(buffer)-2, pContext, params, 1);
746 if (pContext->GetContext()->n_err != SP_ERROR_NONE)
751 /* One byte for null terminator, one for newline */
752 buffer[len++] = '\n';
755 engine->ServerCommand(buffer);
760 static cell_t sm_InsertServerCommand(IPluginContext *pContext, const cell_t *params)
762 g_SourceMod.SetGlobalTarget(LANG_SERVER);
765 size_t len = g_SourceMod.FormatString(buffer, sizeof(buffer)-2, pContext, params, 1);
767 if (pContext->GetContext()->n_err != SP_ERROR_NONE)
772 /* One byte for null terminator, one for newline */
773 buffer[len++] = '\n';
776 InsertServerCommand(buffer);
781 static cell_t sm_ServerExecute(IPluginContext *pContext, const cell_t *params)
783 engine->ServerExecute();
788 static cell_t sm_ClientCommand(IPluginContext *pContext, const cell_t *params)
790 CPlayer *pPlayer = g_Players.GetPlayerByIndex(params[1]);
794 return pContext->ThrowNativeError("Client index %d is invalid", params[1]);
797 if (!pPlayer->IsConnected())
799 return pContext->ThrowNativeError("Client %d is not connected", params[1]);
802 g_SourceMod.SetGlobalTarget(params[1]);
805 g_SourceMod.FormatString(buffer, sizeof(buffer), pContext, params, 2);
807 if (pContext->GetContext()->n_err != SP_ERROR_NONE)
812 engine->ClientCommand(pPlayer->GetEdict(), "%s", buffer);
817 static cell_t FakeClientCommand(IPluginContext *pContext, const cell_t *params)
819 CPlayer *pPlayer = g_Players.GetPlayerByIndex(params[1]);
823 return pContext->ThrowNativeError("Client index %d is invalid", params[1]);
826 if (!pPlayer->IsConnected())
828 return pContext->ThrowNativeError("Client %d is not connected", params[1]);
832 g_SourceMod.FormatString(buffer, sizeof(buffer), pContext, params, 2);
834 if (pContext->GetContext()->n_err != SP_ERROR_NONE)
839 serverpluginhelpers->ClientCommand(pPlayer->GetEdict(), buffer);
844 static cell_t FakeClientCommandEx(IPluginContext *pContext, const cell_t *params)
846 CPlayer *pPlayer = g_Players.GetPlayerByIndex(params[1]);
850 return pContext->ThrowNativeError("Client index %d is invalid", params[1]);
853 if (!pPlayer->IsConnected())
855 return pContext->ThrowNativeError("Client %d is not connected", params[1]);
859 g_SourceMod.FormatString(buffer, sizeof(buffer), pContext, params, 2);
861 if (pContext->GetContext()->n_err != SP_ERROR_NONE)
866 g_HL2.AddToFakeCliCmdQueue(params[1], engine->GetPlayerUserId(pPlayer->GetEdict()), buffer);
871 static cell_t ReplyToCommand(IPluginContext *pContext, const cell_t *params)
873 g_SourceMod.SetGlobalTarget(params[1]);
875 /* Build the format string */
877 size_t len = g_SourceMod.FormatString(buffer, sizeof(buffer)-2, pContext, params, 2);
879 if (pContext->GetContext()->n_err != SP_ERROR_NONE)
884 /* If we're printing to the server, shortcut out */
888 buffer[len++] = '\n';
890 META_CONPRINT(buffer);
894 CPlayer *pPlayer = g_Players.GetPlayerByIndex(params[1]);
898 return pContext->ThrowNativeError("Client index %d is invalid", params[1]);
901 if (!pPlayer->IsConnected())
903 return pContext->ThrowNativeError("Client %d is not connected", params[1]);
906 g_SourceMod.SetGlobalTarget(params[1]);
908 unsigned int replyto = g_ChatTriggers.GetReplyTo();
909 if (replyto == SM_REPLY_CONSOLE)
911 buffer[len++] = '\n';
913 engine->ClientPrintf(pPlayer->GetEdict(), buffer);
914 } else if (replyto == SM_REPLY_CHAT) {
920 g_HL2.TextMsg(params[1], HUD_PRINTTALK, buffer);
926 static cell_t GetCmdReplyTarget(IPluginContext *pContext, const cell_t *params)
928 return g_ChatTriggers.GetReplyTo();
931 static cell_t SetCmdReplyTarget(IPluginContext *pContext, const cell_t *params)
933 return g_ChatTriggers.SetReplyTo(params[1]);
936 static cell_t GetCommandIterator(IPluginContext *pContext, const cell_t *params)
938 GlobCmdIter *iter = new GlobCmdIter;
939 iter->started = false;
941 Handle_t hndl = g_HandleSys.CreateHandle(hCmdIterType, iter, pContext->GetIdentity(), g_pCoreIdent, NULL);
942 if (hndl == BAD_HANDLE)
950 static cell_t ReadCommandIterator(IPluginContext *pContext, const cell_t *params)
954 HandleSecurity sec(pContext->GetIdentity(), g_pCoreIdent);
956 if ((err = g_HandleSys.ReadHandle(params[1], hCmdIterType, &sec, (void **)&iter))
959 return pContext->ThrowNativeError("Invalid GlobCmdIter Handle %x", params[1]);
962 const List<ConCmdInfo *> &cmds = g_ConCmds.GetCommandList();
966 iter->iter = cmds.begin();
967 iter->started = true;
970 while (iter->iter != cmds.end()
971 && !(*(iter->iter))->sourceMod)
976 if (iter->iter == cmds.end())
981 ConCmdInfo *pInfo = (*(iter->iter));
983 pContext->StringToLocalUTF8(params[2], params[3], pInfo->pCmd->GetName(), NULL);
984 pContext->StringToLocalUTF8(params[5], params[6], pInfo->pCmd->GetHelpText(), NULL);
987 pContext->LocalToPhysAddr(params[4], &addr);
988 *addr = pInfo->admin.eflags;
995 static cell_t CheckCommandAccess(IPluginContext *pContext, const cell_t *params)
1003 pContext->LocalToString(params[2], &cmd);
1005 /* Auto-detect a command if we can */
1006 FlagBits bits = params[3];
1007 bool found_command = false;
1008 if (params[0] < 4 || !params[4])
1010 found_command = g_ConCmds.LookForCommandAdminFlags(cmd, &bits);
1015 g_Admins.GetCommandOverride(cmd, Override_Command, &bits);
1018 return g_ConCmds.CheckCommandAccess(params[1], cmd, bits) ? 1 : 0;
1021 static cell_t IsChatTrigger(IPluginContext *pContext, const cell_t *params)
1023 return g_ChatTriggers.IsChatTrigger() ? 1 : 0;
1026 REGISTER_NATIVES(consoleNatives)
1028 {"CreateConVar", sm_CreateConVar},
1029 {"FindConVar", sm_FindConVar},
1030 {"HookConVarChange", sm_HookConVarChange},
1031 {"UnhookConVarChange", sm_UnhookConVarChange},
1032 {"GetConVarBool", sm_GetConVarBool},
1033 {"SetConVarBool", sm_SetConVarNum},
1034 {"GetConVarInt", sm_GetConVarInt},
1035 {"SetConVarInt", sm_SetConVarNum},
1036 {"GetConVarFloat", sm_GetConVarFloat},
1037 {"SetConVarFloat", sm_SetConVarFloat},
1038 {"GetConVarString", sm_GetConVarString},
1039 {"SetConVarString", sm_SetConVarString},
1040 {"GetConVarFlags", sm_GetConVarFlags},
1041 {"SetConVarFlags", sm_SetConVarFlags},
1042 {"ResetConVar", sm_ResetConVar},
1043 {"GetConVarName", sm_GetConVarName},
1044 {"GetConVarBounds", sm_GetConVarBounds},
1045 {"SetConVarBounds", sm_SetConVarBounds},
1046 {"QueryClientConVar", sm_QueryClientConVar},
1047 {"RegServerCmd", sm_RegServerCmd},
1048 {"RegConsoleCmd", sm_RegConsoleCmd},
1049 {"GetCmdArgString", sm_GetCmdArgString},
1050 {"GetCmdArgs", sm_GetCmdArgs},
1051 {"GetCmdArg", sm_GetCmdArg},
1052 {"PrintToServer", sm_PrintToServer},
1053 {"PrintToConsole", sm_PrintToConsole},
1054 {"RegAdminCmd", sm_RegAdminCmd},
1055 {"ServerCommand", sm_ServerCommand},
1056 {"InsertServerCommand", sm_InsertServerCommand},
1057 {"ServerExecute", sm_ServerExecute},
1058 {"ClientCommand", sm_ClientCommand},
1059 {"FakeClientCommand", FakeClientCommand},
1060 {"ReplyToCommand", ReplyToCommand},
1061 {"GetCmdReplySource", GetCmdReplyTarget},
1062 {"SetCmdReplySource", SetCmdReplyTarget},
1063 {"GetCommandIterator", GetCommandIterator},
1064 {"ReadCommandIterator", ReadCommandIterator},
1065 {"CheckCommandAccess", CheckCommandAccess},
1066 {"FakeClientCommandEx", FakeClientCommandEx},
1067 {"IsChatTrigger", IsChatTrigger},