Subversion Repositories Okuu

Rev

Rev 12 | Rev 14 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 12 Rev 13
Line 1... Line 1...
1
/* $Id: bot.c 12 2024-09-11 16:08:33Z nishi $ */
1
/* $Id: bot.c 13 2024-09-12 15:29:22Z nishi $ */
2
 
2
 
3
#include "ok_bot.h"
3
#include "ok_bot.h"
4
 
4
 
5
#include "ok_util.h"
5
#include "ok_util.h"
6
#include "ok_news.h"
6
#include "ok_news.h"
Line 14... Line 14...
14
#include <unistd.h>
14
#include <unistd.h>
15
#include <signal.h>
15
#include <signal.h>
16
#include <stdbool.h>
16
#include <stdbool.h>
17
#include <dirent.h>
17
#include <dirent.h>
18
#include <poll.h>
18
#include <poll.h>
-
 
19
#include <sys/wait.h>
19
 
20
 
20
#include <sys/socket.h>
21
#include <sys/socket.h>
21
#include <netinet/tcp.h>
22
#include <netinet/tcp.h>
22
#include <arpa/inet.h>
23
#include <arpa/inet.h>
23
 
24
 
Line 40... Line 41...
40
extern int ircport;
41
extern int ircport;
41
 
42
 
42
int ok_sock;
43
int ok_sock;
43
struct sockaddr_in ok_addr;
44
struct sockaddr_in ok_addr;
44
 
45
 
45
void ok_close(int sock) { shutdown(sock, SHUT_RDWR);close(sock); }
46
void ok_close(int sock) {
-
 
47
	while(close(sock) == 0);
-
 
48
}
46
 
49
 
47
void ok_bot_kill(int sig) {
50
void ok_bot_kill(int sig) {
48
	fprintf(stderr, "Shutdown\n");
51
	fprintf(stderr, "Shutdown\n");
49
	ircfw_socket_send_cmd(ok_sock, NULL, "QUIT :Shutdown (Signal)");
52
	ircfw_socket_send_cmd(ok_sock, NULL, "QUIT :Shutdown (Signal)");
50
	exit(1);
53
	exit(1);
Line 239... Line 242...
239
							sprintf(construct, "NOTICE %s :\x01VERSION Okuu %s / IRC Frameworks %s: http://nishi.boats/okuu\x01", nick, OKUU_VERSION, IRCFW_VERSION);
242
							sprintf(construct, "NOTICE %s :\x01VERSION Okuu %s / IRC Frameworks %s: http://nishi.boats/okuu\x01", nick, OKUU_VERSION, IRCFW_VERSION);
240
							ircfw_socket_send_cmd(ok_sock, NULL, construct);
243
							ircfw_socket_send_cmd(ok_sock, NULL, construct);
241
						}
244
						}
242
					} else if(sentin[0] == '#') {
245
					} else if(sentin[0] == '#') {
243
						/* This was sent in channel */
246
						/* This was sent in channel */
-
 
247
						pid_t pid = fork();
-
 
248
						int code;
-
 
249
						if(pid == 0){
244
						if(ok_news_write(nick, msg) != 0) {
250
							_exit(ok_news_write(nick, msg));
-
 
251
						}else{
-
 
252
							int status;
-
 
253
							waitpid(pid, &status, 0);
-
 
254
							code = WEXITSTATUS(status);
-
 
255
						}
-
 
256
						if(code != 0) {
245
							sprintf(construct, "PRIVMSG %s :Could not send the message to the USENET", sentin);
257
							sprintf(construct, "PRIVMSG %s :Could not send the message to the USENET", sentin);
246
							ircfw_socket_send_cmd(ok_sock, NULL, construct);
258
							ircfw_socket_send_cmd(ok_sock, NULL, construct);
247
						}
259
						}
248
					}
260
					}
249
 
261