This commit is contained in:
Lorenzo Bianchi 2023-06-05 16:17:20 +02:00
parent 4fa39f47f0
commit f89c162652
4 changed files with 11 additions and 14 deletions

View File

@ -72,7 +72,7 @@ int main(int argc, char *argv[]){
semOp(_SEMID, ID, -1);
printBoard();
printf(PCLIENT "Waiting for oponent\n"); //FIXME: solo se la partita non è finita
printf(PCLIENT "Waiting for opponent\n");
}
return 0;

View File

@ -108,5 +108,10 @@ int main(int argc, char *argv[]){
kill(_PIDS[0], SIGUSR1);
kill(_PIDS[1], SIGUSR1);
semOp(_SEMID, SERVER, -1);
semOp(_SEMID, SERVER, -1);
printf("tutto ok\n");
raise(SIGTERM);
}

View File

@ -85,7 +85,6 @@ void rcvPlayer(player_ds *player) {
msgRcv(player, sizeof(player_ds) - sizeof(long), PLAYER);
}
void rcvGame_end(game_end_t *game) {
printf("aspetto game\n");
msgRcv(game, sizeof(game_end_t) - sizeof(long), GAME_END);
}

View File

@ -126,10 +126,12 @@ void setServerSignal(int sig) {
void sigHandlerClient(int sig) {
// Ctrl+C
if (sig == SIGINT) {
printf(PCLIENT "Quitting game\n");
printf("\n" PCLIENT "Quitting game\n");
game_end_t game = {.mtype = GAME_END, .winner = ID ^ 1};
sndGame_end(&game);
kill(SERVER_PID, SIGUSR1);
printf(PSERVER "You quit\n");
kill(getpid(), SIGTERM);
}
@ -148,19 +150,10 @@ void sigHandlerClient(int sig) {
// Fine partita
if (sig == SIGUSR1) {
struct msqid_ds ds;
if (msgctl(_MSGQID, IPC_STAT, &ds) == -1)
errExitMsg("msgctl");
printf("msg num: %ld\n", ds.msg_qnum);
printf("messaggio?\n");
game_end_t winner;
rcvGame_end(&winner);
printf("messaggio!\n");
printf("%d %d (%ld)\n", ID, winner.winner, winner.mtype);
// printBoard();
printBoard();
if (winner.winner == ID) {
printf(PSERVER "YOU WIN!!!\n");
} else if (winner.winner == -1) {
@ -169,8 +162,8 @@ void sigHandlerClient(int sig) {
printf(PSERVER "YOU LOSE!!!\n");
}
// avviso server che ho ricevuto il messaggio
semOp(_SEMID, SERVER, 1);
printf("test\n");
}
}