Elaborato_SO/src/client.c

60 lines
1.2 KiB
C
Raw Normal View History

2023-05-29 12:16:36 +02:00
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <server.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/sem.h>
#include <sys/stat.h>
#include <string.h>
#include <errExit.h>
#include <signal.h>
#include <custom_msgq.h>
#include <custom_sem.h>
#include <custom_shm.h>
#include <custom_sig.h>
#include <forza4.h>
2023-05-29 16:14:01 +02:00
int ID;
2023-05-31 11:52:32 +02:00
pid_t SERVER_PID;
2023-06-17 12:05:56 +02:00
int clientBot = 0;
2023-05-29 16:14:01 +02:00
2023-05-29 12:16:36 +02:00
void checkClientinput(int argc, char *argv[]);
void setupClient(int argc, char *argv[]) {
2023-05-29 12:35:04 +02:00
// CHECK INPUT
2023-05-29 12:16:36 +02:00
checkClientinput(argc, argv);
2023-05-29 12:35:04 +02:00
// MSGQ
setupClientMsgq();
2023-06-01 08:39:49 +02:00
// SIGNAL
setupClientSignalHandler();
2023-05-29 13:12:38 +02:00
// SHM
setupClientShm();
2023-05-29 15:01:11 +02:00
setupClientSem();
2023-05-29 12:16:36 +02:00
}
void checkClientinput(int argc, char *argv[]){
if (argc < 2) {
printf(PHELP "./F4Client PLAYER_NAME\n"
"\t- PLAYER_NAME \t\tplayer name\n"
);
exit(EXIT_SUCCESS);
2023-06-17 11:10:30 +02:00
} else if (argc > 3) {
2023-06-17 11:39:54 +02:00
errExitMsg("To many arguments");
2023-05-29 12:16:36 +02:00
}
if (!argv[1] || strlen(argv[1]) > MAX_NAME) {
errExitMsg("Invalid player name");
}
2023-06-17 11:10:30 +02:00
if (argv[2]) {
2023-06-17 11:39:54 +02:00
if (strcmp(argv[2], "bot") && strcmp(argv[2], "auto")) {
2023-06-17 11:10:30 +02:00
errExitMsg("Invalid third argument");
}
}
2023-05-29 12:16:36 +02:00
}