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 <stdbool.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include "constants.h"
|
|
|
|
#include "playerdata.h"
|
2022-03-06 00:36:42 +00:00
|
|
|
#include <gnutls/gnutls.h>
|
|
|
|
|
|
|
|
// A message datastructure containing a user/character name and the content:
|
|
|
|
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;
|
|
|
|
|
2022-05-05 18:45:27 +00:00
|
|
|
// ==================
|
|
|
|
// -=[Message I/O]=-:
|
|
|
|
// ==================
|
2022-04-07 00:38:36 +00:00
|
|
|
|
2022-03-06 00:36:42 +00:00
|
|
|
// Sends a message to a given TLS session, wraps the calls to gnutls_write:
|
2022-04-07 00:38:36 +00:00
|
|
|
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);
|
|
|
|
|
|
|
|
// ===================
|
|
|
|
// -=[Output Queue]=-:
|
|
|
|
// ===================
|
|
|
|
typedef struct outputMessage outputMessage;
|
|
|
|
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;
|
|
|
|
|
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-04-07 00:38:36 +00:00
|
|
|
// ==================
|
|
|
|
// -=[Input Queue]=-:
|
|
|
|
// ==================
|
|
|
|
typedef struct inputMessage inputMessage;
|
|
|
|
typedef struct inputMessage
|
|
|
|
{
|
|
|
|
playerInfo * sender;
|
|
|
|
userMessage * content;
|
|
|
|
} inputMessage;
|
|
|
|
|
2022-05-05 18:45:27 +00:00
|
|
|
// =======================
|
|
|
|
// -=[Input Sanitation]=-:
|
|
|
|
// =======================
|
2022-04-07 00:38:36 +00:00
|
|
|
|
|
|
|
// Sanatize user input to ensure it's okay to send to the server:
|
|
|
|
void userInputSanatize(char * inputString, int length);
|
2022-03-06 00:36:42 +00:00
|
|
|
|
2022-10-16 15:13:33 +00:00
|
|
|
// Sanatize user names so they display correctly;
|
|
|
|
void userNameSanatize(char * inputString, int length);
|
|
|
|
|
2022-03-06 00:36:42 +00:00
|
|
|
#endif
|
2022-04-07 00:38:36 +00:00
|
|
|
|