diff options
| author | B. Watson <urchlay@slackware.uk> | 2026-03-08 04:03:03 -0400 |
|---|---|---|
| committer | B. Watson <urchlay@slackware.uk> | 2026-03-08 04:03:03 -0400 |
| commit | 1815d26c7042d3d592e624d8edf73805c7b3bc6d (patch) | |
| tree | 29bb6e9f7d15714ad799ca290d5e03fa9846af09 | |
| parent | ff02ca89a0b0bae712c6bbc1de6bc50be13010a8 (diff) | |
| download | fujinet-chat-1815d26c7042d3d592e624d8edf73805c7b3bc6d.tar.gz | |
Send PMs to the correct window, more protocol stuff, add start+esc hotkey.
| -rw-r--r-- | src/cmd.c | 38 | ||||
| -rw-r--r-- | src/irc.c | 81 | ||||
| -rw-r--r-- | src/screen.c | 3 |
3 files changed, 78 insertions, 44 deletions
@@ -15,6 +15,7 @@ static char *target; static void do_color(void); static void do_info(void); static void do_j(void); +static void do_j1(void); static void do_list(void); static void do_me(void); static void do_msg(void); @@ -23,6 +24,7 @@ static void do_ping(void); static void do_query(void); static void do_quit(void); static void do_quote(void); +static void do_topic(void); static void do_ver(void); typedef struct { @@ -38,7 +40,9 @@ cmd_t command_defs[] = { { "COLOR", do_color, 1 }, { "INFO", do_info, 0 }, { "J", do_j, 1 }, + { "J1", do_j1, 1 }, { "JOIN", do_j, 1 }, + { "JOIN1", do_j1, 1 }, { "LIST", do_list, 1 }, { "M", do_msg, 1 }, { "ME", do_me, 1 }, @@ -49,6 +53,7 @@ cmd_t command_defs[] = { { "QUERY", do_query, 1 }, { "QUIT", do_quit, 0 }, { "QUOTE", do_quote, 1 }, + { "TOPIC", do_topic, 0 }, { "VER", do_ver, 0 }, { "VERSION", do_ver, 0 }, { 0, 0 } @@ -130,12 +135,17 @@ static char *nextarg(char *arg) { return 0; } -static void do_j(void) { - /* TODO: add to channel list, once we have one */ +static void do_j1(void) { txbuf_set_str2("JOIN ", arg1); txbuf_send(); } +static void do_j(void) { + if(!scr_getbyname(arg1)) + scr_create(arg1, 1); + do_j1(); +} + static void do_quit(void) { txbuf_set_str("QUIT"); if(arg1) @@ -162,6 +172,25 @@ static void do_part(void) { txbuf_send(); } +static void do_topic(void) { + if(arg1[0] == '#') { + target = arg1; + arg2 = nextarg(arg1); + } else { + arg2 = arg1; + } + + if(!target) { + err_target_req(); + return; + } + + txbuf_set_str2("TOPIC ", target); + if(arg2) + txbuf_append_str2(" :", arg2); + txbuf_send(); +} + static void do_server_info(void) { txbuf_send_str("INFO"); } @@ -316,7 +345,10 @@ static void cmd_slash(void) { void cmd_command(char *cmd) { command = cmd; - target = scr_get_cur_name(); + if(scr_current > 1) + target = scr_get_cur_name(); + else + target = 0; if(cmd[0] == '/' && cmd[1] && cmd[1] != '/') cmd_slash(); @@ -95,16 +95,14 @@ static void do_privmsg(void) { static void do_join(void) { if(streq_i(usernick, msg_src)) { - /* if our nick is the source, create the screen if needed. if a - screen can't be created, no harm done. */ - if(scr_active == SCR_SERVER) - scr_create(msg_dest, 1); + scr_print_active("You have "); } else { scr_print_active(msg_src); - scr_print_active(" has joined "); - scr_print_active(msg_dest); - scr_eol_active(); + scr_print_active(" has "); } + scr_print_active("joined "); + scr_print_active(msg_dest); + scr_eol_active(); } static void do_nick(void) { @@ -158,11 +156,14 @@ static void do_kick(void) { static void do_mode(void) { int i; - scr_print_active(msg_src); + if(msg_src) + scr_print_active(msg_src); + else + scr_print_active("Server"); scr_print_active(" sets mode: "); for(i = 0; i < msg_argcount; i++) { - scr_print_active(" "); scr_print_active(msg_args[i]); + scr_print_active(" "); } if(msg_text) scr_print_active(msg_text); scr_eol_active(); @@ -227,16 +228,6 @@ static void do_numeric(void) { break; /* - case RPL_NAMREPLY: - "Users in ##channel", msg_text - - case RPL_TOPIC: - case RPL_NOTOPIC: - set the topic for the screen, if there is one - - case RPL_TOPICWHOTIME: - "Topic was set by <nick>", don't try to parse the UNIX timestamp. - case RPL_WHOISCERTFP: case RPL_WHOISREGNICK: case RPL_WHOISUSER: @@ -252,16 +243,8 @@ static void do_numeric(void) { case RPL_WHOISSECURE: case RPL_WHOWASUSER: These always go to the server window. - - case RPL_ENDOFWHOIS: - case RPL_ENDOFWHOWAS: - Don't print. */ - case RPL_ENDOFNAMES: - /* don't print, just noise */ - break; - case ERR_NICKNAMEINUSE: do_catchall(0); if(!regged) { @@ -276,20 +259,29 @@ static void do_numeric(void) { case ERR_NOMOTD: break; + case RPL_NAMREPLY: + scr_print_active(msg_args[2]); + scr_print_active(" users: "); + scr_print_active(msg_text); + scr_print_active("\n"); + break; + + case RPL_ENDOFNAMES: + /* don't print, just noise */ + break; + case RPL_TOPIC: - s = scr_getbyname(msg_args[1]); - scr_print(s, "Topic for "); - scr_print(s, msg_args[1]); - scr_print(s, ": "); - scr_print(s, msg_text); - scr_putc(s, '\n'); + scr_print_active("Topic for "); + scr_print_active(msg_args[1]); + scr_print_active(": "); + scr_print_active(msg_text); + scr_print_active("\n"); break; case RPL_TOPICWHOTIME: - s = scr_getbyname(msg_args[1]); - scr_print(s, "Topic set by: "); - scr_print(s, msg_args[1]); - scr_putc(s, '\n'); + scr_print_active("Topic set by "); + scr_print_active(msg_args[2]); + scr_print_active("\n"); break; default: @@ -306,12 +298,19 @@ static void invalid_msg(char type) { void select_screen(void) { char s; - if(!msg_src || !msg_dest) { + if(!msg_dest) { s = SCR_SERVER; - } else { + } else if(*msg_dest == '#') { s = scr_getbyname(msg_dest); - if(!s && msg_dest[0] != '#') - s = SCR_PRIV; + if(!s) s = SCR_SERVER; + } else { + s = scr_getbyname(msg_src); + if(!s) { + if(streq_i(msg_cmd, "PRIVMSG")) /* or maybe NOTICE? */ + s = SCR_PRIV; + else + s = SCR_SERVER; + } } scr_activate(s); } diff --git a/src/screen.c b/src/screen.c index f442e66..617ea2f 100644 --- a/src/screen.c +++ b/src/screen.c @@ -61,6 +61,7 @@ void scr_init(void) { scr_display(0); } +/* TODO: don't create screen if it already exists! */ char scr_create(const char *name, char display) { int i; @@ -164,6 +165,8 @@ void scr_refresh(void) { char scr_getbyname(const char *name) { char i; + if(!name) return 0; + for(i = 2; i < MAX_SCREENS; i++) { if(strcasecmp(name, scr_names[i]) == 0) return i; |
