ALlowed for the server to change client prompt.

- The server can now send some data in the normally unused "senderName" field for a server mesasge.
- This will be set as the prompt for the client.
This commit is contained in:
Barra Ó Catháin 2023-02-25 23:04:35 +00:00
parent 0add957224
commit 8814a45c52
1 changed files with 20 additions and 4 deletions

View File

@ -29,6 +29,7 @@ typedef struct threadparameters
bool loggingFlag; bool loggingFlag;
WINDOW * window; WINDOW * window;
int characterDelay; int characterDelay;
char * prompt;
} threadparameters; } threadparameters;
// Use sockaddr as a type: // Use sockaddr as a type:
@ -45,13 +46,15 @@ void * messageSender(void * parameters)
FILE * loggingStream = threadParameters->loggingStream; FILE * loggingStream = threadParameters->loggingStream;
bool loggingFlag = threadParameters->loggingFlag; bool loggingFlag = threadParameters->loggingFlag;
WINDOW * window = threadParameters->window; WINDOW * window = threadParameters->window;
char * prompt = threadParameters->prompt;
userMessage sendBuffer; userMessage sendBuffer;
// Repeatedly get input from the user, place it in a userMessage, and send it to the server: // Repeatedly get input from the user, place it in a userMessage, and send it to the server:
while (!shouldExit) while (!shouldExit)
{ {
// Print the prompt: // Print the prompt:
wprintw(window, "\n\n\nCOMM-LINK> "); wprintw(window, "\n\n\n");
wprintw(window, prompt);
if (wgetnstr(window, sendBuffer.messageContent, MAX) == ERR) if (wgetnstr(window, sendBuffer.messageContent, MAX) == ERR)
{ {
// Quit if there's any funny business with getting input: // Quit if there's any funny business with getting input:
@ -111,8 +114,15 @@ void * messageReceiver(void * parameters)
// Check if it's a server message: // Check if it's a server message:
else if (receiveBuffer.senderName[0] == '\0') else if (receiveBuffer.senderName[0] == '\0')
{ {
// Check if the server wants to change the prompt:
if (receiveBuffer.senderName[1] != '\0')
{
strncpy(threadParameters->prompt, &receiveBuffer.senderName[1], 63);
threadParameters->prompt[63] = '\0';
}
// Check if it's a command to disconnect: // Check if it's a command to disconnect:
if (receiveBuffer.messageContent[0] == '\0') if (receiveBuffer.messageContent[0] == '\0' && receiveBuffer.senderName[1] != '\0')
{ {
shouldExit = true; shouldExit = true;
pthread_exit(NULL); pthread_exit(NULL);
@ -307,6 +317,7 @@ int main(int argc, char ** argv)
logArea->tlsSession = tlsSession; logArea->tlsSession = tlsSession;
logArea->loggingFlag = chatLogging; logArea->loggingFlag = chatLogging;
logArea->characterDelay = characterDelay; logArea->characterDelay = characterDelay;
if (chatLog != NULL) if (chatLog != NULL)
{ {
logArea->loggingStream = chatLog; logArea->loggingStream = chatLog;
@ -314,13 +325,18 @@ int main(int argc, char ** argv)
messageArea->window = newwin(3, COLS - 2, LINES - 4, 1); messageArea->window = newwin(3, COLS - 2, LINES - 4, 1);
messageArea->tlsSession = tlsSession; messageArea->tlsSession = tlsSession;
messageArea->loggingFlag = gameLogging; messageArea->loggingFlag = gameLogging;
// Set the appropriate log pointers: // Set the appropriate log pointers:
if (gameLog != NULL) if (gameLog != NULL)
{ {
messageArea->loggingStream = gameLog; messageArea->loggingStream = gameLog;
} }
// Set up the string to hold the current "prompt" that the server has sent:
messageArea->prompt = calloc(64, sizeof(char));
strcpy(messageArea->prompt, "> ");
logArea->prompt = messageArea->prompt;
// Set the two windows to scroll: // Set the two windows to scroll:
scrollok(logArea->window, true); scrollok(logArea->window, true);
scrollok(messageArea->window, true); scrollok(messageArea->window, true);