Made client exit gracefully upon server exit:
- The client now checks the return value of messageReceive. - Renamed lists.c/.h to areadata.c/.h.
This commit is contained in:
parent
b8189ae2de
commit
60110d3abd
|
@ -1,6 +1,6 @@
|
||||||
// Implementation of lists library for SilverMUD.
|
// areadata.c: Implements functions for playerAreas and playerPaths in SilverMUD:
|
||||||
// Barry Kane, 2021
|
// Barra Ó Catháin, 2022.
|
||||||
#include "lists.h"
|
#include "areadata.h"
|
||||||
#include "playerdata.h"
|
#include "playerdata.h"
|
||||||
|
|
||||||
areaNode * createAreaList(playerArea * initialArea)
|
areaNode * createAreaList(playerArea * initialArea)
|
|
@ -1,7 +1,7 @@
|
||||||
// lists.h: A header file for the lists library for SilverMUD.
|
// areadata.h: Contains data structures and functions for playerAreas and playerPaths in SilverMUD:
|
||||||
// Barry Kane, 2021.
|
// Barra Ó Catháin, 2022.
|
||||||
#ifndef LISTS_H
|
#ifndef AREADATA_H
|
||||||
#define LISTS_H
|
#define AREADATA_H
|
||||||
#include "playerdata.h"
|
#include "playerdata.h"
|
||||||
|
|
||||||
typedef struct areaNode areaNode;
|
typedef struct areaNode areaNode;
|
|
@ -13,6 +13,7 @@
|
||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#include <gnutls/gnutls.h>
|
#include <gnutls/gnutls.h>
|
||||||
|
|
||||||
#include "../constants.h"
|
#include "../constants.h"
|
||||||
#include "../playerdata.h"
|
#include "../playerdata.h"
|
||||||
#include "../texteffects.h"
|
#include "../texteffects.h"
|
||||||
|
@ -66,21 +67,29 @@ void * messageSender(void * parameters)
|
||||||
// Send the message off to the server:
|
// Send the message off to the server:
|
||||||
messageSend(threadParameters->tlsSession, &sendBuffer);
|
messageSend(threadParameters->tlsSession, &sendBuffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Rejoin the main thread:
|
||||||
pthread_exit(NULL);
|
pthread_exit(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
void * messageReceiver(void * parameters)
|
void * messageReceiver(void * parameters)
|
||||||
{
|
{
|
||||||
struct threadparameters *threadParameters = parameters;
|
int returnValue = 0;
|
||||||
bool serverMessage = false;
|
|
||||||
userMessage receiveBuffer;
|
userMessage receiveBuffer;
|
||||||
|
bool serverMessage = false;
|
||||||
|
struct threadparameters *threadParameters = parameters;
|
||||||
int screenWidth = getmaxx(threadParameters->window);
|
int screenWidth = getmaxx(threadParameters->window);
|
||||||
|
|
||||||
// Repeatedly take messages from the server and print them to the chat log window:
|
// Repeatedly take messages from the server and print them to the chat log window:
|
||||||
while (!shouldExit)
|
while (!shouldExit)
|
||||||
{
|
{
|
||||||
messageReceive(threadParameters->tlsSession, &receiveBuffer);
|
returnValue = messageReceive(threadParameters->tlsSession, &receiveBuffer);
|
||||||
if (receiveBuffer.senderName[0] == '\0')
|
// Check we haven't been disconnected:
|
||||||
|
if(returnValue == -10 || returnValue == 0)
|
||||||
|
{
|
||||||
|
shouldExit = true;
|
||||||
|
}
|
||||||
|
else if (receiveBuffer.senderName[0] == '\0')
|
||||||
{
|
{
|
||||||
wrapString(receiveBuffer.messageContent,
|
wrapString(receiveBuffer.messageContent,
|
||||||
strlen(receiveBuffer.messageContent) - 1, screenWidth);
|
strlen(receiveBuffer.messageContent) - 1, screenWidth);
|
||||||
|
@ -123,7 +132,7 @@ void * messageReceiver(void * parameters)
|
||||||
pthread_exit(NULL);
|
pthread_exit(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char ** argv)
|
||||||
{
|
{
|
||||||
int socketFileDesc;
|
int socketFileDesc;
|
||||||
struct sockaddr_in serverAddress;
|
struct sockaddr_in serverAddress;
|
||||||
|
@ -276,6 +285,8 @@ int main(int argc, char **argv)
|
||||||
messageArea->window = newwin(3, COLS - 2, LINES - 4, 1);
|
messageArea->window = newwin(3, COLS - 2, LINES - 4, 1);
|
||||||
messageArea->tlsSession = tlsSession;
|
messageArea->tlsSession = tlsSession;
|
||||||
messageArea->loggingFlag = gameLogging;
|
messageArea->loggingFlag = gameLogging;
|
||||||
|
|
||||||
|
// Set the appropriate log pointers:
|
||||||
if (gameLog != NULL)
|
if (gameLog != NULL)
|
||||||
{
|
{
|
||||||
messageArea->loggingStream = gameLog;
|
messageArea->loggingStream = gameLog;
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
// Barry Kane, 2022.
|
// Barry Kane, 2022.
|
||||||
#ifndef GAMELOGIC_H
|
#ifndef GAMELOGIC_H
|
||||||
#define GAMELOGIC_H
|
#define GAMELOGIC_H
|
||||||
#include "lists.h"
|
#include "areadata.h"
|
||||||
#include "constants.h"
|
#include "constants.h"
|
||||||
#include "playerdata.h"
|
#include "playerdata.h"
|
||||||
#include "inputoutput.h"
|
#include "inputoutput.h"
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
#include <netinet/in.h>
|
#include <netinet/in.h>
|
||||||
#include <gnutls/gnutls.h>
|
#include <gnutls/gnutls.h>
|
||||||
|
|
||||||
#include "../lists.h"
|
#include "../areadata.h"
|
||||||
#include "../gamelogic.h"
|
#include "../gamelogic.h"
|
||||||
#include "../constants.h"
|
#include "../constants.h"
|
||||||
#include "../playerdata.h"
|
#include "../playerdata.h"
|
||||||
|
@ -94,7 +94,7 @@ int main()
|
||||||
slowPrint("\n--==== \033[33;40mSILVERKIN INDUSTRIES\033[0m COMM-LINK SERVER ====--\nVersion Alpha 0.3\n", 5000);
|
slowPrint("\n--==== \033[33;40mSILVERKIN INDUSTRIES\033[0m COMM-LINK SERVER ====--\nVersion Alpha 0.3\n", 5000);
|
||||||
|
|
||||||
// Seed random number generator from the current time:
|
// Seed random number generator from the current time:
|
||||||
srandom((unsigned) time(¤tTime));
|
srandom((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++)
|
||||||
|
@ -114,7 +114,8 @@ int main()
|
||||||
{
|
{
|
||||||
slowPrint("\tSocket Creation is:\t\033[32;40mGREEN.\033[0m\n", 5000);
|
slowPrint("\tSocket Creation is:\t\033[32;40mGREEN.\033[0m\n", 5000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//
|
||||||
bzero(&serverAddress, sizeof(serverAddress));
|
bzero(&serverAddress, sizeof(serverAddress));
|
||||||
|
|
||||||
// Assign IP and port:
|
// Assign IP and port:
|
||||||
|
|
Loading…
Reference in New Issue