Skip to content

Commit fc2bb77

Browse files
committed
fix console being unable to execute, fix being unable to execute in client console
1 parent 23ddec2 commit fc2bb77

File tree

3 files changed

+15
-7
lines changed

3 files changed

+15
-7
lines changed

src/admin/admin_manager.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,11 @@ bool CS2AAdminManager::PlayerHasFlag(int slot, uint32_t flag)
220220
bool CS2AAdminManager::CanPlayerUseCommand(int slot, const char *commandName,
221221
const char *commandGroup, uint32_t defaultFlag)
222222
{
223-
if (slot < 0 || slot > MAXPLAYERS)
223+
// Server console always has full access
224+
if (slot < 0)
225+
return true;
226+
227+
if (slot > MAXPLAYERS)
224228
return false;
225229

226230
if (!m_playerHasAdmin[slot])

src/command/command_system.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1287,11 +1287,14 @@ static void ConsoleCommandCallback(const CCommandContext &context, const CComman
12871287
for (int i = 1; i < args.ArgC(); i++)
12881288
cmdArgs.push_back(args[i]);
12891289

1290-
// Dispatch with slot = -1 (server console), silent = false
1291-
g_CS2ACommandSystem.DispatchConsoleCommand(cmdName, cmdArgs);
1290+
// Use the player slot from the command context (-1 for server console)
1291+
int slot = context.GetPlayerSlot().Get();
1292+
1293+
// Dispatch with the caller's slot, silent = false
1294+
g_CS2ACommandSystem.DispatchConsoleCommand(cmdName, cmdArgs, slot);
12921295
}
12931296

1294-
void CS2ACommandSystem::DispatchConsoleCommand(const char *cmdName, const std::vector<std::string> &args)
1297+
void CS2ACommandSystem::DispatchConsoleCommand(const char *cmdName, const std::vector<std::string> &args, int slot)
12951298
{
12961299
std::string lower(cmdName);
12971300
std::transform(lower.begin(), lower.end(), lower.begin(),
@@ -1304,7 +1307,7 @@ void CS2ACommandSystem::DispatchConsoleCommand(const char *cmdName, const std::v
13041307
return;
13051308
}
13061309

1307-
it->second(-1, args, false);
1310+
it->second(slot, args, false);
13081311
}
13091312

13101313
void CS2ACommandSystem::RegisterConsoleCommands()
@@ -1321,6 +1324,6 @@ void CS2ACommandSystem::RegisterConsoleCommands()
13211324
for (auto &entry : m_consoleCommands)
13221325
{
13231326
entry.cmd = new ConCommand(entry.name.c_str(), ConsoleCommandCallback,
1324-
entry.desc.c_str(), FCVAR_NONE);
1327+
entry.desc.c_str(), FCVAR_CLIENT_CAN_EXECUTE);
13251328
}
13261329
}

src/command/command_system.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ class CS2ACommandSystem
3838
// Dispatch a console command to the matching chat command handler.
3939
// cmdName = command name without "mm_" prefix (e.g. "who").
4040
// args = parsed arguments (excluding command name).
41-
void DispatchConsoleCommand(const char *cmdName, const std::vector<std::string> &args);
41+
// slot = player slot (-1 for server console).
42+
void DispatchConsoleCommand(const char *cmdName, const std::vector<std::string> &args, int slot);
4243

4344
// Check if a gagged player should have their message blocked.
4445
bool ShouldBlockChat(int slot);

0 commit comments

Comments
 (0)