Reorganized file structure.
- Reimplemented /LOOK. - Commands are now accepted in both upper and lower case. - Move now accepts a number for easier movement.
This commit is contained in:
parent
151f3002b8
commit
8673bb1ad5
8
Makefile
8
Makefile
|
@ -1,9 +1,9 @@
|
|||
CC = gcc
|
||||
clientsrc = $(wildcard src/misc/*.c) \
|
||||
src/SilverMUDClient.c
|
||||
clientsrc = $(wildcard src/*.c) \
|
||||
src/client/SilverMUDClient.c
|
||||
clientobj = $(clientsrc:.c=.o)
|
||||
serversrc = $(wildcard src/misc/*.c) \
|
||||
src/SilverMUDServer.c
|
||||
serversrc = $(wildcard src/*.c) \
|
||||
src/server/SilverMUDServer.c
|
||||
serverobj = $(serversrc:.c=.o)
|
||||
CLIENTLDFLAGS= -lpthread -lncurses -lgnutls
|
||||
SERVERLDFLAGS= -lpthread -lncurses -lgnutls
|
||||
|
|
|
@ -13,10 +13,10 @@
|
|||
#include <arpa/inet.h>
|
||||
#include <sys/socket.h>
|
||||
#include <gnutls/gnutls.h>
|
||||
#include "misc/constants.h"
|
||||
#include "misc/playerdata.h"
|
||||
#include "misc/texteffects.h"
|
||||
#include "misc/inputoutput.h"
|
||||
#include "../../include/constants.h"
|
||||
#include "../../include/playerdata.h"
|
||||
#include "../../include/texteffects.h"
|
||||
#include "../../include/inputoutput.h"
|
||||
|
||||
// A struct for passing arguments to our threads containing a file descriptor and a window pointer:
|
||||
typedef struct threadparameters
|
||||
|
@ -85,7 +85,8 @@ void * messageReceiver(void * parameters)
|
|||
shouldExit = true;
|
||||
pthread_exit(NULL);
|
||||
}
|
||||
slowPrintNcurses("\n --====<>====-- \n", 8000, threadParameters->window, true);
|
||||
slowPrintNcurses("\n --====<", 8000, threadParameters->window, true);
|
||||
slowPrintNcurses(">====-- \n", 8000, threadParameters->window, true);
|
||||
slowPrintNcurses(receiveBuffer.messageContent, 8000, threadParameters->window, false);
|
||||
slowPrintNcurses("\n --====<>====-- \n", 8000, threadParameters->window, true);
|
||||
}
|
|
@ -1,10 +1,11 @@
|
|||
// gamelogic.c: Contains function definitons for dealing with the game's logic.
|
||||
// Barry Kane, 2022.
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "constants.h"
|
||||
#include "gamelogic.h"
|
||||
#include "playerdata.h"
|
||||
#include "inputoutput.h"
|
||||
#include "../include/constants.h"
|
||||
#include "../include/gamelogic.h"
|
||||
#include "../include/playerdata.h"
|
||||
#include "../include/inputoutput.h"
|
||||
|
||||
// =======================
|
||||
// -=[ Main Game Loop ]=-:
|
||||
|
@ -13,11 +14,13 @@
|
|||
// Thread function which runs the main game loop, given the needed parameters:
|
||||
void * gameLogicLoop(void * parameters)
|
||||
{
|
||||
char formattedString[64];
|
||||
gameLogicParameters * threadParameters = parameters;
|
||||
inputMessage * currentInput = NULL;
|
||||
bool keepRunning = true;
|
||||
while(keepRunning)
|
||||
{
|
||||
// Check for new messages and pop them off the queue:
|
||||
if(threadParameters->inputQueue->currentLength != 0)
|
||||
{
|
||||
while(threadParameters->inputQueue->lock == true)
|
||||
|
@ -26,11 +29,15 @@ void * gameLogicLoop(void * parameters)
|
|||
}
|
||||
currentInput = peekInputMessage(threadParameters->inputQueue);
|
||||
userInputSanatize(currentInput->content->messageContent, MAX);
|
||||
// A slash as the first character means the message is a user command:
|
||||
if(currentInput->content->messageContent[0] == '/')
|
||||
{
|
||||
// TODO: Implement Command Queue.
|
||||
// For now, basic intepretation will do.
|
||||
if(strncmp(¤tInput->content->messageContent[1], "EXIT", 4) == 0)
|
||||
// For now, basic intepretation will do.
|
||||
|
||||
// Exit command: Sends an "empty" exit message to disconnect a client:
|
||||
if(strncmp(¤tInput->content->messageContent[1], "EXIT", 4) == 0 ||
|
||||
strncmp(¤tInput->content->messageContent[1], "exit", 4) == 0)
|
||||
{
|
||||
userMessage * exitMessage = malloc(sizeof(userMessage));
|
||||
exitMessage->senderName[0] = '\0';
|
||||
|
@ -38,9 +45,13 @@ void * gameLogicLoop(void * parameters)
|
|||
queueTargetedOutputMessage(threadParameters->outputQueue, exitMessage, ¤tInput->sender, 1);
|
||||
free(exitMessage);
|
||||
}
|
||||
if(strncmp(¤tInput->content->messageContent[1], "MOVE", 4) == 0)
|
||||
|
||||
// Move command: Moves the current player down a path in their current area, given a pathname or number:
|
||||
if(strncmp(¤tInput->content->messageContent[1], "MOVE", 4) == 0 ||
|
||||
strncmp(¤tInput->content->messageContent[1], "move", 4) == 0)
|
||||
{
|
||||
userMessage * moveMessage = malloc(sizeof(userMessage));
|
||||
bzero(moveMessage, sizeof(userMessage));
|
||||
char requestedPath[32];
|
||||
strncpy(requestedPath, ¤tInput->content->messageContent[6], 32);
|
||||
userInputSanatize(requestedPath, 32);
|
||||
|
@ -55,12 +66,51 @@ void * gameLogicLoop(void * parameters)
|
|||
requestedPath[31] = '\0';
|
||||
if(movePlayerToArea(currentInput->sender, requestedPath) == 0)
|
||||
{
|
||||
strcpy(moveMessage->senderName, "\0");
|
||||
strcpy(moveMessage->messageContent, currentInput->sender->currentArea->areaDescription);
|
||||
moveMessage->senderName[0] = '\0';
|
||||
strncat(moveMessage->messageContent, currentInput->sender->currentArea->areaName, 33);
|
||||
strncat(moveMessage->messageContent, "\n", 2);
|
||||
strncat(moveMessage->messageContent, currentInput->sender->currentArea->areaDescription, 256);
|
||||
strncat(moveMessage->messageContent, "\nYou can go:", 13);
|
||||
for(int index = 0; index < 16; index++)
|
||||
{
|
||||
if(currentInput->sender->currentArea->areaExits[index] != NULL)
|
||||
{
|
||||
snprintf(formattedString, 64, "\n\t%d. %s", index + 1, currentInput->sender->currentArea->areaExits[index]->pathName);
|
||||
strncat(moveMessage->messageContent, formattedString, 64);
|
||||
}
|
||||
}
|
||||
queueTargetedOutputMessage(threadParameters->outputQueue, moveMessage, ¤tInput->sender, 1);
|
||||
}
|
||||
free(moveMessage);
|
||||
}
|
||||
|
||||
// Look command: Sends the current area's name, description, and
|
||||
if(strncmp(¤tInput->content->messageContent[1], "LOOK", 4) == 0 ||
|
||||
strncmp(¤tInput->content->messageContent[1], "look", 4) == 0)
|
||||
{
|
||||
userMessage * lookMessage = malloc(sizeof(userMessage));
|
||||
strncat(lookMessage->messageContent, currentInput->sender->currentArea->areaName, 33);
|
||||
strncat(lookMessage->messageContent, "\n", 2);
|
||||
strncat(lookMessage->messageContent, currentInput->sender->currentArea->areaDescription, 256);
|
||||
strncat(lookMessage->messageContent, "\nYou can go:", 13);
|
||||
for(int index = 0; index < 16; index++)
|
||||
{
|
||||
if(currentInput->sender->currentArea->areaExits[index] != NULL)
|
||||
{
|
||||
snprintf(formattedString, 64, "\n\t%d. %s", index + 1, currentInput->sender->currentArea->areaExits[index]->pathName);
|
||||
strncat(lookMessage->messageContent, formattedString, 64);
|
||||
}
|
||||
}
|
||||
queueTargetedOutputMessage(threadParameters->outputQueue, lookMessage, ¤tInput->sender, 1);
|
||||
free(lookMessage);
|
||||
}
|
||||
|
||||
// Name command: Checks if the name is isn't used and is valid, then changes the player's name:
|
||||
if(strncmp(¤tInput->content->messageContent[1], "NAME", 4) == 0 ||
|
||||
strncmp(¤tInput->content->messageContent[1], "name", 4) == 0)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
|
@ -4,11 +4,11 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdbool.h>
|
||||
#include "constants.h"
|
||||
#include "playerdata.h"
|
||||
#include "inputoutput.h"
|
||||
#include <stdbool.h>
|
||||
#include <gnutls/gnutls.h>
|
||||
#include "../include/constants.h"
|
||||
#include "../include/playerdata.h"
|
||||
#include "../include/inputoutput.h"
|
||||
|
||||
// Sends a message to a given TLS session, wraps the calls to gnutls_write:
|
||||
int messageSend(gnutls_session_t receivingSession, userMessage * messageToSend)
|
|
@ -1,7 +1,7 @@
|
|||
// Implementation of lists library for SilverMUD.
|
||||
// Barry Kane, 2021
|
||||
#include "lists.h"
|
||||
#include "playerdata.h"
|
||||
#include "../include/lists.h"
|
||||
#include "../include/playerdata.h"
|
||||
|
||||
areaNode * createAreaList(playerArea * initialArea)
|
||||
{
|
|
@ -3,11 +3,27 @@
|
|||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include "playerdata.h"
|
||||
#include "../include/playerdata.h"
|
||||
|
||||
// Move a player to a different area given a path in the area:
|
||||
int movePlayerToArea(playerInfo * player, char * requestedPath)
|
||||
{
|
||||
// Check if a number was given first:
|
||||
int selected = atoi(requestedPath);
|
||||
if(selected != 0)
|
||||
{
|
||||
if(player->currentArea->areaExits[selected -1]->areaToJoin != NULL)
|
||||
{
|
||||
player->currentArea = player->currentArea->areaExits[selected - 1]->areaToJoin;
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
// Otherwise search for the description:
|
||||
for (int index = 0; index < 16; index++)
|
||||
{
|
||||
if(player->currentArea->areaExits[index] != NULL)
|
|
@ -14,12 +14,12 @@
|
|||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <gnutls/gnutls.h>
|
||||
#include "misc/lists.h"
|
||||
#include "misc/gamelogic.h"
|
||||
#include "misc/constants.h"
|
||||
#include "misc/playerdata.h"
|
||||
#include "misc/texteffects.h"
|
||||
#include "misc/inputoutput.h"
|
||||
#include "../../include/lists.h"
|
||||
#include "../../include/gamelogic.h"
|
||||
#include "../../include/constants.h"
|
||||
#include "../../include/playerdata.h"
|
||||
#include "../../include/texteffects.h"
|
||||
#include "../../include/inputoutput.h"
|
||||
|
||||
typedef struct sockaddr sockaddr;
|
||||
|
Loading…
Reference in New Issue