Added protocol 3 has a possible request to receive the list of all indeces available.
This commit is contained in:
parent
45e690c24c
commit
eae02d5bf6
37
src/server.c
37
src/server.c
@ -191,6 +191,43 @@ int main(void)
|
|||||||
}
|
}
|
||||||
break;
|
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:
|
default:
|
||||||
fprintf(stderr, "Invalid request type\n");
|
fprintf(stderr, "Invalid request type\n");
|
||||||
break;
|
break;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user