- #ifdef HAVE_THREADS
- THREAD_MUTEX_INIT(cache_sync);
- THREAD_MUTEX_INIT(whohandler_sync);
- THREAD_MUTEX_INIT(whohandler_mass_sync);
- #endif
-
- queue_init();
- init_sockets();
- init_timeq();
- init_lang();
- ssl_init();
- init_parser();
- init_UserNode();
- init_ChanNode();
- init_ModeNode();
- init_bind();
- init_modcmd();
- init_handleinfohandler();
- init_tools();
- register_commands();
- init_bots();
- init_DBHelper();
- qserver_init();
-
- load_languages();
- int update_minutes = get_int_field("statistics.frequency");
- if(!update_minutes) update_minutes = 2;
- timeq_add(update_minutes * 60 + 10, main_statistics, NULL);
-
- timeq_add(90, main_checkauths, NULL);
-
- int worker_threads = get_int_field("General.worker_threads");
- if(!worker_threads) worker_threads = 1;
- running = 1;
- #ifdef HAVE_THREADS
- int tid_id = 0;
- current_threads = calloc(worker_threads, sizeof(*current_threads));
- for(tid_id = 0; tid_id < worker_threads; tid_id++) {
- running_threads++;
- pthread_create(¤t_threads[tid_id], NULL, thread_main, NULL);
- }
- int usleep_delay = 1000000 / TICKS_PER_SECOND;
- while(running) {
- timeq_tick();
- loop_bots();
- qserver_loop();
- queue_loop();
- mysql_free();
- usleep(usleep_delay);
- }
- for(tid_id = 0; tid_id < worker_threads; tid_id++) {
- pthread_join(current_threads[tid_id], NULL);
- }
- running_threads = 0;
- #else
- time_t socket_wait;
- while(running) {
- socket_wait = time(0) + SOCKET_SELECT_TIME;
- do {
- if(!socket_loop(SOCKET_SELECT_TIME)) {
- putlog(LOGLEVEL_ERROR, "No more active Bots... shutting down.");
- cleanup();
- exit(0);
- }
- } while(time(0) < socket_wait);
- timeq_tick();
- loop_bots();
- clearTempUsers();
- destroyEvents();
- qserver_loop();
- queue_loop();
- mysql_free();
- }
- #endif
- cleanup();
- if(hard_restart) {
- restart_process();
- }
- goto main;
-}
-
-void restart_process() {
- /* Append a NULL to the end of argv[]. */
- char **restart_argv = (char **)alloca((process_argc + 1) * sizeof(char *));
- memcpy(restart_argv, process_argv, process_argc * sizeof(char *));
- restart_argv[process_argc] = NULL;
- #ifdef WIN32
- execv(process_argv[0], (const char * const*)restart_argv);
- #else
- execv(process_argv[0], restart_argv);
- #endif
-}
-
-int stricmp (const char *s1, const char *s2)
-{
- if (s1 == NULL) return s2 == NULL ? 0 : -(*s2);
- if (s2 == NULL) return *s1;
- char c1, c2;
- while ((c1 = tolower (*s1)) == (c2 = tolower (*s2)))
- {
- if (*s1 == '\0') break;
- ++s1; ++s2;
- }
- return c1 - c2;