From 3b1d210a9cff7f46fe9517f60b40e4e4617181f3 Mon Sep 17 00:00:00 2001 From: AfonsoCMSousa Date: Thu, 27 Feb 2025 13:01:48 +0000 Subject: [PATCH] Server now returns if it finds a password like the user requested. --- src/server.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/server.c b/src/server.c index ac8d4ab..404e7d2 100644 --- a/src/server.c +++ b/src/server.c @@ -102,23 +102,29 @@ int main(void) if (req.type == 0) { // debug + Request aux; printf("Received request type 0\n"); char *filepath = create(char); filepath = size(filepath, 256); - strcpy(filepath, PASSWORDS); - - sprintf(filepath, "%s%d.bin", filepath, req.level); + sprintf(filepath, "%s%d.bin", PASSWORDS, req.level); if (readl(filepath, buffer, 256) == -1) { - Request aux; + aux.ID = req.ID; memset(&req, 0, sizeof(req)); aux.type = req.type; aux.level = -1; send(connfd, &aux, sizeof(aux), 0); } + + aux.ID = req.ID; + memccpy(aux.key, buffer, 0, 256); + aux.level = req.level; + aux.type = req.type; + send(connfd, &aux, sizeof(aux), 0); + free(filepath); } else if (req.type == 1)