]> git.rm.cloudns.org Git - xonotic/darkplaces.git/commitdiff
cmd: add CON_WARN colour to various non-fatal cvar and command errors
authorbones_was_here <bones_was_here@xonotic.au>
Sun, 10 Dec 2023 10:32:16 +0000 (20:32 +1000)
committerbones_was_here <bones_was_here@xonotic.au>
Mon, 11 Dec 2023 15:32:12 +0000 (01:32 +1000)
Signed-off-by: bones_was_here <bones_was_here@xonotic.au>
cmd.c
cvar.c

diff --git a/cmd.c b/cmd.c
index e1e2c0a0dcfd5ce2236063875dddfaa3d96f42fe..c73a7c6e1c2efbdbdb8107a65ed4af45599bff06 100644 (file)
--- a/cmd.c
+++ b/cmd.c
@@ -312,7 +312,7 @@ void Cbuf_AddText (cmd_state_t *cmd, const char *text)
        Cbuf_Lock(cbuf);
 
        if (cbuf->maxsize - cbuf->size <= l)
-               Con_Print("Cbuf_AddText: overflow\n");
+               Con_Print(CON_WARN "Cbuf_AddText: overflow\n");
        else
        {
                // If the string terminates but the (last) line doesn't, the node will be left in the pending state (to be continued).
@@ -338,7 +338,7 @@ void Cbuf_InsertText (cmd_state_t *cmd, const char *text)
        Cbuf_Lock(cbuf);
 
        if (cbuf->size + l >= cbuf->maxsize)
-               Con_Print("Cbuf_InsertText: overflow\n");
+               Con_Print(CON_WARN "Cbuf_InsertText: overflow\n");
        else
        {
                // bones_was_here assertion: when prepending to the buffer it never makes sense to leave node(s) in the `pending` state,
@@ -586,7 +586,7 @@ static void Cmd_Exec(cmd_state_t *cmd, const char *filename)
        f = (char *)FS_LoadFile (filename, tempmempool, false, NULL);
        if (!f)
        {
-               Con_Printf("couldn't exec %s\n",filename);
+               Con_Printf(CON_WARN "couldn't exec %s\n",filename);
                return;
        }
        Con_Printf("execing %s\n",filename);
@@ -844,7 +844,7 @@ static void Cmd_Exec_f (cmd_state_t *cmd)
        s = FS_Search(Cmd_Argv(cmd, 1), true, true, NULL);
        if(!s || !s->numfilenames)
        {
-               Con_Printf("couldn't exec %s\n",Cmd_Argv(cmd, 1));
+               Con_Printf(CON_WARN "couldn't exec %s\n",Cmd_Argv(cmd, 1));
                return;
        }
 
@@ -946,7 +946,7 @@ static void Cmd_Toggle_f(cmd_state_t *cmd)
                }
                else
                { // Invalid CVar
-                       Con_Printf("ERROR : CVar '%s' not found\n", Cmd_Argv(cmd, 1) );
+                       Con_Printf(CON_WARN "ERROR : CVar '%s' not found\n", Cmd_Argv(cmd, 1) );
                }
        }
 }
@@ -977,7 +977,7 @@ static void Cmd_Alias_f (cmd_state_t *cmd)
        s = Cmd_Argv(cmd, 1);
        if (strlen(s) >= MAX_ALIAS_NAME)
        {
-               Con_Print("Alias name is too long\n");
+               Con_Print(CON_WARN "Alias name is too long\n");
                return;
        }
 
@@ -1789,7 +1789,7 @@ static void Cmd_TokenizeString (cmd_state_t *cmd, const char *text)
                        l = (int)strlen(com_token) + 1;
                        if (cmd->cbuf->tokenizebufferpos + l > CMD_TOKENIZELENGTH)
                        {
-                               Con_Printf("Cmd_TokenizeString: ran out of %i character buffer space for command arguments\n", CMD_TOKENIZELENGTH);
+                               Con_Printf(CON_WARN "Cmd_TokenizeString: ran out of %i character buffer space for command arguments\n", CMD_TOKENIZELENGTH);
                                break;
                        }
                        memcpy (cmd->cbuf->tokenizebuffer + cmd->cbuf->tokenizebufferpos, com_token, l);
