Subversion Repositories IRCServ

Rev

Rev 5 | Rev 8 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

/* $Id: main.c 7 2024-08-25 20:49:55Z nishi $ */

#include "is_version.h"
#include "is_util.h"
#include "is_log.h"
#include "is_socket.h"
#include "is_ircd.h"

#include "../config.h"

#ifdef USE_NICKSERV
#include "is_nickserv.h"
#endif

#ifdef USE_CHANSERV
#include "is_chanserv.h"
#endif

#ifdef USE_MEMOSERV
#include "is_memoserv.h"
#endif

#ifdef USE_OPERSERV
#include "is_operserv.h"
#endif

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <stdbool.h>
#include <string.h>

struct is_config config;

int main(int argc, char** argv) {
        bool daemon = true;
        int i;
        for(i = 1; i < argc; i++) {
                if(strcmp(argv[i], "-D") == 0) {
                        daemon = false;
                        break;
                }
        }

        char* str;
        int st;

        str = is_strcat("IRCServ version ", is_get_version());
        is_log(str);
        free(str);

        is_log("Initializing the socket");
        st = is_socket_init();
        if(st != 0) goto cleanup;

        is_log("Initializing the connection");
        st = is_ircd_connect();
        if(st != 0) goto cleanup;

        is_log("Initializing the services");

#ifdef USE_NICKSERV
        st = is_nickserv_init();
        if(st != 0) goto cleanup;
#endif
#ifdef USE_CHANSERV
        st = is_chanserv_init();
        if(st != 0) goto cleanup;
#endif
#ifdef USE_MEMOSERV
        st = is_memoserv_init();
        if(st != 0) goto cleanup;
#endif
#ifdef USE_OPERSERV
        st = is_operserv_init();
        if(st != 0) goto cleanup;
#endif

        pid_t pid = 0;
        if(daemon) {
                pid = fork();
        }
        if(pid == 0) {
                /* Main */
                is_log("Initialization successful, hello from daemon");

                is_socket_close();
                return 0;
        } else {
                return 0;
        }
cleanup:
        fprintf(stderr, "IRCServ exiting with error, check the log.\n");
        return st;
}