funzia2
This commit is contained in:
parent
4fa39f47f0
commit
f89c162652
|
@ -72,7 +72,7 @@ int main(int argc, char *argv[]){
|
||||||
semOp(_SEMID, ID, -1);
|
semOp(_SEMID, ID, -1);
|
||||||
printBoard();
|
printBoard();
|
||||||
|
|
||||||
printf(PCLIENT "Waiting for oponent\n"); //FIXME: solo se la partita non è finita
|
printf(PCLIENT "Waiting for opponent\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -108,5 +108,10 @@ int main(int argc, char *argv[]){
|
||||||
kill(_PIDS[0], SIGUSR1);
|
kill(_PIDS[0], SIGUSR1);
|
||||||
kill(_PIDS[1], SIGUSR1);
|
kill(_PIDS[1], SIGUSR1);
|
||||||
|
|
||||||
|
semOp(_SEMID, SERVER, -1);
|
||||||
|
semOp(_SEMID, SERVER, -1);
|
||||||
|
|
||||||
|
printf("tutto ok\n");
|
||||||
|
|
||||||
raise(SIGTERM);
|
raise(SIGTERM);
|
||||||
}
|
}
|
||||||
|
|
|
@ -85,7 +85,6 @@ void rcvPlayer(player_ds *player) {
|
||||||
msgRcv(player, sizeof(player_ds) - sizeof(long), PLAYER);
|
msgRcv(player, sizeof(player_ds) - sizeof(long), PLAYER);
|
||||||
}
|
}
|
||||||
void rcvGame_end(game_end_t *game) {
|
void rcvGame_end(game_end_t *game) {
|
||||||
printf("aspetto game\n");
|
|
||||||
msgRcv(game, sizeof(game_end_t) - sizeof(long), GAME_END);
|
msgRcv(game, sizeof(game_end_t) - sizeof(long), GAME_END);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -126,10 +126,12 @@ void setServerSignal(int sig) {
|
||||||
void sigHandlerClient(int sig) {
|
void sigHandlerClient(int sig) {
|
||||||
// Ctrl+C
|
// Ctrl+C
|
||||||
if (sig == SIGINT) {
|
if (sig == SIGINT) {
|
||||||
printf(PCLIENT "Quitting game\n");
|
printf("\n" PCLIENT "Quitting game\n");
|
||||||
game_end_t game = {.mtype = GAME_END, .winner = ID ^ 1};
|
game_end_t game = {.mtype = GAME_END, .winner = ID ^ 1};
|
||||||
sndGame_end(&game);
|
sndGame_end(&game);
|
||||||
kill(SERVER_PID, SIGUSR1);
|
kill(SERVER_PID, SIGUSR1);
|
||||||
|
|
||||||
|
printf(PSERVER "You quit\n");
|
||||||
kill(getpid(), SIGTERM);
|
kill(getpid(), SIGTERM);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -148,19 +150,10 @@ void sigHandlerClient(int sig) {
|
||||||
|
|
||||||
// Fine partita
|
// Fine partita
|
||||||
if (sig == SIGUSR1) {
|
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;
|
game_end_t winner;
|
||||||
rcvGame_end(&winner);
|
rcvGame_end(&winner);
|
||||||
printf("messaggio!\n");
|
|
||||||
printf("%d %d (%ld)\n", ID, winner.winner, winner.mtype);
|
|
||||||
|
|
||||||
// printBoard();
|
printBoard();
|
||||||
if (winner.winner == ID) {
|
if (winner.winner == ID) {
|
||||||
printf(PSERVER "YOU WIN!!!\n");
|
printf(PSERVER "YOU WIN!!!\n");
|
||||||
} else if (winner.winner == -1) {
|
} else if (winner.winner == -1) {
|
||||||
|
@ -169,8 +162,8 @@ void sigHandlerClient(int sig) {
|
||||||
printf(PSERVER "YOU LOSE!!!\n");
|
printf(PSERVER "YOU LOSE!!!\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// avviso server che ho ricevuto il messaggio
|
||||||
semOp(_SEMID, SERVER, 1);
|
semOp(_SEMID, SERVER, 1);
|
||||||
printf("test\n");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue