Changed player names to allocated strings to be friendly to Scheme!

This commit is contained in:
Barra Ó Catháin 2023-11-20 21:33:45 +00:00 committed by Barry Kane
parent aa382fefc2
commit c282fb20ad
2 changed files with 4 additions and 1 deletions

View File

@ -31,6 +31,7 @@ struct Player * createNewPlayer(struct ClientConnection * connection)
{
struct Player * newPlayer = calloc(1, sizeof(struct Player));
newPlayer->connection = connection;
newPlayer->name = calloc(PLAYER_NAME_LENGTH, sizeof(char));
return newPlayer;
}
@ -38,6 +39,7 @@ struct Player * createNewPlayer(struct ClientConnection * connection)
// Deallocates a player:
void deallocatePlayer(struct Player ** player)
{
free((*player)->name);
free(*player);
*player = NULL;
}

View File

@ -5,6 +5,7 @@
// =========================================
#ifndef PLAYER_DATA_H
#define PLAYER_DATA_H
#define PLAYER_NAME_LENGTH 64
#include <stdbool.h>
#include "connections.h"
@ -14,7 +15,7 @@
struct Player
{
struct ClientConnection * connection;
char name[64];
char * name;
};
// Functions: