*** VERSION 5.2.0 ***
[NeonServV5.git] / src / main.c
index 0aa1a1bb8b2bec5be0908f34ec345c7ccb5e78e4..b8341fe0e47338c65cadb513c75b8496a291a0d7 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"
@@ -15,6 +31,8 @@
 #include "timeq.h"
 #include "EventLogger.h"
 #include "ModeNode.h"
+#include "IRCQueue.h"
+#include "lib/ini.h"
 
 time_t start_time;
 
@@ -32,8 +50,50 @@ void cleanup() {
     free_lang();
 }
 
+static int load_mysql_config() {
+    char mysql_host[MAXLEN], mysql_port_str[MAXLEN], mysql_user[MAXLEN], mysql_pass[MAXLEN], mysql_base[MAXLEN];
+    int mysql_serverport;
+    if(loadINI("neonserv.ini") == FILE_SUCCESS) {
+        mysql_host[0] = '\0';
+        ReadString("MySQL", "host", mysql_host);
+        if(!*mysql_host) {
+            perror("invalid neonserv.ini: missing MySQL host");
+            return 0;
+        }
+        mysql_port_str[0] = '\0';
+        ReadString("MySQL", "port", mysql_port_str);
+        mysql_serverport = atoi(mysql_port_str);
+        if(!mysql_serverport)
+            mysql_serverport = 3306;
+        mysql_user[0] = '\0';
+        ReadString("MySQL", "user", mysql_user);
+        if(!*mysql_user) {
+            perror("invalid neonserv.ini: missing MySQL user");
+            return 0;
+        }
+        mysql_pass[0] = '\0';
+        ReadString("MySQL", "pass", mysql_pass);
+        if(!*mysql_pass) {
+            perror("invalid neonserv.ini: missing MySQL pass");
+            return 0;
+        }
+        mysql_base[0] = '\0';
+        ReadString("MySQL", "base", mysql_base);
+        if(!*mysql_base) {
+            perror("invalid neonserv.ini: missing MySQL base");
+            return 0;
+        }
+    } else {
+        perror("Unable to load neonserv.ini");
+        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 +108,9 @@ int main(void)
     }
     #endif
     
-    init_mysql();
+    if(!load_mysql_config()) return 0;
+    
+    queue_init();
     init_lang();
     init_parser();
     init_UserNode();
@@ -72,6 +134,7 @@ int main(void)
         loop_bots();
         clearTempUsers();
         destroyEvents();
+        queue_loop();
     }
 }