Alpha 0.3 release of SilverMUD:

Features Added:
- Basic naming system.
- playerdata.h, containing datastructures related to storing player information.
- Ability to change name via '/NAME'.

Features Changed:
- Client now shows message sender's name.

Features Removed:
- None.

Squashed commit of the following:

commit 0ef71dbfce09c65dd988489557d0acdb3e20114e
Author: Barry Kane <bazzakane@gmail.com>
Date:   Wed Sep 15 00:12:05 2021 +0100

    Incremented Version Number.

    - Incremented version number in preperation for merge.

commit 18a4f416f6
Author: Barry Kane <bazzakane@gmail.com>
Date:   Wed Sep 15 00:07:13 2021 +0100

    Added basic name system

    - Added basic name system.
    - Added playerdata.h.
    - Added basic /NAME command. TODO: Create proper command system.
    - Added datastructures for user messages and user names.

commit 9411803942
Author: Barry Kane <bazzakane@gmail.com>
Date:   Fri Sep 10 15:07:42 2021 +0100

    Increment version message for merge.

    Incremented the version number by 0.1 for the server.
    Added version splash to the client.

commit 7047d0ee08
Author: Barry Kane <bazzakane@gmail.com>
Date:   Fri Sep 10 15:03:02 2021 +0100

    Added two-window messaging to the client.

    Client now has two seperate Ncurses windows for sending and receiving.
    Added SIGINT handler which sets a global boolean to gracefully exit and free memory.
    Sending and Receiving are now on their own threads.
    A pointer-to-struct is now passed to the threads.
    The main thread will now wait to cancel the threads upon receiving SIGINT.
    slowPrintNcurses now takes a window argument.
    The server now doesn't check that a client receives the message that they sent, allowing for full chat history.

commit 33bc9bcda0
Author: Barry Kane <bazzakane@gmail.com>
Date:   Fri Sep 3 18:47:11 2021 +0100

    Adapted client to use Ncurses instead of raw terminal output:
    Created "slowPrintNcurses", which is a version of "slowPrint" compatible with Ncurses screens.
    Ncurses is now used in place of raw-terminal output.
    The screen clears after inital start-up messages.
    C-d no longer exits, and still doesn't spam.
    Added Ncurses to the ld options of client in the Makefile.
    Created ld options for server in the Makefile.

commit 849a80bd37
Author: Barry Kane <barry@omnimenu.ie>
Date:   Thu Aug 19 23:07:58 2021 +0100

    Basic input sanatization:
    Created new library to deal with user input.
    Implemented check in client to prevent C-d spamming the server.
    C-d now exits.
    Implemented check in client to prevent clients sending messages containing only newlines
    to the server.

commit 2c093903a4
Author: Barry Kane <barry@omnimenu.ie>
Date:   Tue Aug 17 18:57:56 2021 +0100

    Git Sanity Check
This commit is contained in:
Barry Kane 2021-09-15 00:22:15 +01:00
parent b9d5c36683
commit 52c0fed848
3 changed files with 72 additions and 14 deletions

View File

@ -9,6 +9,7 @@
#include <ncurses.h>
#include <arpa/inet.h>
#include <sys/socket.h>
#include "misc/playerdata.h"
#include "misc/texteffects.h"
#include "misc/inputhandling.h"
#define MAX 1024
@ -61,13 +62,16 @@ void * messageReceiver(void * parameters)
{
// Takes messages from the server and prints them to the chat log window:
struct threadparameters *threadParameters = parameters;
char receiveBuffer[MAX];
userMessage receiveBuffer;
while (!shouldExit)
{
read(threadParameters->socketDescriptor, receiveBuffer, MAX);
slowPrintNcurses("USER-MESSAGE: ", 8000, threadParameters->window);
slowPrintNcurses(receiveBuffer, 8000, threadParameters->window);
bzero(receiveBuffer, MAX);
read(threadParameters->socketDescriptor, &receiveBuffer.senderName, sizeof(receiveBuffer.senderName));
read(threadParameters->socketDescriptor, &receiveBuffer.messageContent, sizeof(receiveBuffer.messageContent));
slowPrintNcurses(receiveBuffer.senderName, 8000, threadParameters->window);
slowPrintNcurses(": ", 8000, threadParameters->window);
slowPrintNcurses(receiveBuffer.messageContent, 8000, threadParameters->window);
bzero(receiveBuffer.senderName, sizeof(receiveBuffer.senderName));
bzero(receiveBuffer.messageContent, sizeof(receiveBuffer.messageContent));
}
pthread_exit(NULL);
}
@ -83,7 +87,7 @@ int main(int argc, char **argv)
signal(SIGINT, sigintHandler);
// Print welcome message:
slowPrint("\n--==== \033[33;40mSILVERKIN INDUSTRIES\033[0m COMM-LINK CLIENT ====--\nVersion Alpha 0.2\n", 5000);
slowPrint("\n--==== \033[33;40mSILVERKIN INDUSTRIES\033[0m COMM-LINK CLIENT ====--\nVersion Alpha 0.3\n", 5000);
// Give me a socket, and make sure it's working:
sockfd = socket(AF_INET, SOCK_STREAM, 0);

