]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/common/command/generic.qc
Fix restartnotifs command
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / command / generic.qc
index 2e00ff03a105af7a8a91b38b46d811d54f078ad0..4ca8b3780c3d4950c4644be777260836d8da4c01 100644 (file)
@@ -40,8 +40,9 @@ void Curl_URI_Get_Callback(float id, float status, string data)
                cvar_set(do_cvar, data);
                strunzone(do_cvar);
        }
-       if(!do_exec && !do_cvar)
-               print(data);
+       if(!do_exec)
+               if not(do_cvar)
+                       print(data);
 }
 
 
@@ -84,7 +85,7 @@ void GenericCommand_addtolist(float request, float argc)
                        print("Incorrect parameters for ^2addtolist^7\n");
                case CMD_REQUEST_USAGE:
                {
-                       print(strcat("\nUsage:^3 ", GetProgramCommandPrefix(), " addtolist variable value"));
+                       print(strcat("\nUsage:^3 ", GetProgramCommandPrefix(), " addtolist variable value\n"));
                        print("  Where 'variable' is what to add 'value' to.\n");
                        print("See also: ^2removefromlist^7\n");
                        return;
@@ -232,29 +233,45 @@ void GenericCommand_dumpnotifs(float request)
        {
                case CMD_REQUEST_COMMAND:
                {
-                       float fh;
-                       string filename = "notifications_dump.txt";
+                       #ifndef MENUQC
+                       float fh, alsoprint = FALSE;
+                       string filename = argv(1);
+                       
+                       if(filename == "")
+                       {
+                               filename = "notifications.cfg";
+                               alsoprint = FALSE;
+                       }
+                       else if(filename == "-")
+                       {
+                               filename = "notifications.cfg";
+                               alsoprint = TRUE;
+                       }
                        fh = fopen(filename, FILE_WRITE);
                        
                        if(fh >= 0)
                        {
-                               fputs(fh, "dump of notifications list:\n");
-                               Dump_Notifications(fh);
-                               print("Completed dump of notifications in ^2data/data/notifications_dump.txt^7.\n");
+                               Dump_Notifications(fh, alsoprint);
+                               print(sprintf("Dumping notifications... File located in ^2data/data/%s^7.\n", filename));
                                fclose(fh);
                        }
                        else
                        {
-                               print("^1Error: ^7Could not dump to file!\n");
+                               print(sprintf("^1Error: ^7Could not open file '%s'!\n", filename));
                        }
+                       #else
+                       print(_("Notification dump command only works with cl_cmd and sv_cmd.\n"));
+                       #endif
                        return;
                }
                        
                default:
                case CMD_REQUEST_USAGE:
                {
-                       print(strcat("\nUsage:^3 ", GetProgramCommandPrefix(), " dumpnotifs"));
-                       print("  No arguments required.\n");
+                       print(strcat("\nUsage:^3 ", GetProgramCommandPrefix(), " dumpnotifs [filename]"));
+                       print("  Where 'filename' is the file to write (default is notifications.cfg),\n");
+                       print("  if supplied with '-' output to console as well as default,\n");
+                       print("  if left blank, it will only write to default.\n");
                        return;
                }
        }
@@ -341,7 +358,7 @@ void GenericCommand_maplist(float request, float argc)
                        print("Incorrect parameters for ^2maplist^7\n");
                case CMD_REQUEST_USAGE:
                {
-                       print(strcat("\nUsage:^3 ", GetProgramCommandPrefix(), " maplist action [map]"));
+                       print(strcat("\nUsage:^3 ", GetProgramCommandPrefix(), " maplist action [map]\n"));
                        print("  Where 'action' is the command to complete,\n");
                        print("  and 'map' is what it acts upon (if required).\n");
                        print("  Full list of commands here: \"add, cleanup, remove, shuffle.\"\n");
@@ -363,7 +380,7 @@ void GenericCommand_nextframe(float request, float arguments, string command)
                default:
                case CMD_REQUEST_USAGE:
                {
-                       print(strcat("\nUsage:^3 ", GetProgramCommandPrefix(), " nextframe command..."));
+                       print(strcat("\nUsage:^3 ", GetProgramCommandPrefix(), " nextframe command...\n"));
                        print("  Where command will be executed next frame of this VM\n");
                        return;
                }
@@ -401,7 +418,7 @@ void GenericCommand_removefromlist(float request, float argc)
                        print("Incorrect parameters for ^2removefromlist^7\n");
                case CMD_REQUEST_USAGE:
                {
-                       print(strcat("\nUsage:^3 ", GetProgramCommandPrefix(), " removefromlist variable value"));
+                       print(strcat("\nUsage:^3 ", GetProgramCommandPrefix(), " removefromlist variable value\n"));
                        print("  Where 'variable' is what cvar to remove 'value' from.\n");
                        print("See also: ^2addtolist^7\n");
                        return;
@@ -409,6 +426,49 @@ void GenericCommand_removefromlist(float request, float argc)
        }
 }
 
+void GenericCommand_restartnotifs(float request)
+{
+       switch(request)
+       {
+               case CMD_REQUEST_COMMAND:
+               {
+                       #ifndef MENUQC
+                       print(sprintf(
+                               strcat(
+                                       "Restart_Notifications(): Restarting %d notifications... ",
+                                       "Counts: MSG_ANNCE = %d, MSG_INFO = %d, MSG_CENTER = %d, MSG_MULTI = %d, MSG_CHOICE = %d\n"
+                               ),
+                               (
+                                       NOTIF_ANNCE_COUNT +
+                                       NOTIF_INFO_COUNT +
+                                       NOTIF_CENTER_COUNT +
+                                       NOTIF_MULTI_COUNT +
+                                       NOTIF_CHOICE_COUNT
+                               ),
+                               NOTIF_ANNCE_COUNT,
+                               NOTIF_INFO_COUNT,
+                               NOTIF_CENTER_COUNT,
+                               NOTIF_MULTI_COUNT,
+                               NOTIF_CHOICE_COUNT
+                       ));     
+                       Destroy_All_Notifications();
+                       CALL_ACCUMULATED_FUNCTION(RegisterNotifications);
+                       #else
+                       print(_("Notification restart command only works with cl_cmd and sv_cmd.\n"));
+                       #endif
+                       return;
+               }
+                       
+               default:
+               case CMD_REQUEST_USAGE:
+               {
+                       print(strcat("\nUsage:^3 ", GetProgramCommandPrefix(), " restartnotifs"));
+                       print("  No arguments required.\n");
+                       return;
+               }
+       }
+}
+
 void GenericCommand_settemp(float request, float argc)
 {
        switch(request)
@@ -417,15 +477,17 @@ void GenericCommand_settemp(float request, float argc)
                {
                        if(argc >= 3)
                        {
-                               if(cvar_settemp(argv(1), argv(2)))
+                               float f = cvar_settemp(argv(1), argv(2));
+                               if(f == 1)
                                        dprint("Creating new settemp tracker for ", argv(1), " and setting it to \"", argv(2), "\" temporarily.\n"); 
-                               else
+                               else if(f == -1)
                                        dprint("Already had a tracker for ", argv(1), ", updating it to \"", argv(2), "\".\n");
-                       
+                               // else cvar_settemp itself errors out
+
                                return;
                        }
                }
-                       
+
                default:
                        print("Incorrect parameters for ^2settemp^7\n");
                case CMD_REQUEST_USAGE:
@@ -465,6 +527,32 @@ void GenericCommand_settemp_restore(float request, float argc)
        }
 }
 
