Skip to content

Commit

Permalink
add incremental counter support for macros #110
Browse files Browse the repository at this point in the history
  • Loading branch information
dannagle committed Aug 13, 2024
1 parent 1a43150 commit 2fee869
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,7 @@ Packet Sender supports these macros when sending responses:
* {{DATE}} -- Sends the current date in "yyy-mm-dd" format.
* {{TIME}} -- Sends the current time in "hh:mm:ss ap" format.
* {{UNIXTIME}} -- Sends the current epoch time stamp.
* {{COUNTER}} -- Sends an incrementing counter for each packet that uses it. Starts at 1 at launch.
* {{RANDOM}} -- Sends a random number ranging from either 0 to 32767 or 2147483647, depending on 32-bit or 64-bit (default installer for Windows is 32-bit. Mac is 64-bit).
* {{UNIQUE}} -- Sends a random string. Uses an internal UUID to generate it.
Packet Sender will swap the macro with real values before sending.
Expand Down
7 changes: 7 additions & 0 deletions src/packet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -847,6 +847,7 @@ QString Packet::macroSwap(QString data)
{
static QString dateFormat = "";
static QString timeFormat = "";
static quint64 counter = 0;
if(dateFormat.isEmpty()) {
QSettings settings(SETTINGSFILE, QSettings::IniFormat);
dateFormat = settings.value("dateFormat", "yyyy-MM-dd").toString();
Expand Down Expand Up @@ -892,6 +893,12 @@ QString Packet::macroSwap(QString data)
data = data.replace("{{UNIQUE}}", uuidString);
}


if (data.contains("{{COUNTER}}")) {
counter++;
data = data.replace("{{COUNTER}}", QString::number(counter));
}

return data;

}
Expand Down
2 changes: 1 addition & 1 deletion src/settings.ui
Original file line number Diff line number Diff line change
Expand Up @@ -960,7 +960,7 @@
<item>
<widget class="QLabel" name="label_8">
<property name="text">
<string>Available macros: {{DATE}} {{TIME}} {{RANDOM}} {{UNIXTIME}} {{UNIQUE}}</string>
<string>Available macros: {{DATE}} {{TIME}} {{RANDOM}} {{UNIXTIME}} {{UNIQUE}} {{COUNTER}}</string>
</property>
</widget>
</item>
Expand Down

0 comments on commit 2fee869

Please sign in to comment.