Subversion Repositories IRCServ

Rev

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

Rev Author Line No. Line
6 nishi 1
/* $Id: bahamut.c 7 2024-08-25 20:49:55Z nishi $ */
2
 
3
#include "../is_ircd.h"
7 nishi 4
 
5
#include "../is_log.h"
6
#include "../is_util.h"
7
 
8
#include "../../config.h"
9
 
10
#include <stdlib.h>
11
#include <time.h>
12
#include <stdint.h>
13
#include <stdio.h>
14
#include <string.h>
15
 
16
extern struct is_config config;
17
extern struct is_message message;
18
 
19
int is_ircd_connect(void) {
20
	char* cmd;
21
	char* tmp;
22
	char buffer[512];
23
 
24
	cmd = is_strcat3("PASS ", IRC_SECRET, " :TS");
25
	config.send_cmd(NULL, cmd);
26
	free(cmd);
27
 
28
	config.send_cmd(NULL, "CAPAB TS3 SSJOIN NICKIP NOQUIT TSMODE UNCONNECT");
29
 
30
	tmp = is_strcat3("SERVER ", IRC_SERVICE, " 1 :");
31
	cmd = is_strcat(tmp, IRC_SERVICE_DESCRIPTION);
32
	free(tmp);
33
	config.send_cmd(NULL, cmd);
34
	free(cmd);
35
 
36
	sprintf(buffer, "SVINFO 3 3 0 :%lld", (long long)time(NULL));
37
	config.send_cmd(NULL, buffer);
38
 
39
	while(1) {
40
		int st = config.read_cmd();
41
		if(st != 0) return st;
42
		if(strcmp(message.command, "PING") == 0) {
43
			is_log("Connection successful");
44
			return 0;
45
		} else if(strcmp(message.command, "ERROR") == 0) {
46
			if(message.params == NULL) {
47
				is_log("Unknown error");
48
			} else {
49
				is_log(message.params[0] == NULL ? "Unknown error" : message.params[0]);
50
			}
51
			return 1;
52
		}
53
	}
54
	return 0;
55
}