added new self-made config parser with new config style
[NeonServV5.git] / src / main.c
index 0aa1a1bb8b2bec5be0908f34ec345c7ccb5e78e4..183ebaedb3e1e205215b51ed0a8c7395d9beb91d 100644 (file)
@@ -1,3 +1,19 @@
+/* main.c - NeonServ v5.2
+ * Copyright (C) 2011  Philipp Kreil (pk910)
+ * 
+ * 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 "main.h"
 #include "ClientSocket.h"
 #include "timeq.h"
 #include "EventLogger.h"
 #include "ModeNode.h"
+#include "IRCQueue.h"
+#include "DBHelper.h"
+#include "commands.h"
+#include "ConfigParser.h"
 
 time_t start_time;
 
@@ -32,8 +52,44 @@ void cleanup() {
     free_lang();
 }
 
+static int load_mysql_config() {
+    char *mysql_host, *mysql_user, *mysql_pass, *mysql_base;
+    int mysql_serverport;
+    if(loadConfig("neonserv.conf")) {
+        mysql_host = get_string_field("MySQL.host");
+        if(!mysql_host) {
+            perror("invalid neonserv.conf: missing MySQL.host");
+            return 0;
+        }
+        mysql_serverport = get_int_field("MySQL.port");
+        if(!mysql_serverport)
+            mysql_serverport = 3306;
+        mysql_user = get_string_field("MySQL.user");
+        if(!mysql_user) {
+            perror("invalid neonserv.conf: missing MySQL.user");
+            return 0;
+        }
+        mysql_pass = get_string_field("MySQL.pass");
+        if(!mysql_pass) {
+            perror("invalid neonserv.conf: missing MySQL.pass");
+            return 0;
+        }
+        mysql_base = get_string_field("MySQL.base");
+        if(!mysql_base) {
+            perror("invalid neonserv.conf: missing MySQL base");
+            return 0;
+        }
+    } else {
+        perror("Unable to load neonserv.conf");
+        return 0;
+    }
+    init_mysql(mysql_host, mysql_serverport, mysql_user, mysql_pass, mysql_base);
+    return 1;
+}
+
 int main(void)
 {
+    
     start_time = time(0);
     
     #ifdef WIN32
@@ -48,7 +104,9 @@ int main(void)
     }
     #endif
     
-    init_mysql();
+    if(!load_mysql_config()) return 0;
+    
+    queue_init();
     init_lang();
     init_parser();
     init_UserNode();
@@ -58,7 +116,9 @@ int main(void)
        init_modcmd();
     init_handleinfohandler();
     init_tools();
+    register_commands();
     init_bots();
+    init_DBHelper();
     
     load_languages();
     
@@ -72,6 +132,7 @@ int main(void)
         loop_bots();
         clearTempUsers();
         destroyEvents();
+        queue_loop();
     }
 }