summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/gui/curses/gui-display.c25
-rw-r--r--src/irc/Makefile.am1
-rw-r--r--src/irc/irc-channel.c5
-rw-r--r--src/irc/irc-commands.c6
-rw-r--r--src/irc/irc-recv.c284
-rw-r--r--src/irc/irc-send.c11
-rw-r--r--src/irc/irc.h23
7 files changed, 276 insertions, 79 deletions
diff --git a/src/gui/curses/gui-display.c b/src/gui/curses/gui-display.c
index 01eb182a3..883121251 100644
--- a/src/gui/curses/gui-display.c
+++ b/src/gui/curses/gui-display.c
@@ -808,6 +808,7 @@ gui_redraw_window_nick (t_gui_window *window)
if (has_colors ())
gui_window_set_color (window->win_nick, COLOR_WIN_NICK);
+ snprintf (format_empty, 32, "%%-%ds", window->win_nick_width);
for (i = 0; i < window->win_nick_height; i++)
{
mvwprintw (window->win_nick, i, 0, format_empty, " ");
@@ -825,6 +826,7 @@ gui_draw_window_status (t_gui_window *window)
{
t_gui_window *ptr_win;
char format_more[32];
+ int i;
/* TODO: manage splitted windows! */
if (window != gui_current_window)
@@ -913,7 +915,28 @@ gui_draw_window_status (t_gui_window *window)
gui_window_set_color (window->win_status,
COLOR_WIN_STATUS);
}
- wprintw (window->win_status, "%s ", CHANNEL(ptr_win)->name);
+ wprintw (window->win_status, "%s", CHANNEL(ptr_win)->name);
+ if (gui_current_window == CHANNEL(ptr_win)->window)
+ {
+ /* display channel modes */
+ wprintw (window->win_status, "(+");
+ i = 0;
+ while (CHANNEL(ptr_win)->modes[i])
+ {
+ if (CHANNEL(ptr_win)->modes[i] != ' ')
+ wprintw (window->win_status, "%c",
+ CHANNEL(ptr_win)->modes[i]);
+ i++;
+ }
+ if (CHANNEL(ptr_win)->modes[CHANNEL_MODE_KEY] != ' ')
+ wprintw (window->win_status, ",%s",
+ CHANNEL(ptr_win)->key);
+ if (CHANNEL(ptr_win)->modes[CHANNEL_MODE_LIMIT] != ' ')
+ wprintw (window->win_status, ",%d",
+ CHANNEL(ptr_win)->limit);
+ wprintw (window->win_status, ")");
+ }
+ wprintw (window->win_status, " ");
}
if (!SERVER(ptr_win))
{
diff --git a/src/irc/Makefile.am b/src/irc/Makefile.am
index 8bdc84cd8..5a0d5a5a7 100644
--- a/src/irc/Makefile.am
+++ b/src/irc/Makefile.am
@@ -26,4 +26,5 @@ lib_weechat_irc_a_SOURCES = irc.h \
irc-server.c \
irc-channel.c \
irc-nick.c \
+ irc-dcc.c \
irc-display.c
diff --git a/src/irc/irc-channel.c b/src/irc/irc-channel.c
index 06dcd338a..7095d2053 100644
--- a/src/irc/irc-channel.c
+++ b/src/irc/irc-channel.c
@@ -32,6 +32,7 @@
t_irc_channel *current_channel = NULL;
+char *channel_modes = "iklmnst";
/*
@@ -55,6 +56,10 @@ channel_new (t_irc_server *server, int channel_type, char *channel_name,
new_channel->type = channel_type;
new_channel->name = strdup (channel_name);
new_channel->topic = NULL;
+ memset (new_channel->modes, ' ', sizeof (new_channel->modes));
+ new_channel->modes[sizeof (new_channel->modes) - 1] = '\0';
+ new_channel->limit = 0;
+ new_channel->key = NULL;
new_channel->nicks = NULL;
new_channel->last_nick = NULL;
diff --git a/src/irc/irc-commands.c b/src/irc/irc-commands.c
index d3bc5bd8c..7acb23d70 100644
--- a/src/irc/irc-commands.c
+++ b/src/irc/irc-commands.c
@@ -44,6 +44,12 @@ t_irc_command irc_commands[] =
N_("nickname type"),
N_("nickname: user to send ctcp to\ntype: \"action\" or \"version\""),
2, MAX_ARGS, 1, NULL, irc_cmd_send_ctcp, NULL },
+ { "dcc", N_("starts DCC (file or chat)"),
+ N_("action nickname [file]"),
+ N_("action: 'send' (file) or 'chat'\n"
+ "nickname: nickname to send file or chat\n"
+ "file: filename (on local host)"),
+ 2, 3, 1, NULL, irc_cmd_send_dcc, NULL },
{ "deop", N_("removes channel operator status from nickname(s)"),
N_("nickname [nickname]"), "",
1, 1, 1, irc_cmd_send_deop, NULL, NULL },
diff --git a/src/irc/irc-recv.c b/src/irc/irc-recv.c
index 31a3cf2ed..189d63cc7 100644
--- a/src/irc/irc-recv.c
+++ b/src/irc/irc-recv.c
@@ -317,9 +317,6 @@ irc_cmd_recv_mode (t_irc_server *server, char *host, char *arguments)
pos_parm++;
while (pos_parm[0] == ' ')
pos_parm++;
- pos2 = strchr (pos_parm, ' ');
- if (pos2)
- pos2[0] = '\0';
}
set_flag = '+';
@@ -347,7 +344,6 @@ irc_cmd_recv_mode (t_irc_server *server, char *host, char *arguments)
_("sets ban on") :
_("removes ban on"),
pos_parm);
- /* TODO: change & redraw channel modes */
break;
case 'i':
irc_display_mode (ptr_channel->window,
@@ -356,16 +352,68 @@ irc_cmd_recv_mode (t_irc_server *server, char *host, char *arguments)
_("sets invite-only channel flag") :
_("removes invite-only channel flag"),
NULL);
- /* TODO: change & redraw channel modes */
+ SET_CHANNEL_MODE(ptr_channel, (set_flag == '+'),
+ CHANNEL_MODE_INVITE);
+ break;
+ case 'k':
+ pos2 = NULL;
+ if (pos_parm)
+ {
+ pos2 = strchr (pos_parm, ' ');
+ if (pos2)
+ pos2[0] = '\0';
+ }
+ irc_display_mode (ptr_channel->window,
+ arguments, set_flag, "k", host,
+ (set_flag == '+') ?
+ _("sets channel key to") :
+ _("removes channel key"),
+ (set_flag == '+') ?
+ ((pos_parm) ? pos_parm : NULL) :
+ NULL);
+ SET_CHANNEL_MODE(ptr_channel, (set_flag == '+'),
+ CHANNEL_MODE_KEY);
+ if (ptr_channel->key)
+ free (ptr_channel->key);
+ ptr_channel->key = strdup (pos_parm);
+
+ /* look for next parameter */
+ if (pos_parm && pos2)
+ {
+ pos2++;
+ while (pos2[0] == ' ')
+ pos2++;
+ pos_parm = pos2;
+ }
break;
case 'l':
+ pos2 = NULL;
+ if (pos_parm)
+ {
+ pos2 = strchr (pos_parm, ' ');
+ if (pos2)
+ pos2[0] = '\0';
+ }
irc_display_mode (ptr_channel->window,
arguments, set_flag, "l", host,
(set_flag == '+') ?
_("sets the user limit to") :
_("removes user limit"),
- (set_flag == '+') ? pos_parm : NULL);
- /* TODO: change & redraw channel modes */
+ (set_flag == '+') ?
+ ((pos_parm) ? pos_parm : NULL) :
+ NULL);
+ SET_CHANNEL_MODE(ptr_channel, (set_flag == '+'),
+ CHANNEL_MODE_LIMIT);
+ ptr_channel->limit = atoi (pos_parm);
+
+ /* look for next parameter */
+ if (pos_parm && pos2)
+ {
+ pos2++;
+ while (pos2[0] == ' ')
+ pos2++;
+ pos_parm = pos2;
+ }
break;
case 'm':
irc_display_mode (ptr_channel->window,
@@ -374,7 +422,18 @@ irc_cmd_recv_mode (t_irc_server *server, char *host, char *arguments)
_("sets moderated channel flag") :
_("removes moderated channel flag"),
NULL);
- /* TODO: change & redraw channel modes */
+ SET_CHANNEL_MODE(ptr_channel, (set_flag == '+'),
+ CHANNEL_MODE_MODERATED);
+ break;
+ case 'n':
+ irc_display_mode (ptr_channel->window,
+ arguments, set_flag, "n", host,
+ (set_flag == '+') ?
+ _("sets messages from channel only flag") :
+ _("removes messages from channel only flag"),
+ NULL);
+ SET_CHANNEL_MODE(ptr_channel, (set_flag == '+'),
+ CHANNEL_MODE_NO_MSG_OUT);
break;
case 'o':
irc_display_mode (ptr_channel->window,
@@ -391,7 +450,6 @@ irc_cmd_recv_mode (t_irc_server *server, char *host, char *arguments)
gui_redraw_window_nick (ptr_channel->window);
}
break;
- /* TODO: remove this obsolete (?) channel flag? */
case 'p':
irc_display_mode (ptr_channel->window,
arguments, set_flag, "p", host,
@@ -399,7 +457,8 @@ irc_cmd_recv_mode (t_irc_server *server, char *host, char *arguments)
_("sets private channel flag") :
_("removes private channel flag"),
NULL);
- /* TODO: change & redraw channel modes */
+ SET_CHANNEL_MODE(ptr_channel, (set_flag == '+'),
+ CHANNEL_MODE_SECRET);
break;
case 's':
irc_display_mode (ptr_channel->window,
@@ -408,7 +467,8 @@ irc_cmd_recv_mode (t_irc_server *server, char *host, char *arguments)
_("sets secret channel flag") :
_("removes secret channel flag"),
NULL);
- /* TODO: change & redraw channel modes */
+ SET_CHANNEL_MODE(ptr_channel, (set_flag == '+'),
+ CHANNEL_MODE_SECRET);
break;
case 't':
irc_display_mode (ptr_channel->window,
@@ -417,7 +477,8 @@ irc_cmd_recv_mode (t_irc_server *server, char *host, char *arguments)
_("sets topic protection") :
_("removes topic protection"),
NULL);
- /* TODO: change & redraw channel modes */
+ SET_CHANNEL_MODE(ptr_channel, (set_flag == '+'),
+ CHANNEL_MODE_TOPIC);
break;
case 'v':
irc_display_mode (ptr_channel->window,
@@ -438,6 +499,7 @@ irc_cmd_recv_mode (t_irc_server *server, char *host, char *arguments)
}
pos++;
}
+ gui_draw_window_status (gui_current_window);
}
else
{
@@ -741,6 +803,7 @@ int
irc_cmd_recv_privmsg (t_irc_server *server, char *host, char *arguments)
{
char *pos, *pos2, *host2;
+ char *pos_file, *pos_addr, *pos_port, *pos_size; /* for DCC */
t_irc_channel *ptr_channel;
t_irc_nick *ptr_nick;
struct utsname *buf;
@@ -893,79 +956,144 @@ irc_cmd_recv_privmsg (t_irc_server *server, char *host, char *arguments)
COLOR_WIN_CHAT, _("from"));
gui_printf_color (server->window,
COLOR_WIN_CHAT_NICK, " %s\n", host);
+ return 0;
}
- else
+
+ /* ping request from another user => answer */
+ if (strncmp (pos, "\01PING", 5) == 0)
{
- /* ping request from another user => answer */
- if (strncmp (pos, "\01PING", 5) == 0)
+ pos += 5;
+ while (pos[0] == ' ')
+ pos++;
+ pos2 = strchr (pos, '\01');
+ if (pos2)
+ pos2[0] = '\0';
+ else
+ pos = NULL;
+ if (pos && !pos[0])
+ pos = NULL;
+ if (pos)
+ server_sendf (server, "NOTICE %s :\01PING %s\01\r\n",
+ host, pos);
+ else
+ server_sendf (server, "NOTICE %s :\01PING\01\r\n",
+ host);
+ return 0;
+ }
+
+ /* incoming DCC file */
+ if (strncmp (pos, "\01DCC SEND", 9) == 0)
+ {
+ pos2 = strchr (pos, '\01');
+ if (!pos2)
{
- pos += 5;
- while (pos[0] == ' ')
- pos++;
- pos2 = strchr (pos, '\01');
- if (pos2)
- pos2[0] = '\0';
- else
- pos = NULL;
- if (pos && !pos[0])
- pos = NULL;
- if (pos)
- server_sendf (server, "NOTICE %s :\01PING %s\01\r\n",
- host, pos);
- else
- server_sendf (server, "NOTICE %s :\01PING\01\r\n",
- host);
+ gui_printf (server->window,
+ _("%s cannot parse \"%s\" command\n"),
+ WEECHAT_ERROR, "privmsg");
+ return -1;
}
- else
+ pos2[0] = '\0';
+ pos_file = pos + 9;
+ while (pos_file[0] == ' ')
+ pos_file++;
+
+ /* look for file size */
+ pos_size = strrchr (pos_file, ' ');
+ if (!pos_size)
{
- /* private message received => display it */
- ptr_channel = channel_search (server, host);
- if (!ptr_channel)
- {
- ptr_channel = channel_new (server, CHAT_PRIVATE, host, 0);
- if (!ptr_channel)
- {
- gui_printf (server->window,
- _("%s cannot create new private window \"%s\"\n"),
- WEECHAT_ERROR, host);
- return -1;
- }
- }
- if (!ptr_channel->topic)
- {
- ptr_channel->topic = strdup (host2);
- gui_redraw_window_title (ptr_channel->window);
- }
-
- gui_printf_color_type (ptr_channel->window,
- MSG_TYPE_NICK,
- COLOR_WIN_CHAT_DARK, "<");
- if (strstr (pos, server->nick))
- {
- gui_printf_color_type (ptr_channel->window,
- MSG_TYPE_NICK,
- COLOR_WIN_CHAT_HIGHLIGHT,
- "%s", host);
- if ( (cfg_look_infobar_delay_highlight > 0)
- && (ptr_channel->window != gui_current_window) )
- gui_infobar_printf (cfg_look_infobar_delay_highlight,
- COLOR_WIN_INFOBAR_HIGHLIGHT,
- _("Private %s> %s"),
- host, pos);
- }
- else
- gui_printf_color_type (ptr_channel->window,
- MSG_TYPE_NICK,
- COLOR_WIN_NICK_PRIVATE,
- "%s", host);
- gui_printf_color_type (ptr_channel->window,
- MSG_TYPE_NICK,
- COLOR_WIN_CHAT_DARK, "> ");
- gui_printf_color_type (ptr_channel->window,
- MSG_TYPE_MSG,
- COLOR_WIN_CHAT, "%s\n", pos);
+ gui_printf (server->window,
+ _("%s cannot parse \"%s\" command\n"),
+ WEECHAT_ERROR, "privmsg");
+ return -1;
+ }
+ pos2 = pos_size;
+ pos_size++;
+ while (pos2[0] == ' ')
+ pos2--;
+ pos2[1] = '\0';
+
+ /* look for DCC port */
+ pos_port = strrchr (pos_file, ' ');
+ if (!pos_port)
+ {
+ gui_printf (server->window,
+ _("%s cannot parse \"%s\" command\n"),
+ WEECHAT_ERROR, "privmsg");
+ return -1;
}
+ pos2 = pos_port;
+ pos_port++;
+ while (pos2[0] == ' ')
+ pos2--;
+ pos2[1] = '\0';
+
+ /* look for DCC address (IP) */
+ pos_addr = strrchr (pos_file, ' ');
+ if (!pos_addr)
+ {
+ gui_printf (server->window,
+ _("%s cannot parse \"%s\" command\n"),
+ WEECHAT_ERROR, "privmsg");
+ return -1;
+ }
+ pos2 = pos_addr;
+ pos_addr++;
+ while (pos2[0] == ' ')
+ pos2--;
+ pos2[1] = '\0';
+
+ wee_log_printf ("Incoming DCC file (NOT DEVELOPED!): "
+ "\"%s\", address=\"%s\", port=\"%s\", size=\"%s\"\n",
+ pos_file, pos_addr, pos_port, pos_size);
+ return 0;
}
+
+ /* private message received => display it */
+ ptr_channel = channel_search (server, host);
+ if (!ptr_channel)
+ {
+ ptr_channel = channel_new (server, CHAT_PRIVATE, host, 0);
+ if (!ptr_channel)
+ {
+ gui_printf (server->window,
+ _("%s cannot create new private window \"%s\"\n"),
+ WEECHAT_ERROR, host);
+ return -1;
+ }
+ }
+ if (!ptr_channel->topic)
+ {
+ ptr_channel->topic = strdup (host2);
+ gui_redraw_window_title (ptr_channel->window);
+ }
+
+ gui_printf_color_type (ptr_channel->window,
+ MSG_TYPE_NICK,
+ COLOR_WIN_CHAT_DARK, "<");
+ if (strstr (pos, server->nick))
+ {
+ gui_printf_color_type (ptr_channel->window,
+ MSG_TYPE_NICK,
+ COLOR_WIN_CHAT_HIGHLIGHT,
+ "%s", host);
+ if ( (cfg_look_infobar_delay_highlight > 0)
+ && (ptr_channel->window != gui_current_window) )
+ gui_infobar_printf (cfg_look_infobar_delay_highlight,
+ COLOR_WIN_INFOBAR_HIGHLIGHT,
+ _("Private %s> %s"),
+ host, pos);
+ }
+ else
+ gui_printf_color_type (ptr_channel->window,
+ MSG_TYPE_NICK,
+ COLOR_WIN_NICK_PRIVATE,
+ "%s", host);
+ gui_printf_color_type (ptr_channel->window,
+ MSG_TYPE_NICK,
+ COLOR_WIN_CHAT_DARK, "> ");
+ gui_printf_color_type (ptr_channel->window,
+ MSG_TYPE_MSG,
+ COLOR_WIN_CHAT, "%s\n", pos);
}
else
{
diff --git a/src/irc/irc-send.c b/src/irc/irc-send.c
index e0890d978..ff7c9bc52 100644
--- a/src/irc/irc-send.c
+++ b/src/irc/irc-send.c
@@ -179,6 +179,17 @@ irc_cmd_send_ctcp (t_irc_server *server, char *arguments)
}
/*
+ * irc_cmd_send_dcc: starts DCC (file or chat)
+ */
+
+int
+irc_cmd_send_dcc (t_irc_server *server, char *arguments)
+{
+ /* TODO: write this command! */
+ return 0;
+}
+
+/*
* irc_cmd_send_deop: remove operator privileges from nickname(s)
*/
diff --git a/src/irc/irc.h b/src/irc/irc.h
index 112018892..1ad068aed 100644
--- a/src/irc/irc.h
+++ b/src/irc/irc.h
@@ -34,6 +34,20 @@
#define CHANNEL_PREFIX "#&+!"
+#define NUM_CHANNEL_MODES 7
+#define CHANNEL_MODE_INVITE 0
+#define CHANNEL_MODE_KEY 1
+#define CHANNEL_MODE_LIMIT 2
+#define CHANNEL_MODE_MODERATED 3
+#define CHANNEL_MODE_NO_MSG_OUT 4
+#define CHANNEL_MODE_SECRET 5
+#define CHANNEL_MODE_TOPIC 6
+#define SET_CHANNEL_MODE(channel, set, mode) \
+ if (set) \
+ channel->modes[mode] = channel_modes[mode]; \
+ else \
+ channel->modes[mode] = ' ';
+
#define DEFAULT_IRC_PORT 6667
/* nick types */
@@ -64,6 +78,9 @@ struct t_irc_channel
int type; /* channel type */
char *name; /* name of channel (exemple: "#abc") */
char *topic; /* topic of channel (host for private) */
+ char modes[NUM_CHANNEL_MODES+1];/* channel modes */
+ int limit; /* user limit (0 is limit not set) */
+ char *key; /* channel key (NULL if no key is set) */
t_irc_nick *nicks; /* nicks on the channel */
t_irc_nick *last_nick; /* last nick on the channel */
t_gui_window *window; /* GUI window allocated for channel */
@@ -139,6 +156,7 @@ extern t_irc_command irc_commands[];
extern t_irc_server *irc_servers, *current_irc_server;
extern t_irc_message *recv_msgq, *msgq_last_msg;
extern t_irc_channel *current_channel;
+extern char *channel_modes;
/* server functions (irc-server.c) */
@@ -180,6 +198,10 @@ extern t_irc_nick *nick_search (t_irc_channel *, char *);
extern void nick_count (t_irc_channel *, int *, int *, int *, int *, int *);
extern int nick_get_max_length (t_irc_channel *);
+/* DCC functions (irc-dcc.c) */
+
+extern void dcc_send ();
+
/* IRC display (irc-diplay.c) */
extern void irc_display_prefix (/*@null@*/ t_gui_window *, char *);
@@ -195,6 +217,7 @@ extern void irc_login (t_irc_server *);
extern int irc_cmd_send_admin (t_irc_server *, char *);
extern int irc_cmd_send_away (t_irc_server *, char *);
extern int irc_cmd_send_ctcp (t_irc_server *, char *);
+extern int irc_cmd_send_dcc (t_irc_server *, char *);
extern int irc_cmd_send_deop (t_irc_server *, int, char **);
extern int irc_cmd_send_devoice (t_irc_server *, int, char **);
extern int irc_cmd_send_die (t_irc_server *, char *);