diff --git a/src/areadata.c b/src/areadata.c index 45c0caa..50a61b9 100644 --- a/src/areadata.c +++ b/src/areadata.c @@ -70,81 +70,3 @@ int createOneWayPath(playerArea * fromArea, playerArea * toArea, char * descript return 0; } - -// ========================= -// -=[ Area/Path Lists: ]=-: -// ========================= - -// Create and initialize an areaList: -areaNode * createAreaList(playerArea * initialArea) -{ - areaNode * newAreaList = malloc(sizeof(areaNode)); - newAreaList->data = initialArea; - newAreaList->next = NULL; - newAreaList->prev = NULL; - return newAreaList; -} - -// Adds an areaNode to the end of a list, returning it's position: -int addAreaNodeToList(areaNode * toList, playerArea * areaToAdd) -{ - areaNode * current; - int index = 0; - current = toList; - while(current->next != NULL) - { - current = current->next; - index++; - } - current->next = malloc(sizeof(areaNode)); - current->next->prev = current; - current->next->data = areaToAdd; - current->next->next = NULL; - return 0; -} - -// Removes an areaNode from the list, returning 0 on success and -1 on failure: -int deleteAreaNodeFromList(areaNode * fromList, playerArea * areaToDelete) -{ - areaNode * current = fromList; - while(current->data != areaToDelete && current->next != NULL) - { - current = current->next; - } - if(current->next == NULL && current->data != areaToDelete) - { - return -1; - } - current->prev->next = current->next; - if(current->next != NULL) - { - current->next->prev = current->prev; - } - free(current); - return 0; -} - -// Return the areaNode at the given index from the list: -areaNode * getAreaNode(areaNode * fromList, int listIndex) -{ - areaNode * current = fromList; - for(int index = 0; index < listIndex; index++) - { - if(current->next != NULL) - { - current = current->next; - } - else - { - return NULL; - } - } - return current; -} - -// Return the playerArea of the areaNode at the given index from the list: -playerArea * getAreaFromList(areaNode * fromList, int listIndex) -{ - areaNode * current = getAreaNode(fromList, listIndex); - return current->data; -} diff --git a/src/areadata.h b/src/areadata.h index 6edde90..e983019 100644 --- a/src/areadata.h +++ b/src/areadata.h @@ -35,54 +35,6 @@ int createPath(playerArea * fromArea, playerArea * toArea, char * fromDescriptio // Create a one-way path between two areas given two areas and a string: int createOneWayPath(playerArea * fromArea, playerArea * toArea, char * description); -// ========================= -// -=[ Area/Path Lists: ]=-: -// ========================= - -typedef struct areaNode areaNode; -typedef struct pathNode pathNode; - -struct pathNode -{ - playerPath * data; - pathNode * next; - pathNode * prev; -}; - -struct areaNode -{ - playerArea * data; - areaNode * next; - areaNode * prev; -}; - -// Create and initialize an areaList: -areaNode * createAreaList(playerArea * initialArea); - -// Create and initialize an pathList: -pathNode * createPathList(playerPath * initialPath); - -// Adds an areaNode to the end of a list, returning it's position: -int addAreaNodeToList(areaNode * toList, playerArea * areaToAdd); - -// Removes an areaNode from the list, returning 0 on success and -1 on failure: -int deleteAreaNodeFromList(areaNode * fromList, playerArea * areaToDelete); - -// Adds an pathNode to the end of a list, returning it's position: -int addPathNodeToList(pathNode * toList, playerPath * pathToAdd); - -// Removes an pathNode from the list, returning 0 on success and -1 on failure: -int deletePathNodeFromList(pathNode * fromList, playerPath * pathToDelete); - -// Return the areaNode at the given index from the list: -areaNode * getAreaNode(areaNode * fromList, int listIndex); - -// Return the pathNode at the given index from the list: -pathNode * getPathNode(pathNode * fromList, int listIndex); - -// Return the playerArea of the areaNode at the given index from the list: -playerArea * getAreaFromList(areaNode * fromList, int listIndex); - // TO BE IMPLEMENTED: /* int saveAreaList(areaNode * listToSave); */ diff --git a/src/client/SilverMUDClient.c b/src/client/SilverMUDClient.c index aeab0ed..9a26cbd 100644 --- a/src/client/SilverMUDClient.c +++ b/src/client/SilverMUDClient.c @@ -125,7 +125,7 @@ void * messageReceiver(void * parameters) serverMessage = false; } slowPrintNcurses(receiveBuffer.senderName, 4000, threadParameters->window, true); - slowPrintNcurses(": ", 4000, threadParameters->window, true); + slowPrintNcurses(": ", 4000, threadParameters->window, true); slowPrintNcurses(receiveBuffer.messageContent, 4000, threadParameters->window, false); } } @@ -156,7 +156,7 @@ int main(int argc, char ** argv) switch (currentopt) { case 'i': - { + { memcpy(ipAddress, optarg, 32); break; } @@ -192,7 +192,7 @@ int main(int argc, char ** argv) { port = atoi(optarg); break; - } + } case 'd': { characterDelay = atoi(optarg); @@ -225,7 +225,7 @@ int main(int argc, char ** argv) serverAddress.sin_port = htons(port); // Connect the server and client sockets, Kronk: - if (connect(socketFileDesc, (sockaddr*)&serverAddress, sizeof(serverAddress)) != 0) + if (connect(socketFileDesc, (sockaddr*)&serverAddress, sizeof(serverAddress)) != 0) { slowPrint("Connection with the Silverkin Industries Comm-Link Server Failed:\nPlease contact your service representative.\n", characterDelay); exit(0); @@ -256,7 +256,7 @@ int main(int argc, char ** argv) // Use the default for the GnuTLS handshake timeout: gnutls_handshake_set_timeout(tlsSession, GNUTLS_DEFAULT_HANDSHAKE_TIMEOUT); - // Repeatedly attempt to handshake unless we encounter a fatal error: + // Repeatedly attempt to handshake unless we encounter a fatal error: int returnValue = -1; do { diff --git a/src/gamelogic.c b/src/gamelogic.c index 20d8f14..73be73b 100644 --- a/src/gamelogic.c +++ b/src/gamelogic.c @@ -40,8 +40,8 @@ void * gameLogicLoop(void * parameters) { queueMessagedCommand(commandQueue, currentInput); } - else if(currentInput->sender->currentArea == getAreaFromList(threadParameters->areaList, 0)) - { + else if(currentInput->sender->currentArea == getFromList(threadParameters->areaList, 0)->area) + { currentInput = NULL; threadParameters->inputQueue->lock = false; dequeueInputMessage(threadParameters->inputQueue); @@ -338,7 +338,7 @@ int evaluateNextCommand(gameLogicParameters * parameters, commandQueue * queue) if(strncmp(currentCommand->command, "move", 4) == 0) { char requestedPath[32]; - if(strlen(currentCommand->arguments) > 0 && currentCommand->caller->currentArea != getAreaFromList(parameters->areaList, 0)) + if(strlen(currentCommand->arguments) > 0 && currentCommand->caller->currentArea != getFromList(parameters->areaList, 0)->area) { memcpy(requestedPath, currentCommand->arguments, 32); userNameSanatize(requestedPath, 32); @@ -393,7 +393,7 @@ int evaluateNextCommand(gameLogicParameters * parameters, commandQueue * queue) // TODO: Implement login/character creation. Will be a while: if(strncmp(currentCommand->command, "join", 4) == 0) { - if(currentCommand->caller->currentArea == getAreaFromList(parameters->areaList, 0)) + if(currentCommand->caller->currentArea == getFromList(parameters->areaList, 0)->area) { bool validName = true; for(int index = 0; index < *parameters->playerCount; index++) @@ -410,7 +410,7 @@ int evaluateNextCommand(gameLogicParameters * parameters, commandQueue * queue) if(validName) { strncpy(currentCommand->caller->playerName, currentCommand->arguments, 16); - currentCommand->caller->currentArea = getAreaFromList(parameters->areaList, 1); + currentCommand->caller->currentArea = getFromList(parameters->areaList, 1)->area; // 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; diff --git a/src/gamelogic.h b/src/gamelogic.h index 7660063..26a910d 100644 --- a/src/gamelogic.h +++ b/src/gamelogic.h @@ -16,7 +16,7 @@ typedef struct gameLogicParameters { int * playerCount; - areaNode * areaList; + list * areaList; playerInfo * connectedPlayers; inputMessageQueue * inputQueue; outputMessageQueue * outputQueue; diff --git a/src/server/SilverMUDServer.c b/src/server/SilverMUDServer.c index b7a4161..01fd0d6 100644 --- a/src/server/SilverMUDServer.c +++ b/src/server/SilverMUDServer.c @@ -67,26 +67,32 @@ int main(int argc, char ** argv) // -==[ TEST GAME-STATE INITIALIZATION ]==- // Initialize test areas: - areaNode * areas = createAreaList(createArea("Login Area", "Please login with the /join command.")); - addAreaNodeToList(areas, createArea("Octal One - Docking Bay Alpha", - "You are standing in the main docking bay of the largest station in the Octal System. " - "The sheer size of the bay is awe-inpiring. The number of ships is endless. " - "The bay is curved along with the body of the station. A catwalk runs along the back wall of the bay. " - "Two large arches lie at each end, leading to the other bays, and in the center, a set of doors leading to the interior of the station.")); + list * areas = createList(AREA); + addToList(areas, createArea("Login Area", "Please login with the /join command."), AREA); - addAreaNodeToList(areas, createArea("Octal One - Station Access Control", - "You enter into the hallway leading to the main interior of the station." - "The attendant informs you that due to a computer error, exits cannot be proccessed at the moment, so you will be unable to leave, until it is resolved. " - "He apologizes profusely for the inconvenience, and clears you for entry if you wish to continue.")); + // Create the areas: + addToList(areas, createArea("Octal One - Docking Bay Alpha", + "You are standing in the main docking bay of the largest station in the Octal System. " + "The sheer size of the bay is awe-inpiring. The number of ships is endless. " + "The bay is curved along with the body of the station. A catwalk runs along the back wall of the bay. " + "Two large arches lie at each end, leading to the other bays, and in the center, a set of doors leading to the interior of the station."), AREA); + + addToList(areas, createArea("Octal One - Station Access Control", + "You enter into the hallway leading to the main interior of the station." + "The attendant informs you that due to a computer error, exits cannot be proccessed at the moment," + " so you will be unable to leave, until it is resolved. " + "He apologizes profusely for the inconvenience, and clears you for entry if you wish to continue."), AREA); - addAreaNodeToList(areas, createArea("Octal One - Floor Zero", - "You've never quite seen so many people in one place. A large ring of shopfronts surrounds an area filled with benches and tables. " - "There's so many buisnesses in sight that you feel you could find everything you need, and this is only one of 25 main floors, " - "not to mention the 6 outer pylons which surround the main hull of the station. Staircases lead to an upper platform allowing access to the pylons. ")); + addToList(areas, createArea("Octal One - Floor Zero", + "You've never quite seen so many people in one place. A large ring of shopfronts surrounds an area filled with benches and tables. " + "There's so many buisnesses in sight that you feel you could find everything you need, and this is only one of 25 main floors, " + "not to mention the 6 outer pylons which surround the main hull of the station. Staircases lead to an upper platform allowing access to the pylons. "), AREA); // Initialize test paths: - createPath(getAreaFromList(areas, 1), getAreaFromList(areas, 2), "Enter the station interior.", "Return to Docking Bay Alpha."); - createOneWayPath(getAreaFromList(areas, 2), getAreaFromList(areas, 3), "Continue to station interior. "); + createPath(getFromList(areas, 1)->area, getFromList(areas, 2)->area, + "Enter the station interior.", "Return to Docking Bay Alpha."); + createOneWayPath(getFromList(areas, 2)->area, getFromList(areas, 3)->area, + "Continue to station interior. "); skillList * globalSkillList = malloc(sizeof(skillList)); globalSkillList->head = NULL; @@ -106,7 +112,7 @@ int main(int argc, char ** argv) // OH NO IT'S NOT MEMORY SAFE BETTER REWRITE IT IN RUST // But wait, we know the string won't be too big, so it's fine. strcpy(connectedPlayers[index].playerName, testString); - connectedPlayers[index].currentArea = getAreaFromList(areas, 0); + connectedPlayers[index].currentArea = getFromList(areas, 0)->area; connectedPlayers[index].stats = calloc(1, sizeof(statBlock)); connectedPlayers[index].stats->specPoints = 30; connectedPlayers[index].stats->skillPoints = 30; @@ -300,7 +306,7 @@ int main(int argc, char ** argv) // Clear out the old player state so that a new one may join: sprintf(testString, "UNNAMED %d", index); strcpy(connectedPlayers[index].playerName, testString); - connectedPlayers[index].currentArea = getAreaFromList(areas, 0); + connectedPlayers[index].currentArea = getFromList(areas, 0)->area; // Prepare a fresh SSL session for the next new player: gnutls_init(&tlssessions[index], GNUTLS_SERVER); diff --git a/tests/corestat-from-string.c b/tests/corestat-from-string.c deleted file mode 100644 index ab70d82..0000000 --- a/tests/corestat-from-string.c +++ /dev/null @@ -1,11 +0,0 @@ -// Hopefully optimized corestat to string: -#include -#include -#include -#include -#include "../src/playerdata.h" - -void main(int argc, char ** argv) -{ - getCoreStatFromString(argv[1], strlen(argv[1])); -}