]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/common/command/generic.qc
Merge branch 'master' into Mario/monsters
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / command / generic.qc
index e97745cfb2aa608af64770eec7bc0c218fc6b917..8a564b8e7d0ef059237057d81861f84ac27a1625 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);
 }
 
 
@@ -226,40 +227,94 @@ void GenericCommand_dumpcommands(float request)
        }
 }
 
-void GenericCommand_dumpnotifs(float request)
+void GenericCommand_dumpmonsters(float request)
 {
        switch(request)
        {
                case CMD_REQUEST_COMMAND:
                {
-                       float fh, alsoprint;
+                       #ifdef SVQC
+                       mon_config_file = -1;
+                       mon_config_alsoprint = -1;
+                       string filename = argv(1);
+                       
+                       if(filename == "")
+                       {
+                               filename = "monsters_dump.cfg";
+                               mon_config_alsoprint = FALSE;
+                       }
+                       else if(filename == "-")
+                       {
+                               filename = "monsters_dump.cfg";
+                               mon_config_alsoprint = TRUE;
+                       }
+                       mon_config_file = fopen(filename, FILE_WRITE);
+                       
+                       if(mon_config_file >= 0)
+                       {
+                               Dump_Monster_Settings();
+                               print(sprintf("Dumping monsters... File located in ^2data/data/%s^7.\n", filename));
+                               fclose(mon_config_file);
+                               mon_config_file = -1;
+                               mon_config_alsoprint = -1;
+                       }
+                       else
+                       {
+                               print(sprintf("^1Error: ^7Could not open file '%s'!\n", filename));
+                       }
+                       #else
+                       print(_("Monsters dump command only works with sv_cmd.\n"));
+                       #endif
+                       return;
+               }
                        
+               default:
+               case CMD_REQUEST_USAGE:
+               {
+                       print(strcat("\nUsage:^3 ", GetProgramCommandPrefix(), " dumpmonsters [filename]"));
+                       print("  Where 'filename' is the file to write (default is monsters_dump.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;
+               }
+       }
+}
+
+void GenericCommand_dumpnotifs(float request)
+{
+       switch(request)
+       {
+               case CMD_REQUEST_COMMAND:
+               {
+                       #ifndef MENUQC
+                       float fh, alsoprint = FALSE;
                        string filename = argv(1);
                        
                        if(filename == "")
                        {
-                               filename = "notifications_dump.txt";
+                               filename = "notifications.cfg";
                                alsoprint = FALSE;
                        }
                        else if(filename == "-")
                        {
-                               filename = "notifications_dump.txt";
+                               filename = "notifications.cfg";
                                alsoprint = TRUE;
                        }
                        fh = fopen(filename, FILE_WRITE);
                        
                        if(fh >= 0)
                        {
-                               fputs(fh, "dump of notifications list:\n");
-                               if(alsoprint) { print("dump of notifications list:\n"); }
                                Dump_Notifications(fh, alsoprint);
-                               print(sprintf("File located in ^2data/data/%s^7.\n", filename));
+                               print(sprintf("Dumping notifications... File located in ^2data/data/%s^7.\n", filename));
                                fclose(fh);
                        }
                        else
                        {
                                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;
                }
                        
@@ -267,7 +322,7 @@ void GenericCommand_dumpnotifs(float request)
                case CMD_REQUEST_USAGE:
                {
                        print(strcat("\nUsage:^3 ", GetProgramCommandPrefix(), " dumpnotifs [filename]"));
-                       print("  Where 'filename' is the file to write (default is notifications_dump.txt),\n");
+                       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;
@@ -424,6 +479,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)
@@ -482,6 +580,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)
@@ -513,14 +637,17 @@ void GenericCommand_(float request)
 #define GENERIC_COMMANDS(request,arguments,command) \
        GENERIC_COMMAND("addtolist", GenericCommand_addtolist(request, arguments), "Add a string to a cvar") \
        GENERIC_COMMAND("dumpcommands", GenericCommand_dumpcommands(request), "Dump all commands on the program to *_cmd_dump.txt") \
+       GENERIC_COMMAND("dumpmonsters", GenericCommand_dumpmonsters(request), "Dump all monsters into monsters_dump.cfg") \
        GENERIC_COMMAND("dumpnotifs", GenericCommand_dumpnotifs(request), "Dump all notifications into notifications_dump.txt") \
        GENERIC_COMMAND("maplist", GenericCommand_maplist(request, arguments), "Automatic control of maplist") \
        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()