+void GenericCommand_runtest(float request, float argc)
+{
+       switch(request)
+       {
+               case CMD_REQUEST_COMMAND:
+               {
+                       if(argc > 1)
+                       {
+                               float i;
+                               for(i = 1; i < argc; ++i)
+                                       TEST_Run(argv(i));
+                       }
+                       else
+                               TEST_RunAll();
+                       return;
+               }
+                       
+               default:
+               case CMD_REQUEST_USAGE:
+               {
+                       print(strcat("\nUsage:^3 ", GetProgramCommandPrefix(), " [function to run]"));
+                       return;
+               }
+       }
+}
+
 /* use this when creating a new command, making sure to place it in alphabetical order... also,
 ** ADD ALL NEW COMMANDS TO commands.cfg WITH PROPER ALIASES IN THE SAME FASHION!
 void GenericCommand_(float request)
@@ -501,9 +589,11 @@ void GenericCommand_(float request)
        GENERIC_COMMAND("nextframe", GenericCommand_nextframe(request, arguments, command), "Execute the given command next frame of this VM") \
        GENERIC_COMMAND("qc_curl", GenericCommand_qc_curl(request, arguments), "Queries a URL") \
        GENERIC_COMMAND("removefromlist", GenericCommand_removefromlist(request, arguments), "Remove a string from a cvar") \
+       GENERIC_COMMAND("restartnotifs", GenericCommand_restartnotifs(request), "Re-initialize all notifications") \
        GENERIC_COMMAND("rpn", GenericCommand_rpn(request, arguments, command), "RPN calculator") \
        GENERIC_COMMAND("settemp", GenericCommand_settemp(request, arguments), "Temporarily set a value to a cvar which is restored later") \
        GENERIC_COMMAND("settemp_restore", GenericCommand_settemp_restore(request, arguments), "Restore all cvars set by settemp command") \
+       GENERIC_COMMAND("runtest", GenericCommand_runtest(request, arguments), "Run unit tests") \
        /* nothing */
 
 void GenericCommand_macro_help()