aboutsummaryrefslogtreecommitdiff
path: root/src/irc.c
diff options
context:
space:
mode:
authorB. Watson <urchlay@slackware.uk>2026-03-12 00:07:09 -0400
committerB. Watson <urchlay@slackware.uk>2026-03-12 00:07:09 -0400
commit1d7cac2297c8c52777ee47b52571e8277b372c85 (patch)
tree44de28956dceb95235fce2669cc192acfd6627cb /src/irc.c
parentd9a00af38048c71364952326c3039834bcfb47d0 (diff)
downloadfujinet-chat-1d7cac2297c8c52777ee47b52571e8277b372c85.tar.gz
refactoring...
Diffstat (limited to 'src/irc.c')
-rw-r--r--src/irc.c105
1 files changed, 51 insertions, 54 deletions
diff --git a/src/irc.c b/src/irc.c
index faf5f91..27fce4c 100644
--- a/src/irc.c
+++ b/src/irc.c
@@ -703,6 +703,48 @@ static void hunt_screen(signed char dir) {
scr_display(s);
}
+static char *get_cur_chan(void) {
+ if(scr_current == SCR_SERVER && last_chan[0])
+ return last_chan;
+ else if (scr_current > 2 && scr_names[scr_current][0] == '#')
+ return scr_names[scr_current];
+ else
+ return 0;
+}
+
+static char *get_cur_nick(void) {
+ if(scr_current == SCR_PRIV && last_pm_nick[0])
+ return last_pm_nick;
+ else if (scr_current > 2 && scr_names[scr_current][0] != '#')
+ return scr_names[scr_current];
+ else
+ return 0;
+}
+
+static void send2_with_space(char *s1, char *s2) {
+ txbuf_set_str3(s1, " ", s2);
+ txbuf_send();
+}
+
+static void send_cur_nick_cmd(char *cmd) {
+ char *nick;
+
+ if(!(nick = get_cur_nick()))
+ return;
+
+ send2_with_space(cmd, nick);
+}
+
+static void send_cur_chan_cmd(char *cmd) {
+ char *chan;
+
+ if(!(chan = get_cur_chan()))
+ return;
+
+ send2_with_space(cmd, chan);
+}
+
+/*
static char cur_is_chan(void) {
return (scr_current > 2 && scr_names[scr_current][0] == '#');
}
@@ -710,6 +752,7 @@ static char cur_is_chan(void) {
static char cur_is_query(void) {
return (scr_current > 2 && !cur_is_chan());
}
+*/
void switch_to_active() {
char i;
@@ -744,59 +787,13 @@ void join_last_invite(void) {
// TODO!
}
-/* TODO: factor out stuff into scr_is_channel(), scr_is_query() */
-void ui_whois_or_ping(char is_ping) {
+void ui_ping(void) {
char *nick;
- if(scr_current == SCR_SERVER)
+ if(!(nick = get_cur_nick()))
return;
- if(cur_is_chan())
- return;
-
- if(scr_current == SCR_PRIV)
- nick = last_pm_nick;
- else
- nick = scr_names[scr_current];
-
- if(!nick[0]) return;
-
- if(is_ping) {
- cmd_ctcp_ping(nick);
- } else {
- txbuf_set_str2("WHOIS ", nick);
- txbuf_send();
- }
-}
-
-void ui_topic(void) {
- if(!cur_is_chan())
- return;
- txbuf_set_str2("TOPIC ", scr_names[scr_current]);
- txbuf_send();
-}
-
-void ui_part(void) {
- if(!cur_is_chan())
- return;
- txbuf_set_str2("PART ", scr_names[scr_current]);
- txbuf_send();
-}
-
-void ui_names(void) {
- char *chan;
-
- if(scr_current == SCR_SERVER && *last_chan)
- chan = last_chan;
- else if(cur_is_chan())
- chan = scr_names[scr_current];
- else
- return;
-
- if(!chan[0]) return;
-
- txbuf_set_str2("NAMES ", scr_names[scr_current]);
- txbuf_send();
+ cmd_ctcp_ping(nick);
}
static void start_keystroke(void) {
@@ -821,7 +818,7 @@ static void start_keystroke(void) {
scrollback();
return;
case 0x24: /* ^X */
- ui_part();
+ send_cur_chan_cmd("PART");
/* fall thru */
case CH_ESC:
scr_prev = SCR_PRIV;
@@ -863,16 +860,16 @@ static void start_keystroke(void) {
join_last_invite();
return;
case 'w':
- ui_whois_or_ping(0);
+ send_cur_nick_cmd("WHOIS");
return;
case 'n':
- ui_names();
+ send_cur_chan_cmd("NAMES");
return;
case 'p':
- ui_whois_or_ping(1);
+ ui_ping();
return;
case 't':
- ui_topic();
+ send_cur_chan_cmd("TOPIC");
break;
case 's':
edbox_hide();