names msg

This commit is contained in:
Lorenzo Bianchi 2023-05-16 23:42:42 +02:00
parent 3ce987fe90
commit 951d66265a
3 changed files with 10 additions and 12 deletions

View File

@ -42,12 +42,12 @@ typedef struct {
int move;
} move_t;
#define MAX_NAME 16
typedef struct {
long mtype; // type 3
int id;
char *name_player;
char name_player[MAX_NAME];
} player_names_t;
#define MAX_NAME 16
#endif

View File

@ -7,6 +7,7 @@
#include <signal.h>
#include <sys/sem.h>
#include <sys/shm.h>
#include <string.h>
#include <custom_sem.h>
#include <structures.h>
@ -108,8 +109,9 @@ int main(int argc, char *argv[]){
// mando il mio nome al server
printf("%s\n", argv[1]);
player_names_t name = {.mtype = 3, .id = msg.player_id, .name_player = argv[1]};
char name_tmp[MAX_NAME];
strcpy(name_tmp, argv[1]);
player_names_t name = {.mtype = 3, .id = msg.player_id, .name_player = name_tmp};
if (msgsnd(msgid, &name, sizeof(player_names_t) - sizeof(long), 0) == -1) {
errExit("msgsnd", "mandare nome");
}

View File

@ -151,10 +151,7 @@ int main(int argc, char *argv[]){
semOp(semid, 2, -1);
player_names_t names; // lo so si possono usare nomi piu chiari ma problema tuo (mi riferisco a te e me futuro)
char **name = (char**)malloc(2 * sizeof(char *)); //FIXME: non riesco a farlo statico
for (int h=0; h<2; h++) {
name[h] = (char*)malloc(MAX_NAME * sizeof(char));
}
char name[2][MAX_NAME];
// ricevuta nome primo client
if (msgrcv(msgid, &names, sizeof(player_names_t) - sizeof(long), 3, 0) == -1) {
@ -163,8 +160,7 @@ int main(int argc, char *argv[]){
printf("TEST\n");
printf("%d\n", names.id);
printf("%s\n", names.name_player);
name[names.id] = names.name_player;
printf("%s\n", names.name_player);
// name[names.id] = names.name_player;
printfServer("Player ");
printf("%s connected\n", name[names.id]); //
@ -175,7 +171,7 @@ int main(int argc, char *argv[]){
if (msgrcv(msgid, &names, sizeof(player_names_t) - sizeof(long), 3, 0) == -1) {
errExit("msgrcv", "ricevuta secondo nome");
}
name[names.id] = names.name_player;
// name[names.id] = names.name_player;
printfServer("Player ");
printf("%s connected\n", name[names.id]);