1
0
mirror of https://github.com/irssi/irssi.git synced 2024-06-30 06:45:25 +00: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) \
(((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,
int automatic)
{
@ -99,8 +113,7 @@ static void irc_channels_join(IRC_SERVER_REC *server, const char *data,
tmp = chanlist;
for (;; tmp++) {
if (*tmp != NULL) {
channel = server_ischannel(SERVER(server), *tmp) ? g_strdup(*tmp) :
g_strdup_printf("#%s", *tmp);
channel = force_channel_name(server, *tmp);
chanrec = irc_channel_find(server, channel);
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 */
static CHANNEL_REC *irc_channel_find_server(SERVER_REC *server,
const char *channel)
static CHANNEL_REC *irc_channel_find_server(IRC_SERVER_REC *server, const char *channel)
{
GSList *tmp;
char *fmt_channel;
/* if 'channel' has no leading # this lookup is going to fail, add a
* octothorpe in front of it to handle this case. */
fmt_channel = server_ischannel(SERVER(server), channel) ?
g_strdup(channel) :
g_strdup_printf("#%s", channel);
fmt_channel = force_channel_name(server, channel);
for (tmp = server->channels; tmp != NULL; tmp = tmp->next) {
CHANNEL_REC *rec = tmp->data;
@ -189,12 +199,12 @@ static CHANNEL_REC *irc_channel_find_server(SERVER_REC *server,
continue;
/* 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);
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);
return rec;
}
@ -210,7 +220,8 @@ static void sig_server_connected(SERVER_REC *server)
if (!IS_IRC_SERVER(server))
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))
irc_channels_join;
}

View File

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