From a99296e31eeacd8e3b01ed3c3648c94d094b7799 Mon Sep 17 00:00:00 2001 From: Barry Kane Date: Mon, 27 Feb 2023 16:35:32 +0000 Subject: [PATCH] Added a list of players in the area to /look. - /look now lists the current players in the area. --- src/gamelogic.c | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/src/gamelogic.c b/src/gamelogic.c index 36c5d55..85c5fdb 100644 --- a/src/gamelogic.c +++ b/src/gamelogic.c @@ -235,8 +235,44 @@ int evaluateNextCommand(gameLogicParameters * parameters, queue * queue) // Queue the outputMessage: pushQueue(parameters->outputQueue, lookOutputMessage, OUTPUT_MESSAGE); } - free(lookMessage); + // Clear the message: + memset(lookMessage, 0, sizeof(userMessage)); + if(currentCommand->caller->currentArea != getFromList(parameters->areaList, 0)->area) + { + // Show the players in the area: + charCount = 23; + strncat(lookMessage->messageContent, "These players are here:", 24); + + int playerNumber = 1; + for(int index = 0; index < *(parameters->playerCount); index++) + { + if (parameters->connectedPlayers[index].currentArea == currentCommand->caller->currentArea) + { + if ((charCount + 38) >= MAX) + { + lookOutputMessage = createTargetedOutputMessage(lookMessage, ¤tCommand->caller, 1); + + // Queue the outputMessage: + pushQueue(parameters->outputQueue, lookOutputMessage, OUTPUT_MESSAGE); + memset(lookMessage, 0, sizeof(userMessage)); + charCount = 0; + } + snprintf(formattedString, 38, "\n%02d. %32s", playerNumber++, + parameters->connectedPlayers[index].playerName); + strncat(lookMessage->messageContent, formattedString, 37); + charCount += 38; + + // Allocate another outputMessage for the queue: + lookOutputMessage = createTargetedOutputMessage(lookMessage, ¤tCommand->caller, 1); + + // Queue the outputMessage: + pushQueue(parameters->outputQueue, lookOutputMessage, OUTPUT_MESSAGE); + } + } + } + + free(lookMessage); break; }