]> git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - cmd.c
Clean up qtypes.h. Use stdbool.h on non-MSVC. Replace allcaps with lowercase
[xonotic/darkplaces.git] / cmd.c
diff --git a/cmd.c b/cmd.c
index e4428aad869a6b24d08b069d07f0f69a5f0a89fe..83ff546c212d8c93f1fd6abd5ae2d2feb054a68d 100644 (file)
--- a/cmd.c
+++ b/cmd.c
@@ -27,6 +27,9 @@ cmd_state_t cmd_clientfromserver;
 cmd_state_t cmd_server;
 cmd_state_t cmd_serverfromclient;
 
+cmd_userdefined_t cmd_userdefined_all;
+cmd_userdefined_t cmd_userdefined_null;
+
 typedef struct cmd_iter_s {
        cmd_state_t *cmd;
 }
@@ -193,7 +196,7 @@ void Cbuf_AddText (cmd_state_t *cmd, const char *text)
        l = (int)strlen(text);
 
        Cbuf_Lock(cmd);
-       if (cmd->text.cursize + l >= (size_t)cmd->text.maxsize)
+       if (cmd->text.maxsize - cmd->text.cursize <= l)
                Con_Print("Cbuf_AddText: overflow\n");
        else
                SZ_Write(&cmd->text, (const unsigned char *)text, l);
@@ -325,7 +328,7 @@ void Cbuf_Execute (cmd_state_t *cmd)
                // better than CRASHING on overlong input lines that may SOMEHOW enter the buffer
                if(i >= MAX_INPUTLINE)
                {
-                       Con_Printf("Warning: console input buffer had an overlong line. Ignored.\n");
+                       Con_Warnf("Warning: console input buffer had an overlong line. Ignored.\n");
                        line[0] = 0;
                }
                else
@@ -522,6 +525,7 @@ static void Cmd_Exec(cmd_state_t *cmd, const char *filename)
 "sys_ticrate 0.01388889\n"
 "r_shadow_gloss 1\n"
 "r_shadow_bumpscale_basetexture 0\n"
+"csqc_polygons_defaultmaterial_nocullface 0\n"
                                );
                        break;
                case GAME_NEHAHRA:
@@ -546,6 +550,7 @@ static void Cmd_Exec(cmd_state_t *cmd, const char *filename)
 "sys_ticrate 0.01388889\n"
 "r_shadow_gloss 1\n"
 "r_shadow_bumpscale_basetexture 0\n"
+"csqc_polygons_defaultmaterial_nocullface 0\n"
                                );
                        break;
                // hipnotic mission pack has issues in their 'friendly monster' ai, which seem to attempt to attack themselves for some reason when findradius() returns non-solid entities.
@@ -574,6 +579,7 @@ static void Cmd_Exec(cmd_state_t *cmd, const char *filename)
 "sys_ticrate 0.02\n"
 "r_shadow_gloss 1\n"
 "r_shadow_bumpscale_basetexture 0\n"
+"csqc_polygons_defaultmaterial_nocullface 0\n"
                                );
                        break;
                // rogue mission pack has a guardian boss that does not wake up if findradius returns one of the entities around its spawn area
@@ -599,6 +605,7 @@ static void Cmd_Exec(cmd_state_t *cmd, const char *filename)
 "sys_ticrate 0.01388889\n"
 "r_shadow_gloss 1\n"
 "r_shadow_bumpscale_basetexture 0\n"
+"csqc_polygons_defaultmaterial_nocullface 0\n"
                                );
                        break;
                case GAME_TENEBRAE:
@@ -623,6 +630,7 @@ static void Cmd_Exec(cmd_state_t *cmd, const char *filename)
 "sys_ticrate 0.01388889\n"
 "r_shadow_gloss 2\n"
 "r_shadow_bumpscale_basetexture 4\n"
+"csqc_polygons_defaultmaterial_nocullface 0\n"
                                );
                        break;
                case GAME_NEXUIZ:
@@ -647,6 +655,14 @@ static void Cmd_Exec(cmd_state_t *cmd, const char *filename)
 "sys_ticrate 0.01388889\n"
 "sv_gameplayfix_q2airaccelerate 1\n"
 "sv_gameplayfix_stepmultipletimes 1\n"
+"csqc_polygons_defaultmaterial_nocullface 1\n"
+                               );
+                       break;
+               case GAME_XONOTIC:
+               case GAME_VORETOURNAMENT:
+                       // compatibility for versions prior to 2020-05-25, this can be overridden in newer versions to get the default behavior and be consistent with FTEQW engine
+                       Cbuf_InsertText(cmd, "\n"
+"csqc_polygons_defaultmaterial_nocullface 1\n"
                                );
                        break;
                // Steel Storm: Burning Retribution csqc misinterprets CSQC_InputEvent if type is a value other than 0 or 1
