Skip to content

Commit

Permalink
feat: show_netmessages setting
Browse files Browse the repository at this point in the history
0 = none, 1 = all except srtimer, 2 = all
Fixes #12
  • Loading branch information
ThisAMJ committed Sep 22, 2024
1 parent ff1d3ae commit b412560
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 20 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,4 @@ This file contains a few configuration settings, configured using lines of the f
- `show_passing_checksums [0/1]`. Defaults to 0 (off).
- `show_wait [0/1]`. Defaults to 1 (on).
- `show_splits [0/1]`. Defaults to 1 (on). Shows splits when a speedrun finishes.
- `show_netmessages [0/1/2]`. 0 = don't show, 1 = show all except srtimer, 2 (default) = show all.
52 changes: 32 additions & 20 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ struct {
bool show_passing_checksums; // should we output successful checksums?
bool show_wait; // should we show when 'wait' was run?
bool show_splits; // should we show split times?
int show_netmessages; // 0 = don't show, 1 = show all except srtimer, 2 = show all
} g_config;

static bool _allow_initial_cvar(const char *var, const char *val) {
Expand Down Expand Up @@ -297,31 +298,33 @@ static bool handleMessage(struct demo_msg *msg) {
char *type = decoded;
char *data = decoded + strlen(type) + 1;

fprintf(g_outfile, "\t\t[%5u] NetMessage (%s): %s", msg->tick, orange ? "o" : "b", type);
if (g_config.show_netmessages == 2 || (g_config.show_netmessages == 1 && strcmp(type, "srtimer"))) {
fprintf(g_outfile, "\t\t[%5u] NetMessage (%s): %s", msg->tick, orange ? "o" : "b", type);

// print data
int datalen = strlen(data);
bool printdata = true;
if (!strcmp(type, "srtimer")) {
datalen = 4;
printdata = false;
}
if (!strcmp(type, "cmboard")) {
datalen = 0;
}
// print data
int datalen = strlen(data);
bool printdata = true;
if (!strcmp(type, "srtimer")) {
datalen = 4;
printdata = false;
}
if (!strcmp(type, "cmboard")) {
datalen = 0;
}

if (datalen > 0) {
if (printdata) fprintf(g_outfile, " = %s (", data);
else fprintf(g_outfile, " (");
if (datalen > 0) {
if (printdata) fprintf(g_outfile, " = %s (", data);
else fprintf(g_outfile, " (");

for (int i = 0; i < datalen; ++i) {
fprintf(g_outfile, "%02X", (unsigned char)data[i]);
if (i < datalen - 1) fprintf(g_outfile, " ");
for (int i = 0; i < datalen; ++i) {
fprintf(g_outfile, "%02X", (unsigned char)data[i]);
if (i < datalen - 1) fprintf(g_outfile, " ");
}
if (datalen > 0) fprintf(g_outfile, ")");
}
if (datalen > 0) fprintf(g_outfile, ")");
}

fprintf(g_outfile, "\n");
fprintf(g_outfile, "\n");
}
}
g_expected_len = 0;
g_partial[0] = 0;
Expand Down Expand Up @@ -442,6 +445,7 @@ int main(int argc, char **argv) {
g_config.show_passing_checksums = false;
g_config.show_wait = true;
g_config.show_splits = true;
g_config.show_netmessages = 2;
struct var_whitelist *general_conf = config_read_var_whitelist(GENERAL_CONF_FILE);
if (general_conf) {
for (struct var_whitelist *ptr = general_conf; ptr->var_name; ++ptr) {
Expand Down Expand Up @@ -479,6 +483,14 @@ int main(int argc, char **argv) {
continue;
}

if (!strcmp(ptr->var_name, "show_netmessages")) {
int val = atoi(ptr->val);
if (val < 0) val = 0;
if (val > 2) val = 2;
g_config.show_netmessages = val;
continue;
}

fprintf(g_errfile, "bad config option '%s'\n", ptr->var_name);
}
config_free_var_whitelist(general_conf);
Expand Down

0 comments on commit b412560

Please sign in to comment.