The current map played shouldn't appear in MapChooser votes or RTV votes now. It can still be nominated in RTV though.
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>
45 #include <sm_trie_tpl.h>
47 #define NET_SETCONVAR 5
51 ConVarBound_Upper = 0,
55 HandleType_t hCmdIterType = 0;
60 List<ConCmdInfo *>::iterator iter;
63 class ConsoleHelpers :
65 public IHandleTypeDispatch
68 virtual void OnSourceModAllInitialized()
71 g_HandleSys.InitAccessDefaults(NULL, &access);
72 access.access[HandleAccess_Clone] = HANDLE_RESTRICT_OWNER | HANDLE_RESTRICT_IDENTITY;
74 hCmdIterType = g_HandleSys.CreateType(NULL, this, 0, NULL, &access, g_pCoreIdent, NULL);
76 virtual void OnHandleDestroy(HandleType_t type, void *object)
78 GlobCmdIter *iter = (GlobCmdIter *)object;
83 class CommandFlagsHelper : public IConCommandTracker
86 void OnUnlinkConCommandBase(ConCommandBase *pBase, const char *name, bool is_read_safe)
88 m_CmdFlags.remove(name);
90 bool GetFlags(const char *name, int *flags)
92 ConCommandBase **ppCmd;
94 if ((ppCmd=m_CmdFlags.retrieve(name)))
96 TrackConCommandBase((*ppCmd), this);
97 *flags = (*ppCmd)->GetFlags();
100 else if ((pCmd=FindConCommandBase(name)))
102 m_CmdFlags.insert(name, pCmd);
103 TrackConCommandBase(pCmd, this);
104 *flags = pCmd->GetFlags();
112 bool SetFlags(const char *name, int flags)
114 ConCommandBase **ppCmd;
115 ConCommandBase *pCmd;
116 if ((ppCmd=m_CmdFlags.retrieve(name)))
118 (*ppCmd)->SetFlags(flags);
119 TrackConCommandBase((*ppCmd), this);
122 else if ((pCmd=FindConCommandBase(name)))
124 m_CmdFlags.insert(name, pCmd);
125 pCmd->SetFlags(flags);
126 TrackConCommandBase(pCmd, this);
135 KTrie<ConCommandBase *> m_CmdFlags;
136 } s_CommandFlagsHelper;
138 static void ReplicateConVar(ConVar *pConVar)
140 int maxClients = g_Players.GetMaxClients();
143 bf_write buffer(data, sizeof(data));
145 buffer.WriteUBitLong(NET_SETCONVAR, 5);
147 buffer.WriteString(pConVar->GetName());
148 buffer.WriteString(pConVar->GetString());
150 for (int i = 1; i <= maxClients; i++)
152 CPlayer *pPlayer = g_Players.GetPlayerByIndex(i);
154 if (pPlayer && pPlayer->IsInGame() && !pPlayer->IsFakeClient())
156 INetChannel *netchan = static_cast<INetChannel *>(engine->GetPlayerNetInfo(i));
157 netchan->SendData(buffer);
162 static void NotifyConVar(ConVar *pConVar)
164 IGameEvent *pEvent = gameevents->CreateEvent("server_cvar");
165 pEvent->SetString("cvarname", pConVar->GetName());
166 if (IsFlagSet(pConVar, FCVAR_PROTECTED))
168 pEvent->SetString("cvarvalue", "***PROTECTED***");
172 pEvent->SetString("cvarvalue", pConVar->GetString());
175 gameevents->FireEvent(pEvent);
178 static cell_t sm_CreateConVar(IPluginContext *pContext, const cell_t *params)
180 char *name, *defaultVal, *helpText;
182 pContext->LocalToString(params[1], &name);
184 // While the engine seems to accept a blank convar name, it causes a crash upon server quit
185 if (name == NULL || strcmp(name, "") == 0)
187 return pContext->ThrowNativeError("Convar with blank name is not permitted");
190 pContext->LocalToString(params[2], &defaultVal);
191 pContext->LocalToString(params[3], &helpText);
193 bool hasMin = params[5] ? true : false;
194 bool hasMax = params[7] ? true : false;
195 float min = sp_ctof(params[6]);
196 float max = sp_ctof(params[8]);
198 Handle_t hndl = g_ConVarManager.CreateConVar(pContext, name, defaultVal, helpText, params[4], hasMin, min, hasMax, max);
200 if (hndl == BAD_HANDLE)
202 return pContext->ThrowNativeError("Convar \"%s\" was not created. A console command with the same might already exist.", name);
208 static cell_t sm_FindConVar(IPluginContext *pContext, const cell_t *params)
212 pContext->LocalToString(params[1], &name);
214 return g_ConVarManager.FindConVar(name);
217 static cell_t sm_HookConVarChange(IPluginContext *pContext, const cell_t *params)
219 Handle_t hndl = static_cast<Handle_t>(params[1]);
223 if ((err=g_ConVarManager.ReadConVarHandle(hndl, &pConVar))
226 return pContext->ThrowNativeError("Invalid convar handle %x (error %d)", hndl, err);
229 IPluginFunction *pFunction = pContext->GetFunctionById(params[2]);
233 return pContext->ThrowNativeError("Invalid function id (%X)", params[2]);
236 g_ConVarManager.HookConVarChange(pConVar, pFunction);
241 static cell_t sm_UnhookConVarChange(IPluginContext *pContext, const cell_t *params)
243 Handle_t hndl = static_cast<Handle_t>(params[1]);
247 if ((err=g_ConVarManager.ReadConVarHandle(hndl, &pConVar))
250 return pContext->ThrowNativeError("Invalid convar handle %x (error %d)", hndl, err);
253 IPluginFunction *pFunction = pContext->GetFunctionById(params[2]);
257 return pContext->ThrowNativeError("Invalid function id (%X)", params[2]);
260 g_ConVarManager.UnhookConVarChange(pConVar, pFunction);
265 static cell_t sm_GetConVarBool(IPluginContext *pContext, const cell_t *params)
267 Handle_t hndl = static_cast<Handle_t>(params[1]);
271 if ((err=g_ConVarManager.ReadConVarHandle(hndl, &pConVar))
274 return pContext->ThrowNativeError("Invalid convar handle %x (error %d)", hndl, err);
277 return pConVar->GetBool();
280 static cell_t sm_GetConVarInt(IPluginContext *pContext, const cell_t *params)
282 Handle_t hndl = static_cast<Handle_t>(params[1]);
286 if ((err=g_ConVarManager.ReadConVarHandle(hndl, &pConVar))
289 return pContext->ThrowNativeError("Invalid convar handle %x (error %d)", hndl, err);
292 return pConVar->GetInt();
295 /* This handles both SetConVarBool() and SetConVarInt() */
296 static cell_t sm_SetConVarNum(IPluginContext *pContext, const cell_t *params)
298 Handle_t hndl = static_cast<Handle_t>(params[1]);
302 if ((err=g_ConVarManager.ReadConVarHandle(hndl, &pConVar))
305 return pContext->ThrowNativeError("Invalid convar handle %x (error %d)", hndl, err);
308 pConVar->SetValue(params[2]);
310 /* Should we replicate it? */
311 if (params[3] && IsFlagSet(pConVar, FCVAR_REPLICATED))
313 ReplicateConVar(pConVar);
316 /* Should we notify clients? */
317 if (params[4] && IsFlagSet(pConVar, FCVAR_NOTIFY))
319 NotifyConVar(pConVar);
325 static cell_t sm_GetConVarFloat(IPluginContext *pContext, const cell_t *params)
327 Handle_t hndl = static_cast<Handle_t>(params[1]);
331 if ((err=g_ConVarManager.ReadConVarHandle(hndl, &pConVar))
334 return pContext->ThrowNativeError("Invalid convar handle %x (error %d)", hndl, err);
337 float value = pConVar->GetFloat();
339 return sp_ftoc(value);
342 static cell_t sm_SetConVarFloat(IPluginContext *pContext, const cell_t *params)
344 Handle_t hndl = static_cast<Handle_t>(params[1]);
348 if ((err=g_ConVarManager.ReadConVarHandle(hndl, &pConVar))
351 return pContext->ThrowNativeError("Invalid convar handle %x (error %d)", hndl, err);
354 float value = sp_ctof(params[2]);
355 pConVar->SetValue(value);
357 /* Should we replicate it? */
358 if (params[3] && IsFlagSet(pConVar, FCVAR_REPLICATED))
360 ReplicateConVar(pConVar);
363 /* Should we notify clients? */
364 if (params[4] && IsFlagSet(pConVar, FCVAR_NOTIFY))
366 NotifyConVar(pConVar);
372 static cell_t sm_GetConVarString(IPluginContext *pContext, const cell_t *params)
374 Handle_t hndl = static_cast<Handle_t>(params[1]);
378 if ((err=g_ConVarManager.ReadConVarHandle(hndl, &pConVar))
381 return pContext->ThrowNativeError("Invalid convar handle %x (error %d)", hndl, err);
384 pContext->StringToLocalUTF8(params[2], params[3], pConVar->GetString(), NULL);
389 static cell_t sm_SetConVarString(IPluginContext *pContext, const cell_t *params)
391 Handle_t hndl = static_cast<Handle_t>(params[1]);
395 if ((err=g_ConVarManager.ReadConVarHandle(hndl, &pConVar))
398 return pContext->ThrowNativeError("Invalid convar handle %x (error %d)", hndl, err);
402 pContext->LocalToString(params[2], &value);
404 pConVar->SetValue(value);
406 /* Should we replicate it? */
407 if (params[3] && IsFlagSet(pConVar, FCVAR_REPLICATED))
409 ReplicateConVar(pConVar);
412 /* Should we notify clients? */
413 if (params[4] && IsFlagSet(pConVar, FCVAR_NOTIFY))
415 NotifyConVar(pConVar);
421 static cell_t sm_ResetConVar(IPluginContext *pContext, const cell_t *params)
423 Handle_t hndl = static_cast<Handle_t>(params[1]);
427 if ((err=g_ConVarManager.ReadConVarHandle(hndl, &pConVar))
430 return pContext->ThrowNativeError("Invalid convar handle %x (error %d)", hndl, err);
435 /* Should we replicate it? */
436 if (params[2] && IsFlagSet(pConVar, FCVAR_REPLICATED))
438 ReplicateConVar(pConVar);
441 /* Should we notify clients? */
442 if (params[3] && IsFlagSet(pConVar, FCVAR_NOTIFY))
444 NotifyConVar(pConVar);
450 static cell_t sm_GetConVarFlags(IPluginContext *pContext, const cell_t *params)
452 Handle_t hndl = static_cast<Handle_t>(params[1]);
456 if ((err=g_ConVarManager.ReadConVarHandle(hndl, &pConVar))
459 return pContext->ThrowNativeError("Invalid convar handle %x (error %d)", hndl, err);
462 return pConVar->GetFlags();
465 static cell_t sm_SetConVarFlags(IPluginContext *pContext, const cell_t *params)
467 Handle_t hndl = static_cast<Handle_t>(params[1]);
471 if ((err=g_ConVarManager.ReadConVarHandle(hndl, &pConVar))
474 return pContext->ThrowNativeError("Invalid convar handle %x (error %d)", hndl, err);
477 pConVar->SetFlags(params[2]);
482 static cell_t sm_GetConVarBounds(IPluginContext *pContext, const cell_t *params)
484 Handle_t hndl = static_cast<Handle_t>(params[1]);
488 if ((err=g_ConVarManager.ReadConVarHandle(hndl, &pConVar))
491 return pContext->ThrowNativeError("Invalid convar handle %x (error %d)", hndl, err);
500 case ConVarBound_Upper:
501 hasBound = pConVar->GetMax(bound);
503 case ConVarBound_Lower:
504 hasBound = pConVar->GetMin(bound);
507 return pContext->ThrowNativeError("Invalid ConVarBounds value %d");
510 pContext->LocalToPhysAddr(params[3], &addr);
511 *addr = sp_ftoc(bound);
516 static cell_t sm_SetConVarBounds(IPluginContext *pContext, const cell_t *params)
518 Handle_t hndl = static_cast<Handle_t>(params[1]);
522 if ((err=g_ConVarManager.ReadConVarHandle(hndl, &pConVar))
525 return pContext->ThrowNativeError("Invalid convar handle %x (error %d)", hndl, err);
530 case ConVarBound_Upper:
531 pConVar->SetMax(params[3] ? true : false, sp_ctof(params[4]));
533 case ConVarBound_Lower:
534 pConVar->SetMin(params[3] ? true : false, sp_ctof(params[4]));
537 return pContext->ThrowNativeError("Invalid ConVarBounds value %d");
543 static cell_t sm_GetConVarName(IPluginContext *pContext, const cell_t *params)
545 Handle_t hndl = static_cast<Handle_t>(params[1]);
549 if ((err=g_ConVarManager.ReadConVarHandle(hndl, &pConVar))
552 return pContext->ThrowNativeError("Invalid convar handle %x (error %d)", hndl, err);
555 pContext->StringToLocalUTF8(params[2], params[3], pConVar->GetName(), NULL);
560 static bool s_QueryAlreadyWarned = false;
562 static cell_t sm_QueryClientConVar(IPluginContext *pContext, const cell_t *params)
566 IPluginFunction *pCallback;
568 if (!g_ConVarManager.IsQueryingSupported())
570 if (!s_QueryAlreadyWarned)
572 s_QueryAlreadyWarned = true;
573 return pContext->ThrowNativeError("Game does not support client convar querying (one time warning)");
579 pPlayer = g_Players.GetPlayerByIndex(params[1]);
583 return pContext->ThrowNativeError("Client index %d is invalid", params[1]);
586 if (!pPlayer->IsConnected())
588 return pContext->ThrowNativeError("Client %d is not connected", params[1]);
591 /* Trying a query on a bot results in callback not be fired, so don't bother */
592 if (pPlayer->IsFakeClient())
597 pContext->LocalToString(params[2], &name);
598 pCallback = pContext->GetFunctionById(params[3]);
602 return pContext->ThrowNativeError("Invalid function id (%X)", params[3]);
605 return g_ConVarManager.QueryClientConVar(pPlayer->GetEdict(), name, pCallback, params[4]);
608 static cell_t sm_RegServerCmd(IPluginContext *pContext, const cell_t *params)
611 IPluginFunction *pFunction;
613 pContext->LocalToString(params[1], &name);
614 pContext->LocalToString(params[3], &help);
615 pFunction = pContext->GetFunctionById(params[2]);
619 return pContext->ThrowNativeError("Invalid function id (%X)", params[2]);
622 if (!g_ConCmds.AddServerCommand(pFunction, name, help, params[4]))
624 return pContext->ThrowNativeError("Command \"%s\" could not be created. A convar with the same name already exists.", name);
630 static cell_t sm_RegConsoleCmd(IPluginContext *pContext, const cell_t *params)
633 IPluginFunction *pFunction;
635 pContext->LocalToString(params[1], &name);
636 pContext->LocalToString(params[3], &help);
637 pFunction = pContext->GetFunctionById(params[2]);
641 return pContext->ThrowNativeError("Invalid function id (%X)", params[2]);
644 if (!g_ConCmds.AddConsoleCommand(pFunction, name, help, params[4]))
646 return pContext->ThrowNativeError("Command \"%s\" could not be created. A convar with the same name already exists.", name);
652 static cell_t sm_RegAdminCmd(IPluginContext *pContext, const cell_t *params)
656 IPluginFunction *pFunction;
657 FlagBits flags = params[3];
658 int cmdflags = params[6];
660 pContext->LocalToString(params[1], &name);
661 pContext->LocalToString(params[4], &help);
662 pContext->LocalToString(params[5], (char **)&group);
663 pFunction = pContext->GetFunctionById(params[2]);
665 if (group[0] == '\0')
667 CPlugin *pPlugin = g_PluginSys.GetPluginByCtx(pContext->GetContext());
668 group = pPlugin->GetFilename();
673 return pContext->ThrowNativeError("Invalid function id (%X)", params[2]);
676 if (!g_ConCmds.AddAdminCommand(pFunction, name, group, flags, help, cmdflags))
678 return pContext->ThrowNativeError("Command \"%s\" could not be created. A convar with the same name already exists.", name);
684 static cell_t sm_GetCmdArgs(IPluginContext *pContext, const cell_t *params)
686 const CCommand *pCmd = g_HL2.PeekCommandStack();
690 return pContext->ThrowNativeError("No command callback available");
693 return pCmd->ArgC() - 1;
696 static cell_t sm_GetCmdArg(IPluginContext *pContext, const cell_t *params)
698 const CCommand *pCmd = g_HL2.PeekCommandStack();
702 return pContext->ThrowNativeError("No command callback available");
707 const char *arg = pCmd->Arg(params[1]);
709 pContext->StringToLocalUTF8(params[2], params[3], arg ? arg : "", &length);
711 return (cell_t)length;
714 static cell_t sm_GetCmdArgString(IPluginContext *pContext, const cell_t *params)
716 const CCommand *pCmd = g_HL2.PeekCommandStack();
720 return pContext->ThrowNativeError("No command callback available");
723 const char *args = pCmd->ArgS();
731 pContext->StringToLocalUTF8(params[1], params[2], args, &length);
733 return (cell_t)length;
736 static cell_t sm_PrintToServer(IPluginContext *pCtx, const cell_t *params)
742 pCtx->LocalToString(params[1], &fmt);
743 size_t res = atcprintf(buffer, sizeof(buffer)-2, fmt, pCtx, params, &arg);
745 buffer[res++] = '\n';
748 META_CONPRINT(buffer);
753 static cell_t sm_PrintToConsole(IPluginContext *pCtx, const cell_t *params)
755 int index = params[1];
756 if ((index < 0) || (index > g_Players.GetMaxClients()))
758 return pCtx->ThrowNativeError("Client index %d is invalid", index);
761 CPlayer *pPlayer = NULL;
764 pPlayer = g_Players.GetPlayerByIndex(index);
765 if (!pPlayer->IsInGame())
767 return pCtx->ThrowNativeError("Client %d is not in game", index);
770 /* Silent fail on bots, engine will crash */
771 if (pPlayer->IsFakeClient())
781 pCtx->LocalToString(params[2], &fmt);
782 size_t res = atcprintf(buffer, sizeof(buffer)-2, fmt, pCtx, params, &arg);
784 buffer[res++] = '\n';
789 engine->ClientPrintf(pPlayer->GetEdict(), buffer);
791 META_CONPRINT(buffer);
797 static cell_t sm_ServerCommand(IPluginContext *pContext, const cell_t *params)
799 g_SourceMod.SetGlobalTarget(LANG_SERVER);
802 size_t len = g_SourceMod.FormatString(buffer, sizeof(buffer)-2, pContext, params, 1);
804 if (pContext->GetContext()->n_err != SP_ERROR_NONE)
809 /* One byte for null terminator, one for newline */
810 buffer[len++] = '\n';
813 engine->ServerCommand(buffer);
818 static cell_t sm_InsertServerCommand(IPluginContext *pContext, const cell_t *params)
820 g_SourceMod.SetGlobalTarget(LANG_SERVER);
823 size_t len = g_SourceMod.FormatString(buffer, sizeof(buffer)-2, pContext, params, 1);
825 if (pContext->GetContext()->n_err != SP_ERROR_NONE)
830 /* One byte for null terminator, one for newline */
831 buffer[len++] = '\n';
834 InsertServerCommand(buffer);
839 static cell_t sm_ServerExecute(IPluginContext *pContext, const cell_t *params)
841 engine->ServerExecute();
846 static cell_t sm_ClientCommand(IPluginContext *pContext, const cell_t *params)
848 CPlayer *pPlayer = g_Players.GetPlayerByIndex(params[1]);
852 return pContext->ThrowNativeError("Client index %d is invalid", params[1]);
855 if (!pPlayer->IsConnected())
857 return pContext->ThrowNativeError("Client %d is not connected", params[1]);
860 g_SourceMod.SetGlobalTarget(params[1]);
863 g_SourceMod.FormatString(buffer, sizeof(buffer), pContext, params, 2);
865 if (pContext->GetContext()->n_err != SP_ERROR_NONE)
870 engine->ClientCommand(pPlayer->GetEdict(), "%s", buffer);
875 static cell_t FakeClientCommand(IPluginContext *pContext, const cell_t *params)
877 CPlayer *pPlayer = g_Players.GetPlayerByIndex(params[1]);
881 return pContext->ThrowNativeError("Client index %d is invalid", params[1]);
884 if (!pPlayer->IsConnected())
886 return pContext->ThrowNativeError("Client %d is not connected", params[1]);
890 g_SourceMod.FormatString(buffer, sizeof(buffer), pContext, params, 2);
892 if (pContext->GetContext()->n_err != SP_ERROR_NONE)
897 serverpluginhelpers->ClientCommand(pPlayer->GetEdict(), buffer);
902 static cell_t FakeClientCommandEx(IPluginContext *pContext, const cell_t *params)
904 CPlayer *pPlayer = g_Players.GetPlayerByIndex(params[1]);
908 return pContext->ThrowNativeError("Client index %d is invalid", params[1]);
911 if (!pPlayer->IsConnected())
913 return pContext->ThrowNativeError("Client %d is not connected", params[1]);
917 g_SourceMod.FormatString(buffer, sizeof(buffer), pContext, params, 2);
919 if (pContext->GetContext()->n_err != SP_ERROR_NONE)
924 g_HL2.AddToFakeCliCmdQueue(params[1], engine->GetPlayerUserId(pPlayer->GetEdict()), buffer);
929 static cell_t ReplyToCommand(IPluginContext *pContext, const cell_t *params)
931 g_SourceMod.SetGlobalTarget(params[1]);
933 /* Build the format string */
935 size_t len = g_SourceMod.FormatString(buffer, sizeof(buffer)-2, pContext, params, 2);
937 if (pContext->GetContext()->n_err != SP_ERROR_NONE)
942 /* If we're printing to the server, shortcut out */
946 buffer[len++] = '\n';
948 META_CONPRINT(buffer);
952 CPlayer *pPlayer = g_Players.GetPlayerByIndex(params[1]);
956 return pContext->ThrowNativeError("Client index %d is invalid", params[1]);
959 if (!pPlayer->IsConnected())
961 return pContext->ThrowNativeError("Client %d is not connected", params[1]);
964 g_SourceMod.SetGlobalTarget(params[1]);
966 unsigned int replyto = g_ChatTriggers.GetReplyTo();
967 if (replyto == SM_REPLY_CONSOLE)
969 buffer[len++] = '\n';
971 engine->ClientPrintf(pPlayer->GetEdict(), buffer);
972 } else if (replyto == SM_REPLY_CHAT) {
978 g_HL2.TextMsg(params[1], HUD_PRINTTALK, buffer);
984 static cell_t GetCmdReplyTarget(IPluginContext *pContext, const cell_t *params)
986 return g_ChatTriggers.GetReplyTo();
989 static cell_t SetCmdReplyTarget(IPluginContext *pContext, const cell_t *params)
991 return g_ChatTriggers.SetReplyTo(params[1]);
994 static cell_t GetCommandIterator(IPluginContext *pContext, const cell_t *params)
996 GlobCmdIter *iter = new GlobCmdIter;
997 iter->started = false;
999 Handle_t hndl = g_HandleSys.CreateHandle(hCmdIterType, iter, pContext->GetIdentity(), g_pCoreIdent, NULL);
1000 if (hndl == BAD_HANDLE)
1008 static cell_t ReadCommandIterator(IPluginContext *pContext, const cell_t *params)
1012 HandleSecurity sec(pContext->GetIdentity(), g_pCoreIdent);
1014 if ((err = g_HandleSys.ReadHandle(params[1], hCmdIterType, &sec, (void **)&iter))
1015 != HandleError_None)
1017 return pContext->ThrowNativeError("Invalid GlobCmdIter Handle %x", params[1]);
1020 const List<ConCmdInfo *> &cmds = g_ConCmds.GetCommandList();
1024 iter->iter = cmds.begin();
1025 iter->started = true;
1028 while (iter->iter != cmds.end()
1029 && !(*(iter->iter))->sourceMod)
1034 if (iter->iter == cmds.end())
1039 ConCmdInfo *pInfo = (*(iter->iter));
1041 pContext->StringToLocalUTF8(params[2], params[3], pInfo->pCmd->GetName(), NULL);
1042 pContext->StringToLocalUTF8(params[5], params[6], pInfo->pCmd->GetHelpText(), NULL);
1045 pContext->LocalToPhysAddr(params[4], &addr);
1046 *addr = pInfo->admin.eflags;
1053 static cell_t CheckCommandAccess(IPluginContext *pContext, const cell_t *params)
1061 pContext->LocalToString(params[2], &cmd);
1063 /* Auto-detect a command if we can */
1064 FlagBits bits = params[3];
1065 bool found_command = false;
1066 if (params[0] < 4 || !params[4])
1068 found_command = g_ConCmds.LookForCommandAdminFlags(cmd, &bits);
1073 g_Admins.GetCommandOverride(cmd, Override_Command, &bits);
1076 return g_ConCmds.CheckCommandAccess(params[1], cmd, bits) ? 1 : 0;
1079 static cell_t IsChatTrigger(IPluginContext *pContext, const cell_t *params)
1081 return g_ChatTriggers.IsChatTrigger() ? 1 : 0;
1084 static cell_t SetCommandFlags(IPluginContext *pContext, const cell_t *params)
1087 pContext->LocalToString(params[1], &name);
1089 return (s_CommandFlagsHelper.SetFlags(name, params[2])) ? 1 : 0;
1092 static cell_t GetCommandFlags(IPluginContext *pContext, const cell_t *params)
1096 pContext->LocalToString(params[1], &name);
1098 return (s_CommandFlagsHelper.GetFlags(name, &flags)) ? flags : -1;
1101 REGISTER_NATIVES(consoleNatives)
1103 {"CreateConVar", sm_CreateConVar},
1104 {"FindConVar", sm_FindConVar},
1105 {"HookConVarChange", sm_HookConVarChange},
1106 {"UnhookConVarChange", sm_UnhookConVarChange},
1107 {"GetConVarBool", sm_GetConVarBool},
1108 {"SetConVarBool", sm_SetConVarNum},
1109 {"GetConVarInt", sm_GetConVarInt},
1110 {"SetConVarInt", sm_SetConVarNum},
1111 {"GetConVarFloat", sm_GetConVarFloat},
1112 {"SetConVarFloat", sm_SetConVarFloat},
1113 {"GetConVarString", sm_GetConVarString},
1114 {"SetConVarString", sm_SetConVarString},
1115 {"GetConVarFlags", sm_GetConVarFlags},
1116 {"SetConVarFlags", sm_SetConVarFlags},
1117 {"ResetConVar", sm_ResetConVar},
1118 {"GetConVarName", sm_GetConVarName},
1119 {"GetConVarBounds", sm_GetConVarBounds},
1120 {"SetConVarBounds", sm_SetConVarBounds},
1121 {"QueryClientConVar", sm_QueryClientConVar},
1122 {"RegServerCmd", sm_RegServerCmd},
1123 {"RegConsoleCmd", sm_RegConsoleCmd},
1124 {"GetCmdArgString", sm_GetCmdArgString},
1125 {"GetCmdArgs", sm_GetCmdArgs},
1126 {"GetCmdArg", sm_GetCmdArg},
1127 {"PrintToServer", sm_PrintToServer},
1128 {"PrintToConsole", sm_PrintToConsole},
1129 {"RegAdminCmd", sm_RegAdminCmd},
1130 {"ServerCommand", sm_ServerCommand},
1131 {"InsertServerCommand", sm_InsertServerCommand},
1132 {"ServerExecute", sm_ServerExecute},
1133 {"ClientCommand", sm_ClientCommand},
1134 {"FakeClientCommand", FakeClientCommand},
1135 {"ReplyToCommand", ReplyToCommand},
1136 {"GetCmdReplySource", GetCmdReplyTarget},
1137 {"SetCmdReplySource", SetCmdReplyTarget},
1138 {"GetCommandIterator", GetCommandIterator},
1139 {"ReadCommandIterator", ReadCommandIterator},
1140 {"CheckCommandAccess", CheckCommandAccess},
1141 {"FakeClientCommandEx", FakeClientCommandEx},
1142 {"IsChatTrigger", IsChatTrigger},
1143 {"SetCommandFlags", SetCommandFlags},
1144 {"GetCommandFlags", GetCommandFlags},