+/*
+ * Cloudwalk FIXME: This idea sounded great in my head but...
+ * How do we handle commands that can be received by the client,
+ * but which the server can also execute locally?
+ *
+ * If we create a callback where the engine will forward to server
+ * but try to execute the command locally if it's dedicated,
+ * we're back to intermixing client and server code which I'm
+ * trying to avoid. There's no other way I can think of to
+ * implement that behavior that doesn't involve an #ifdef, or
+ * making a mess of hooks.
+ */
+qbool Cmd_Callback(cmd_state_t *cmd, cmd_function_t *func, const char *text, cmd_source_t src)
+{
+ if (func->function)
+ func->function(cmd);
+ else
+ Con_Printf("Command \"%s\" can not be executed\n", Cmd_Argv(cmd, 0));
+ return true;
+}
+
+qbool Cmd_CL_Callback(cmd_state_t *cmd, cmd_function_t *func, const char *text, cmd_source_t src)
+{
+ // TODO: Assign these functions to QC commands directly?
+ if(func->qcfunc)
+ {
+ if(((func->flags & CF_CLIENT) && CL_VM_ConsoleCommand(text)) ||
+ ((func->flags & CF_SERVER) && SV_VM_ConsoleCommand(text)))
+ return true;
+
+ if (func->overridden) // If this QC command overrides an engine command,
+ func = func->overridden; // fall back to that command.
+ }
+ if (func->flags & CF_SERVER_FROM_CLIENT)
+ {
+ if(host_isclient.integer)
+ {
+ CL_ForwardToServer_f(cmd);
+ return true;
+ }
+ else if(!(func->flags & CF_SERVER))
+ {
+ Con_Printf("Cannot execute client commands from a dedicated server console.\n");
+ return true;
+ }
+ }
+ return Cmd_Callback(cmd, func, text, src);
+}
+
+qbool Cmd_SV_Callback(cmd_state_t *cmd, cmd_function_t *func, const char *text, cmd_source_t src)
+{
+ if(func->qcfunc && (func->flags & CF_SERVER))
+ return SV_VM_ConsoleCommand(text);
+ else if (src == src_client)
+ {
+ if((func->flags & CF_CHEAT) && !sv_cheats.integer)
+ SV_ClientPrintf("No cheats allowed. The server must have sv_cheats set to 1\n");
+ else
+ func->function(cmd);
+ return true;
+ }
+ return false;
+}
+
+qbool Cmd_SV_NotFound(cmd_state_t *cmd, cmd_function_t *func, const char *text, cmd_source_t src)
+{
+ if (cmd->source == src_client)
+ {
+ Con_Printf("Client \"%s\" tried to execute \"%s\"\n", host_client->name, text);
+ return true;
+ }
+ return false;
+}