알려진 버그 픽스
This commit is contained in:
@@ -34,6 +34,7 @@ FetchContent_MakeAvailable(JSONCPP)
|
||||
|
||||
file(GLOB_RECURSE additional_sources CONFIGURE_DEPENDS
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/../impl/*.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/src/Utils/*.cpp"
|
||||
)
|
||||
|
||||
add_executable(${PROJECT_NAME}
|
||||
|
||||
20
Server/include/Utils/ConfigManager.hpp
Normal file
20
Server/include/Utils/ConfigManager.hpp
Normal file
@@ -0,0 +1,20 @@
|
||||
#pragma once
|
||||
#include "precomp.hpp"
|
||||
#include <json/json.h>
|
||||
|
||||
namespace Chattr {
|
||||
class ConfigManager {
|
||||
public:
|
||||
struct Config {
|
||||
Json::Value configJsonRoot;
|
||||
std::uint32_t ipVersion = 0;
|
||||
std::uint32_t listenPort = 0;
|
||||
spdlog::level::level_enum logLevel = spdlog::level::off;
|
||||
gsl::czstring logFileName = "";
|
||||
std::uint32_t logfileSize = 0;
|
||||
std::uint32_t logfileCount = 0;
|
||||
};
|
||||
|
||||
static Config load();
|
||||
};
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
[2025-04-22 20:30:06.838] [Chattering Logger] [critical] [bind()] Invalid argument
|
||||
[2025-04-22 22:26:22.198] [Chattering Logger] [critical] [bind()] Socket operation on non-socket
|
||||
[2025-04-22 23:38:21.098] [Chattering Logger] [critical] [listen()] Operation not supported
|
||||
[2025-04-22 23:39:00.008] [Chattering Logger] [critical] [listen()] Operation not supported
|
||||
[2025-04-22 23:40:54.696] [Chattering Logger] [critical] [listen()] Operation not supported
|
||||
[2025-04-22 23:41:11.774] [Chattering Logger] [critical] [listen()] Operation not supported
|
||||
[2025-04-22 23:41:21.669] [Chattering Logger] [critical] [listen()] Operation not supported
|
||||
53
Server/src/Utils/ConfigManager.cpp
Normal file
53
Server/src/Utils/ConfigManager.cpp
Normal file
@@ -0,0 +1,53 @@
|
||||
#include "Utils/ConfigManager.hpp"
|
||||
#include "precomp.hpp"
|
||||
#include <fstream>
|
||||
#include <json/json.h>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
namespace Chattr {
|
||||
ConfigManager::Config ConfigManager::load() {
|
||||
Config config;
|
||||
|
||||
std::ifstream configfile("config.json", std::ifstream::binary);
|
||||
if (!configfile.is_open()) {
|
||||
std::ofstream defaultConfig("config.json", std::ios::out);
|
||||
config.configJsonRoot["IP Version"] = 6;
|
||||
config.configJsonRoot["Listen Port"] = 9010;
|
||||
config.configJsonRoot["LogLevel"] = 1;
|
||||
config.configJsonRoot["LogfileName"] = "Chattering.log";
|
||||
config.configJsonRoot["LogfileSize"] = UINT32_MAX;
|
||||
config.configJsonRoot["LogfileCount"] = 5;
|
||||
defaultConfig << config.configJsonRoot;
|
||||
defaultConfig.close();
|
||||
spdlog::critical("\"config.json\" is missing. Default configuration has been written.");
|
||||
}
|
||||
try {
|
||||
if (configfile.is_open())
|
||||
configfile >> config.configJsonRoot;
|
||||
|
||||
config.ipVersion = config.configJsonRoot["IP Version"].asInt();
|
||||
if (config.ipVersion != 4 && config.ipVersion != 6)
|
||||
throw std::runtime_error("Invalid IP Version.");
|
||||
|
||||
config.listenPort = config.configJsonRoot["Listen Port"].asInt();
|
||||
if (config.listenPort < 0 || config.listenPort > 65535)
|
||||
throw std::runtime_error("Invalid listen port.");
|
||||
|
||||
int ll_ = config.configJsonRoot["LogLevel"].asInt();
|
||||
if (ll_ >= 0 && ll_ < spdlog::level::n_levels)
|
||||
config.logLevel = (spdlog::level::level_enum)ll_;
|
||||
else
|
||||
throw std::runtime_error("Invalid log level.");
|
||||
|
||||
config.logFileName = config.configJsonRoot["LogfileName"].asCString();
|
||||
config.logfileSize = config.configJsonRoot["LogfileSize"].asUInt();
|
||||
config.logfileCount = config.configJsonRoot["LogfileCount"].asUInt();
|
||||
}
|
||||
catch (Json::RuntimeError e) {
|
||||
spdlog::critical(std::string(std::string("[Json Error: ]") + e.what()).c_str());
|
||||
std::exit(EXIT_FAILURE);
|
||||
}
|
||||
return config;
|
||||
}
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
{
|
||||
"IP Version" : 4,
|
||||
"Listen Port" : 9010,
|
||||
"LogLevel" : 1,
|
||||
"LogfileCount" : 5,
|
||||
"LogfileName" : "Chattering.log",
|
||||
"LogfileSize" : 4294967295
|
||||
}
|
||||
@@ -7,27 +7,26 @@ int main() {
|
||||
auto config = Chattr::ConfigManager::load();
|
||||
Chattr::log::setDefaultLogger(config.logLevel, config.logFileName, config.logfileSize, config.logfileCount);
|
||||
|
||||
|
||||
struct Chattr::TCPSocket sock;
|
||||
if (config.ipVersion == 4) {
|
||||
sock.init(AF_INET);
|
||||
|
||||
struct sockaddr_in serveraddr;
|
||||
serveraddr.sin_family = AF_INET;
|
||||
serveraddr.sin_addr.s_addr = htonl(INADDR_ANY);
|
||||
serveraddr.sin_port = htons(config.listenPort);
|
||||
struct Chattr::Address serveraddr;
|
||||
serveraddr.addr_in.sin_family = AF_INET;
|
||||
serveraddr.addr_in.sin_addr.s_addr = htonl(INADDR_ANY);
|
||||
serveraddr.addr_in.sin_port = htons(config.listenPort);
|
||||
|
||||
sock.bind(&serveraddr);
|
||||
sock.bind(&serveraddr.addr_in);
|
||||
}
|
||||
else {
|
||||
sock.init(AF_INET6);
|
||||
|
||||
struct sockaddr_in6 serveraddr;
|
||||
serveraddr.sin6_family = AF_INET6;
|
||||
serveraddr.sin6_addr = in6addr_any;
|
||||
serveraddr.sin6_port = htons(config.listenPort);
|
||||
struct Chattr::Address serveraddr;
|
||||
serveraddr.addr_in6.sin6_family = AF_INET6;
|
||||
serveraddr.addr_in6.sin6_addr = in6addr_any;
|
||||
serveraddr.addr_in6.sin6_port = htons(config.listenPort);
|
||||
|
||||
sock.bind(&serveraddr);
|
||||
sock.bind(&serveraddr.addr_in6);
|
||||
}
|
||||
sock.listen(SOMAXCONN);
|
||||
struct Chattr::TCPSocket clientSock;
|
||||
|
||||
Reference in New Issue
Block a user