From: Samual Lenks Date: Fri, 21 Dec 2012 08:29:40 +0000 (-0500) Subject: Improve the dumpnotifs command X-Git-Tag: xonotic-v0.7.0~62^2~23^2~321 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=7825c6ee327e7dcfb1443a98248810f7a0a033a0;p=xonotic%2Fxonotic-data.pk3dir.git Improve the dumpnotifs command --- diff --git a/qcsrc/common/command/generic.qc b/qcsrc/common/command/generic.qc index b7954e338..e97745cfb 100644 --- a/qcsrc/common/command/generic.qc +++ b/qcsrc/common/command/generic.qc @@ -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; } } diff --git a/qcsrc/common/notifications.qc b/qcsrc/common/notifications.qc index 09e9f02f5..adcbf0104 100644 --- a/qcsrc/common/notifications.qc +++ b/qcsrc/common/notifications.qc @@ -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; }