besterd/source/server/server.d

54 lines
1.1 KiB
D
Raw Normal View History

2020-04-16 15:02:34 +02:00
module server.server;
import server.types;
2020-04-16 16:50:57 +02:00
import std.conv : to;
import std.socket : SocketOSException;
import utils.debugging : debugPrint;
2020-04-19 13:11:49 +02:00
import std.stdio : File,;
import std.json : parseJSON, JSONValue;
2020-04-16 15:02:34 +02:00
JSONValue getConfig(string configurationFilePath)
2020-04-16 15:02:34 +02:00
{
2020-04-17 18:47:05 +02:00
/* TODO: Open the file here */
File configFile;
configFile.open(configurationFilePath);
/* The file buffer */
byte[] fileBuffer;
/* Allocate the buffer to be the size of the file */
fileBuffer.length = configFile.size();
/* Read the content of the file */
/* TODO: Error handling ErrnoException */
fileBuffer = configFile.rawRead(fileBuffer);
configFile.close();
JSONValue config;
/* TODO: JSON error checking */
config = parseJSON(cast(string)fileBuffer);
return config;
}
void startServer(string configurationFilePath)
{
/* The server configuration */
JSONValue serverConfiguration = getConfig(configurationFilePath);
writeln(serverConfiguration);
/* The server */
BesterServer server = null;
2020-04-17 18:47:05 +02:00
2020-04-16 16:50:57 +02:00
try
{
server = new BesterServer(serverConfiguration);
2020-04-16 16:50:57 +02:00
server.run();
}
catch(SocketOSException exception)
{
debugPrint("Error binding: " ~ exception.toString());
2020-04-16 16:50:57 +02:00
}
2020-04-16 15:02:34 +02:00
}