Compare commits

...

2 Commits

Author SHA1 Message Date
Barra Ó Catháin 0a2d03fdaa Added environment variable handling.
* source/server/main.c (main):
- Added environment variable handling.
- Moved "Using" messages to after both command line arguments and enviroment variables are checked and applied.
- Command-line arguments override enviroment variables.
2024-03-19 23:20:08 +00:00
Barra Ó Catháin 9660fd4c60 Fix config.h.
* source/client/client-drawing.c: Change to correct include directive for config.h.
* source/client/main.c: Change to correct include directive for config.h.
2024-03-19 22:55:45 +00:00
3 changed files with 36 additions and 7 deletions

View File

@ -3,7 +3,7 @@
// | Copyright (C) 2023, Barra Ó Catháin |
// | See end of file for copyright notice. |
// ==========================================
#include "../config.h"
#include <config.h>
#include "client-drawing.h"
void redrawClientLayout(WINDOW * gameWindow, WINDOW * chatWindow, WINDOW * inputWindow)

View File

@ -6,6 +6,7 @@
#include <stdio.h>
#include <netdb.h>
#include <string.h>
#include <config.h>
#include <stdlib.h>
#include <getopt.h>
#include <limits.h>
@ -16,7 +17,6 @@
#include <sys/socket.h>
#include <gnutls/gnutls.h>
#include "../config.h"
#include "../messages.h"
#include "client-drawing.h"
#include "receiving-thread.h"

View File

@ -63,9 +63,24 @@ int main (int argc, char ** argv)
{"port", required_argument, 0, 'p' },
{"host", required_argument, 0, 'h' },
{"interface", required_argument, 0, 'i' }
};
};
// Check environment variables:
if (getenv("SILVERMUD_SERVER_PORT") != NULL)
{
portSpecified = true;
strncpy(serverPort, getenv("SILVERMUD_SERVER_HOST"), HOST_NAME_MAX);
}
if (getenv("SILVERMUD_SERVER_HOST") != NULL)
{
hostSpecified = true;
strncpy(serverHostname, getenv("SILVERMUD_SERVER_HOST"), HOST_NAME_MAX);
}
if (getenv("SILVERMUD_SERVER_INTERFACE") != NULL)
{
interfaceSpecified = true;
strncpy(serverInterface, getenv("SILVERMUD_SERVER_INTERFACE"), HOST_NAME_MAX);
}
// Parse command-line options:
int selectedOption = 0, optionIndex = 0;
@ -75,14 +90,13 @@ int main (int argc, char ** argv)
{
case 'p':
{
printf("Using port: %s\n", optarg);
portSpecified = true;
strncpy(serverPort, optarg, HOST_NAME_MAX);
break;
}
case 'h':
{
printf("Using hostname: %s\n", optarg);
hostSpecified = true;
strncpy(serverHostname, optarg, HOST_NAME_MAX);
break;
@ -96,7 +110,22 @@ int main (int argc, char ** argv)
}
}
}
if (portSpecified)
{
printf("Using port: %s\n", serverPort);
}
if (hostSpecified)
{
printf("Using hostname: %s\n", serverHostname);
}
if (interfaceSpecified)
{
printf("Using interface: %s\n", serverInterface);
}
// Initialize Scheme:
scm_init_guile();