0.6.1 final release; pacman game added; irc improved (IPv6 support); websrv fixed...
[ZeXOS.git] / apps / irc / main.c
blob0686817d3d5258ae84c4ea7703325f293784529c
1 /*
2 * ZeX/OS
3 * Copyright (C) 2008 Tomas 'ZeXx86' Jedrzejek (zexx86@gmail.com)
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #include <stdio.h>
21 #include <string.h>
22 #include <stdlib.h>
23 #include "commands.h"
24 #include "config.h"
25 #include "proto.h"
26 #include "net.h"
28 CONFIG config;
30 extern char *buf;
32 int pick_nick ()
34 char nick[64];
36 printf ("Pick a nick: ");
38 scanf ("%s", nick);
40 printf ("\nPlease wait ..\n");
42 config.nick = strdup (nick);
44 return 1;
47 int init (char *address, int port, int flags)
49 pick_nick ();
51 if (!init_net (address, port, flags))
52 return 0;
54 config.server = address;
55 config.server_len = strlen (address);
57 if (!init_proto ())
58 return 0;
60 if (!commands_init ())
61 return 0;
63 return 1;
66 int loop ()
68 while (1) {
69 if (!net_loop ())
70 return 0;
72 if (!proto_parser ())
73 return 0;
75 if (!commands_get ())
76 return 0;
78 #ifndef LINUX
79 schedule ();
80 #endif
83 return 1;
86 int quit ()
88 net_close ();
90 printf ("Bye !\n");
92 return 1;
95 void syntax ()
97 printf ("irc: <address> <port> [-6]\nGNU/GPL3 - Coded by ZeXx86\n");
100 int main (int argc, char **argv)
102 if (argc == 1) {
103 syntax ();
104 return 0;
107 int port = 0;
108 int proto = 0;
110 if (argc > 2) {
111 port = atoi (argv[2]);
113 if (!strncmp (argv[argc-1], "-6", 2)) {
114 proto |= NET_IPV6;
115 printf ("> IPv6 mode\n");
119 if (!port)
120 port = 6667; /* set default port, when user not specify any */
122 printf ("-= IRC Client =-\n");
124 if (!init (argv[1], port, proto)) {
125 printf ("ERROR -> init () failed\n");
126 return -1;
129 loop ();
131 quit ();
133 /* free buffers */
134 free (buf);
135 free (config.nick);
136 free (config.server);
138 if (config.channel_len)
139 free (config.channel);
141 return 0;