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 <string.h>
|
||||
#include <unistd.h>
|
||||
#include <getopt.h>
|
||||
#include <stdbool.h>
|
||||
#include <pthread.h>
|
||||
#include <ncurses.h>
|
||||
|
@ -28,6 +29,7 @@ typedef struct threadparameters
|
|||
bool loggingFlag;
|
||||
WINDOW * window;
|
||||
int characterDelay;
|
||||
char * prompt;
|
||||
} threadparameters;
|
||||
|
||||
// Use sockaddr as a type:
|
||||
|
@ -44,13 +46,19 @@ void * messageSender(void * parameters)
|
|||
FILE * loggingStream = threadParameters->loggingStream;
|
||||
bool loggingFlag = threadParameters->loggingFlag;
|
||||
WINDOW * window = threadParameters->window;
|
||||
char * prompt = threadParameters->prompt;
|
||||
userMessage sendBuffer;
|
||||
|
||||
// Repeatedly get input from the user, place it in a userMessage, and send it to the server:
|
||||
while (!shouldExit)
|
||||
{
|
||||
usleep(100000);
|
||||
// Clear the window:
|
||||
wprintw(window, "\n\n\n");
|
||||
|
||||
// Print the prompt:
|
||||
wprintw(window, "\n\n\nCOMM-LINK> ");
|
||||
wprintw(window, prompt);
|
||||
|
||||
if (wgetnstr(window, sendBuffer.messageContent, MAX) == ERR)
|
||||
{
|
||||
// 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:
|
||||
messageSend(tlsSession, &sendBuffer);
|
||||
bzero(&sendBuffer, sizeof(char) * MAX);
|
||||
memset(&sendBuffer, 0, sizeof(char) * MAX);
|
||||
}
|
||||
|
||||
// Rejoin the main thread:
|
||||
|
@ -110,6 +118,13 @@ void * messageReceiver(void * parameters)
|
|||
// Check if it's a server message:
|
||||
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:
|
||||
if (receiveBuffer.messageContent[0] == '\0')
|
||||
{
|
||||
|
@ -306,6 +321,7 @@ int main(int argc, char ** argv)
|
|||
logArea->tlsSession = tlsSession;
|
||||
logArea->loggingFlag = chatLogging;
|
||||
logArea->characterDelay = characterDelay;
|
||||
|
||||
if (chatLog != NULL)
|
||||
{
|
||||
logArea->loggingStream = chatLog;
|
||||
|
@ -313,13 +329,18 @@ int main(int argc, char ** argv)
|
|||
messageArea->window = newwin(3, COLS - 2, LINES - 4, 1);
|
||||
messageArea->tlsSession = tlsSession;
|
||||
messageArea->loggingFlag = gameLogging;
|
||||
|
||||
|
||||
// Set the appropriate log pointers:
|
||||
if (gameLog != NULL)
|
||||
{
|
||||
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:
|
||||
scrollok(logArea->window, true);
|
||||
scrollok(messageArea->window, true);
|
||||
|
|
|
@ -108,7 +108,7 @@ void * gameLogicHandler(void * parameters)
|
|||
free(recipients);
|
||||
}
|
||||
}
|
||||
bzero(currentInput, sizeof(inputMessage));
|
||||
memset(currentInput, 0, sizeof(inputMessage));
|
||||
currentInput = NULL;
|
||||
threadParameters->inputQueue->lock = false;
|
||||
popQueue(threadParameters->inputQueue);
|
||||
|
@ -204,7 +204,7 @@ int evaluateNextCommand(gameLogicParameters * parameters, queue * queue)
|
|||
pushQueue(parameters->outputQueue, lookOutputMessage, OUTPUT_MESSAGE);
|
||||
|
||||
//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:
|
||||
int charCount = 13;
|
||||
|
@ -221,7 +221,7 @@ int evaluateNextCommand(gameLogicParameters * parameters, queue * queue)
|
|||
// Queue the outputMessage:
|
||||
pushQueue(parameters->outputQueue, lookOutputMessage, OUTPUT_MESSAGE);
|
||||
|
||||
bzero(lookMessage, sizeof(userMessage));
|
||||
memset(lookMessage, 0, sizeof(userMessage));
|
||||
charCount = 0;
|
||||
}
|
||||
snprintf(formattedString, 64, "\n\t%ld. %s", index + 1,
|
||||
|
@ -314,7 +314,7 @@ int evaluateNextCommand(gameLogicParameters * parameters, queue * queue)
|
|||
// Queue the outputMessage:
|
||||
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)
|
||||
{
|
||||
size_t skillIndex = 0;
|
||||
|
@ -335,7 +335,7 @@ int evaluateNextCommand(gameLogicParameters * parameters, queue * queue)
|
|||
|
||||
// Queue the outputMessage:
|
||||
pushQueue(parameters->outputQueue, statOutputMessage, OUTPUT_MESSAGE);
|
||||
bzero(statMessage, sizeof(userMessage));
|
||||
memset(statMessage, 0, sizeof(userMessage));
|
||||
charCount = 0;
|
||||
break;
|
||||
}
|
||||
|
@ -555,7 +555,7 @@ int evaluateNextCommand(gameLogicParameters * parameters, queue * queue)
|
|||
// Queue the outputMessage:
|
||||
pushQueue(parameters->outputQueue, listOutputMessage, OUTPUT_MESSAGE);
|
||||
|
||||
bzero(listMessage, sizeof(userMessage));
|
||||
memset(listMessage, 0, sizeof(userMessage));
|
||||
charCount = 0;
|
||||
addNewline = false;
|
||||
}
|
||||
|
@ -635,6 +635,7 @@ int evaluateNextCommand(gameLogicParameters * parameters, queue * queue)
|
|||
{
|
||||
currentCommand->caller->talkingWith = NULL;
|
||||
strcpy(talkMessage->messageContent, "Conversation ended.");
|
||||
strncat(&talkMessage->senderName[1], " > ", 4);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -645,6 +646,8 @@ int evaluateNextCommand(gameLogicParameters * parameters, queue * queue)
|
|||
currentCommand->caller->talkingWith = &(parameters->connectedPlayers[playerIndex]);
|
||||
|
||||
// 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);
|
||||
strcat(talkMessage->messageContent, " is talking to you.");
|
||||
|
||||
|
@ -662,9 +665,12 @@ int evaluateNextCommand(gameLogicParameters * parameters, queue * queue)
|
|||
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:
|
||||
outputMessage * talkOutputMessage = createTargetedOutputMessage(talkMessage, ¤tCommand->caller, 1);
|
||||
|
||||
|
@ -719,6 +725,21 @@ int evaluateNextCommand(gameLogicParameters * parameters, queue * queue)
|
|||
{
|
||||
strncpy(currentCommand->caller->playerName, currentCommand->arguments, 16);
|
||||
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
|
||||
// continue until the command is queued:
|
||||
queue->lock = false;
|
||||
|
@ -731,8 +752,8 @@ int evaluateNextCommand(gameLogicParameters * parameters, queue * queue)
|
|||
}
|
||||
|
||||
// Remove the current command and unlock the queue:
|
||||
bzero(currentCommand->command, sizeof(char) * 16);
|
||||
bzero(currentCommand->arguments, sizeof(char) * MAX);
|
||||
memset(currentCommand->command, 0, sizeof(char) * 16);
|
||||
memset(currentCommand->arguments, 0, sizeof(char) * MAX);
|
||||
currentCommand = NULL;
|
||||
queue->lock = false;
|
||||
popQueue(queue);
|
||||
|
@ -783,7 +804,7 @@ outcome statCheck(playerInfo * player, int chance, coreStat statToCheck)
|
|||
return ERROR;
|
||||
}
|
||||
}
|
||||
int attempt = (random() % 100) + modifier;
|
||||
int attempt = (rand() % 100) + modifier;
|
||||
if (attempt >= chance)
|
||||
{
|
||||
if (attempt >= 98)
|
||||
|
@ -856,7 +877,7 @@ outcome skillCheck(playerInfo * player, int chance, char * skillName, size_t ski
|
|||
}
|
||||
|
||||
// Attempt the check:
|
||||
int attempt = (random() % 100) + modifier;
|
||||
int attempt = (rand() % 100) + modifier;
|
||||
if (attempt >= chance)
|
||||
{
|
||||
if (attempt >= 98)
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
#include <string.h>
|
||||
#include <signal.h>
|
||||
#include <unistd.h>
|
||||
#include <getopt.h>
|
||||
#include <ncurses.h>
|
||||
#include <pthread.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);
|
||||
|
||||
// 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.
|
||||
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);
|
||||
}
|
||||
|
||||
bzero(&serverAddress, sizeof(serverAddress));
|
||||
memset(&serverAddress, 0, sizeof(serverAddress));
|
||||
|
||||
// Assign IP and port:
|
||||
serverAddress.sin_family = AF_INET;
|
||||
|
@ -284,7 +285,7 @@ int main(int argc, char ** argv)
|
|||
while (returnVal < 0 && gnutls_error_is_fatal(returnVal) == 0);
|
||||
|
||||
// Send a greeting message:
|
||||
strcpy(sendBuffer.senderName, "");
|
||||
memcpy(sendBuffer.senderName, "\0 Login > \0", 11);
|
||||
strcpy(sendBuffer.messageContent, "Welcome to the server!");
|
||||
messageSend(tlssessions[index], &sendBuffer);
|
||||
strcpy(receiveBuffer.messageContent, "/look");
|
||||
|
|
Loading…
Reference in New Issue