]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Improve the dumpnotifs command
authorSamual Lenks <samual@xonotic.org>
Fri, 21 Dec 2012 08:29:40 +0000 (03:29 -0500)
committerSamual Lenks <samual@xonotic.org>
Fri, 21 Dec 2012 08:29:40 +0000 (03:29 -0500)
qcsrc/common/command/generic.qc
qcsrc/common/notifications.qc

index b7954e338f79ae9952581f3e061ff8520055b423..e97745cfb2aa608af64770eec7bc0c218fc6b917 100644 (file)
@@ -232,20 +232,33 @@ void GenericCommand_dumpnotifs(float request)
        {
                case CMD_REQUEST_COMMAND:
                {
-                       float fh;
-                       string filename = "notifications_dump.txt";
+                       float fh, alsoprint;
+                       
+                       string filename = argv(1);
+                       
+                       if(filename == "")
+                       {
+                               filename = "notifications_dump.txt";
+                               alsoprint = FALSE;
+                       }
+                       else if(filename == "-")
+                       {
+                               filename = "notifications_dump.txt";
+                               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");
+                               if(alsoprint) { print("dump of notifications list:\n"); }
+                               Dump_Notifications(fh, alsoprint);
+                               print(sprintf("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));
                        }
                        return;
                }
@@ -253,8 +266,10 @@ void GenericCommand_dumpnotifs(float request)
                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_dump.txt),\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;
                }
        }
index 09e9f02f59a755b13213bb4a9e78de3fdd2da502..adcbf01044af7294766aa02525fd1069ea6d5099 100644 (file)
@@ -631,13 +631,15 @@ string CCR(string input)
 //  Debug/Maintenance Functions
 // =============================
 
-#define NOTIF_Write(type,name,text) fputs(fh, (sprintf("seta %s 1 // %s - %s\n", name, type, strreplace("\n", "\\n", text))))
-void Dump_Notifications(float fh)
+#define NOTIF_Write(type,name,text) notif_msg = sprintf("seta %s 1 // %s - %s\n", name, type, strreplace("\n", "\\n", text)); fputs(fh, notif_msg); if(alsoprint) { print(strreplace("^", "^^", notif_msg)); }
+void Dump_Notifications(float fh, float alsoprint)
 {
-       #define MSG_INFO_NOTIF(name,strnum,flnum,args,hudargs,icon,normal,gentle) { NOTIF_Write("MSG_INFO", VAR_TO_TEXT(name), normal); }
-       #define MSG_CENTER_NOTIF(name,strnum,flnum,args,cpid,durcnt,normal,gentle) { NOTIF_Write("MSG_CENTER", VAR_TO_TEXT(name), normal); }
-       #define MSG_WEAPON_NOTIF(name,infoname,centername) { NOTIF_Write("MSG_WEAPON", VAR_TO_TEXT(name),sprintf("infoname: %s, centername: %s", VAR_TO_TEXT(infoname), VAR_TO_TEXT(centername))); }
-       #define MSG_DEATH_NOTIF(name,infoname,centername) { NOTIF_Write("MSG_DEATH", VAR_TO_TEXT(name), sprintf("infoname: %s, centername: %s", VAR_TO_TEXT(infoname), VAR_TO_TEXT(centername))); }
+       float MSG_INFO_NOTIFS, MSG_CENTER_NOTIFS, MSG_WEAPON_NOTIFS, MSG_DEATH_NOTIFS;
+       string notif_msg;
+       #define MSG_INFO_NOTIF(name,strnum,flnum,args,hudargs,icon,normal,gentle) { ++MSG_INFO_NOTIFS; NOTIF_Write("MSG_INFO", VAR_TO_TEXT(name), normal) }
+       #define MSG_CENTER_NOTIF(name,strnum,flnum,args,cpid,durcnt,normal,gentle) { ++MSG_CENTER_NOTIFS; NOTIF_Write("MSG_CENTER", VAR_TO_TEXT(name), normal) }
+       #define MSG_WEAPON_NOTIF(name,infoname,centername) { ++MSG_WEAPON_NOTIFS; NOTIF_Write("MSG_WEAPON", VAR_TO_TEXT(name),sprintf("infoname: %s, centername: %s", VAR_TO_TEXT(infoname), VAR_TO_TEXT(centername))) }
+       #define MSG_DEATH_NOTIF(name,infoname,centername) { ++MSG_DEATH_NOTIFS; NOTIF_Write("MSG_DEATH", VAR_TO_TEXT(name), sprintf("infoname: %s, centername: %s", VAR_TO_TEXT(infoname), VAR_TO_TEXT(centername))) }
        MSG_INFO_NOTIFICATIONS
        MSG_CENTER_NOTIFICATIONS
        MSG_WEAPON_NOTIFICATIONS
@@ -646,6 +648,7 @@ void Dump_Notifications(float fh)
        #undef MSG_CENTER_NOTIF
        #undef MSG_WEAPON_NOTIF
        #undef MSG_DEATH_NOTIF
+       print(sprintf("Notification counts: MSG_INFO = %d, MSG_CENTER = %d, MSG_WEAPON = %d, MSG_DEATH = %d\n", MSG_INFO_NOTIFS, MSG_CENTER_NOTIFS, MSG_WEAPON_NOTIFS, MSG_DEATH_NOTIFS));
        return;
 }