// inputoutput.h: Header file contatning function prototypes and datastructures // for dealing with input and output. // Barry Kane, 2022. #ifndef INPUTOUTPUT_H #define INPUTOUTPUT_H #include #include #include #include #include "constants.h" #include "playerdata.h" // Forward-declare some data structures to prevent cyclic dependencies: typedef struct queue queue; // ======================== // -=[ Data Structures ]=-: // ======================== // Contains a character/player name and the content of a message: typedef struct userMessage { char senderName[32]; char messageContent[MAX]; } userMessage; // Contains a message sent to the server and a pointer to the playerInfo of the connection which sent it: typedef struct inputMessage { playerInfo * sender; userMessage * content; } inputMessage; // Contains a message to be sent, the amount of recipients, and pointers to their playerInfo: typedef struct outputMessage { int recipientsCount; userMessage * content; playerInfo ** recipients; } outputMessage; // Contains pointers to the necessary information to be shared outputThreadHandler function: typedef struct outputThreadParameters { queue * outputQueue; gnutls_session_t * tlssessions; playerInfo * connectedPlayers; } outputThreadParameters; // ======================== // -=[ Functions ]=-: // ======================== // Sends a message to a given TLS session, wraps the calls to gnutls_write: int messageSend(gnutls_session_t receivingSession, userMessage * messageToSend); // Receives a message from a given TLS session, wraps the calls to gnutls_read: int messageReceive(gnutls_session_t receiveFromSession, userMessage * receiveToMessage); // Create a targetedOutput message to be delivered to the players pointed to in recipients: outputMessage * createTargetedOutputMessage(userMessage * messageToQueue, playerInfo ** recipients, int recipientCount); // A function for the output thread, which sends queued messages: void * outputThreadHandler(void * parameters); // Sanatize user input to ensure it's okay to process: void userInputSanatize(char * inputString, int length); // Sanatize user names so they display correctly: void userNameSanatize(char * inputString, int length); #endif