This commit is contained in:
Lorenzo Bianchi 2023-05-25 14:28:45 +02:00
parent 4168ada3e2
commit 4c6e50dfc2
7 changed files with 25 additions and 28 deletions

View File

@ -5,10 +5,8 @@
- al momomento i client non sanno ancora le dimensioni del campo (le hanno ricevute ma non settate)
(in realta non so perche funzioni la checkwin al momento)
- sistemare se usare printfServer/Client
- ho messo input del server globale, alcune funzioni non ne usufruiscono ancora (tip shm);
- printfServer mette \n all'inizio quindi non stampa lultima riga al momento
- define per i semafori invece di usare 1/-1
- ho fatto le define per i semafori invece di usare 1/-1
- ctrl+c con time

View File

@ -159,7 +159,7 @@ int main(int argc, char *argv[]){
int pos;
do {
scanf("%d", &move.move);
move.move = checkMove(boardClient, move.move);
move.move = checkMove(boardClient, move.move - 1);
} while (move.move == -1);
// mando mossa al server

View File

@ -20,7 +20,7 @@
#include <custom_sig.h>
int main(int argc, char *argv[]){
printf("Il mio pid per killarmi: %d\n", getpid()); //TMP
printf("Il mio pid per killarmi: %d\n", getpid()); //FIXME: TMP
// CHECK_INPUT
_INPUT_S = check_input(argc, argv);

View File

@ -19,8 +19,6 @@ void setupServerSem() {
}
resetServerSem(_SEMID);
printf("%d\n", _SEMID);
}
void semOp(int semid, short sem_num, short sem_op) {

View File

@ -4,6 +4,7 @@
#include <custom_shm.h>
#include <errExit.h>
#include <forza4.h>
int _SHMID;
@ -17,21 +18,25 @@ int getShmid(int row, int col) {
}
tile_t * shmServerAt(int shmid) {
tile_t *result = (tile_t *)shmat(shmid, NULL, 0);
if (result == SHMERR) {
tile_t *board = (tile_t *)shmat(shmid, NULL, 0);
if (board == SHMERR) {
errExit("shmat", "shmServerAt");
}
return result;
for (int i=0; i < _ROWS * _COLLUMS; i++) {
board[i] = 0;
}
return board;
}
tile_t * shmClientAt(int shmid) {
tile_t *result = (tile_t *)shmat(shmid, NULL, SHM_RDONLY);
if (result == SHMERR) {
tile_t *board = (tile_t *)shmat(shmid, NULL, SHM_RDONLY);
if (board == SHMERR) {
errExit("shmat", "shmClientAt");
}
return result;
return board;
}
void shmDt(void *shm_ptr) {

View File

@ -67,7 +67,7 @@ void sigHandlerServer(int sig) {
// msgq
if (_MSGQID) {
printf(PSERVER "Deleting msg\n");
if (msgctl(_MSGQID, IPC_RMID, NULL) == -1) { //TODO: funzione
if (msgctl(_MSGQID, IPC_RMID, NULL) == -1) { //TODO: funzioni
errExit("msgctl", "sigHandlerServer");
}
}

View File

@ -82,22 +82,18 @@ int checkWinAll(tile_t *board){
void printBoard(tile_t *board) {
for (int i=0; i < _ROWS; i++) {
printf("|");
for (int j=0; j < _COLLUMS; j++) {
printf(" ");
printTile(board[getIndex(i, j)]);
if (j != _COLLUMS - 1) {
printf(" | ");
} else {
printf("\n");
}
}
for (int j=0; i != _ROWS - 1 && j < _COLLUMS - 1; j++) {
printf("----");
}
if (i < _ROWS - 1) {
printf("---\n");
printf(" ");
}
printf("|\n");
}
for (int i=0; i<_ROWS; i++) {
printf("--");
}
printf("------\n");
}
void printTile(tile_t t) {
@ -118,7 +114,7 @@ void printTile(tile_t t) {
// gli si passa la colona partendo da 1
// se
int checkMove(tile_t *board, int collums) {
if (collums <= 0 || collums > _COLLUMS) {
if (collums < 0 || collums >= _COLLUMS) {
char buf[100];
sprintf(buf, "the collums must be between 1 and %d", _COLLUMS);
warningMsg(buf);