@@ -671,6 +687,7 @@ static void Cmd_Exec(cmd_state_t *cmd, const char *filename)
 "sv_gameplayfix_downtracesupportsongroundflag 1\n"
 "sys_ticrate 0.01388889\n"
 "cl_csqc_generatemousemoveevents 0\n"
+"csqc_polygons_defaultmaterial_nocullface 1\n"
                                );
                        break;
                default:
@@ -693,6 +710,7 @@ static void Cmd_Exec(cmd_state_t *cmd, const char *filename)
 "sv_gameplayfix_swiminbmodels 1\n"
 "sv_gameplayfix_downtracesupportsongroundflag 1\n"
 "sys_ticrate 0.01388889\n"
+"csqc_polygons_defaultmaterial_nocullface 0\n"
                                );
                        break;
                }
@@ -1104,9 +1122,9 @@ static const char *Cmd_GetCvarValue(cmd_state_t *cmd, const char *var, size_t va
        {
                // empty cvar name?
                if(alias)
-                       Con_Printf("Warning: Could not expand $ in alias %s\n", alias->name);
+                       Con_Warnf("Warning: Could not expand $ in alias %s\n", alias->name);
                else
-                       Con_Printf("Warning: Could not expand $\n");
+                       Con_Warnf("Warning: Could not expand $\n");
                return "$";
        }
 
@@ -1152,9 +1170,9 @@ static const char *Cmd_GetCvarValue(cmd_state_t *cmd, const char *var, size_t va
                if(required)
                {
                        if(alias)
-                               Con_Printf("Error: Could not expand $%s in alias %s\n", varname, alias->name);
+                               Con_Errorf("Error: Could not expand $%s in alias %s\n", varname, alias->name);
                        else
-                               Con_Printf("Error: Could not expand $%s\n", varname);
+                               Con_Errorf("Error: Could not expand $%s\n", varname);
                        return NULL;
                }
                else if(optional)
@@ -1164,9 +1182,9 @@ static const char *Cmd_GetCvarValue(cmd_state_t *cmd, const char *var, size_t va
                else
                {
                        if(alias)
-                               Con_Printf("Warning: Could not expand $%s in alias %s\n", varname, alias->name);
+                               Con_Warnf("Warning: Could not expand $%s in alias %s\n", varname, alias->name);
                        else
-                               Con_Printf("Warning: Could not expand $%s\n", varname);
+                               Con_Warnf("Warning: Could not expand $%s\n", varname);
                        dpsnprintf(varval, sizeof(varval), "$%s", varname);
                        return varval;
                }
@@ -1499,6 +1517,7 @@ void Cmd_Init_Commands(qboolean dedicated_server)
 //
        // client-only commands
        Cmd_AddCommand(&cmd_client, "cmd", Cmd_ForwardToServer_f, "send a console commandline to the server (used by some mods)");
+       Cmd_AddCommand(&cmd_clientfromserver, "cmd", Cmd_ForwardToServer_f, "send a console commandline to the server (used by some mods)");
        Cmd_AddCommand(&cmd_client, "wait", Cmd_Wait_f, "make script execution wait for next rendered frame");
        Cmd_AddCommand(&cmd_client, "cprint", Cmd_Centerprint_f, "print something at the screen center");
 
@@ -1978,11 +1997,18 @@ const char **Cmd_CompleteAliasBuildList (cmd_state_t *cmd, const char *partial)
        return buf;
 }
 
-void Cmd_ClearCsqcFuncs (cmd_state_t *cmd)
+// TODO: Make this more generic?
+void Cmd_ClearCSQCCommands (cmd_state_t *cmd)
 {
        cmd_function_t *func;
-       for (func = cmd->userdefined->csqc_functions; func; func = func->next)
-               func->csqcfunc = false;
+       cmd_function_t **next = &cmd->userdefined->csqc_functions;
+       
+       while(*next)
+       {
+               func = *next;
+               *next = func->next;
+               Z_Free(func);
+       }
 }
 
 /*
@@ -2046,7 +2072,7 @@ void Cmd_ExecuteString (cmd_state_t *cmd, const char *text, cmd_source_t src, qb
        // if it's a client command and no command was found, say so.
        if (cmd->source == src_client)
        {
-               Con_Printf("player \"%s\" tried to %s\n", host_client->name, text);
+               Con_Printf("Client \"%s\" tried to execute \"%s\"\n", host_client->name, text);
                goto done;
        }
 
@@ -2061,9 +2087,13 @@ 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));
-
+       if (!Cvar_Command(cmd) && host_framecount > 0) {
+               if (cmd == &cmd_clientfromserver) {
+                       Con_Printf("Server tried to execute \"%s\"\n", Cmd_Argv(cmd, 0));
+               } else {
+                       Con_Printf("Unknown command \"%s\"\n", Cmd_Argv(cmd, 0));
+               }
+       }
 done:
        cmd->tokenizebufferpos = oldpos;
        if (lockmutex)