View File

@ -1,4 +1,4 @@
// Silverkin Industries Comm-Link Server, Engineering Sample Alpha 0.1.
// Silverkin Industries Comm-Link Server, Engineering Sample Alpha 0.3.
// PROJECT CODENAME: WHAT DO I PAY YOU FOR? | Level-3 Clearance.
// Barry Kane, 2021
#include <netdb.h>
@ -12,6 +12,7 @@
#include <arpa/inet.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include "misc/playerdata.h"
#include "misc/texteffects.h"
const int PORT = 5000;
const int MAX = 1024;
@ -23,13 +24,21 @@ int main()
socketCheck, activityCheck, readLength;
int clientSockets[64];
int maxClients = 64;
userMessage sendBuffer;
char receiveBuffer[MAX];
fd_set connectedClients;
playerInfo connectedPlayers[64];
struct sockaddr_in serverAddress, clientAddress;
// Initialize playerdata:
for (int index = 0; index < maxClients; index++)
{
strcpy(connectedPlayers[index].playerName, "UNNAMED");
}
// Give an intro: Display the Silverkin Industries logo and splash text.
slowPrint(logostring, 3000);
slowPrint("\n--==== \033[33;40mSILVERKIN INDUSTRIES\033[0m COMM-LINK SERVER ====--\nVersion Alpha 0.2\n", 5000);
slowPrint("\n--==== \033[33;40mSILVERKIN INDUSTRIES\033[0m COMM-LINK SERVER ====--\nVersion Alpha 0.3\n", 5000);
// Initialize the sockets to 0, so we don't crash.
for (int index = 0; index < maxClients; index++)
@ -164,20 +173,48 @@ int main()
close(socketCheck);
clientSockets[i] = 0;
}
// Name change command: Move logic to a command interpreter later:
else if (receiveBuffer[0] == '/')
{
char newName[32];
if(strncmp(receiveBuffer, "/NAME", 5) == 0)
{
strncpy(newName, &receiveBuffer[6], 32);
// Remove newlines:
for (int index = 0; index < 32; index++)
{
if (newName[index] == '\n')
{
newName[index] = '\0';
}
}
for (int index = 0; index < maxClients; index++)
{
if(strncmp(newName, connectedPlayers[index].playerName, 32) == 0)
{
break;
}
}
strncpy(connectedPlayers[i].playerName, newName, 32);
}
}
// Echo back the message that came in:
else
{
printf("%d: %s", clientSockets[i], receiveBuffer);
printf("%d/%s: %s", clientSockets[i], connectedPlayers[i].playerName, receiveBuffer);
fflush(stdout);
strcpy(sendBuffer.senderName, connectedPlayers[i].playerName);
strcpy(sendBuffer.messageContent, receiveBuffer);
for (int sendIndex = 0; sendIndex < clientsAmount; sendIndex++)
{
if(clientSockets[sendIndex] != STDIN_FILENO && clientSockets[sendIndex] != STDOUT_FILENO && clientSockets[sendIndex] != STDERR_FILENO)
{
write(clientSockets[sendIndex], receiveBuffer, sizeof(receiveBuffer));
write(clientSockets[sendIndex], sendBuffer.senderName, sizeof(sendBuffer.senderName));
write(clientSockets[sendIndex], sendBuffer.messageContent, sizeof(sendBuffer.messageContent));
}
}
bzero(receiveBuffer, sizeof(receiveBuffer));
bzero(sendBuffer.senderName, sizeof(sendBuffer.senderName));
bzero(sendBuffer.messageContent, sizeof(sendBuffer.messageContent));
}
}
}

17
src/misc/playerdata.h Normal file
View File

@ -0,0 +1,17 @@
// playerdata.h: Header file containing data structures for player data and function
// definitions for interacting with said data.
// Barry Kane, 2021.
typedef struct userMessage
{
char senderName[32];
char messageContent[1024];
} userMessage;
typedef struct playerInfo
{
char playerName[32];
} playerInfo;