+int main(int argc, char *argv[]) {
+ memset(&process_state, 0, sizeof(process_state));
+ printf("NeonServ v%s\n\n", NEONSERV_VERSION);
+
+ process_state.argv = argv;
+ process_state.argc = argc;
+ process_state.run_as_daemon = 1;
+ strcpy(process_state.config, DEFAULT_CONF_FILE);
+ strcpy(process_state.pidfile, DEFAULT_PID_FILE);
+
+ //parse argv
+ main_parse_arguments();
+
+ //initialize memory debugger BEFORE allocating memory
+ #ifdef ENABLE_MEMORY_DEBUG
+ initMemoryDebug();
+ #endif
+
+ //deny root startup
+ #ifndef WIN32
+ if(geteuid() == 0 || getuid() == 0) {
+ fprintf(stderr, "NeonServ may not be run with super user privileges.\n");
+ exit(0);
+ }
+ #endif
+
+ //load configuration
+ int errid;
+ if(errid = reload_configuration()) {
+ fprintf(stderr, "Unable to load configuration file `%s`. (errid: %d)\n", process_state.config, errid);
+ exit(0);
+ }
+
+ //check mysql configuration
+ if(!reload_mysql()) {
+ fprintf(stderr, "Unable to load MySQL configuration.\n");
+ exit(0);
+ }
+
+ //check module configuration
+ char **modulelist = get_all_fieldnames("modules");
+ if(!modulelist || !modulelist[0]) {
+ fprintf(stderr, "Unable to load Module configuration.\n");
+ exit(0);
+ }
+ free(modulelist);
+
+ #if HAVE_THREADS
+ THREAD_MUTEX_INIT(log_sync);
+ THREAD_MUTEX_INIT(cache_sync);
+ THREAD_MUTEX_INIT(whohandler_sync);
+ THREAD_MUTEX_INIT(whohandler_mass_sync);
+ #endif
+
+ //connect to mysql and check if it's the frst bot startup
+ init_mysql();
+ check_firstrun();
+
+ //deamonize if wanted
+ if(process_state.run_as_daemon)
+ main_daemonize();
+
+ //set signal handlers
+ signal(SIGABRT, sighandler);
+ signal(SIGFPE, sighandler);
+ signal(SIGILL, sighandler);
+ signal(SIGINT, sighandler);
+ signal(SIGSEGV, sighandler);
+ signal(SIGTERM, sighandler);
+
+ //set start time and initialize other code parts
+ process_state.running = 1;
+ process_state.start_time = time(0);
+ initialize_subsystems();
+
+ //start timers
+ timeq_add(CLEAR_CACHE_INTERVAL, 0, clear_cache, NULL);
+ timeq_add(90, 0, main_checkauths, NULL);
+
+ //start worker threads
+ main_start_threads(); //BLOCKING
+
+ //shutdown sequence...
+ shutdown_subsystems();
+ if(process_state.restart)
+ main_restart_process(); //terminates the current process on success
+
+ //eop (end of program :P)
+ //trust me, thats the end!
+ exit(0);