summaryrefslogtreecommitdiffstats
path: root/src/Core
diff options
context:
space:
mode:
Diffstat (limited to 'src/Core')
-rw-r--r--src/Core/ConfigManager.cpp61
-rw-r--r--src/Core/ConfigManager.h56
-rw-r--r--src/Core/ConnectionManager.cpp16
-rw-r--r--src/Core/ConnectionManager.h2
-rw-r--r--src/Core/Makefile.am4
-rw-r--r--src/Core/Makefile.in7
6 files changed, 132 insertions, 14 deletions
diff --git a/src/Core/ConfigManager.cpp b/src/Core/ConfigManager.cpp
new file mode 100644
index 0000000..b358671
--- /dev/null
+++ b/src/Core/ConfigManager.cpp
@@ -0,0 +1,61 @@
+/*
+ * ConfigManager.cpp
+ *
+ * Copyright (C) 2008 Matthias Schiffer <matthias@gamezock.de>
+ *
+ * This program is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "ConfigManager.h"
+#include <Common/Util.h>
+
+#include <iostream>
+
+namespace Mad {
+namespace Core {
+
+bool ConfigManager::parseLine(const std::string &key, const std::string &value) {
+ if(Common::Util::tolower(key) == "configmethod") {
+ if(Common::Util::tolower(value) == "mysql")
+ methods |= (unsigned short)MYSQL;
+ else
+ return false;
+ }
+ else if(Common::Util::tolower(key) == "listen") {
+ try {
+ listeners.push_back(Net::IPAddress(value));
+ }
+ catch(Net::InvalidAddressException &e) {
+ // TODO Logging
+ }
+ }
+ else {
+ // TODO Logging
+
+ return false;
+ }
+
+ return true;
+}
+
+ConfigManager::ConfigManager() {
+ loadFile("mad-core.conf");
+}
+
+ConfigManager::~ConfigManager() {
+ // TODO Auto-generated destructor stub
+}
+
+}
+}
diff --git a/src/Core/ConfigManager.h b/src/Core/ConfigManager.h
new file mode 100644
index 0000000..00c5933
--- /dev/null
+++ b/src/Core/ConfigManager.h
@@ -0,0 +1,56 @@
+/*
+ * ConfigManager.h
+ *
+ * Copyright (C) 2008 Matthias Schiffer <matthias@gamezock.de>
+ *
+ * This program is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef MAD_CORE_CONFIGMANAGER_H_
+#define MAD_CORE_CONFIGMANAGER_H_
+
+#include <Common/ConfigManager.h>
+#include <Net/IPAddress.h>
+#include <vector>
+
+namespace Mad {
+namespace Core {
+
+class ConfigManager : public Common::ConfigManager {
+ private:
+ enum Methods {
+ MYSQL = (1 << 0)
+ };
+
+ unsigned short methods;
+
+ std::vector<Net::IPAddress> listeners;
+
+ protected:
+ virtual bool parseLine(const std::string &key, const std::string &value);
+
+ public:
+ ConfigManager();
+ virtual ~ConfigManager();
+
+ const std::vector<Net::IPAddress>& getListenerAddresses() const {return listeners;}
+
+ //virtual const std::string& getValue(const std::string &value) const;
+};
+
+}
+
+}
+
+#endif /* MAD_CORE_CONFIGMANAGER_H_ */
diff --git a/src/Core/ConnectionManager.cpp b/src/Core/ConnectionManager.cpp
index 020c8a7..48d9c17 100644
--- a/src/Core/ConnectionManager.cpp
+++ b/src/Core/ConnectionManager.cpp
@@ -50,15 +50,15 @@ void ConnectionManager::refreshPollfds() {
}
}
-ConnectionManager::ConnectionManager() {
- try {
- // TODO: Get listener addresses from config
- listeners.push_back(new Net::Listener(Net::IPAddress("0.0.0.0", 6666)));
- }
- catch(Net::Exception &e) {
- // TODO: Log error
+ConnectionManager::ConnectionManager(const std::vector<Net::IPAddress> &listenerAddresses) {
+ for(std::vector<Net::IPAddress>::const_iterator address = listenerAddresses.begin(); address != listenerAddresses.end(); ++address) {
+ try {
+ listeners.push_back(new Net::Listener(*address));
+ }
+ catch(Net::Exception &e) {
+ // TODO: Log error
+ }
}
-
refreshPollfds();
}
diff --git a/src/Core/ConnectionManager.h b/src/Core/ConnectionManager.h
index c7fe669..54d5d5e 100644
--- a/src/Core/ConnectionManager.h
+++ b/src/Core/ConnectionManager.h
@@ -56,7 +56,7 @@ class ConnectionManager {
void refreshPollfds();
public:
- ConnectionManager();
+ ConnectionManager(const std::vector<Net::IPAddress> &listenerAddresses);
virtual ~ConnectionManager();
bool wait(int timeout) {
diff --git a/src/Core/Makefile.am b/src/Core/Makefile.am
index b2a2874..241c030 100644
--- a/src/Core/Makefile.am
+++ b/src/Core/Makefile.am
@@ -1,5 +1,5 @@
noinst_LTLIBRARIES = libcore.la
-libcore_la_SOURCES = ConnectionManager.cpp
+libcore_la_SOURCES = ConfigManager.cpp ConnectionManager.cpp
-noinst_HEADERS = ConnectionManager.h
+noinst_HEADERS = ConfigManager.h ConnectionManager.h
diff --git a/src/Core/Makefile.in b/src/Core/Makefile.in
index af39f87..1920fbb 100644
--- a/src/Core/Makefile.in
+++ b/src/Core/Makefile.in
@@ -45,7 +45,7 @@ CONFIG_HEADER = $(top_builddir)/src/config.h
CONFIG_CLEAN_FILES =
LTLIBRARIES = $(noinst_LTLIBRARIES)
libcore_la_LIBADD =
-am_libcore_la_OBJECTS = ConnectionManager.lo
+am_libcore_la_OBJECTS = ConfigManager.lo ConnectionManager.lo
libcore_la_OBJECTS = $(am_libcore_la_OBJECTS)
DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)/src
depcomp = $(SHELL) $(top_srcdir)/depcomp
@@ -180,8 +180,8 @@ target_alias = @target_alias@
top_builddir = @top_builddir@
top_srcdir = @top_srcdir@
noinst_LTLIBRARIES = libcore.la
-libcore_la_SOURCES = ConnectionManager.cpp
-noinst_HEADERS = ConnectionManager.h
+libcore_la_SOURCES = ConfigManager.cpp ConnectionManager.cpp
+noinst_HEADERS = ConfigManager.h ConnectionManager.h
all: all-am
.SUFFIXES:
@@ -233,6 +233,7 @@ mostlyclean-compile:
distclean-compile:
-rm -f *.tab.c
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ConfigManager.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ConnectionManager.Plo@am__quote@
.cpp.o: