Talking now changes the prompt.

- The server will now change the prompt for a user who begins a conversation with another player to that player's name.
This commit is contained in:
Barra Ó Catháin 2023-02-26 00:16:07 +00:00
parent 8814a45c52
commit 408033d48a
3 changed files with 32 additions and 7 deletions

View File

@ -52,9 +52,13 @@ void * messageSender(void * parameters)
// Repeatedly get input from the user, place it in a userMessage, and send it to the server:
while (!shouldExit)
{
// Print the prompt:
usleep(100000);
// Clear the window:
wprintw(window, "\n\n\n");
// Print the prompt:
wprintw(window, prompt);
if (wgetnstr(window, sendBuffer.messageContent, MAX) == ERR)
{
// Quit if there's any funny business with getting input:
@ -122,7 +126,7 @@ void * messageReceiver(void * parameters)
}
// Check if it's a command to disconnect:
if (receiveBuffer.messageContent[0] == '\0' && receiveBuffer.senderName[1] != '\0')
if (receiveBuffer.messageContent[0] == '\0')
{
shouldExit = true;
pthread_exit(NULL);
@ -333,8 +337,8 @@ int main(int argc, char ** argv)
}
// Set up the string to hold the current "prompt" that the server has sent:
messageArea->prompt = calloc(64, sizeof(char));
strcpy(messageArea->prompt, "> ");
messageArea->prompt = calloc(32, sizeof(char));
strcpy(messageArea->prompt, " Login > ");
logArea->prompt = messageArea->prompt;
// Set the two windows to scroll:

View File

@ -599,6 +599,7 @@ int evaluateNextCommand(gameLogicParameters * parameters, queue * queue)
{
currentCommand->caller->talkingWith = NULL;
strcpy(talkMessage->messageContent, "Conversation ended.");
strncat(&talkMessage->senderName[1], " > ", 4);
}
else
{
@ -609,6 +610,8 @@ int evaluateNextCommand(gameLogicParameters * parameters, queue * queue)
currentCommand->caller->talkingWith = &(parameters->connectedPlayers[playerIndex]);
// Fill out the message to inform the receiving user what is happening:
strncat(&talkMessage->senderName[1], currentCommand->caller->playerName, 27);
strncat(&talkMessage->senderName[1], " > ", 4);
strncpy(talkMessage->messageContent, currentCommand->caller->playerName, 31);
strcat(talkMessage->messageContent, " is talking to you.");
@ -626,7 +629,10 @@ int evaluateNextCommand(gameLogicParameters * parameters, queue * queue)
strcat(talkMessage->messageContent, parameters->connectedPlayers[playerIndex].playerName);
}
}
}
if(talkMessage->messageContent[0] == '\0')
{
strcpy(talkMessage->messageContent, "There is no player by that name connected.");
}
// Allocate an outputMessage for the queue:
@ -683,6 +689,21 @@ int evaluateNextCommand(gameLogicParameters * parameters, queue * queue)
{
strncpy(currentCommand->caller->playerName, currentCommand->arguments, 16);
currentCommand->caller->currentArea = getFromList(parameters->areaList, 1)->area;
// Allocate a userMessage containing null characters as the first char in both fields:
userMessage * joinMessage = calloc(1, (sizeof(userMessage)));
memcpy(joinMessage->senderName, "\0 > \0", 5);
strcpy(joinMessage->messageContent, "Logged in successfully.");
// Allocate an outputMessage for the queue:
outputMessage * joinOutputMessage = createTargetedOutputMessage(joinMessage, &currentCommand->caller, 1);
// Queue the outputMessage:
pushQueue(parameters->outputQueue, joinOutputMessage, OUTPUT_MESSAGE);
// Free the userMessage
free(joinMessage);
// Call the look command after joining. It's fine to unlock, because the loop won't
// continue until the command is queued:
queue->lock = false;

View File

@ -285,7 +285,7 @@ int main(int argc, char ** argv)
while (returnVal < 0 && gnutls_error_is_fatal(returnVal) == 0);
// Send a greeting message:
strcpy(sendBuffer.senderName, "");
memcpy(sendBuffer.senderName, "\0 Login > \0", 11);
strcpy(sendBuffer.messageContent, "Welcome to the server!");
messageSend(tlssessions[index], &sendBuffer);
strcpy(receiveBuffer.messageContent, "/look");