From b95ed984f8bd2fe413d53d4b8677fe3d04bc1ad9 Mon Sep 17 00:00:00 2001 From: Treeki Date: Tue, 28 Jan 2014 00:08:33 +0100 Subject: implement server configuration loading/saving --- bouncer/netcore.cpp | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'bouncer/netcore.cpp') diff --git a/bouncer/netcore.cpp b/bouncer/netcore.cpp index dee6ef7..0dd929f 100644 --- a/bouncer/netcore.cpp +++ b/bouncer/netcore.cpp @@ -1,4 +1,5 @@ #include "core.h" +#include "ini.h" NetCore::NetCore() { @@ -321,10 +322,49 @@ void NetCore::sendToClients(Packet::Type type, const Buffer &data) { + +void NetCore::loadConfig() { + auto sections = INI::load("config.ini"); + + for (auto §ion : sections) { + if (section.title == "Server" && serverCount < SERVER_LIMIT) { + Server *s = constructServer(section.data["type"].c_str()); + if (s) { + s->loadFromConfig(section.data); + registerServer(s); + } + } + } +} + +void NetCore::saveConfig() { + std::list sections; + + for (int i = 0; i < serverCount; i++) { + INI::Section section; + section.title = "Server"; + + servers[i]->saveToConfig(section.data); + + sections.push_back(section); + } + + INI::save("config.ini", sections); +} + + + + Client *Bouncer::constructClient() { return new MobileClient(this); } +Server *Bouncer::constructServer(const char *type) { + if (strcmp(type, "IRCServer") == 0) + return new IRCServer(this); + + return 0; +} -- cgit v1.2.3