2022-03-06 00:36:42 +00:00
|
|
|
// inputoutput.h: Header file contatning function prototypes and datastructures
|
|
|
|
// for dealing with input and output.
|
|
|
|
// Barry Kane, 2022.
|
2022-04-07 00:38:36 +00:00
|
|
|
#ifndef INPUTOUTPUT_H
|
2022-03-06 00:36:42 +00:00
|
|
|
#define INPUTOUTPUT_H
|
2022-04-07 00:38:36 +00:00
|
|
|
#include <ctype.h>
|
|
|
|
#include <stdlib.h>
|
2022-12-21 00:49:26 +00:00
|
|
|
#include <stdbool.h>
|
|
|
|
#include <gnutls/gnutls.h>
|
2022-04-07 00:38:36 +00:00
|
|
|
#include "constants.h"
|
|
|
|
#include "playerdata.h"
|
2022-03-06 00:36:42 +00:00
|
|
|
|
2023-04-11 13:41:44 +00:00
|
|
|
// Forward-declare some data structures to prevent cyclic dependencies:
|
2022-12-21 00:49:26 +00:00
|
|
|
typedef struct queue queue;
|
|
|
|
|
|
|
|
// ========================
|
|
|
|
// -=[ Data Structures ]=-:
|
|
|
|
// ========================
|
|
|
|
|
|
|
|
// Contains a character/player name and the content of a message:
|
2022-03-06 00:36:42 +00:00
|
|
|
typedef struct userMessage
|
2022-10-16 15:13:33 +00:00
|
|
|
{
|
2022-03-06 00:36:42 +00:00
|
|
|
char senderName[32];
|
2022-04-07 00:38:36 +00:00
|
|
|
char messageContent[MAX];
|
2022-03-06 00:36:42 +00:00
|
|
|
} userMessage;
|
|
|
|
|
2023-02-15 21:30:40 +00:00
|
|
|
// Contains a message sent to the server and a pointer to the playerInfo of the connection which sent it:
|
2022-12-21 00:49:26 +00:00
|
|
|
typedef struct inputMessage
|
|
|
|
{
|
|
|
|
playerInfo * sender;
|
|
|
|
userMessage * content;
|
|
|
|
} inputMessage;
|
2022-04-07 00:38:36 +00:00
|
|
|
|
2023-02-15 21:30:40 +00:00
|
|
|
// Contains a message to be sent, the amount of recipients, and pointers to their playerInfo:
|
2022-04-07 00:38:36 +00:00
|
|
|
typedef struct outputMessage
|
|
|
|
{
|
2022-12-20 15:55:24 +00:00
|
|
|
int recipientsCount;
|
2022-04-07 00:38:36 +00:00
|
|
|
userMessage * content;
|
2022-12-20 15:55:24 +00:00
|
|
|
playerInfo ** recipients;
|
2022-04-07 00:38:36 +00:00
|
|
|
} outputMessage;
|
|
|
|
|
2023-02-15 21:30:40 +00:00
|
|
|
// Contains pointers to the necessary information to be shared outputThreadHandler function:
|
2022-12-21 00:49:26 +00:00
|
|
|
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);
|
|
|
|
|
2022-12-20 15:55:24 +00:00
|
|
|
// Create a targetedOutput message to be delivered to the players pointed to in recipients:
|
|
|
|
outputMessage * createTargetedOutputMessage(userMessage * messageToQueue, playerInfo ** recipients, int recipientCount);
|
2022-03-06 00:36:42 +00:00
|
|
|
|
2022-12-21 00:49:26 +00:00
|
|
|
// A function for the output thread, which sends queued messages:
|
|
|
|
void * outputThreadHandler(void * parameters);
|
2022-04-07 00:38:36 +00:00
|
|
|
|
2022-12-21 00:49:26 +00:00
|
|
|
// Sanatize user input to ensure it's okay to process:
|
2022-04-07 00:38:36 +00:00
|
|
|
void userInputSanatize(char * inputString, int length);
|
2022-03-06 00:36:42 +00:00
|
|
|
|
2022-12-21 00:49:26 +00:00
|
|
|
// Sanatize user names so they display correctly:
|
2022-10-16 15:13:33 +00:00
|
|
|
void userNameSanatize(char * inputString, int length);
|
|
|
|
|
2022-03-06 00:36:42 +00:00
|
|
|
#endif
|
2022-04-07 00:38:36 +00:00
|
|
|
|