1
0
mirror of https://github.com/irssi/irssi.git synced 2024-07-21 03:14:16 -04:00

Merge pull request #54 from ailin-nemui/chantypes

use chantypes instead of # for irc channel defaults
This commit is contained in:
ailin-nemui 2021-12-30 23:23:53 +01:00 committed by GitHub
commit f7fd4d72e4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 12 deletions

View File

@ -63,6 +63,20 @@ IRC_CHANNEL_REC *irc_channel_create(IRC_SERVER_REC *server, const char *name,
#define get_join_key(key) \ #define get_join_key(key) \
(((key) == NULL || *(key) == '\0') ? "x" : (key)) (((key) == NULL || *(key) == '\0') ? "x" : (key))
static char *force_channel_name(IRC_SERVER_REC *server, const char *name)
{
char *chantypes;
if (server_ischannel(SERVER(server), name))
return g_strdup(name);
chantypes = g_hash_table_lookup(server->isupport, "chantypes");
if (chantypes == NULL || *chantypes == '\0')
chantypes = "#";
return g_strdup_printf("%c%s", *chantypes, name);
}
static void irc_channels_join(IRC_SERVER_REC *server, const char *data, static void irc_channels_join(IRC_SERVER_REC *server, const char *data,
int automatic) int automatic)
{ {
@ -99,8 +113,7 @@ static void irc_channels_join(IRC_SERVER_REC *server, const char *data,
tmp = chanlist; tmp = chanlist;
for (;; tmp++) { for (;; tmp++) {
if (*tmp != NULL) { if (*tmp != NULL) {
channel = server_ischannel(SERVER(server), *tmp) ? g_strdup(*tmp) : channel = force_channel_name(server, *tmp);
g_strdup_printf("#%s", *tmp);
chanrec = irc_channel_find(server, channel); chanrec = irc_channel_find(server, channel);
if (chanrec == NULL) { if (chanrec == NULL) {
@ -170,17 +183,14 @@ static void irc_channels_join(IRC_SERVER_REC *server, const char *data,
} }
/* function for finding IRC channels - adds support for !channels */ /* function for finding IRC channels - adds support for !channels */
static CHANNEL_REC *irc_channel_find_server(SERVER_REC *server, static CHANNEL_REC *irc_channel_find_server(IRC_SERVER_REC *server, const char *channel)
const char *channel)
{ {
GSList *tmp; GSList *tmp;
char *fmt_channel; char *fmt_channel;
/* if 'channel' has no leading # this lookup is going to fail, add a /* if 'channel' has no leading # this lookup is going to fail, add a
* octothorpe in front of it to handle this case. */ * octothorpe in front of it to handle this case. */
fmt_channel = server_ischannel(SERVER(server), channel) ? fmt_channel = force_channel_name(server, channel);
g_strdup(channel) :
g_strdup_printf("#%s", channel);
for (tmp = server->channels; tmp != NULL; tmp = tmp->next) { for (tmp = server->channels; tmp != NULL; tmp = tmp->next) {
CHANNEL_REC *rec = tmp->data; CHANNEL_REC *rec = tmp->data;
@ -189,12 +199,12 @@ static CHANNEL_REC *irc_channel_find_server(SERVER_REC *server,
continue; continue;
/* check both !ABCDEchannel and !channel */ /* check both !ABCDEchannel and !channel */
if (IRC_SERVER(server)->nick_comp_func(fmt_channel, rec->name) == 0) { if (server->nick_comp_func(fmt_channel, rec->name) == 0) {
g_free(fmt_channel); g_free(fmt_channel);
return rec; return rec;
} }
if (IRC_SERVER(server)->nick_comp_func(fmt_channel, rec->visible_name) == 0) { if (server->nick_comp_func(fmt_channel, rec->visible_name) == 0) {
g_free(fmt_channel); g_free(fmt_channel);
return rec; return rec;
} }
@ -210,7 +220,8 @@ static void sig_server_connected(SERVER_REC *server)
if (!IS_IRC_SERVER(server)) if (!IS_IRC_SERVER(server))
return; return;
server->channel_find_func = irc_channel_find_server; server->channel_find_func =
(CHANNEL_REC * (*) (SERVER_REC *, const char *) ) irc_channel_find_server;
server->channels_join = (void (*) (SERVER_REC *, const char *, int)) server->channels_join = (void (*) (SERVER_REC *, const char *, int))
irc_channels_join; irc_channels_join;
} }

View File

@ -84,9 +84,10 @@ static int ischannel_func(SERVER_REC *server, const char *data)
chantypes = "#&!+"; /* normal, local, secure, modeless */ chantypes = "#&!+"; /* normal, local, secure, modeless */
statusmsg = g_hash_table_lookup(irc_server->isupport, "statusmsg"); statusmsg = g_hash_table_lookup(irc_server->isupport, "statusmsg");
if (statusmsg == NULL) if (statusmsg == NULL && strchr(chantypes, '@') == NULL)
statusmsg = "@"; statusmsg = "@";
if (statusmsg != NULL)
data += strspn(data, statusmsg); data += strspn(data, statusmsg);
/* strchr(3) considers the trailing NUL as part of the string, make sure /* strchr(3) considers the trailing NUL as part of the string, make sure