Server now returns if it finds a password like the user requested.

This commit is contained in:
Afonso Clerigo Mendes de Sousa 2025-02-27 13:01:48 +00:00
parent a6a4fbf7ac
commit 3b1d210a9c

View File

@ -102,23 +102,29 @@ int main(void)
if (req.type == 0) if (req.type == 0)
{ {
// debug // debug
Request aux;
printf("Received request type 0\n"); printf("Received request type 0\n");
char *filepath = create(char); char *filepath = create(char);
filepath = size(filepath, 256); filepath = size(filepath, 256);
strcpy(filepath, PASSWORDS); sprintf(filepath, "%s%d.bin", PASSWORDS, req.level);
sprintf(filepath, "%s%d.bin", filepath, req.level);
if (readl(filepath, buffer, 256) == -1) if (readl(filepath, buffer, 256) == -1)
{ {
Request aux;
aux.ID = req.ID; aux.ID = req.ID;
memset(&req, 0, sizeof(req)); memset(&req, 0, sizeof(req));
aux.type = req.type; aux.type = req.type;
aux.level = -1; aux.level = -1;
send(connfd, &aux, sizeof(aux), 0); 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); free(filepath);
} }
else if (req.type == 1) else if (req.type == 1)