2025-01-06 16:25:39 +08:00
|
|
|
#pragma once
|
|
|
|
#include <SimpleIni.h>
|
|
|
|
#include <of_path.h>
|
|
|
|
#include <util.h>
|
|
|
|
|
|
|
|
using namespace ofen;
|
|
|
|
|
|
|
|
struct TransmSet {
|
|
|
|
std::string group;
|
|
|
|
std::string ip{};
|
2025-03-28 11:00:13 +08:00
|
|
|
std::string comment{};
|
2025-01-06 16:25:39 +08:00
|
|
|
long port{};
|
|
|
|
long grp_id{};
|
|
|
|
};
|
|
|
|
|
|
|
|
struct CmdParam {
|
|
|
|
std::string removeValue;
|
|
|
|
std::string appendValue;
|
2025-04-07 11:49:13 +08:00
|
|
|
std::string connectValue;
|
2025-01-06 16:25:39 +08:00
|
|
|
bool showValue{false};
|
|
|
|
long use_config{-1};
|
2025-01-06 18:59:11 +08:00
|
|
|
bool parsed{false};
|
2025-03-28 11:00:13 +08:00
|
|
|
bool direct_use{false};
|
2025-03-28 12:01:35 +08:00
|
|
|
bool last_use{false};
|
2025-03-28 12:20:58 +08:00
|
|
|
bool null_use{false};
|
2025-01-06 16:25:39 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
class CServerConfig
|
|
|
|
{
|
|
|
|
public:
|
2025-03-01 03:49:40 +08:00
|
|
|
CServerConfig();
|
2025-01-06 16:25:39 +08:00
|
|
|
~CServerConfig();
|
|
|
|
|
|
|
|
public:
|
|
|
|
bool baseInit();
|
|
|
|
bool read_ini(std::vector<TransmSet>& set);
|
2025-03-28 11:00:13 +08:00
|
|
|
long have_ini(const std::vector<TransmSet>& set, const std::string& ip, long port);
|
2025-01-06 16:25:39 +08:00
|
|
|
bool write_ini(const std::vector<TransmSet>& set);
|
2025-03-28 11:00:13 +08:00
|
|
|
long append_ini(const std::string& ip, long port, const std::string& comment);
|
2025-01-06 16:25:39 +08:00
|
|
|
bool remove_ini(long num);
|
2025-02-06 09:37:24 +08:00
|
|
|
static bool get_ini(const std::vector<TransmSet>& set, long num, TransmSet& use);
|
2025-03-28 12:56:06 +08:00
|
|
|
std::string get_config_dir() const;
|
2025-01-06 16:25:39 +08:00
|
|
|
|
2025-03-28 12:01:35 +08:00
|
|
|
public:
|
|
|
|
bool save_last_use(const std::string& ip, long port);
|
2025-03-28 12:20:58 +08:00
|
|
|
bool get_last_use(std::string& ip, long& port);
|
2025-03-28 12:01:35 +08:00
|
|
|
|
2025-01-06 16:25:39 +08:00
|
|
|
private:
|
|
|
|
void gen_default_ini(const std::string& path);
|
|
|
|
|
|
|
|
private:
|
|
|
|
bool init_{false};
|
|
|
|
CSimpleIniA ini_handle_{};
|
|
|
|
std::string config_path_{};
|
2025-03-28 12:56:06 +08:00
|
|
|
std::string config_dir_{};
|
2025-01-06 16:25:39 +08:00
|
|
|
};
|