@@ -1821,7 +1821,7 @@ void Cmd_AddCommand(int flags, const char *cmd_name, xcommand_t function, const
                        // fail if the command is a variable name
                        if (Cvar_FindVar(cmd->cvars, cmd_name, ~0))
                        {
-                               Con_Printf("Cmd_AddCommand: %s already defined as a var\n", cmd_name);
+                               Con_Printf(CON_WARN "Cmd_AddCommand: %s already defined as a var\n", cmd_name);
                                return;
                        }
 
@@ -1832,7 +1832,7 @@ void Cmd_AddCommand(int flags, const char *cmd_name, xcommand_t function, const
                                {
                                        if (!strcmp(cmd_name, func->name))
                                        {
-                                               Con_Printf("Cmd_AddCommand: %s already defined\n", cmd_name);
+                                               Con_Printf(CON_WARN "Cmd_AddCommand: %s already defined\n", cmd_name);
                                                continue;
                                        }
                                }
@@ -2158,7 +2158,7 @@ qbool Cmd_Callback(cmd_state_t *cmd, cmd_function_t *func, const char *text, cmd
        if (func->function)
                func->function(cmd);
        else
-               Con_Printf("Command \"%s\" can not be executed\n", Cmd_Argv(cmd, 0));
+               Con_Printf(CON_WARN "Command \"%s\" can not be executed\n", Cmd_Argv(cmd, 0));
        return true;
 }
 
@@ -2183,7 +2183,7 @@ qbool Cmd_CL_Callback(cmd_state_t *cmd, cmd_function_t *func, const char *text,
                }
                else if(!(func->flags & CF_SERVER))
                {
-                       Con_Printf("Cannot execute client commands from a dedicated server console.\n");
+                       Con_Printf(CON_WARN "Cannot execute client commands from a dedicated server console.\n");
                        return true;
                }
        }
@@ -2197,7 +2197,7 @@ qbool Cmd_SV_Callback(cmd_state_t *cmd, cmd_function_t *func, const char *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");
+                       SV_ClientPrintf(CON_WARN "No cheats allowed. The server must have sv_cheats set to 1\n");
                else
                        func->function(cmd);
                return true;
@@ -2276,7 +2276,7 @@ void Cmd_ExecuteString (cmd_state_t *cmd, const char *text, cmd_source_t src, qb
 
 // check cvars
        if (!Cvar_Command(cmd) && host.framecount > 0)
-               Con_Printf("Unknown command \"%s\"\n", Cmd_Argv(cmd, 0));
+               Con_Printf(CON_WARN "Unknown command \"%s\"\n", Cmd_Argv(cmd, 0));
 done:
        cmd->cbuf->tokenizebufferpos = oldpos;
        if (lockmutex)
@@ -2298,7 +2298,7 @@ int Cmd_CheckParm (cmd_state_t *cmd, const char *parm)
 
        if (!parm)
        {
-               Con_Printf ("Cmd_CheckParm: NULL");
+               Con_Printf(CON_WARN "Cmd_CheckParm: NULL");
                return 0;
        }
 
diff --git a/cvar.c b/cvar.c
index e711df4624bdad92dc87a3806b3b2ac5c26bb0fa..642080e75809623e4a1b95dbe164107b7e810775 100644 (file)
--- a/cvar.c
+++ b/cvar.c
@@ -368,7 +368,7 @@ void Cvar_Callback(cvar_t *var)
 {
        if (var == NULL)
        {
-               Con_Print("Cvar_Callback: var == NULL\n");
+               Con_Print(CON_WARN "Cvar_Callback: var == NULL\n");
                return;
        }
 
@@ -432,7 +432,7 @@ void Cvar_SetQuick (cvar_t *var, const char *value)
 {
        if (var == NULL)
        {
-               Con_Print("Cvar_SetQuick: var == NULL\n");
+               Con_Print(CON_WARN "Cvar_SetQuick: var == NULL\n");
                return;
        }
 
@@ -454,7 +454,7 @@ void Cvar_Set(cvar_state_t *cvars, const char *var_name, const char *value)
        var = Cvar_FindVar(cvars, var_name, ~0);
        if (var == NULL)
        {
-               Con_Printf("Cvar_Set: variable %s not found\n", var_name);
+               Con_Printf(CON_WARN "Cvar_Set: variable %s not found\n", var_name);
                return;
        }
        Cvar_SetQuick(var, value);
@@ -491,7 +491,7 @@ void Cvar_RegisterCallback(cvar_t *variable, void (*callback)(cvar_t *))
 {
        if (variable == NULL)
        {
-               Con_Print("Cvar_RegisterCallback: var == NULL\n");
+               Con_Print(CON_WARN "Cvar_RegisterCallback: var == NULL\n");
                return;
        }
        variable->callback = callback;
@@ -654,7 +654,7 @@ void Cvar_RegisterVariable (cvar_t *variable)
        // check for overlap with a command
        if (Cmd_Exists(cmd_local, variable->name))
        {
-               Con_Printf("Cvar_RegisterVariable: %s is a command\n", variable->name);
+               Con_Printf(CON_WARN "Cvar_RegisterVariable: %s is a command\n", variable->name);
                return;
        }
 
@@ -715,14 +715,14 @@ cvar_t *Cvar_Get(cvar_state_t *cvars, const char *name, const char *value, int f
        // check for pure evil
        if (!*name)
        {
-               Con_Printf("Cvar_Get: invalid variable name\n");
+               Con_Printf(CON_WARN "Cvar_Get: invalid variable name\n");
                return NULL;
        }
 
        // check for overlap with a command
        if (Cmd_Exists(cmd_local, name))
        {
-               Con_Printf("Cvar_Get: %s is a command\n", name);
+               Con_Printf(CON_WARN "Cvar_Get: %s is a command\n", name);
                return NULL;
        }
 
@@ -758,10 +758,10 @@ qbool Cvar_Readonly (cvar_t *var, const char *cmd_name)
 {
        if (var->flags & CF_READONLY)
        {
+               Con_Print(CON_WARN);
                if(cmd_name)
                        Con_Printf("%s: ",cmd_name);
-               Con_Printf("%s", var->name);
-               Con_Printf(" is read-only\n");
+               Con_Printf("%s is read-only\n", var->name);
                return true;
        }
        return false;