Skip to content
This repository was archived by the owner on Aug 20, 2025. It is now read-only.

Commit fc0f892

Browse files
Enter input before displaying results (if in tty) to prevent spoilers before being able to open visualizer
1 parent 69a4e31 commit fc0f892

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

src/con_lib.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,26 @@ static bool core_static_isMyCore(const t_obj *obj)
1010
return (obj->s_core.team_id == game.my_team_id);
1111
}
1212

13+
static void core_static_awaitEnterPress(void)
14+
{
15+
if (!isatty(STDIN_FILENO))
16+
return;
17+
printf("The game has ended! But who won?...\n");
18+
printf("Press ENTER to reveal the result...\n");
19+
fflush(stdout);
20+
fd_set rfds;
21+
FD_ZERO(&rfds);
22+
FD_SET(STDIN_FILENO, &rfds);
23+
struct timeval tv;
24+
tv.tv_sec = 30;
25+
tv.tv_usec = 0;
26+
int rv = select(STDIN_FILENO + 1, &rfds, NULL, NULL, &tv);
27+
if (rv > 0) {
28+
int c;
29+
while ((c = getchar()) != '\n' && c != EOF) {}
30+
}
31+
}
32+
1333
/**
1434
* @brief Starts the connection to the server. This function should be called before any other function from this library.
1535
*
@@ -99,6 +119,7 @@ int core_startGame(const char *team_name, int argc, char **argv, void (*tick_cal
99119
}
100120

101121
// handle game end
122+
core_static_awaitEnterPress();
102123
if (my_core && my_core->hp > 0)
103124
printf("Game over! You won!\n");
104125
else

0 commit comments

Comments
 (0)