Subversion Repositories IRCServ

Rev

Rev 6 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

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

#include "../is_ircd.h"

#include "../is_log.h"
#include "../is_util.h"

#include "../../config.h"

#include <stdlib.h>
#include <time.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>

extern struct is_config config;
extern struct is_message message;

int is_ircd_connect(void) {
        char* cmd;
        char* tmp;
        char buffer[512];

        cmd = is_strcat3("PASS ", IRC_SECRET, " :TS");
        config.send_cmd(NULL, cmd);
        free(cmd);

        config.send_cmd(NULL, "CAPAB TS3 SSJOIN NICKIP NOQUIT TSMODE UNCONNECT");

        tmp = is_strcat3("SERVER ", IRC_SERVICE, " 1 :");
        cmd = is_strcat(tmp, IRC_SERVICE_DESCRIPTION);
        free(tmp);
        config.send_cmd(NULL, cmd);
        free(cmd);

        sprintf(buffer, "SVINFO 3 3 0 :%lld", (long long)time(NULL));
        config.send_cmd(NULL, buffer);

        while(1) {
                int st = config.read_cmd();
                if(st != 0) return st;
                if(strcmp(message.command, "PING") == 0) {
                        is_log("Connection successful");
                        return 0;
                } else if(strcmp(message.command, "ERROR") == 0) {
                        if(message.params == NULL) {
                                is_log("Unknown error");
                        } else {
                                is_log(message.params[0] == NULL ? "Unknown error" : message.params[0]);
                        }
                        return 1;
                }
        }
        return 0;
}