client playing
This commit is contained in:
parent
99e065a65c
commit
7b631e5b22
|
@ -18,13 +18,17 @@
|
|||
|
||||
tile_t *boardClient = NULL;
|
||||
|
||||
void checkClientinput(int argc, char *argv[]);
|
||||
|
||||
void sigHandlerClient(int sig) {
|
||||
// Ctrl+C
|
||||
if (sig == SIGINT) {
|
||||
//TODO:
|
||||
|
||||
sig = SIGTERM;
|
||||
}
|
||||
|
||||
// Terminazione e chiusura terminale
|
||||
if (sig == SIGTERM || sig == SIGHUP) {
|
||||
// shm
|
||||
if (boardClient) {
|
||||
|
@ -38,6 +42,11 @@ void sigHandlerClient(int sig) {
|
|||
printf("\n");
|
||||
}
|
||||
|
||||
// Fine partita
|
||||
if (sig == SIGUSR1) {
|
||||
|
||||
}
|
||||
|
||||
exit(0);
|
||||
}
|
||||
|
||||
|
@ -45,9 +54,8 @@ void sigHandlerClient(int sig) {
|
|||
//TODO: mettere main ma non l'ho fatto per makefile
|
||||
int main(int argc, char *argv[]){
|
||||
|
||||
//TODO: controllo input
|
||||
checkClientinput(argc, argv);
|
||||
|
||||
input_server_t input;
|
||||
|
||||
// SIGNAL
|
||||
printfClient("Setting up signal\n");
|
||||
|
@ -56,6 +64,7 @@ int main(int argc, char *argv[]){
|
|||
sigdelset(&mySet, SIGINT);
|
||||
sigdelset(&mySet, SIGTERM);
|
||||
sigdelset(&mySet, SIGHUP);
|
||||
sigdelset(&mySet, SIGUSR1);
|
||||
sigprocmask(SIG_SETMASK, &mySet, NULL);
|
||||
|
||||
if (signal(SIGINT, sigHandlerClient) == SIG_ERR) {
|
||||
|
@ -75,6 +84,7 @@ int main(int argc, char *argv[]){
|
|||
}
|
||||
|
||||
// msg
|
||||
input_server_t input;
|
||||
msg_t msg;
|
||||
|
||||
// msgrcv
|
||||
|
@ -104,10 +114,10 @@ int main(int argc, char *argv[]){
|
|||
|
||||
|
||||
|
||||
|
||||
semOp(semid, msg.player_id, -1); // aspetta che il server gli dia il permesso di connettersi
|
||||
// aspetto che il server mi dia il permesso di collegarmi e segnalo collegamento al server
|
||||
semOp(semid, msg.player_id, -1);
|
||||
printfClient("Connecting to server...\n");
|
||||
semOp(semid, 2, 1); // finito operazioni di connessione
|
||||
semOp(semid, 2, 1);
|
||||
|
||||
|
||||
// mando i miei dati al server
|
||||
|
@ -121,23 +131,48 @@ int main(int argc, char *argv[]){
|
|||
|
||||
semOp(semid, msg.player_id, -1);
|
||||
|
||||
printfServer("Opponent found\n");
|
||||
printfClient("Opponent found\n");
|
||||
|
||||
|
||||
|
||||
move_t move = {.mtype = 2};
|
||||
// PARTITA
|
||||
move_t move = {.mtype = 2};
|
||||
int current_move;
|
||||
|
||||
while (1) { //FIXME: potenzialmente da cambiare questo while (ma forse bastano i segnali)
|
||||
semOp(semid, msg.player_id, -1); // aspetto il mio turno
|
||||
// aspetto il mio turno
|
||||
semOp(semid, msg.player_id, -1);
|
||||
|
||||
printfServer("Tocca a te: \n");
|
||||
scanf("%d", &move.move);
|
||||
// input e controllo
|
||||
printfServer("Your Turn: \n");
|
||||
do {
|
||||
scanf("%d", &move.move);
|
||||
move.move--;
|
||||
current_move = checkMove(move.move);
|
||||
} while(current_move < 0);
|
||||
|
||||
// mando mossa al server
|
||||
move.move = current_move;
|
||||
if (msgsnd(msgid, &move, sizeof(move_t) - sizeof(long), 0) == -1) {
|
||||
errExit("msgsnd", "partita_client");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void checkClientinput(int argc, char *argv[]){
|
||||
if (argc < 2) {
|
||||
printf("\033[92m<Help>\033[39m ./F4Client PLAYER_NAME\n"
|
||||
"\t- PLAYER_NAME \t\tplayer name\n"
|
||||
);
|
||||
exit(EXIT_SUCCESS);
|
||||
} else if (argc > 2) {
|
||||
printfClient("To many arguments!\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if (!argv[1]) { //FIXME: è possibile che succeda?
|
||||
errExitMsg("Invalid player name");
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue