#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include void checkClientinput(int argc, char *argv[]); //TODO: mettere main ma non l'ho fatto per makefile int main(int argc, char *argv[]){ printf("Il mio pid per killarmi: %d\n", getpid()); //TMP setupClient(argc, argv); // // MSGQ // msg input_server_t input; msg_t msg; // msgrcv printf(PCLIENT "Waiting for message...\n"); rcvMsg(&msg); input = msg.server_in; // // SHM printf(PCLIENT "Setting up shm\n"); int shmBoardid = getShmid(); _BOARD = shmClientAt(shmBoardid); // // SEM printf(PCLIENT "Setting up sem\n"); key_t semKey = ftok(KEYFILE, 'S'); int semid; if ((semid = semget(semKey, 3, S_IRUSR | S_IWUSR | IPC_CREAT)) == -1) { errExit("getsem", "F4Client"); } // // aspetto che il server mi dia il permesso di collegarmi e segnalo collegamento al server semOp(semid, msg.player_id, -1); printf(PCLIENT "Connecting to server...\n"); semOp(semid, 2, 1); // mando i miei dati al server player_ds player = {.mtype = 3, .id = msg.player_id, .pid = getpid()}; strcpy(player.name_player, argv[1]); sndPlayer(&player); printf(PCLIENT "Searching for oponent...\n"); semOp(semid, msg.player_id, -1); printf(PCLIENT "Opponent found\n"); // PARTITA move_t move = {.mtype = 2}; setRows(input.rows); //FIXME: da mettere in un setup setCollums(input.collums); setTokens(msg.server_in.player1Token, msg.server_in.player2Token); while (1) { // aspetto il mio turno semOp(semid, msg.player_id, -1); // mettere id eccetera in var printBoard(_BOARD); // input e controllo printf(PCLIENT "Your Turn: "); int pos; do { scanf("%d", &move.move); move.move = checkMove(_BOARD, move.move - 1); } while (move.move == -1); // mando mossa al server sndMove(&move); semOp(semid, msg.player_id, -1); printBoard(_BOARD); printf(PCLIENT "Waiting for oponent\n"); //FIXME: solo se la partita non รจ finita } return 0; }