summaryrefslogtreecommitdiff
path: root/src/irc
diff options
context:
space:
mode:
Diffstat (limited to 'src/irc')
-rw-r--r--src/irc/irc-commands.c2
-rw-r--r--src/irc/irc-mode.c17
-rw-r--r--src/irc/irc-recv.c149
-rw-r--r--src/irc/irc-server.c9
-rw-r--r--src/irc/irc.h3
5 files changed, 135 insertions, 45 deletions
diff --git a/src/irc/irc-commands.c b/src/irc/irc-commands.c
index 923019237..8621047e5 100644
--- a/src/irc/irc-commands.c
+++ b/src/irc/irc-commands.c
@@ -307,6 +307,8 @@ t_irc_command irc_commands[] =
"", 1, MAX_ARGS, 0, 1, NULL, irc_cmd_send_whowas, NULL },
{ "001", N_("a server message"), "", "",
NULL, 0, 0, 0, 1, NULL, NULL, irc_cmd_recv_001 },
+ { "005", N_("a server message"), "", "",
+ NULL, 0, 0, 0, 1, NULL, NULL, irc_cmd_recv_005 },
{ "221", N_("user mode string"), "", "",
NULL, 0, 0, 0, 1, NULL, NULL, irc_cmd_recv_221 },
{ "301", N_("away message"), "", "",
diff --git a/src/irc/irc-mode.c b/src/irc/irc-mode.c
index 155022f6f..289619217 100644
--- a/src/irc/irc-mode.c
+++ b/src/irc/irc-mode.c
@@ -257,3 +257,20 @@ irc_mode_user_set (t_irc_server *server, char *modes)
modes++;
}
}
+
+/*
+ * irc_mode_nick_prefix_allowed: return <> 0 if nick prefix is allowed by server
+ * for example :
+ * IRC: 005 (...) PREFIX=(ov)@+
+ * => allowed prefixes: @+
+ */
+
+int
+irc_mode_nick_prefix_allowed (t_irc_server *server, char prefix)
+{
+ /* if server did not send any prefix info, then consider this prefix is allowed */
+ if (!server->prefix)
+ return 1;
+
+ return (strchr (server->prefix, prefix) != NULL);
+}
diff --git a/src/irc/irc-recv.c b/src/irc/irc-recv.c
index 350d7ef92..6c564753d 100644
--- a/src/irc/irc-recv.c
+++ b/src/irc/irc-recv.c
@@ -2478,6 +2478,41 @@ irc_cmd_recv_001 (t_irc_server *server, char *host, char *nick, char *arguments)
}
/*
+ * irc_cmd_recv_005: '005' command (some infos from server)
+ */
+
+int
+irc_cmd_recv_005 (t_irc_server *server, char *host, char *nick, char *arguments)
+{
+ char *pos, *pos2;
+
+ irc_cmd_recv_server_msg (server, host, nick, arguments);
+
+ pos = strstr (arguments, "PREFIX=");
+ if (pos)
+ {
+ pos += 7;
+ if (pos[0] == '(')
+ {
+ pos2 = strchr (pos, ')');
+ if (!pos2)
+ return 0;
+ pos = pos2 + 1;
+ }
+ pos2 = strchr (pos, ' ');
+ if (pos2)
+ pos2[0] = '\0';
+ if (server->prefix)
+ free (server->prefix);
+ server->prefix = strdup (pos);
+ if (pos2)
+ pos2[0] = ' ';
+ }
+
+ return 0;
+}
+
+/*
* irc_cmd_recv_221: '221' command (user mode string)
*/
@@ -4285,6 +4320,7 @@ irc_cmd_recv_353 (t_irc_server *server, char *host, char *nick, char *arguments)
{
char *pos, *pos_nick;
int is_chanowner, is_chanadmin, is_chanadmin2, is_op, is_halfop, has_voice;
+ int prefix_found;
t_irc_channel *ptr_channel;
t_gui_buffer *ptr_buffer;
@@ -4357,54 +4393,77 @@ irc_cmd_recv_353 (t_irc_server *server, char *host, char *nick, char *arguments)
is_op = 0;
is_halfop = 0;
has_voice = 0;
- while ((pos[0] == '@') || (pos[0] == '%') || (pos[0] == '+'))
+ prefix_found = 1;
+
+ while (prefix_found)
{
- if (pos[0] == '@')
- {
- is_op = 1;
- if (!command_ignored && !ptr_channel)
- gui_printf (ptr_buffer, "%s@",
- GUI_COLOR(COLOR_WIN_NICK_OP));
- }
- if (pos[0] == '%')
- {
- is_halfop = 1;
- if (!command_ignored && !ptr_channel)
- gui_printf (ptr_buffer, "%s%%",
- GUI_COLOR(COLOR_WIN_NICK_HALFOP));
- }
- if (pos[0] == '+')
+ prefix_found = 0;
+
+ switch (pos[0])
{
- has_voice = 1;
- if (!command_ignored && !ptr_channel)
- gui_printf (ptr_buffer, "%s+",
- GUI_COLOR(COLOR_WIN_NICK_VOICE));
+ case '@': /* op */
+ if (irc_mode_nick_prefix_allowed (server, '@'))
+ {
+ prefix_found = 1;
+ is_op = 1;
+ if (!command_ignored && !ptr_channel)
+ gui_printf (ptr_buffer, "%s@",
+ GUI_COLOR(COLOR_WIN_NICK_OP));
+ }
+ break;
+ case '%': /* half-op */
+ if (irc_mode_nick_prefix_allowed (server, '%'))
+ {
+ prefix_found = 1;
+ is_halfop = 1;
+ if (!command_ignored && !ptr_channel)
+ gui_printf (ptr_buffer, "%s%%",
+ GUI_COLOR(COLOR_WIN_NICK_HALFOP));
+ }
+ break;
+ case '+': /* voice */
+ if (irc_mode_nick_prefix_allowed (server, '+'))
+ {
+ prefix_found = 1;
+ has_voice = 1;
+ if (!command_ignored && !ptr_channel)
+ gui_printf (ptr_buffer, "%s+",
+ GUI_COLOR(COLOR_WIN_NICK_VOICE));
+ }
+ break;
+ case '~': /* channel owner */
+ if (irc_mode_nick_prefix_allowed (server, '~'))
+ {
+ prefix_found = 1;
+ is_chanowner = 1;
+ if (!command_ignored && !ptr_channel)
+ gui_printf (ptr_buffer, "%s~",
+ GUI_COLOR(COLOR_WIN_NICK_OP));
+ }
+ break;
+ case '&': /* channel admin */
+ if (irc_mode_nick_prefix_allowed (server, '&'))
+ {
+ prefix_found = 1;
+ is_chanadmin = 1;
+ if (!command_ignored && !ptr_channel)
+ gui_printf (ptr_buffer, "%s&",
+ GUI_COLOR(COLOR_WIN_NICK_OP));
+ }
+ break;
+ case '!': /* channel admin (2) */
+ if (irc_mode_nick_prefix_allowed (server, '!'))
+ {
+ prefix_found = 1;
+ is_chanadmin2 = 1;
+ if (!command_ignored && !ptr_channel)
+ gui_printf (ptr_buffer, "%s!",
+ GUI_COLOR(COLOR_WIN_NICK_OP));
+ }
+ break;
}
- pos++;
- }
- if (pos[0] == '~')
- {
- is_chanowner = 1;
- pos++;
- if (!command_ignored && !ptr_channel)
- gui_printf (ptr_buffer, "%s~",
- GUI_COLOR(COLOR_WIN_NICK_OP));
- }
- if (pos[0] == '&')
- {
- is_chanadmin = 1;
- pos++;
- if (!command_ignored && !ptr_channel)
- gui_printf (ptr_buffer, "%s&",
- GUI_COLOR(COLOR_WIN_NICK_OP));
- }
- if (pos[0] == '!')
- {
- is_chanadmin2 = 1;
- pos++;
- if (!command_ignored && !ptr_channel)
- gui_printf (ptr_buffer, "%s!",
- GUI_COLOR(COLOR_WIN_NICK_OP));
+ if (prefix_found)
+ pos++;
}
pos_nick = pos;
pos = strchr (pos, ' ');
diff --git a/src/irc/irc-server.c b/src/irc/irc-server.c
index 60b3e3c56..0b6d2af30 100644
--- a/src/irc/irc-server.c
+++ b/src/irc/irc-server.c
@@ -116,6 +116,7 @@ server_init (t_irc_server *server)
server->unterminated_message = NULL;
server->nick = NULL;
server->nick_modes = NULL;
+ server->prefix = NULL;
server->reconnect_start = 0;
server->reconnect_join = 0;
server->is_away = 0;
@@ -403,6 +404,8 @@ server_destroy (t_irc_server *server)
free (server->nick);
if (server->nick_modes)
free (server->nick_modes);
+ if (server->prefix)
+ free (server->prefix);
if (server->away_message)
free (server->away_message);
if (server->outqueue)
@@ -1946,6 +1949,11 @@ server_disconnect (t_irc_server *server, int reconnect)
free (server->nick_modes);
server->nick_modes = NULL;
}
+ if (server->prefix)
+ {
+ free (server->prefix);
+ server->prefix = NULL;
+ }
server->is_away = 0;
server->away_time = 0;
server->lag = 0;
@@ -2219,6 +2227,7 @@ server_print_log (t_irc_server *server)
weechat_log_printf (" unterminated_message: '%s'\n", server->unterminated_message);
weechat_log_printf (" nick. . . . . . . . : '%s'\n", server->nick);
weechat_log_printf (" nick_modes. . . . . : '%s'\n", server->nick_modes);
+ weechat_log_printf (" prefix. . . . . . . : '%s'\n", server->prefix);
weechat_log_printf (" reconnect_start . . : %ld\n", server->reconnect_start);
weechat_log_printf (" reconnect_join. . . : %d\n", server->reconnect_join);
weechat_log_printf (" is_away . . . . . . : %d\n", server->is_away);
diff --git a/src/irc/irc.h b/src/irc/irc.h
index 0090f5c3f..47a565142 100644
--- a/src/irc/irc.h
+++ b/src/irc/irc.h
@@ -182,6 +182,7 @@ struct t_irc_server
char *unterminated_message; /* beginning of a message in input buf */
char *nick; /* current nickname */
char *nick_modes; /* nick modes */
+ char *prefix; /* nick prefix allowed (from msg 005) */
time_t reconnect_start; /* this time + delay = reconnect time */
int reconnect_join; /* 1 if channels opened to rejoin */
int is_away; /* 1 is user is marked as away */
@@ -447,6 +448,7 @@ extern void nick_print_log (t_irc_nick *);
extern void irc_mode_channel_set (t_irc_channel *, char *);
extern void irc_mode_user_set (t_irc_server *, char *);
+extern int irc_mode_nick_prefix_allowed (t_irc_server *, char);
/* DCC functions (irc-dcc.c) */
@@ -568,6 +570,7 @@ extern int irc_cmd_recv_server_reply (t_irc_server *, char *, char *, char *);
extern int irc_cmd_recv_topic (t_irc_server *, char *, char *, char *);
extern int irc_cmd_recv_wallops (t_irc_server *, char *, char *, char *);
extern int irc_cmd_recv_001 (t_irc_server *, char *, char *, char *);
+extern int irc_cmd_recv_005 (t_irc_server *, char *, char *, char *);
extern int irc_cmd_recv_221 (t_irc_server *, char *, char *, char *);
extern int irc_cmd_recv_301 (t_irc_server *, char *, char *, char *);
extern int irc_cmd_recv_302 (t_irc_server *, char *, char *, char *);