/* FujiNetChat, an IRC client. Based on NetCat and the old FujiChat. */ #define SELF "FujiNetChat" #define VERSION "0.0" #define BANNER SELF " v" VERSION " (B. Watson)\n" #define DEF_URL "N:TCP://irc.libera.chat:6667" #define DEF_NICK "FNChatTest" #define DEF_CHANNEL "##atari" #include #include #include #include #include #include #include // for kbhit() and cgetc() // #include "conio.h" // our local one. #include "nio.h" #include "irc.h" #include "screen.h" #include "edbox.h" char url[256] = DEF_URL; // URL char usernick[32] = DEF_NICK; char tmp[8]; // temporary # to string unsigned char err; // error code of last operation. unsigned char trip=0; // if trip=1, fujinet is asking us for attention. bool old_enabled=false; // were interrupts enabled for old vector void* old_vprced; // old PROCEED vector, restored on exit. unsigned short bw=0; // # of bytes waiting. unsigned char rx_buf[MAX_IRC_MSG_LEN]; // RX buffer. unsigned char tx_buf[MAX_IRC_MSG_LEN]; // TX buffer. unsigned int txbuflen; // TX buffer length char channel[32] = DEF_CHANNEL; /* TODO: user modes (default +iw), fg/bg color... */ extern void ih(); // defined in intr.s void get_config(void) { scr_print_current(BANNER); while(1) { scr_print_current("URL?\n"); edbox_readline(url, sizeof(url)); scr_print_current("Nick?\n"); edbox_readline(usernick, sizeof(usernick)); scr_print_current("Channel?\n"); edbox_readline(channel, sizeof(channel)); scr_print_current("Are these settings OK [Y/n]?\n"); if(tolower(cgetc()) != 'n') break; } } void txbuf_init(void) { txbuflen = tx_buf[0] = 0; } void txbuf_append_str(const char *str) { while(*str) { tx_buf[txbuflen++] = *str++; } } void txbuf_set_str(const char *str) { txbuf_init(); txbuf_append_str(str); } void txbuf_send(void) { if(!txbuflen) return; nwrite(url, tx_buf, txbuflen); txbuf_init(); } void txbuf_send_str(const char *str) { txbuf_init(); txbuf_append_str(str); txbuf_send(); } int fn_connect(void) { scr_print(SCR_SERVER, "Connecting to: "); scr_print(SCR_SERVER, url); scr_print(SCR_SERVER, "\n"); err = nopen(url, FNET_TRANSLATION); if(err != SUCCESS) { scr_print(SCR_SERVER, "Connection failed: "); print_errnum(); return 0; } // Open successful, set up interrupt old_vprced = OS.vprced; // save the old interrupt vector old_enabled = PIA.pactl & 1; // keep track of old interrupt state PIA.pactl &= (~1); // Turn off interrupts before changing vector OS.vprced = ih; // Set PROCEED interrupt vector to our interrupt handler. PIA.pactl |= 1; // Indicate to PIA we are ready for PROCEED interrupt. return 1; } void fn_disconnect(void) { // Restore old PROCEED interrupt. PIA.pactl &= ~1; // disable interrupts OS.vprced=old_vprced; PIA.pactl |= old_enabled; } int main(void) { OS.shflok = 0; // turn off shift-lock. OS.soundr = 0; // Turn off SIO beeping sound scr_init(); while(1) { get_config(); edbox_callback = cmd_execute; if(fn_connect()) { irc_register(); irc_loop(); fn_disconnect(); } } OS.soundr = 3; // Restore SIO beeping sound return 0; }