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.
|
||||
// Barry Kane, 2021
|
||||
#include "lists.h"
|
||||
// areadata.c: Implements functions for playerAreas and playerPaths in SilverMUD:
|
||||
// Barra Ó Catháin, 2022.
|
||||
#include "areadata.h"
|
||||
#include "playerdata.h"
|
||||
|
||||
areaNode * createAreaList(playerArea * initialArea)
|
|
@ -1,7 +1,7 @@
|
|||
// lists.h: A header file for the lists library for SilverMUD.
|
||||
// Barry Kane, 2021.
|
||||
#ifndef LISTS_H
|
||||
#define LISTS_H
|
||||
// areadata.h: Contains data structures and functions for playerAreas and playerPaths in SilverMUD:
|
||||
// Barra Ó Catháin, 2022.
|
||||
#ifndef AREADATA_H
|
||||
#define AREADATA_H
|
||||
#include "playerdata.h"
|
||||
|
||||
typedef struct areaNode areaNode;
|
|
@ -13,6 +13,7 @@
|
|||
#include <arpa/inet.h>
|
||||
#include <sys/socket.h>
|
||||
#include <gnutls/gnutls.h>
|
||||
|
||||
#include "../constants.h"
|
||||
#include "../playerdata.h"
|
||||
#include "../texteffects.h"
|
||||
|
@ -66,21 +67,29 @@ void * messageSender(void * parameters)
|
|||
// Send the message off to the server:
|
||||
messageSend(threadParameters->tlsSession, &sendBuffer);
|
||||
}
|
||||
|
||||
// Rejoin the main thread:
|
||||
pthread_exit(NULL);
|
||||
}
|
||||
|
||||
void * messageReceiver(void * parameters)
|
||||
{
|
||||
struct threadparameters *threadParameters = parameters;
|
||||
bool serverMessage = false;
|
||||
int returnValue = 0;
|
||||
userMessage receiveBuffer;
|
||||
bool serverMessage = false;
|
||||
struct threadparameters *threadParameters = parameters;
|
||||
int screenWidth = getmaxx(threadParameters->window);
|
||||
|
||||
// Repeatedly take messages from the server and print them to the chat log window:
|
||||
while (!shouldExit)
|
||||
{
|
||||
messageReceive(threadParameters->tlsSession, &receiveBuffer);
|
||||
if (receiveBuffer.senderName[0] == '\0')
|
||||
returnValue = messageReceive(threadParameters->tlsSession, &receiveBuffer);
|
||||
// Check we haven't been disconnected:
|
||||
if(returnValue == -10 || returnValue == 0)
|
||||
{
|
||||
shouldExit = true;
|
||||
}
|
||||
else if (receiveBuffer.senderName[0] == '\0')
|
||||
{
|
||||
wrapString(receiveBuffer.messageContent,
|
||||
strlen(receiveBuffer.messageContent) - 1, screenWidth);
|
||||
|
@ -123,7 +132,7 @@ void * messageReceiver(void * parameters)
|
|||
pthread_exit(NULL);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
int main(int argc, char ** argv)
|
||||
{
|
||||
int socketFileDesc;
|
||||
struct sockaddr_in serverAddress;
|
||||
|
@ -276,6 +285,8 @@ 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;
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
// Barry Kane, 2022.
|
||||
#ifndef GAMELOGIC_H
|
||||
#define GAMELOGIC_H
|
||||
#include "lists.h"
|
||||
#include "areadata.h"
|
||||
#include "constants.h"
|
||||
#include "playerdata.h"
|
||||
#include "inputoutput.h"
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
#include <netinet/in.h>
|
||||
#include <gnutls/gnutls.h>
|
||||
|
||||
#include "../lists.h"
|
||||
#include "../areadata.h"
|
||||
#include "../gamelogic.h"
|
||||
#include "../constants.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);
|
||||
|
||||
// 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.
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
bzero(&serverAddress, sizeof(serverAddress));
|
||||
|
||||
// Assign IP and port:
|
||||
|
|
Loading…
Reference in New Issue