non funziona se abbandona il giocatore NON di turno
This commit is contained in:
parent
c744bb47b4
commit
5f6986b685
4
TODO.txt
4
TODO.txt
|
@ -6,4 +6,6 @@
|
|||
|
||||
- se le ipcs non si sono chiuse bene non funzia
|
||||
|
||||
- controllare pareggi
|
||||
- controllare se funzionano pareggi
|
||||
|
||||
- non funziona labbandono del giocatore non di turno
|
|
@ -108,5 +108,5 @@ int main(int argc, char *argv[]){
|
|||
kill(_PIDS[0], SIGUSR1);
|
||||
kill(_PIDS[1], SIGUSR1);
|
||||
|
||||
return 0;
|
||||
raise(SIGTERM);
|
||||
}
|
||||
|
|
|
@ -44,13 +44,20 @@ void sigHandlerServer(int sig) {
|
|||
|
||||
sndGame_end(&game);
|
||||
sndGame_end(&game);
|
||||
|
||||
kill(_PIDS[0], SIGUSR1); //FIXME: fare una funzione per queste robe perche anche gia scritta a fine F4Server
|
||||
semOp(_SEMID, SERVER, -1);
|
||||
kill(_PIDS[1], SIGUSR1);
|
||||
|
||||
// aspetto terminazione dei due figli
|
||||
semOp(_SEMID, 0, -1);
|
||||
semOp(_SEMID, 1, -1);
|
||||
// aspetto che i figli ricevano i messaggi
|
||||
printf("aspettato uno\n");
|
||||
semOp(_SEMID, SERVER, -1);
|
||||
|
||||
printf("aspettato\n");
|
||||
|
||||
printf("%d %d\n", _PIDS[0], _PIDS[1]);
|
||||
|
||||
kill(_PIDS[0], SIGTERM);
|
||||
kill(_PIDS[1], SIGTERM);
|
||||
|
||||
raise(SIGTERM);
|
||||
}
|
||||
|
@ -129,11 +136,9 @@ void setServerSignal(int sig) {
|
|||
void sigHandlerClient(int sig) {
|
||||
// Ctrl+C
|
||||
if (sig == SIGINT) {
|
||||
// per la sicurezza premere una seconda volta chiude il client
|
||||
printf(PCLIENT "Quitting game\n");
|
||||
game_end_t game = {.mtype = GAME_END, .winner = ID ^ 1};
|
||||
sndGame_end(&game);
|
||||
printf("server pid: %d\n", SERVER_PID);
|
||||
kill(SERVER_PID, SIGUSR1);
|
||||
}
|
||||
|
||||
|
@ -152,12 +157,18 @@ 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");
|
||||
|
||||
printBoard();
|
||||
// printBoard();
|
||||
if (winner.winner == ID) {
|
||||
printf(PSERVER "YOU WIN!!!\n");
|
||||
} else if (winner.winner == -1) {
|
||||
|
@ -166,7 +177,8 @@ void sigHandlerClient(int sig) {
|
|||
printf(PSERVER "YOU LOSE!!!\n");
|
||||
}
|
||||
|
||||
semOp(_SEMID, ID, 1);
|
||||
semOp(_SEMID, SERVER, 1);
|
||||
printf("test\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue