Talking messages now appear in the chat log correctly.

- Added logic to properly add the relevant users in the correct order to ensure message delivery.
This commit is contained in:
Barra Ó Catháin 2023-02-27 20:00:50 +00:00
parent 84c20dfdbf
commit 8f08265c52
1 changed files with 29 additions and 12 deletions

View File

@ -89,14 +89,32 @@ void * gameLogicHandler(void * parameters)
} }
else else
{ {
// Allocate an array of one playerInfo to store the pointer to the other player in the conversation: // Allocate an array of two playerInfo to store the pointers to the players in the conversation:
playerInfo ** recipients = calloc(1, (sizeof(playerInfo*))); playerInfo ** recipients = calloc(2, (sizeof(playerInfo*)));
// Set the talkingWith player as the recipient of the message: // Find which player is first in the player list:
recipients[0] = currentInput->sender->talkingWith; bool senderIsFirst = false;
for(int playerIndex = 0; playerIndex < *threadParameters->playerCount; playerIndex++)
{
if(&threadParameters->connectedPlayers[playerIndex] == currentInput->sender)
{
senderIsFirst = true;
break;
}
if(&threadParameters->connectedPlayers[playerIndex] == currentInput->sender->talkingWith)
{
senderIsFirst = false;
break;
}
}
// Set the proper recipients:
recipients[0] = (senderIsFirst) ? currentInput->sender : currentInput->sender->talkingWith;
recipients[1] = (senderIsFirst) ? currentInput->sender->talkingWith : currentInput->sender;
// There's only one recipient: // There's only one recipient:
int recipientIndex = 1; int recipientIndex = 2;
// Create the outputMessage for the queue: // Create the outputMessage for the queue:
outputMessage * newOutputMessage = createTargetedOutputMessage(currentInput->content, recipients, recipientIndex); outputMessage * newOutputMessage = createTargetedOutputMessage(currentInput->content, recipients, recipientIndex);
@ -262,14 +280,13 @@ int evaluateNextCommand(gameLogicParameters * parameters, queue * queue)
parameters->connectedPlayers[index].playerName); parameters->connectedPlayers[index].playerName);
strncat(lookMessage->messageContent, formattedString, 64); strncat(lookMessage->messageContent, formattedString, 64);
charCount += 38; charCount += 38;
// Allocate another outputMessage for the queue:
lookOutputMessage = createTargetedOutputMessage(lookMessage, &currentCommand->caller, 1);
// Queue the outputMessage:
pushQueue(parameters->outputQueue, lookOutputMessage, OUTPUT_MESSAGE);
} }
} }
// Allocate another outputMessage for the queue:
lookOutputMessage = createTargetedOutputMessage(lookMessage, &currentCommand->caller, 1);
// Queue the outputMessage:
pushQueue(parameters->outputQueue, lookOutputMessage, OUTPUT_MESSAGE);
} }
free(lookMessage); free(lookMessage);