79 lines
1.9 KiB
C
79 lines
1.9 KiB
C
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <sys/types.h>
|
|
#include <sys/ipc.h>
|
|
#include <sys/stat.h>
|
|
#include <sys/msg.h>
|
|
#include <signal.h>
|
|
#include <sys/sem.h>
|
|
#include <sys/shm.h>
|
|
#include <string.h>
|
|
#include <unistd.h>
|
|
|
|
#include <custom_sem.h>
|
|
#include <structures.h>
|
|
#include <custom_shm.h>
|
|
#include <errExit.h>
|
|
#include <custom_msgq.h>
|
|
#include <forza4.h>
|
|
#include <client.h>
|
|
|
|
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
|
|
|
|
msg_t msg;
|
|
setupClient(argc, argv);
|
|
|
|
printf("fin qua funzia (spero) %d\n", _SEMID);
|
|
scanf("%d");
|
|
|
|
// 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};
|
|
|
|
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;
|
|
} |