Squashed current warnings.
- Fixed all current warnings. - Added the ability to set the text delay as a command line option in the server.
This commit is contained in:
parent
ca8ba5e410
commit
c68e66e7bc
|
@ -16,11 +16,11 @@ playerArea * createArea(char * nameString, char * descriptionString)
|
||||||
|
|
||||||
// Copy the strings into the newly created area:
|
// Copy the strings into the newly created area:
|
||||||
strncpy(createdArea->areaName, nameString, 32 - 1);
|
strncpy(createdArea->areaName, nameString, 32 - 1);
|
||||||
strncpy(createdArea->areaDescription, descriptionString, MAX - 35);
|
strncpy(createdArea->areaDescription, descriptionString, MAX - 36);
|
||||||
|
|
||||||
// Properly null-terminate the strings:
|
// Properly null-terminate the strings:
|
||||||
createdArea->areaName[31] = '\0';
|
createdArea->areaName[31] = '\0';
|
||||||
createdArea->areaDescription[MAX] = '\0';
|
createdArea->areaDescription[MAX - 36] = '\0';
|
||||||
|
|
||||||
// Ensure that all the paths are set to NULL:
|
// Ensure that all the paths are set to NULL:
|
||||||
for(int index = 0; index < 16; index++)
|
for(int index = 0; index < 16; index++)
|
||||||
|
|
|
@ -157,12 +157,12 @@ int main(int argc, char ** argv)
|
||||||
{
|
{
|
||||||
case 'i':
|
case 'i':
|
||||||
{
|
{
|
||||||
strncpy(ipAddress, optarg, 32);
|
memcpy(ipAddress, optarg, 32);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 'c':
|
case 'c':
|
||||||
{
|
{
|
||||||
strncpy(chatLogPath, optarg, PATH_MAX + 1);
|
memcpy(chatLogPath, optarg, PATH_MAX + 1);
|
||||||
chatLog = fopen(chatLogPath, "a+");
|
chatLog = fopen(chatLogPath, "a+");
|
||||||
if (chatLog == NULL)
|
if (chatLog == NULL)
|
||||||
{
|
{
|
||||||
|
@ -176,7 +176,7 @@ int main(int argc, char ** argv)
|
||||||
}
|
}
|
||||||
case 'g':
|
case 'g':
|
||||||
{
|
{
|
||||||
strncpy(gameLogPath, optarg, PATH_MAX + 1);
|
memcpy(gameLogPath, optarg, PATH_MAX + 1);
|
||||||
gameLog = fopen(gameLogPath, "a+");
|
gameLog = fopen(gameLogPath, "a+");
|
||||||
if (gameLog == NULL)
|
if (gameLog == NULL)
|
||||||
{
|
{
|
||||||
|
|
|
@ -112,14 +112,17 @@ int queueMessagedCommand(commandQueue * queue, inputMessage * messageToQueue)
|
||||||
strtok(messageToQueue->content->messageContent, " ");
|
strtok(messageToQueue->content->messageContent, " ");
|
||||||
|
|
||||||
// Copy the command and arguments to the new commandEvent:
|
// Copy the command and arguments to the new commandEvent:
|
||||||
strncpy(newCommand->command, &messageToQueue->content->messageContent[1], 16);
|
memcpy(newCommand->command, &messageToQueue->content->messageContent[1], 16);
|
||||||
strncpy(newCommand->arguments, &messageToQueue->content->messageContent[strlen(newCommand->command) + 2],
|
memcpy(newCommand->arguments, &messageToQueue->content->messageContent[strlen(newCommand->command) + 2],
|
||||||
MAX - (strlen(newCommand->command) + 2));
|
MAX - (strlen(newCommand->command) + 2));
|
||||||
|
|
||||||
// Ensure the arguments are safe to parse, without adding newlines:
|
// Ensure the arguments are safe to parse, without adding newlines:
|
||||||
userNameSanatize(newCommand->command, 16);
|
userNameSanatize(newCommand->command, 16);
|
||||||
|
newCommand->command[15] = '\0';
|
||||||
|
|
||||||
userNameSanatize(newCommand->arguments, MAX);
|
userNameSanatize(newCommand->arguments, MAX);
|
||||||
|
newCommand->arguments[MAX - 1] = '\0';
|
||||||
|
|
||||||
// Lowercase the command for easier comparison:
|
// Lowercase the command for easier comparison:
|
||||||
for (char * character = newCommand->command; *character; ++character)
|
for (char * character = newCommand->command; *character; ++character)
|
||||||
{
|
{
|
||||||
|
@ -336,7 +339,7 @@ int evaluateNextCommand(gameLogicParameters * parameters, commandQueue * queue)
|
||||||
char requestedPath[32];
|
char requestedPath[32];
|
||||||
if(strlen(currentCommand->arguments) > 0 && currentCommand->caller->currentArea != getAreaFromList(parameters->areaList, 0))
|
if(strlen(currentCommand->arguments) > 0 && currentCommand->caller->currentArea != getAreaFromList(parameters->areaList, 0))
|
||||||
{
|
{
|
||||||
strncpy(requestedPath, currentCommand->arguments, 32);
|
memcpy(requestedPath, currentCommand->arguments, 32);
|
||||||
userNameSanatize(requestedPath, 32);
|
userNameSanatize(requestedPath, 32);
|
||||||
requestedPath[31] = '\0';
|
requestedPath[31] = '\0';
|
||||||
if(movePlayerToArea(currentCommand->caller, requestedPath) == 0)
|
if(movePlayerToArea(currentCommand->caller, requestedPath) == 0)
|
||||||
|
|
|
@ -265,17 +265,17 @@ int dequeueInputMessage(inputMessageQueue * queue)
|
||||||
int queueInputMessage(inputMessageQueue * queue, userMessage messageToQueue, playerInfo * sendingPlayer)
|
int queueInputMessage(inputMessageQueue * queue, userMessage messageToQueue, playerInfo * sendingPlayer)
|
||||||
{
|
{
|
||||||
// Copy the message into a new input message:
|
// Copy the message into a new input message:
|
||||||
inputMessage * inputMessage = malloc(sizeof(inputMessage));
|
inputMessage * input = malloc(sizeof(inputMessage));
|
||||||
|
|
||||||
// Allocate the internal userMessage to store the message:
|
// Allocate the internal userMessage to store the message:
|
||||||
inputMessage->content = malloc(sizeof(userMessage));
|
input->content = malloc(sizeof(userMessage));
|
||||||
|
|
||||||
// Copy the userMessage to the internal userMessage:
|
// Copy the userMessage to the internal userMessage:
|
||||||
strncpy(inputMessage->content->senderName, messageToQueue.senderName, 32);
|
strncpy(input->content->senderName, messageToQueue.senderName, 32);
|
||||||
strncpy(inputMessage->content->messageContent, messageToQueue.messageContent, MAX);
|
strncpy(input->content->messageContent, messageToQueue.messageContent, MAX);
|
||||||
|
|
||||||
// We have no targets, NULL sends to all players in an area:
|
// We have no targets, NULL sends to all players in an area:
|
||||||
inputMessage->sender = sendingPlayer;
|
input->sender = sendingPlayer;
|
||||||
|
|
||||||
// Wait for the queue to unlock:
|
// Wait for the queue to unlock:
|
||||||
while (queue->lock);
|
while (queue->lock);
|
||||||
|
@ -295,8 +295,8 @@ int queueInputMessage(inputMessageQueue * queue, userMessage messageToQueue, pla
|
||||||
// If the queue is empty, set the first message as both the front and back of the queue:
|
// If the queue is empty, set the first message as both the front and back of the queue:
|
||||||
if(queue->front == NULL)
|
if(queue->front == NULL)
|
||||||
{
|
{
|
||||||
queue->front = inputMessage;
|
queue->front = input;
|
||||||
queue->back = inputMessage;
|
queue->back = input;
|
||||||
queue->currentLength++;
|
queue->currentLength++;
|
||||||
|
|
||||||
// Unlock the queue:
|
// Unlock the queue:
|
||||||
|
@ -306,8 +306,8 @@ int queueInputMessage(inputMessageQueue * queue, userMessage messageToQueue, pla
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
queue->back->next = inputMessage;
|
queue->back->next = input;
|
||||||
queue->back = inputMessage;
|
queue->back = input;
|
||||||
queue->currentLength++;
|
queue->currentLength++;
|
||||||
|
|
||||||
// Unlock the queue:
|
// Unlock the queue:
|
||||||
|
|
|
@ -58,36 +58,39 @@ int addSkillNode(skillList * skillList, playerSkill * skill)
|
||||||
// Remove a skill node from a skill list:
|
// Remove a skill node from a skill list:
|
||||||
int removeSkillNode(skillList * skillList, playerSkill * skill)
|
int removeSkillNode(skillList * skillList, playerSkill * skill)
|
||||||
{
|
{
|
||||||
|
// Check the validity of the pointers:
|
||||||
|
if(skillList->head == NULL || skill == NULL)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
if(skillList->head->skill == skill)
|
if(skillList->head->skill == skill)
|
||||||
{
|
{
|
||||||
|
skillNode * newHead = skillList->head->next;
|
||||||
free(skillList->head->skill);
|
free(skillList->head->skill);
|
||||||
if(skillList->head->next != NULL)
|
free(skillList->head);
|
||||||
{
|
skillList->head = newHead;
|
||||||
skillNode * deletedNode = skillList->head;
|
return 0;
|
||||||
skillList->head = skillList->head->next;
|
|
||||||
free(deletedNode);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
skillNode * currentNode = skillList->head;
|
|
||||||
skillNode * previousNode = skillList->head;
|
|
||||||
while(currentNode->skill != skill)
|
|
||||||
{
|
|
||||||
if(currentNode->next == NULL)
|
|
||||||
{
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
previousNode = currentNode;
|
|
||||||
currentNode = currentNode->next;
|
|
||||||
}
|
|
||||||
free(currentNode->skill);
|
|
||||||
previousNode->next = currentNode->next;
|
|
||||||
free(currentNode);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return -1;
|
|
||||||
|
else
|
||||||
|
{
|
||||||
|
skillNode * currentNode = skillList->head;
|
||||||
|
skillNode * previousNode = skillList->head;
|
||||||
|
while(currentNode->skill != skill)
|
||||||
|
{
|
||||||
|
if(currentNode->next == NULL)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
previousNode = currentNode;
|
||||||
|
currentNode = currentNode->next;
|
||||||
|
}
|
||||||
|
free(currentNode->skill);
|
||||||
|
previousNode->next = currentNode->next;
|
||||||
|
free(currentNode);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Take a skill and add it to the player's skill list:
|
// Take a skill and add it to the player's skill list:
|
||||||
|
|
|
@ -27,12 +27,14 @@
|
||||||
typedef struct sockaddr sockaddr;
|
typedef struct sockaddr sockaddr;
|
||||||
void sigintHandler(int signal)
|
void sigintHandler(int signal)
|
||||||
{
|
{
|
||||||
|
printf("Caught signal %d.\n", signal);
|
||||||
exit(EXIT_SUCCESS);
|
exit(EXIT_SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char ** argv)
|
int main(int argc, char ** argv)
|
||||||
{
|
{
|
||||||
time_t currentTime;
|
time_t currentTime;
|
||||||
|
unsigned delay = 4000;
|
||||||
int socketFileDesc, connectionFileDesc, length, clientsAmount,
|
int socketFileDesc, connectionFileDesc, length, clientsAmount,
|
||||||
socketCheck, activityCheck, returnVal;
|
socketCheck, activityCheck, returnVal;
|
||||||
fd_set connectedClients;
|
fd_set connectedClients;
|
||||||
|
@ -44,6 +46,20 @@ int main(int argc, char ** argv)
|
||||||
struct sockaddr_in serverAddress, clientAddress;
|
struct sockaddr_in serverAddress, clientAddress;
|
||||||
inputMessageQueue * inputQueue = createInputMessageQueue();
|
inputMessageQueue * inputQueue = createInputMessageQueue();
|
||||||
outputMessageQueue * outputQueue = createOutputMessageQueue();
|
outputMessageQueue * outputQueue = createOutputMessageQueue();
|
||||||
|
|
||||||
|
// Parse command-line options:
|
||||||
|
int currentopt = 0;
|
||||||
|
while ((currentopt = getopt(argc, argv, "d:")) != -1)
|
||||||
|
{
|
||||||
|
switch(currentopt)
|
||||||
|
{
|
||||||
|
case 'd':
|
||||||
|
{
|
||||||
|
delay = atoi(optarg);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Set the handler for SIGINT:
|
// Set the handler for SIGINT:
|
||||||
signal(2, sigintHandler);
|
signal(2, sigintHandler);
|
||||||
|
@ -97,8 +113,8 @@ int main(int argc, char ** argv)
|
||||||
// -==[ TEST GAME-STATE INITIALIZATION END ]==-
|
// -==[ TEST GAME-STATE INITIALIZATION END ]==-
|
||||||
|
|
||||||
// Give an intro: Display the Silverkin Industries logo and splash text.
|
// Give an intro: Display the Silverkin Industries logo and splash text.
|
||||||
slowPrint(logostring, 3000);
|
slowPrint(logostring, delay);
|
||||||
slowPrint("\n--==== \033[33;40mSILVERKIN INDUSTRIES\033[0m COMM-LINK SERVER ====--\nVersion Alpha 0.4\n", 5000);
|
slowPrint("\n--==== \033[33;40mSILVERKIN INDUSTRIES\033[0m COMM-LINK SERVER ====--\nVersion Alpha 0.4\n", delay);
|
||||||
|
|
||||||
// Seed random number generator from the current time:
|
// Seed random number generator from the current time:
|
||||||
srandom((unsigned)time(¤tTime));
|
srandom((unsigned)time(¤tTime));
|
||||||
|
@ -119,7 +135,7 @@ int main(int argc, char ** argv)
|
||||||
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
slowPrint("\tSocket Creation is:\t\033[32;40mGREEN.\033[0m\n", 5000);
|
slowPrint("\tSocket Creation is:\t\033[32;40mGREEN.\033[0m\n", delay);
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
@ -139,7 +155,7 @@ int main(int argc, char ** argv)
|
||||||
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
slowPrint("\tSocket Binding is:\t\033[32;40mGREEN.\033[0m\n", 5000);
|
slowPrint("\tSocket Binding is:\t\033[32;40mGREEN.\033[0m\n", delay);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Let's start listening:
|
// Let's start listening:
|
||||||
|
@ -150,7 +166,7 @@ int main(int argc, char ** argv)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
slowPrint("\tServer Listener is:\t\033[32;40mGREEN.\033[0m\n", 5000);
|
slowPrint("\tServer Listener is:\t\033[32;40mGREEN.\033[0m\n", delay);
|
||||||
}
|
}
|
||||||
length = sizeof(clientAddress);
|
length = sizeof(clientAddress);
|
||||||
|
|
||||||
|
@ -173,7 +189,7 @@ int main(int argc, char ** argv)
|
||||||
gnutls_credentials_set(tlssessions[index], GNUTLS_CRD_ANON, &serverkey);
|
gnutls_credentials_set(tlssessions[index], GNUTLS_CRD_ANON, &serverkey);
|
||||||
gnutls_handshake_set_timeout(tlssessions[index], GNUTLS_DEFAULT_HANDSHAKE_TIMEOUT);
|
gnutls_handshake_set_timeout(tlssessions[index], GNUTLS_DEFAULT_HANDSHAKE_TIMEOUT);
|
||||||
}
|
}
|
||||||
slowPrint("\tTLS Preparation is:\t\033[32;40mGREEN.\033[0m\n", 5000);
|
slowPrint("\tTLS Preparation is:\t\033[32;40mGREEN.\033[0m\n", delay);
|
||||||
|
|
||||||
// Prepare the game logic thread:
|
// Prepare the game logic thread:
|
||||||
gameLogicParameters * gameLogicThreadParameters = malloc(sizeof(gameLogicParameters));
|
gameLogicParameters * gameLogicThreadParameters = malloc(sizeof(gameLogicParameters));
|
||||||
|
@ -185,8 +201,8 @@ int main(int argc, char ** argv)
|
||||||
gameLogicThreadParameters->areaList = areas;
|
gameLogicThreadParameters->areaList = areas;
|
||||||
pthread_create(&gameLogicThread, NULL, &gameLogicLoop, gameLogicThreadParameters);
|
pthread_create(&gameLogicThread, NULL, &gameLogicLoop, gameLogicThreadParameters);
|
||||||
|
|
||||||
slowPrint("\tEvent Thread is:\t\033[32;40mGREEN.\033[0m\n", 5000);
|
slowPrint("\tEvent Thread is:\t\033[32;40mGREEN.\033[0m\n", delay);
|
||||||
slowPrint("=====\n", 5000);
|
slowPrint("=====\n", delay);
|
||||||
struct timeval timeout = {0, 500};
|
struct timeval timeout = {0, 500};
|
||||||
|
|
||||||
while(true)
|
while(true)
|
||||||
|
|
Loading…
Reference in New Issue