Forgot to pull.
Merge branch 'dev' of ssh://dunseverick.ocathain.ie:2222/barra/SilverMUD into dev
This commit is contained in:
commit
50f4e6c38a
|
@ -7,6 +7,7 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include <getopt.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
#include <ncurses.h>
|
#include <ncurses.h>
|
||||||
|
@ -28,6 +29,7 @@ typedef struct threadparameters
|
||||||
bool loggingFlag;
|
bool loggingFlag;
|
||||||
WINDOW * window;
|
WINDOW * window;
|
||||||
int characterDelay;
|
int characterDelay;
|
||||||
|
char * prompt;
|
||||||
} threadparameters;
|
} threadparameters;
|
||||||
|
|
||||||
// Use sockaddr as a type:
|
// Use sockaddr as a type:
|
||||||
|
@ -44,13 +46,19 @@ void * messageSender(void * parameters)
|
||||||
FILE * loggingStream = threadParameters->loggingStream;
|
FILE * loggingStream = threadParameters->loggingStream;
|
||||||
bool loggingFlag = threadParameters->loggingFlag;
|
bool loggingFlag = threadParameters->loggingFlag;
|
||||||
WINDOW * window = threadParameters->window;
|
WINDOW * window = threadParameters->window;
|
||||||
|
char * prompt = threadParameters->prompt;
|
||||||
userMessage sendBuffer;
|
userMessage sendBuffer;
|
||||||
|
|
||||||
// Repeatedly get input from the user, place it in a userMessage, and send it to the server:
|
// Repeatedly get input from the user, place it in a userMessage, and send it to the server:
|
||||||
while (!shouldExit)
|
while (!shouldExit)
|
||||||
{
|
{
|
||||||
|
usleep(100000);
|
||||||
|
// Clear the window:
|
||||||
|
wprintw(window, "\n\n\n");
|
||||||
|
|
||||||
// Print the prompt:
|
// Print the prompt:
|
||||||
wprintw(window, "\n\n\nCOMM-LINK> ");
|
wprintw(window, prompt);
|
||||||
|
|
||||||
if (wgetnstr(window, sendBuffer.messageContent, MAX) == ERR)
|
if (wgetnstr(window, sendBuffer.messageContent, MAX) == ERR)
|
||||||
{
|
{
|
||||||
// Quit if there's any funny business with getting input:
|
// Quit if there's any funny business with getting input:
|
||||||
|
@ -73,7 +81,7 @@ void * messageSender(void * parameters)
|
||||||
|
|
||||||
// Send the message off to the server:
|
// Send the message off to the server:
|
||||||
messageSend(tlsSession, &sendBuffer);
|
messageSend(tlsSession, &sendBuffer);
|
||||||
bzero(&sendBuffer, sizeof(char) * MAX);
|
memset(&sendBuffer, 0, sizeof(char) * MAX);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Rejoin the main thread:
|
// Rejoin the main thread:
|
||||||
|
@ -110,6 +118,13 @@ void * messageReceiver(void * parameters)
|
||||||
// Check if it's a server message:
|
// Check if it's a server message:
|
||||||
else if (receiveBuffer.senderName[0] == '\0')
|
else if (receiveBuffer.senderName[0] == '\0')
|
||||||
{
|
{
|
||||||
|
// Check if the server wants to change the prompt:
|
||||||
|
if (receiveBuffer.senderName[1] != '\0')
|
||||||
|
{
|
||||||
|
strncpy(threadParameters->prompt, &receiveBuffer.senderName[1], 63);
|
||||||
|
threadParameters->prompt[63] = '\0';
|
||||||
|
}
|
||||||
|
|
||||||
// Check if it's a command to disconnect:
|
// Check if it's a command to disconnect:
|
||||||
if (receiveBuffer.messageContent[0] == '\0')
|
if (receiveBuffer.messageContent[0] == '\0')
|
||||||
{
|
{
|
||||||
|
@ -306,6 +321,7 @@ int main(int argc, char ** argv)
|
||||||
logArea->tlsSession = tlsSession;
|
logArea->tlsSession = tlsSession;
|
||||||
logArea->loggingFlag = chatLogging;
|
logArea->loggingFlag = chatLogging;
|
||||||
logArea->characterDelay = characterDelay;
|
logArea->characterDelay = characterDelay;
|
||||||
|
|
||||||
if (chatLog != NULL)
|
if (chatLog != NULL)
|
||||||
{
|
{
|
||||||
logArea->loggingStream = chatLog;
|
logArea->loggingStream = chatLog;
|
||||||
|
@ -320,6 +336,11 @@ int main(int argc, char ** argv)
|
||||||
messageArea->loggingStream = gameLog;
|
messageArea->loggingStream = gameLog;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Set up the string to hold the current "prompt" that the server has sent:
|
||||||
|
messageArea->prompt = calloc(32, sizeof(char));
|
||||||
|
strcpy(messageArea->prompt, " Login > ");
|
||||||
|
logArea->prompt = messageArea->prompt;
|
||||||
|
|
||||||
// Set the two windows to scroll:
|
// Set the two windows to scroll:
|
||||||
scrollok(logArea->window, true);
|
scrollok(logArea->window, true);
|
||||||
scrollok(messageArea->window, true);
|
scrollok(messageArea->window, true);
|
||||||
|
|
|
@ -108,7 +108,7 @@ void * gameLogicHandler(void * parameters)
|
||||||
free(recipients);
|
free(recipients);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
bzero(currentInput, sizeof(inputMessage));
|
memset(currentInput, 0, sizeof(inputMessage));
|
||||||
currentInput = NULL;
|
currentInput = NULL;
|
||||||
threadParameters->inputQueue->lock = false;
|
threadParameters->inputQueue->lock = false;
|
||||||
popQueue(threadParameters->inputQueue);
|
popQueue(threadParameters->inputQueue);
|
||||||
|
@ -204,7 +204,7 @@ int evaluateNextCommand(gameLogicParameters * parameters, queue * queue)
|
||||||
pushQueue(parameters->outputQueue, lookOutputMessage, OUTPUT_MESSAGE);
|
pushQueue(parameters->outputQueue, lookOutputMessage, OUTPUT_MESSAGE);
|
||||||
|
|
||||||
//queueTargetedOutputMessage(parameters->outputQueue, lookMessage, ¤tCommand->caller, 1);
|
//queueTargetedOutputMessage(parameters->outputQueue, lookMessage, ¤tCommand->caller, 1);
|
||||||
bzero(lookMessage, sizeof(userMessage));
|
memset(lookMessage, 0, sizeof(userMessage));
|
||||||
|
|
||||||
// Loop through the paths and send the appropriate amount of messages:
|
// Loop through the paths and send the appropriate amount of messages:
|
||||||
int charCount = 13;
|
int charCount = 13;
|
||||||
|
@ -221,7 +221,7 @@ int evaluateNextCommand(gameLogicParameters * parameters, queue * queue)
|
||||||
// Queue the outputMessage:
|
// Queue the outputMessage:
|
||||||
pushQueue(parameters->outputQueue, lookOutputMessage, OUTPUT_MESSAGE);
|
pushQueue(parameters->outputQueue, lookOutputMessage, OUTPUT_MESSAGE);
|
||||||
|
|
||||||
bzero(lookMessage, sizeof(userMessage));
|
memset(lookMessage, 0, sizeof(userMessage));
|
||||||
charCount = 0;
|
charCount = 0;
|
||||||
}
|
}
|
||||||
snprintf(formattedString, 64, "\n\t%ld. %s", index + 1,
|
snprintf(formattedString, 64, "\n\t%ld. %s", index + 1,
|
||||||
|
@ -314,7 +314,7 @@ int evaluateNextCommand(gameLogicParameters * parameters, queue * queue)
|
||||||
// Queue the outputMessage:
|
// Queue the outputMessage:
|
||||||
pushQueue(parameters->outputQueue, statOutputMessage, OUTPUT_MESSAGE);
|
pushQueue(parameters->outputQueue, statOutputMessage, OUTPUT_MESSAGE);
|
||||||
|
|
||||||
bzero(statMessage->messageContent, sizeof(char) * MAX);
|
memset(statMessage->messageContent, 0, sizeof(char) * MAX);
|
||||||
if (currentCommand->caller->skills->head != NULL)
|
if (currentCommand->caller->skills->head != NULL)
|
||||||
{
|
{
|
||||||
size_t skillIndex = 0;
|
size_t skillIndex = 0;
|
||||||
|
@ -335,7 +335,7 @@ int evaluateNextCommand(gameLogicParameters * parameters, queue * queue)
|
||||||
|
|
||||||
// Queue the outputMessage:
|
// Queue the outputMessage:
|
||||||
pushQueue(parameters->outputQueue, statOutputMessage, OUTPUT_MESSAGE);
|
pushQueue(parameters->outputQueue, statOutputMessage, OUTPUT_MESSAGE);
|
||||||
bzero(statMessage, sizeof(userMessage));
|
memset(statMessage, 0, sizeof(userMessage));
|
||||||
charCount = 0;
|
charCount = 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -555,7 +555,7 @@ int evaluateNextCommand(gameLogicParameters * parameters, queue * queue)
|
||||||
// Queue the outputMessage:
|
// Queue the outputMessage:
|
||||||
pushQueue(parameters->outputQueue, listOutputMessage, OUTPUT_MESSAGE);
|
pushQueue(parameters->outputQueue, listOutputMessage, OUTPUT_MESSAGE);
|
||||||
|
|
||||||
bzero(listMessage, sizeof(userMessage));
|
memset(listMessage, 0, sizeof(userMessage));
|
||||||
charCount = 0;
|
charCount = 0;
|
||||||
addNewline = false;
|
addNewline = false;
|
||||||
}
|
}
|
||||||
|
@ -635,6 +635,7 @@ int evaluateNextCommand(gameLogicParameters * parameters, queue * queue)
|
||||||
{
|
{
|
||||||
currentCommand->caller->talkingWith = NULL;
|
currentCommand->caller->talkingWith = NULL;
|
||||||
strcpy(talkMessage->messageContent, "Conversation ended.");
|
strcpy(talkMessage->messageContent, "Conversation ended.");
|
||||||
|
strncat(&talkMessage->senderName[1], " > ", 4);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -645,6 +646,8 @@ int evaluateNextCommand(gameLogicParameters * parameters, queue * queue)
|
||||||
currentCommand->caller->talkingWith = &(parameters->connectedPlayers[playerIndex]);
|
currentCommand->caller->talkingWith = &(parameters->connectedPlayers[playerIndex]);
|
||||||
|
|
||||||
// Fill out the message to inform the receiving user what is happening:
|
// Fill out the message to inform the receiving user what is happening:
|
||||||
|
strncat(&talkMessage->senderName[1], currentCommand->caller->playerName, 27);
|
||||||
|
strncat(&talkMessage->senderName[1], " > ", 4);
|
||||||
strncpy(talkMessage->messageContent, currentCommand->caller->playerName, 31);
|
strncpy(talkMessage->messageContent, currentCommand->caller->playerName, 31);
|
||||||
strcat(talkMessage->messageContent, " is talking to you.");
|
strcat(talkMessage->messageContent, " is talking to you.");
|
||||||
|
|
||||||
|
@ -662,7 +665,10 @@ int evaluateNextCommand(gameLogicParameters * parameters, queue * queue)
|
||||||
strcat(talkMessage->messageContent, parameters->connectedPlayers[playerIndex].playerName);
|
strcat(talkMessage->messageContent, parameters->connectedPlayers[playerIndex].playerName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
if(talkMessage->messageContent[0] == '\0')
|
||||||
|
{
|
||||||
|
strcpy(talkMessage->messageContent, "There is no player by that name connected.");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Allocate an outputMessage for the queue:
|
// Allocate an outputMessage for the queue:
|
||||||
|
@ -719,6 +725,21 @@ int evaluateNextCommand(gameLogicParameters * parameters, queue * queue)
|
||||||
{
|
{
|
||||||
strncpy(currentCommand->caller->playerName, currentCommand->arguments, 16);
|
strncpy(currentCommand->caller->playerName, currentCommand->arguments, 16);
|
||||||
currentCommand->caller->currentArea = getFromList(parameters->areaList, 1)->area;
|
currentCommand->caller->currentArea = getFromList(parameters->areaList, 1)->area;
|
||||||
|
|
||||||
|
// Allocate a userMessage containing null characters as the first char in both fields:
|
||||||
|
userMessage * joinMessage = calloc(1, (sizeof(userMessage)));
|
||||||
|
memcpy(joinMessage->senderName, "\0 > \0", 5);
|
||||||
|
strcpy(joinMessage->messageContent, "Logged in successfully.");
|
||||||
|
|
||||||
|
// Allocate an outputMessage for the queue:
|
||||||
|
outputMessage * joinOutputMessage = createTargetedOutputMessage(joinMessage, ¤tCommand->caller, 1);
|
||||||
|
|
||||||
|
// Queue the outputMessage:
|
||||||
|
pushQueue(parameters->outputQueue, joinOutputMessage, OUTPUT_MESSAGE);
|
||||||
|
|
||||||
|
// Free the userMessage
|
||||||
|
free(joinMessage);
|
||||||
|
|
||||||
// Call the look command after joining. It's fine to unlock, because the loop won't
|
// Call the look command after joining. It's fine to unlock, because the loop won't
|
||||||
// continue until the command is queued:
|
// continue until the command is queued:
|
||||||
queue->lock = false;
|
queue->lock = false;
|
||||||
|
@ -731,8 +752,8 @@ int evaluateNextCommand(gameLogicParameters * parameters, queue * queue)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove the current command and unlock the queue:
|
// Remove the current command and unlock the queue:
|
||||||
bzero(currentCommand->command, sizeof(char) * 16);
|
memset(currentCommand->command, 0, sizeof(char) * 16);
|
||||||
bzero(currentCommand->arguments, sizeof(char) * MAX);
|
memset(currentCommand->arguments, 0, sizeof(char) * MAX);
|
||||||
currentCommand = NULL;
|
currentCommand = NULL;
|
||||||
queue->lock = false;
|
queue->lock = false;
|
||||||
popQueue(queue);
|
popQueue(queue);
|
||||||
|
@ -783,7 +804,7 @@ outcome statCheck(playerInfo * player, int chance, coreStat statToCheck)
|
||||||
return ERROR;
|
return ERROR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
int attempt = (random() % 100) + modifier;
|
int attempt = (rand() % 100) + modifier;
|
||||||
if (attempt >= chance)
|
if (attempt >= chance)
|
||||||
{
|
{
|
||||||
if (attempt >= 98)
|
if (attempt >= 98)
|
||||||
|
@ -856,7 +877,7 @@ outcome skillCheck(playerInfo * player, int chance, char * skillName, size_t ski
|
||||||
}
|
}
|
||||||
|
|
||||||
// Attempt the check:
|
// Attempt the check:
|
||||||
int attempt = (random() % 100) + modifier;
|
int attempt = (rand() % 100) + modifier;
|
||||||
if (attempt >= chance)
|
if (attempt >= chance)
|
||||||
{
|
{
|
||||||
if (attempt >= 98)
|
if (attempt >= 98)
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include <getopt.h>
|
||||||
#include <ncurses.h>
|
#include <ncurses.h>
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
@ -131,7 +132,7 @@ int main(int argc, char ** argv)
|
||||||
slowPrint("\n--==== \033[33;40mSILVERKIN INDUSTRIES\033[0m COMM-LINK SERVER ====--\nVersion Alpha 0.5\n", delay);
|
slowPrint("\n--==== \033[33;40mSILVERKIN INDUSTRIES\033[0m COMM-LINK SERVER ====--\nVersion Alpha 0.5\n", delay);
|
||||||
|
|
||||||
// Seed random number generator from the current time:
|
// Seed random number generator from the current time:
|
||||||
srandom((unsigned)time(¤tTime));
|
srand((unsigned)time(¤tTime));
|
||||||
|
|
||||||
// Initialize the sockets to 0, so we don't crash.
|
// Initialize the sockets to 0, so we don't crash.
|
||||||
for (int index = 0; index < PLAYERCOUNT; index++)
|
for (int index = 0; index < PLAYERCOUNT; index++)
|
||||||
|
@ -152,7 +153,7 @@ int main(int argc, char ** argv)
|
||||||
slowPrint("\tSocket Creation is:\t\033[32;40mGREEN.\033[0m\n", delay);
|
slowPrint("\tSocket Creation is:\t\033[32;40mGREEN.\033[0m\n", delay);
|
||||||
}
|
}
|
||||||
|
|
||||||
bzero(&serverAddress, sizeof(serverAddress));
|
memset(&serverAddress, 0, sizeof(serverAddress));
|
||||||
|
|
||||||
// Assign IP and port:
|
// Assign IP and port:
|
||||||
serverAddress.sin_family = AF_INET;
|
serverAddress.sin_family = AF_INET;
|
||||||
|
@ -284,7 +285,7 @@ int main(int argc, char ** argv)
|
||||||
while (returnVal < 0 && gnutls_error_is_fatal(returnVal) == 0);
|
while (returnVal < 0 && gnutls_error_is_fatal(returnVal) == 0);
|
||||||
|
|
||||||
// Send a greeting message:
|
// Send a greeting message:
|
||||||
strcpy(sendBuffer.senderName, "");
|
memcpy(sendBuffer.senderName, "\0 Login > \0", 11);
|
||||||
strcpy(sendBuffer.messageContent, "Welcome to the server!");
|
strcpy(sendBuffer.messageContent, "Welcome to the server!");
|
||||||
messageSend(tlssessions[index], &sendBuffer);
|
messageSend(tlssessions[index], &sendBuffer);
|
||||||
strcpy(receiveBuffer.messageContent, "/look");
|
strcpy(receiveBuffer.messageContent, "/look");
|
||||||
|
|
Loading…
Reference in New Issue