1
0
mirror of https://github.com/weechat/weechat.git synced 2026-07-08 02:33:12 +02:00

Added missing modes (channel & user), now all modes are allowed (bug #16606), added "%m" for completion with self nick (on current server)

This commit is contained in:
Sebastien Helleu
2006-08-07 22:26:55 +00:00
parent f8c913a77a
commit 1d211a16da
58 changed files with 4444 additions and 5938 deletions
+16
View File
@@ -348,6 +348,19 @@ completion_list_add_key_cmd (t_completion *completion)
}
}
/*
* completion_list_add_self_nick: add self nick on server to completion list
*/
void
completion_list_add_self_nick (t_completion *completion)
{
if (completion->server)
{
completion_list_add (completion, ((t_irc_server *)(completion->server))->nick);
}
}
/*
* completion_list_add_channel_nicks: add channel nicks to completion list
*/
@@ -755,6 +768,9 @@ completion_build_list_template (t_completion *completion, char *template)
case 'k': /* key cmd/funtcions*/
completion_list_add_key_cmd (completion);
break;
case 'm': /* self nickname */
completion_list_add_self_nick (completion);
break;
case 'n': /* channel nicks */
completion_list_add_channel_nicks (completion);
break;
+12 -32
View File
@@ -25,6 +25,7 @@
#endif
#include <stdlib.h>
#include <string.h>
#include "../../common/weechat.h"
#include "../gui.h"
@@ -73,8 +74,8 @@ gui_input_set_color (t_gui_window *window, int irc_color)
int
gui_input_get_prompt_length (t_gui_window *window, char *nick)
{
char *pos, saved_char, *modes;
int char_size, length, mode_found;
char *pos, saved_char;
int char_size, length;
length = 0;
pos = cfg_look_input_format;
@@ -99,18 +100,9 @@ gui_input_get_prompt_length (t_gui_window *window, char *nick)
case 'm':
if (SERVER(window->buffer))
{
mode_found = 0;
for (modes = SERVER(window->buffer)->nick_modes;
modes && modes[0]; modes++)
{
if (modes[0] != ' ')
{
length++;
mode_found = 1;
}
}
if (mode_found)
length++;
if (SERVER(window->buffer)->nick_modes
&& SERVER(window->buffer)->nick_modes[0])
length += strlen (SERVER(window->buffer)->nick_modes);
}
pos++;
break;
@@ -155,8 +147,8 @@ gui_input_get_prompt_length (t_gui_window *window, char *nick)
void
gui_input_draw_prompt (t_gui_window *window, char *nick)
{
char *pos, saved_char, *modes;
int char_size, mode_found;
char *pos, saved_char;
int char_size;
wmove (GUI_CURSES(window)->win_input, 0, 0);
pos = cfg_look_input_format;
@@ -191,25 +183,13 @@ gui_input_draw_prompt (t_gui_window *window, char *nick)
case 'm':
if (SERVER(window->buffer))
{
mode_found = 0;
for (modes = SERVER(window->buffer)->nick_modes;
modes && modes[0]; modes++)
{
if (modes[0] != ' ')
mode_found = 1;
}
if (mode_found)
if (SERVER(window->buffer)->nick_modes
&& SERVER(window->buffer)->nick_modes[0])
{
gui_window_set_weechat_color (GUI_CURSES(window)->win_input,
COLOR_WIN_INPUT);
wprintw (GUI_CURSES(window)->win_input, "+");
for (modes = SERVER(window->buffer)->nick_modes;
modes && modes[0]; modes++)
{
if (modes[0] != ' ')
wprintw (GUI_CURSES(window)->win_input, "%c",
modes[0]);
}
wprintw (GUI_CURSES(window)->win_input, "%s",
SERVER(window->buffer)->nick_modes);
}
}
pos++;
+5 -23
View File
@@ -44,7 +44,7 @@ gui_status_draw (t_gui_buffer *buffer, int erase)
t_gui_window *ptr_win;
t_weechat_hotlist *ptr_hotlist;
char format[32], str_nicks[32], *more;
int i, first_mode, x, server_pos, server_total;
int x, server_pos, server_total;
int display_name, names_count;
/* make gcc happy */
@@ -171,28 +171,10 @@ gui_status_draw (t_gui_buffer *buffer, int erase)
wprintw (GUI_CURSES(ptr_win)->win_status, "(");
gui_window_set_weechat_color (GUI_CURSES(ptr_win)->win_status,
COLOR_WIN_STATUS);
i = 0;
first_mode = 1;
while (CHANNEL(ptr_win->buffer)->modes[i])
{
if (CHANNEL(ptr_win->buffer)->modes[i] != ' ')
{
if (first_mode)
{
wprintw (GUI_CURSES(ptr_win)->win_status, "+");
first_mode = 0;
}
wprintw (GUI_CURSES(ptr_win)->win_status, "%c",
CHANNEL(ptr_win->buffer)->modes[i]);
}
i++;
}
if (CHANNEL(ptr_win->buffer)->modes[CHANNEL_MODE_KEY] != ' ')
wprintw (GUI_CURSES(ptr_win)->win_status, ",%s",
CHANNEL(ptr_win->buffer)->key);
if (CHANNEL(ptr_win->buffer)->modes[CHANNEL_MODE_LIMIT] != ' ')
wprintw (GUI_CURSES(ptr_win)->win_status, ",%d",
CHANNEL(ptr_win->buffer)->limit);
if (CHANNEL(ptr_win->buffer)->modes
&& (strcmp (CHANNEL(ptr_win->buffer)->modes, "+") != 0))
wprintw (GUI_CURSES(ptr_win)->win_status, "%s",
CHANNEL(ptr_win->buffer)->modes);
gui_window_set_weechat_color (GUI_CURSES(ptr_win)->win_status,
COLOR_WIN_STATUS_DELIMITERS);
wprintw (GUI_CURSES(ptr_win)->win_status, ")");
+1
View File
@@ -99,6 +99,7 @@ gui_buffer_new (t_gui_window *window, void *server, void *channel, int type,
gui_buffers->all_servers = 1;
if (cfg_log_auto_server)
gui_log_start (gui_buffers);
gui_buffers->completion.server = server;
return gui_buffers;
}
+1
View File
@@ -26,6 +26,7 @@ lib_weechat_irc_a_SOURCES = irc.h \
irc-server.c \
irc-channel.c \
irc-nick.c \
irc-mode.c \
irc-dcc.c \
irc-ignore.c \
irc-display.c
+5 -3
View File
@@ -61,9 +61,7 @@ channel_new (t_irc_server *server, int channel_type, char *channel_name)
new_channel->dcc_chat = NULL;
new_channel->name = strdup (channel_name);
new_channel->topic = NULL;
new_channel->modes = (char *) malloc (NUM_CHANNEL_MODES + 1);
memset (new_channel->modes, ' ', NUM_CHANNEL_MODES);
new_channel->modes[NUM_CHANNEL_MODES] = '\0';
new_channel->modes = NULL;
new_channel->limit = 0;
new_channel->key = NULL;
new_channel->nicks_count = 0;
@@ -127,6 +125,10 @@ channel_free (t_irc_server *server, t_irc_channel *channel)
free (channel->name);
if (channel->topic)
free (channel->topic);
if (channel->modes)
free (channel->modes);
if (channel->key)
free (channel->key);
nick_free_all (channel);
if (channel->away_message)
free (channel->away_message);
+1 -1
View File
@@ -156,7 +156,7 @@ t_irc_command irc_commands[] =
" s: mark a user for receive server notices\n"
" w: user receives wallops\n"
" o: operator flag"),
"", 1, MAX_ARGS, 0, 1, NULL, irc_cmd_send_mode, irc_cmd_recv_mode },
"%c|%m", 1, MAX_ARGS, 0, 1, NULL, irc_cmd_send_mode, irc_cmd_recv_mode },
{ "motd", N_("get the \"Message Of The Day\""),
N_("[target]"),
N_("target: server name"),
+251
View File
@@ -0,0 +1,251 @@
/*
* Copyright (c) 2003-2006 by FlashCode <flashcode@flashtux.org>
* See README for License detail, AUTHORS for developers list.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
/* irc-mode.c: IRC channel/user modes management */
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdlib.h>
#include <string.h>
#include "../common/weechat.h"
#include "irc.h"
#include "../common/command.h"
#include "../gui/gui.h"
/*
* irc_mode_channel_set_nick: set a mode for a nick on a channel
*/
void
irc_mode_channel_set_nick (t_irc_channel *channel, char *nick,
char set_flag, int flag)
{
t_irc_nick *ptr_nick;
if (nick)
{
ptr_nick = nick_search (channel, nick);
if (ptr_nick)
{
NICK_SET_FLAG(ptr_nick, (set_flag == '+'), flag);
nick_resort (channel, ptr_nick);
gui_nicklist_draw (channel->buffer, 1, 1);
}
}
}
/*
* irc_mode_channel_get_flag: search for flag before current position
*/
char
irc_mode_channel_get_flag (char *str, char *pos)
{
char set_flag;
set_flag = '+';
pos--;
while (pos >= str)
{
if (pos[0] == '-')
return '-';
if (pos[0] == '+')
return '+';
pos--;
}
return set_flag;
}
/*
* irc_mode_channel_set: set channel modes
*/
void
irc_mode_channel_set (t_irc_channel *channel, char *modes)
{
char *pos_args, set_flag, **argv, *pos, *ptr_arg;
int argc, current_arg;
argc = 0;
argv = NULL;
current_arg = 0;
pos_args = strchr (modes, ' ');
if (pos_args)
{
pos_args[0] = '\0';
pos_args++;
while (pos_args[0] == ' ')
pos_args++;
argv = explode_string (pos_args, " ", 0, &argc);
if (argc > 0)
current_arg = argc - 1;
}
if (modes && modes[0])
{
set_flag = '+';
pos = modes + strlen (modes) - 1;
while (pos >= modes)
{
switch (pos[0])
{
case ':':
case ' ':
case '+':
case '-':
break;
default:
set_flag = irc_mode_channel_get_flag (modes, pos);
ptr_arg = ((argc > 0) && (current_arg >= 0)) ?
argv[current_arg--] : NULL;
switch (pos[0])
{
case 'h':
irc_mode_channel_set_nick (channel, ptr_arg,
set_flag, NICK_HALFOP);
break;
case 'k':
if (channel->key)
{
free (channel->key);
channel->key = NULL;
}
if ((set_flag == '+') && ptr_arg)
channel->key = strdup (ptr_arg);
break;
case 'l':
if (set_flag == '-')
channel->limit = 0;
if ((set_flag == '+') && ptr_arg)
channel->limit = atoi (ptr_arg);
break;
case 'o':
irc_mode_channel_set_nick (channel, ptr_arg,
set_flag, NICK_OP);
break;
case 'v':
irc_mode_channel_set_nick (channel, ptr_arg,
set_flag, NICK_VOICE);
break;
}
break;
}
pos--;
}
}
if (argv)
free_exploded_string (argv);
}
/*
* irc_mode_user_add: add a user mode
*/
void
irc_mode_user_add (t_irc_server *server, char mode)
{
char str_mode[2];
str_mode[0] = mode;
str_mode[1] = '\0';
if (server->nick_modes)
{
if (!strchr (server->nick_modes, mode))
{
server->nick_modes = (char *) realloc (server->nick_modes,
strlen (server->nick_modes) + 1 + 1);
strcat (server->nick_modes, str_mode);
gui_status_draw (gui_current_window->buffer, 1);
gui_input_draw (gui_current_window->buffer, 1);
}
}
else
{
server->nick_modes = (char *) malloc (2);
strcpy (server->nick_modes, str_mode);
gui_status_draw (gui_current_window->buffer, 1);
gui_input_draw (gui_current_window->buffer, 1);
}
}
/*
* irc_mode_user_remove: remove a user mode
*/
void
irc_mode_user_remove (t_irc_server *server, char mode)
{
char *pos;
int new_size;
if (server->nick_modes)
{
pos = strchr (server->nick_modes, mode);
if (pos)
{
new_size = strlen (server->nick_modes);
memmove (pos, pos + 1, strlen (pos + 1) + 1);
server->nick_modes = (char *) realloc (server->nick_modes,
new_size);
gui_status_draw (gui_current_window->buffer, 1);
gui_input_draw (gui_current_window->buffer, 1);
}
}
}
/*
* irc_mode_user_set: set user modes
*/
void
irc_mode_user_set (t_irc_server *server, char *modes)
{
char set_flag;
set_flag = '+';
while (modes && modes[0])
{
switch (modes[0])
{
case ':':
case ' ':
break;
case '+':
set_flag = '+';
break;
case '-':
set_flag = '-';
break;
default:
if (set_flag == '+')
irc_mode_user_add (server, modes[0]);
else
irc_mode_user_remove (server, modes[0]);
break;
}
modes++;
}
}
+81 -617
View File
@@ -646,583 +646,6 @@ irc_cmd_recv_kill (t_irc_server *server, char *host, char *nick, char *arguments
return 0;
}
/*
* irc_get_channel_modes: get channel modes
*/
void irc_get_channel_modes (t_irc_server *server, t_irc_channel *channel,
char *channel_name,
char *nick_host, char *modes, char *parm,
int no_display)
{
char *pos, set_flag, unknown_mode[3];
t_irc_nick *ptr_nick;
set_flag = '+';
while (modes && modes[0])
{
switch (modes[0])
{
case '+':
set_flag = '+';
break;
case '-':
set_flag = '-';
break;
case 'b':
pos = NULL;
if (parm)
{
pos = strchr (parm, ' ');
if (pos)
pos[0] = '\0';
}
if (nick_host && !no_display)
irc_display_mode (server, channel->buffer,
channel_name, NULL, set_flag,
"b", nick_host,
(set_flag == '+') ?
_("sets ban on") :
_("removes ban on"),
(parm) ? parm : NULL);
/* look for next parameter */
if (parm && pos)
{
pos++;
while (pos[0] == ' ')
pos++;
parm = pos;
}
break;
case 'd':
pos = NULL;
if (parm)
{
pos = strchr (parm, ' ');
if (pos)
pos[0] = '\0';
}
if (nick_host && !no_display)
irc_display_mode (server, channel->buffer,
channel_name, NULL, set_flag,
"d", nick_host,
(set_flag == '+') ?
_("sets realname ban on") :
_("removes realname ban on"),
(parm) ? parm : NULL);
/* look for next parameter */
if (parm && pos)
{
pos++;
while (pos[0] == ' ')
pos++;
parm = pos;
}
break;
case 'e':
pos = NULL;
if (parm)
{
pos = strchr (parm, ' ');
if (pos)
pos[0] = '\0';
}
if (nick_host && !no_display)
irc_display_mode (server, channel->buffer,
channel_name, NULL, set_flag,
"e", nick_host,
(set_flag == '+') ?
_("sets ban exemption on") :
_("removes ban exemption on"),
(parm) ? parm : NULL);
/* look for next parameter */
if (parm && pos)
{
pos++;
while (pos[0] == ' ')
pos++;
parm = pos;
}
break;
case 'f':
pos = NULL;
if (parm)
{
pos = strchr (parm, ' ');
if (pos)
pos[0] = '\0';
}
if (nick_host && !no_display)
irc_display_mode (server, channel->buffer,
channel_name, NULL, set_flag,
"f", nick_host,
(set_flag == '+') ?
_("sets mode +f") :
_("removes mode +f"),
(parm) ? parm : NULL);
/* look for next parameter */
if (parm && pos)
{
pos++;
while (pos[0] == ' ')
pos++;
parm = pos;
}
break;
case 'h':
pos = NULL;
if (parm)
{
pos = strchr (parm, ' ');
if (pos)
pos[0] = '\0';
}
if (nick_host && !no_display)
irc_display_mode (server, channel->buffer,
channel_name, NULL, set_flag,
"h", nick_host,
(set_flag == '+') ?
_("gives half channel operator status to") :
_("removes half channel operator status from"),
(parm) ? parm : NULL);
if (parm)
{
ptr_nick = nick_search (channel, parm);
if (ptr_nick)
{
NICK_SET_FLAG(ptr_nick, (set_flag == '+'), NICK_HALFOP);
nick_resort (channel, ptr_nick);
gui_nicklist_draw (channel->buffer, 1, 1);
}
}
/* look for next parameter */
if (parm && pos)
{
pos++;
while (pos[0] == ' ')
pos++;
parm = pos;
}
break;
case 'i':
if (nick_host && !no_display)
irc_display_mode (server, channel->buffer,
channel_name, NULL, set_flag,
"i", nick_host,
(set_flag == '+') ?
_("sets invite-only channel flag") :
_("removes invite-only channel flag"),
NULL);
CHANNEL_SET_MODE(channel, (set_flag == '+'),
CHANNEL_MODE_INVITE);
break;
case 'I':
pos = NULL;
if (parm)
{
pos = strchr (parm, ' ');
if (pos)
pos[0] = '\0';
}
if (nick_host && !no_display)
irc_display_mode (server, channel->buffer,
channel_name, NULL, set_flag,
"I", nick_host,
(set_flag == '+') ?
_("sets invite-only exemption on") :
_("removes invite-only exemption on"),
(parm) ? parm : NULL);
/* look for next parameter */
if (parm && pos)
{
pos++;
while (pos[0] == ' ')
pos++;
parm = pos;
}
break;
case 'k':
pos = NULL;
if (parm)
{
pos = strchr (parm, ' ');
if (pos)
pos[0] = '\0';
}
if (nick_host && !no_display)
irc_display_mode (server, channel->buffer,
channel_name, NULL, set_flag,
"k", nick_host,
(set_flag == '+') ?
_("sets channel key to") :
_("removes channel key"),
(set_flag == '+') ?
((parm) ? parm : NULL) :
NULL);
CHANNEL_SET_MODE(channel, (set_flag == '+'),
CHANNEL_MODE_KEY);
if (channel->key)
free (channel->key);
channel->key = strdup (parm);
/* look for next parameter */
if (parm && pos)
{
pos++;
while (pos[0] == ' ')
pos++;
parm = pos;
}
break;
case 'l':
pos = NULL;
if (parm)
{
pos = strchr (parm, ' ');
if (pos)
pos[0] = '\0';
}
if (nick_host && !no_display)
irc_display_mode (server, channel->buffer,
channel_name, NULL, set_flag,
"l", nick_host,
(set_flag == '+') ?
_("sets the user limit to") :
_("removes user limit"),
(set_flag == '+') ?
((parm) ? parm : NULL) :
NULL);
CHANNEL_SET_MODE(channel, (set_flag == '+'),
CHANNEL_MODE_LIMIT);
if (set_flag == '-')
channel->limit = 0;
if ((set_flag == '+') && parm)
channel->limit = atoi (parm);
/* look for next parameter */
if (parm && pos)
{
pos++;
while (pos[0] == ' ')
pos++;
parm = pos;
}
break;
case 'm':
if (nick_host && !no_display)
irc_display_mode (server, channel->buffer,
channel_name, NULL, set_flag,
"m", nick_host,
(set_flag == '+') ?
_("sets moderated channel flag") :
_("removes moderated channel flag"),
NULL);
CHANNEL_SET_MODE(channel, (set_flag == '+'),
CHANNEL_MODE_MODERATED);
break;
case 'n':
if (nick_host && !no_display)
irc_display_mode (server, channel->buffer,
channel_name, NULL, set_flag,
"n", nick_host,
(set_flag == '+') ?
_("sets messages from channel only flag") :
_("removes messages from channel only flag"),
NULL);
CHANNEL_SET_MODE(channel, (set_flag == '+'),
CHANNEL_MODE_NO_MSG_OUT);
break;
case 'o':
pos = NULL;
if (parm)
{
pos = strchr (parm, ' ');
if (pos)
pos[0] = '\0';
}
if (nick_host && !no_display)
irc_display_mode (server, channel->buffer,
channel_name, NULL, set_flag,
"o", nick_host,
(set_flag == '+') ?
_("gives channel operator status to") :
_("removes channel operator status from"),
(parm) ? parm : NULL);
if (parm)
{
ptr_nick = nick_search (channel, parm);
if (ptr_nick)
{
NICK_SET_FLAG(ptr_nick, (set_flag == '+'), NICK_OP);
nick_resort (channel, ptr_nick);
gui_nicklist_draw (channel->buffer, 1, 1);
}
}
/* look for next parameter */
if (parm && pos)
{
pos++;
while (pos[0] == ' ')
pos++;
parm = pos;
}
break;
case 'p':
if (nick_host && !no_display)
irc_display_mode (server, channel->buffer,
channel_name, NULL, set_flag,
"p", nick_host,
(set_flag == '+') ?
_("sets private channel flag") :
_("removes private channel flag"),
NULL);
CHANNEL_SET_MODE(channel, (set_flag == '+'),
CHANNEL_MODE_PRIVATE);
break;
case 'q':
pos = NULL;
if (parm)
{
pos = strchr (parm, ' ');
if (pos)
pos[0] = '\0';
}
if (nick_host && !no_display)
irc_display_mode (server, channel->buffer,
channel_name, NULL, set_flag,
"q", nick_host,
(set_flag == '+') ?
_("sets quiet on") :
_("removes quiet on"),
(parm) ? parm : NULL);
/* look for next parameter */
if (parm && pos)
{
pos++;
while (pos[0] == ' ')
pos++;
parm = pos;
}
break;
case 's':
if (nick_host && !no_display)
irc_display_mode (server, channel->buffer,
channel_name, NULL, set_flag,
"s", nick_host,
(set_flag == '+') ?
_("sets secret channel flag") :
_("removes secret channel flag"),
NULL);
CHANNEL_SET_MODE(channel, (set_flag == '+'),
CHANNEL_MODE_SECRET);
break;
case 't':
if (nick_host && !no_display)
irc_display_mode (server, channel->buffer,
channel_name, NULL, set_flag,
"t", nick_host,
(set_flag == '+') ?
_("sets topic protection") :
_("removes topic protection"),
NULL);
CHANNEL_SET_MODE(channel, (set_flag == '+'),
CHANNEL_MODE_TOPIC);
break;
case 'v':
pos = NULL;
if (parm)
{
pos = strchr (parm, ' ');
if (pos)
pos[0] = '\0';
}
if (nick_host && !no_display)
irc_display_mode (server, channel->buffer,
channel_name, NULL, set_flag,
"v", nick_host,
(set_flag == '+') ?
_("gives voice to") :
_("removes voice from"),
(parm) ? parm : NULL);
if (parm)
{
ptr_nick = nick_search (channel, parm);
if (ptr_nick)
{
NICK_SET_FLAG(ptr_nick, (set_flag == '+'), NICK_VOICE);
nick_resort (channel, ptr_nick);
gui_nicklist_draw (channel->buffer, 1, 1);
}
}
/* look for next parameter */
if (parm && pos)
{
pos++;
while (pos[0] == ' ')
pos++;
parm = pos;
}
break;
default: /* unknown mode received */
pos = NULL;
if (parm)
{
pos = strchr (parm, ' ');
if (pos)
pos[0] = '\0';
}
if (nick_host && !no_display)
{
unknown_mode[0] = set_flag;
unknown_mode[1] = modes[0];
unknown_mode[2] = '\0';
irc_display_mode (server, channel->buffer,
channel_name, NULL, set_flag,
unknown_mode + 1, nick_host,
unknown_mode,
(parm) ? parm : NULL);
}
/* look for next parameter */
if (parm && pos)
{
pos++;
while (pos[0] == ' ')
pos++;
parm = pos;
}
break;
}
modes++;
}
}
/*
* irc_get_nick_modes: get nick modes
*/
void irc_get_nick_modes (t_irc_server *server,
char *nick_host, char *modes, int no_display)
{
char set_flag, unknown_mode[3];
set_flag = '+';
while (modes && modes[0])
{
switch (modes[0])
{
case ':':
break;
case '+':
set_flag = '+';
break;
case '-':
set_flag = '-';
break;
case 'a':
if (nick_host && !no_display)
irc_display_mode (server, server->buffer,
NULL, server->nick, set_flag,
"a", nick_host,
(set_flag == '+') ?
_("sets away") :
_("removes away"),
NULL);
NICK_SET_MODE(server, (set_flag == '+'), NICK_MODE_AWAY);
break;
case 'i':
if (nick_host && !no_display)
irc_display_mode (server, server->buffer,
NULL, server->nick, set_flag,
"i", nick_host,
(set_flag == '+') ?
_("sets invisible") :
_("removes invisible"),
NULL);
NICK_SET_MODE(server, (set_flag == '+'), NICK_MODE_INVISIBLE);
break;
case 'w':
if (nick_host && !no_display)
irc_display_mode (server, server->buffer,
NULL, server->nick, set_flag,
"w", nick_host,
(set_flag == '+') ?
_("sets wallops") :
_("removes wallops"),
NULL);
NICK_SET_MODE(server, (set_flag == '+'), NICK_MODE_WALLOPS);
break;
case 'r':
if (nick_host && !no_display)
irc_display_mode (server, server->buffer,
NULL, server->nick, set_flag,
"r", nick_host,
(set_flag == '+') ?
_("sets restricted") :
_("removes restricted"),
NULL);
NICK_SET_MODE(server, (set_flag == '+'), NICK_MODE_RESTRICTED);
break;
case 'o':
if (nick_host && !no_display)
irc_display_mode (server, server->buffer,
NULL, server->nick, set_flag,
"o", nick_host,
(set_flag == '+') ?
_("sets operator") :
_("removes operator"),
NULL);
NICK_SET_MODE(server, (set_flag == '+'), NICK_MODE_OPERATOR);
break;
case 'O':
if (nick_host && !no_display)
irc_display_mode (server, server->buffer,
NULL, server->nick, set_flag,
"O", nick_host,
(set_flag == '+') ?
_("sets local operator") :
_("removes local operator"),
NULL);
NICK_SET_MODE(server, (set_flag == '+'), NICK_MODE_LOCAL_OPERATOR);
break;
case 's':
if (nick_host && !no_display)
irc_display_mode (server, server->buffer,
NULL, server->nick, set_flag,
"s", nick_host,
(set_flag == '+') ?
_("sets server notices") :
_("removes server notices"),
NULL);
NICK_SET_MODE(server, (set_flag == '+'), NICK_MODE_LOCAL_OPERATOR);
break;
default: /* unknown mode received */
if (nick_host && !no_display)
{
unknown_mode[0] = set_flag;
unknown_mode[1] = modes[0];
unknown_mode[2] = '\0';
irc_display_mode (server, server->buffer,
NULL, server->nick, set_flag,
unknown_mode + 1, nick_host,
unknown_mode, NULL);
}
break;
}
modes++;
}
}
/*
* irc_cmd_recv_mode: 'mode' message received
*/
@@ -1230,7 +653,7 @@ void irc_get_nick_modes (t_irc_server *server,
int
irc_cmd_recv_mode (t_irc_server *server, char *host, char *nick, char *arguments)
{
char *pos, *pos_parm;
char *pos_modes, *pos;
t_irc_channel *ptr_channel;
/* no host => we can't identify sender of message! */
@@ -1243,8 +666,8 @@ irc_cmd_recv_mode (t_irc_server *server, char *host, char *nick, char *arguments
return -1;
}
pos = strchr (arguments, ' ');
if (!pos)
pos_modes = strchr (arguments, ' ');
if (!pos_modes)
{
irc_display_prefix (server, server->buffer, PREFIX_ERROR);
gui_printf_nolog (server->buffer,
@@ -1252,18 +675,19 @@ irc_cmd_recv_mode (t_irc_server *server, char *host, char *nick, char *arguments
WEECHAT_ERROR, "mode");
return -1;
}
pos[0] = '\0';
pos++;
while (pos[0] == ' ')
pos++;
pos_modes[0] = '\0';
pos_modes++;
while (pos_modes[0] == ' ')
pos_modes++;
if (pos_modes[0] == ':')
pos_modes++;
pos_parm = strchr (pos, ' ');
if (pos_parm)
/* remove spaces after modes */
pos = pos_modes + strlen (pos_modes) - 1;
while ((pos >= pos_modes) && (pos[0] == ' '))
{
pos_parm[0] = '\0';
pos_parm++;
while (pos_parm[0] == ' ')
pos_parm++;
pos[0] = '\0';
pos--;
}
if (string_is_channel (arguments))
@@ -1271,10 +695,23 @@ irc_cmd_recv_mode (t_irc_server *server, char *host, char *nick, char *arguments
ptr_channel = channel_search (server, arguments);
if (ptr_channel)
{
irc_get_channel_modes (server, ptr_channel, arguments, nick,
pos, pos_parm, command_ignored);
gui_status_draw (ptr_channel->buffer, 1);
gui_input_draw (ptr_channel->buffer, 1);
if (!command_ignored)
{
irc_display_prefix (server, ptr_channel->buffer, PREFIX_INFO);
gui_printf (ptr_channel->buffer,
_("Mode %s%s %s[%s%s%s]%s by %s%s\n"),
GUI_COLOR(COLOR_WIN_CHAT_CHANNEL),
ptr_channel->name,
GUI_COLOR(COLOR_WIN_CHAT_DARK),
GUI_COLOR(COLOR_WIN_CHAT),
pos_modes,
GUI_COLOR(COLOR_WIN_CHAT_DARK),
GUI_COLOR(COLOR_WIN_CHAT),
GUI_COLOR(COLOR_WIN_CHAT_NICK),
nick);
}
irc_mode_channel_set (ptr_channel, pos_modes);
server_sendf (server, "MODE %s\r\n", ptr_channel->name);
}
else
{
@@ -1287,9 +724,19 @@ irc_cmd_recv_mode (t_irc_server *server, char *host, char *nick, char *arguments
}
else
{
irc_get_nick_modes (server, nick, pos, command_ignored);
gui_status_draw (gui_current_window->buffer, 1);
gui_input_draw (gui_current_window->buffer, 1);
if (!command_ignored)
{
irc_display_prefix (server, server->buffer, PREFIX_INFO);
gui_printf (server->buffer,
_("User mode %s%s %s[%s%s%s]\n"),
GUI_COLOR(COLOR_WIN_CHAT_NICK),
nick,
GUI_COLOR(COLOR_WIN_CHAT_DARK),
GUI_COLOR(COLOR_WIN_CHAT),
pos_modes,
GUI_COLOR(COLOR_WIN_CHAT_DARK));
}
irc_mode_user_set (server, pos_modes);
}
return 0;
}
@@ -2957,12 +2404,13 @@ irc_cmd_recv_221 (t_irc_server *server, char *host, char *nick, char *arguments)
if (!command_ignored)
{
irc_display_prefix (server, server->buffer, PREFIX_SERVER);
gui_printf (server->buffer, _("User mode %s[%s%s%s/%s%s%s]\n"),
GUI_COLOR(COLOR_WIN_CHAT_DARK),
gui_printf (server->buffer,
_("User mode for %s%s%s is %s[%s%s%s]\n"),
GUI_COLOR(COLOR_WIN_CHAT_NICK),
arguments,
GUI_COLOR(COLOR_WIN_CHAT),
GUI_COLOR(COLOR_WIN_CHAT_NICK),
GUI_COLOR(COLOR_WIN_CHAT_DARK),
GUI_COLOR(COLOR_WIN_CHAT),
pos_mode,
GUI_COLOR(COLOR_WIN_CHAT_DARK));
}
@@ -3931,7 +3379,7 @@ irc_cmd_recv_323 (t_irc_server *server, char *host, char *nick, char *arguments)
int
irc_cmd_recv_324 (t_irc_server *server, char *host, char *nick, char *arguments)
{
char *pos_channel, *pos, *pos_parm;
char *pos_channel, *pos_modes, *pos;
t_irc_channel *ptr_channel;
/* make gcc happy */
@@ -3946,28 +3394,44 @@ irc_cmd_recv_324 (t_irc_server *server, char *host, char *nick, char *arguments)
while (pos_channel[0] == ' ')
pos_channel++;
pos = strchr (pos_channel, ' ');
if (pos)
pos_modes = strchr (pos_channel, ' ');
if (pos_modes)
{
pos[0] = '\0';
pos++;
while (pos[0] == ' ')
pos++;
pos_parm = strchr (pos, ' ');
if (pos_parm)
pos_modes[0] = '\0';
pos_modes++;
while (pos_modes[0] == ' ')
pos_modes++;
/* remove spaces after modes */
pos = pos_modes + strlen (pos_modes) - 1;
while ((pos >= pos_modes) && (pos[0] == ' '))
{
pos_parm[0] = '\0';
pos_parm++;
while (pos_parm[0] == ' ')
pos_parm++;
pos[0] = '\0';
pos--;
}
/* search channel */
ptr_channel = channel_search (server, pos_channel);
if (ptr_channel)
{
irc_get_channel_modes (server, ptr_channel, NULL, NULL,
pos, pos_parm, command_ignored);
gui_status_draw (ptr_channel->buffer, 0);
if (pos_modes[0])
{
if (ptr_channel->modes)
ptr_channel->modes = (char *) realloc (ptr_channel->modes,
strlen (pos_modes) + 1);
else
ptr_channel->modes = (char *) malloc (strlen (pos_modes) + 1);
strcpy (ptr_channel->modes, pos_modes);
}
else
{
if (ptr_channel->modes)
{
free (ptr_channel->modes);
ptr_channel->modes = NULL;
}
}
gui_status_draw (ptr_channel->buffer, 1);
}
}
}
+3 -5
View File
@@ -102,9 +102,7 @@ server_init (t_irc_server *server)
server->ssl_connected = 0;
server->unterminated_message = NULL;
server->nick = NULL;
server->nick_modes = (char *) malloc (NUM_NICK_MODES + 1);
memset (server->nick_modes, ' ', NUM_NICK_MODES);
server->nick_modes[NUM_NICK_MODES] = '\0';
server->nick_modes = NULL;
server->reconnect_start = 0;
server->reconnect_join = 0;
server->is_away = 0;
@@ -1755,8 +1753,8 @@ server_disconnect (t_irc_server *server, int reconnect)
if (server->nick_modes)
{
memset (server->nick_modes, ' ', NUM_NICK_MODES);
server->nick_modes[NUM_NICK_MODES] = '\0';
free (server->nick_modes);
server->nick_modes = NULL;
}
server->is_away = 0;
server->away_time = 0;
+5 -29
View File
@@ -85,21 +85,6 @@ struct t_irc_nick
#define CHANNEL_TYPE_PRIVATE 1
#define CHANNEL_TYPE_DCC_CHAT 2
#define NUM_CHANNEL_MODES 8
#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 CHANNEL_MODE_PRIVATE 7
#define CHANNEL_SET_MODE(channel, set, mode) \
if (set) \
channel->modes[mode] = channel_modes[mode]; \
else \
channel->modes[mode] = ' ';
typedef struct t_irc_channel t_irc_channel;
struct t_irc_channel
@@ -125,20 +110,6 @@ struct t_irc_channel
/* server types */
#define NUM_NICK_MODES 7
#define NICK_MODE_AWAY 0
#define NICK_MODE_INVISIBLE 1
#define NICK_MODE_WALLOPS 2
#define NICK_MODE_RESTRICTED 3
#define NICK_MODE_OPERATOR 4
#define NICK_MODE_LOCAL_OPERATOR 5
#define NICK_MODE_SERVER_NOTICES 6
#define NICK_SET_MODE(server, set, mode) \
if (set) \
server->nick_modes[mode] = nick_modes[mode]; \
else \
server->nick_modes[mode] = ' ';
typedef struct t_irc_server t_irc_server;
struct t_irc_server
@@ -432,6 +403,11 @@ extern int nick_get_max_length (t_irc_channel *);
extern void nick_set_away (t_irc_channel *, t_irc_nick *, int);
extern void nick_print_log (t_irc_nick *);
/* mode functions (irc-mode.c) */
extern void irc_mode_channel_set (t_irc_channel *, char *);
extern void irc_mode_user_set (t_irc_server *, char *);
/* DCC functions (irc-dcc.c) */
extern void dcc_redraw (int);
+1
View File
@@ -834,6 +834,7 @@ weechat_plugin_get_server_info (t_weechat_plugin *plugin)
new_server_info->is_connected = ptr_server->is_connected;
new_server_info->ssl_connected = ptr_server->ssl_connected;
new_server_info->nick = (ptr_server->nick) ? strdup (ptr_server->nick) : strdup ("");
new_server_info->nick_modes = (ptr_server->nick_modes) ? strdup (ptr_server->nick_modes) : strdup ("");
new_server_info->is_away = ptr_server->is_away;
new_server_info->away_time = ptr_server->away_time;
new_server_info->lag = ptr_server->lag;
+4
View File
@@ -1371,6 +1371,10 @@ weechat_lua_get_server_info (lua_State *L)
lua_pushstring (lua_current_interpreter, "nick");
lua_pushstring (lua_current_interpreter, ptr_server->nick);
lua_rawset (lua_current_interpreter, -3);
lua_pushstring (lua_current_interpreter, "nick_modes");
lua_pushstring (lua_current_interpreter, ptr_server->nick_modes);
lua_rawset (lua_current_interpreter, -3);
lua_pushstring (lua_current_interpreter, "away_time");
lua_pushstring (lua_current_interpreter, timebuffer);
+1
View File
@@ -1163,6 +1163,7 @@ static XS (XS_weechat_get_server_info)
hv_store (server_hash_member, "is_connected", 12, newSViv (ptr_server->is_connected), 0);
hv_store (server_hash_member, "ssl_connected", 13, newSViv (ptr_server->ssl_connected), 0);
hv_store (server_hash_member, "nick", 4, newSVpv (ptr_server->nick, 0), 0);
hv_store (server_hash_member, "nick_modes", 10, newSVpv (ptr_server->nick_modes, 0), 0);
hv_store (server_hash_member, "away_time", 9, newSVpv (timebuffer, 0), 0);
hv_store (server_hash_member, "lag", 3, newSViv (ptr_server->lag), 0);
@@ -1134,6 +1134,8 @@ weechat_python_get_server_info (PyObject *self, PyObject *args)
Py_BuildValue("i", ptr_server->ssl_connected));
PyDict_SetItem(server_hash_member, Py_BuildValue("s", "nick"),
Py_BuildValue("s", ptr_server->nick));
PyDict_SetItem(server_hash_member, Py_BuildValue("s", "nick_modes"),
Py_BuildValue("s", ptr_server->nick_modes));
PyDict_SetItem(server_hash_member, Py_BuildValue("s", "away_time"),
Py_BuildValue("s", timebuffer));
PyDict_SetItem(server_hash_member, Py_BuildValue("s", "lag"),
+2
View File
@@ -1354,6 +1354,8 @@ weechat_ruby_get_server_info (VALUE class)
INT2FIX(ptr_server->ssl_connected));
rb_hash_aset (server_hash_member, rb_str_new2("nick"),
rb_str_new2(ptr_server->nick));
rb_hash_aset (server_hash_member, rb_str_new2("nick_modes"),
rb_str_new2(ptr_server->nick_modes));
rb_hash_aset (server_hash_member, rb_str_new2("away_time"),
rb_str_new2(timebuffer));
rb_hash_aset (server_hash_member, rb_str_new2("lag"),
+1
View File
@@ -107,6 +107,7 @@ struct t_plugin_server_info
int is_connected; /* 1 if WeeChat is connected to server */
int ssl_connected; /* = 1 if connected with SSL */
char *nick; /* current nickname */
char *nick_modes; /* nick modes */
int is_away; /* 1 is user is marker as away */
time_t away_time; /* time() when user marking as away */
int lag; /* lag (in milliseconds) */