game end
This commit is contained in:
parent
7b631e5b22
commit
674737db05
|
@ -52,4 +52,9 @@ typedef struct {
|
|||
pid_t pid;
|
||||
} player_ds;
|
||||
|
||||
typedef struct {
|
||||
long mtype; // type 4
|
||||
int winner; // -1 se draw
|
||||
} game_end_t;
|
||||
|
||||
#endif
|
|
@ -16,6 +16,9 @@
|
|||
#include <errExit.h>
|
||||
#include <nonsodovemetterle.h>
|
||||
|
||||
int msgid;
|
||||
int game_state;
|
||||
|
||||
tile_t *boardClient = NULL;
|
||||
|
||||
void checkClientinput(int argc, char *argv[]);
|
||||
|
@ -40,14 +43,18 @@ void sigHandlerClient(int sig) {
|
|||
}
|
||||
|
||||
printf("\n");
|
||||
|
||||
exit(0);
|
||||
}
|
||||
|
||||
// Fine partita
|
||||
if (sig == SIGUSR1) {
|
||||
|
||||
game_end_t winner;
|
||||
if (msgrcv(msgid, &winner, sizeof(game_end_t) - sizeof(long), 4, 0) == -1) {
|
||||
errExit("msgrcv", "fine partita");
|
||||
}
|
||||
game_state = winner.winner;
|
||||
}
|
||||
|
||||
exit(0);
|
||||
}
|
||||
|
||||
|
||||
|
@ -56,7 +63,6 @@ int main(int argc, char *argv[]){
|
|||
|
||||
checkClientinput(argc, argv);
|
||||
|
||||
|
||||
// SIGNAL
|
||||
printfClient("Setting up signal\n");
|
||||
sigset_t mySet;
|
||||
|
@ -73,12 +79,18 @@ int main(int argc, char *argv[]){
|
|||
if (signal(SIGTERM, sigHandlerClient) == SIG_ERR) {
|
||||
errExit("signal SIGTERM", "F4Client");
|
||||
}
|
||||
if (signal(SIGHUP, sigHandlerClient) == SIG_ERR) {
|
||||
errExit("signal SIGHUP", "F4Client");
|
||||
}
|
||||
if (signal(SIGUSR1, sigHandlerClient) == SIG_ERR) {
|
||||
errExit("signal SIGUSR1", "F4Client");
|
||||
}
|
||||
//
|
||||
|
||||
// MSGQ
|
||||
printfClient("Setting up msgq\n");
|
||||
key_t msgKey = ftok(KEYFILE, 'M');
|
||||
int msgid = msgget(msgKey, IPC_CREAT | S_IRUSR | S_IWUSR);
|
||||
msgid = msgget(msgKey, IPC_CREAT | S_IRUSR | S_IWUSR);
|
||||
if (msgid == -1) {
|
||||
errExit("msgget", "F4Client");
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue