From eae02d5bf624c5d157e0c17dee203f74b0b2e644 Mon Sep 17 00:00:00 2001 From: AfonsoCMSousa Date: Thu, 27 Feb 2025 23:36:16 +0000 Subject: [PATCH] Added protocol 3 has a possible request to receive the list of all indeces available. --- src/server.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/src/server.c b/src/server.c index 3318adf..c46d2db 100644 --- a/src/server.c +++ b/src/server.c @@ -191,6 +191,43 @@ int main(void) } break; } + case 3: + { + // Return the client with + // level == how many keys are being sent + // key == the list of levels that have keys + + // debug + printf("Received request type 3\n"); + + Request aux; + aux.ID = req.ID; + aux.type = req.type; + + FILE *file; + int levelCount = 0; + char levels[256] = {0}; + + for (int i = 0; i < 256; i++) + { + char filepath[256]; + sprintf(filepath, "%s%d.bin", PASSWORDS, i); + + file = fopen(filepath, "r"); + if (file != NULL) + { + levels[levelCount] = i; + levelCount++; + fclose(file); + } + } + + aux.level = levelCount; + memcpy(aux.key, levels, 256); + + send(connfd, &aux, sizeof(aux), 0); + break; + } default: fprintf(stderr, "Invalid request type\n"); break;