checkout first slide + truncate long slides

This commit is contained in:
Daniele Lacamera 2024-11-29 16:14:53 +01:00
parent d3c0fbf8aa
commit dabeea8d5e

View file

@ -122,7 +122,6 @@ int main() {
struct Client clients[MAX_CLIENTS] = {0};
setuid(UID); /* Drop privileges */
printf("User ID: %d\n", getuid());
server_fd = socket(AF_INET, SOCK_STREAM, 0);
if (server_fd < 0) {
@ -199,6 +198,7 @@ int main() {
} else {
struct Client *client = &clients[slot];
char cp_command[CMD_SIZE];
char co_command[CMD_SIZE];
client->fd = client_fd;
snprintf(client->repo_path, PATH_SIZE, "/tmp/git_repo_%d", client_fd);
snprintf(client->slides_path, PATH_SIZE, "%s/%s", client->repo_path, SLIDES_PATH);
@ -207,7 +207,10 @@ int main() {
snprintf(cp_command, sizeof(cp_command), "cp -a . %s", client->repo_path);
system(cp_command);
execute_git_slides(client->repo_path, "prev");
/* Check out 'start' branch */
snprintf(co_command, sizeof(co_command), "cd %s && git checkout start", client->repo_path);
system(co_command);
load_slide_content(client->slides_path, client->current_slide);
send_telnet_negotiation(client_fd);
@ -230,7 +233,10 @@ int main() {
for (i = 1; i < num_fds; i++) {
if (fds[i].revents & POLLIN) {
char command;
int ret;
int r;
int client_idx = i - 1;
char *p;
struct Client *client = &clients[client_idx];
ssize_t n = read(client->fd, &command, 1);
@ -242,6 +248,19 @@ int main() {
printf("Input from client: %d, command: %02x (size: %d)\n", client->fd, (uint8_t)command, n);
handle_client_input(client, command);
/* Detect if the slide has more than 40 rows */
p = client->current_slide;
for (r = 0; r < 32; r++) {
p = strchr(p, '\n');
if (p == NULL) {
break;
}
p++;
}
if ((p) && (r == 32)) {
printf("BIG SLIDE\n");
*p = '\0';
}
clear_screen(client->fd);
write(client->fd, client->current_slide, strlen(client->current_slide));
}