Esempio n. 1
0
static void event_invite(IRC_SERVER_REC *server, const char *data)
{
    char *params, *channel, *shortchan;

    g_return_if_fail(data != NULL);

    params = event_get_params(data, 2, NULL, &channel);

    if (irc_channel_find(server, channel) == NULL) {
        /* check if we're supposed to autojoin this channel */
        CHANNEL_SETUP_REC *setup;

        setup = channel_setup_find(channel, server->connrec->chatnet);
        if (setup == NULL && channel[0] == '!' &&
                strlen(channel) > 6) {
            shortchan = g_strdup_printf("!%s", channel+6);
            setup = channel_setup_find(shortchan,
                                       server->connrec->chatnet);
            g_free(shortchan);
        }
        if (setup != NULL && setup->autojoin && settings_get_bool("join_auto_chans_on_invite"))
            server->channels_join(SERVER(server), channel, TRUE);
    }

    g_free_not_null(server->last_invite);
    server->last_invite = g_strdup(channel);
    g_free(params);
}
Esempio n. 2
0
static void autolog_open_check(TEXT_DEST_REC *dest)
{
	const char *deftarget;
	SERVER_REC *server = dest->server;
	const char *server_tag = dest->server_tag;
	const char *target = dest->target;
	int level = dest->level;

	/* FIXME: kind of a kludge, but we don't want to reopen logs when
	   we're parting the channel with /WINDOW CLOSE.. Maybe a small
	   timeout would be nice instead of immediately closing the log file
	   after "window item destroyed" */
	if (level == MSGLEVEL_PARTS ||
	    (autolog_level & level) == 0 || target == NULL || *target == '\0')
		return;

	deftarget = server ? server->nick : "unknown";

	/* log only channels that have been saved to the config */
	if (settings_get_bool("autolog_only_saved_channels") && IS_CHANNEL(window_item_find(server, target))
		&& channel_setup_find(target, server_tag) == NULL)
		return;

	if (autolog_ignore_targets != NULL &&
	    strarray_find_dest(autolog_ignore_targets, dest))
		return;

	if (target != NULL)
		autolog_open(server, server_tag, g_strcmp0(target, "*") ? target : deftarget);
}
Esempio n. 3
0
static void event_no_such_channel(IRC_SERVER_REC *server, const char *data)
{
    CHANNEL_REC *chanrec;
    CHANNEL_SETUP_REC *setup;
    char *params, *channel;

    params = event_get_params(data, 2, NULL, &channel);
    chanrec = *channel == '!' && channel[1] != '\0' ?
              channel_find(SERVER(server), channel) : NULL;

    if (chanrec != NULL) {
        /* !channel didn't exist, so join failed */
        setup = channel_setup_find(chanrec->name,
                                   chanrec->server->connrec->chatnet);
        if (setup != NULL && setup->autojoin) {
            /* it's autojoin channel though, so create it */
            irc_send_cmdv(server, "JOIN !%s", chanrec->name);
            g_free(params);
            return;
        }
    }

    check_join_failure(server, channel);
    g_free(params);
}
Esempio n. 4
0
/* Send the auto send command to channel */
void channel_send_autocommands(CHANNEL_REC *channel)
{
	CHANNEL_SETUP_REC *rec;
	NICK_REC *nick;
	char **bots, **bot;

	g_return_if_fail(IS_CHANNEL(channel));

	rec = channel_setup_find(channel->name, channel->server->connrec->chatnet);
	if (rec == NULL || rec->autosendcmd == NULL || !*rec->autosendcmd)
		return;

	if (rec->botmasks == NULL || !*rec->botmasks) {
		/* just send the command. */
		eval_special_string(rec->autosendcmd, "", channel->server, channel);
		return;
	}

	/* find first available bot.. */
	bots = g_strsplit(rec->botmasks, " ", -1);
	for (bot = bots; *bot != NULL; bot++) {
		const char *botnick = *bot;

		nick = nicklist_find_mask(channel,
					  channel->server->isnickflag(*botnick) ?
					  botnick+1 : botnick);
		if (nick != NULL &&
		    match_nick_flags(channel->server, nick, *botnick)) {
			eval_special_string(rec->autosendcmd, nick->nick,
					    channel->server, channel);
			break;
		}
	}
	g_strfreev(bots);
}
Esempio n. 5
0
static void cmd_channel_add_modify(const char *data, gboolean add)
{
	GHashTable *optlist;
        CHATNET_REC *chatnetrec;
	CHANNEL_SETUP_REC *rec;
	char *botarg, *botcmdarg, *chatnet, *channel, *password;
	void *free_arg;

	if (!cmd_get_params(data, &free_arg, 3 | PARAM_FLAG_OPTIONS,
		"channel add", &optlist, &channel, &chatnet, &password))
		return;

	if (*chatnet == '\0' || *channel == '\0') {
		cmd_param_error(CMDERR_NOT_ENOUGH_PARAMS);
	}

	chatnetrec = chatnet_find(chatnet);
	if (chatnetrec == NULL) {
		printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE,
			TXT_UNKNOWN_CHATNET, chatnet);
		cmd_params_free(free_arg);
		return;
	}

	botarg = g_hash_table_lookup(optlist, "bots");
	botcmdarg = g_hash_table_lookup(optlist, "botcmd");

	rec = channel_setup_find(channel, chatnet);
	if (rec == NULL) {
		if (add == FALSE) {
			printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE,
				TXT_CHANSETUP_NOT_FOUND, channel, chatnet);
			cmd_params_free(free_arg);
			return;
		}

		rec = CHAT_PROTOCOL(chatnetrec)->create_channel_setup();
		rec->name = g_strdup(channel);
		rec->chatnet = g_strdup(chatnet);
	} else {
		if (g_hash_table_lookup(optlist, "bots")) g_free_and_null(rec->botmasks);
		if (g_hash_table_lookup(optlist, "botcmd")) g_free_and_null(rec->autosendcmd);
		if (*password != '\0') g_free_and_null(rec->password);
	}
	if (g_hash_table_lookup(optlist, "auto")) rec->autojoin = TRUE;
	if (g_hash_table_lookup(optlist, "noauto")) rec->autojoin = FALSE;
	if (botarg != NULL && *botarg != '\0') rec->botmasks = g_strdup(botarg);
	if (botcmdarg != NULL && *botcmdarg != '\0') rec->autosendcmd = g_strdup(botcmdarg);
	if (*password != '\0' && g_strcmp0(password, "-") != 0) rec->password = g_strdup(password);

	signal_emit("channel add fill", 2, rec, optlist);

	channel_setup_create(rec);
	printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE,
		    TXT_CHANSETUP_ADDED, channel, chatnet);

	cmd_params_free(free_arg);
}
Esempio n. 6
0
/* SYNTAX: CHANNEL REMOVE <channel> <network> */
static void cmd_channel_remove(const char *data)
{
	CHANNEL_SETUP_REC *rec;
	char *chatnet, *channel;
	void *free_arg;

	if (!cmd_get_params(data, &free_arg, 2, &channel, &chatnet))
		return;
	if (*chatnet == '\0' || *channel == '\0')
		cmd_param_error(CMDERR_NOT_ENOUGH_PARAMS);

	rec = channel_setup_find(channel, chatnet);
	if (rec == NULL)
		printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE, TXT_CHANSETUP_NOT_FOUND, channel, chatnet);
	else {
		printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE, TXT_CHANSETUP_REMOVED, channel, chatnet);
		channel_setup_remove(rec);
	}
	cmd_params_free(free_arg);
}
Esempio n. 7
0
static void irc_channels_join(IRC_SERVER_REC *server, const char *data,
			      int automatic)
{
	CHANNEL_SETUP_REC *schannel;
	IRC_CHANNEL_REC *chanrec;
	GString *outchans, *outkeys;
	char *channels, *keys, *key;
	char **chanlist, **keylist, **tmp, **tmpkey, *channel, *channame;
	void *free_arg;
	int use_keys;

	g_return_if_fail(data != NULL);
	g_return_if_fail(IS_IRC_SERVER(server) && server->connected);
	if (*data == '\0') return;

	if (!cmd_get_params(data, &free_arg, 2 | PARAM_FLAG_GETREST,
			    &channels, &keys))
		return;

        chanlist = g_strsplit(channels, ",", -1);
	keylist = g_strsplit(keys, ",", -1);

	outchans = g_string_new(NULL);
	outkeys = g_string_new(NULL);

	use_keys = *keys != '\0';
	tmpkey = keylist;
	for (tmp = chanlist; *tmp != NULL; tmp++) {
		channel = ischannel(**tmp) ? g_strdup(*tmp) :
			g_strdup_printf("#%s", *tmp);

		chanrec = irc_channel_find(server, channel);
		if (chanrec == NULL) {
			schannel = channel_setup_find(channel, server->connrec->chatnet);

                        g_string_sprintfa(outchans, "%s,", channel);
                        if (*tmpkey != NULL && **tmpkey != '\0')
                        	key = *tmpkey;
                        else if (schannel != NULL && schannel->password != NULL) {
				/* get password from setup record */
                                use_keys = TRUE;
				key = schannel->password;
			} else key = NULL;

			g_string_sprintfa(outkeys, "%s,", get_join_key(key));
			channame = channel + (channel[0] == '!' &&
					      channel[1] == '!');
			chanrec = irc_channel_create(server, channame,
						     automatic);
			if (key != NULL) chanrec->key = g_strdup(key);
		}
		g_free(channel);

		if (*tmpkey != NULL)
                        tmpkey++;
	}

	if (outchans->len > 0) {
		g_string_truncate(outchans, outchans->len-1);
		g_string_truncate(outkeys, outkeys->len-1);
		irc_send_cmdv(IRC_SERVER(server),
			      use_keys ? "JOIN %s %s" : "JOIN %s",
			      outchans->str, outkeys->str);
	}

	g_string_free(outchans, TRUE);
	g_string_free(outkeys, TRUE);

	g_strfreev(chanlist);
	g_strfreev(keylist);

	cmd_params_free(free_arg);
}
Esempio n. 8
0
static void irc_channels_join(IRC_SERVER_REC *server, const char *data,
			      int automatic)
{
	CHANNEL_SETUP_REC *schannel;
	IRC_CHANNEL_REC *chanrec;
	GString *outchans, *outkeys;
	char *channels, *keys, *key, *space;
	char **chanlist, **keylist, **tmp, **tmpkey, **tmpstr, *channel, *channame;
	void *free_arg;
	int use_keys, cmdlen;

	g_return_if_fail(data != NULL);
	g_return_if_fail(IS_IRC_SERVER(server) && server->connected);
	if (*data == '\0') return;

	if (!cmd_get_params(data, &free_arg, 2 | PARAM_FLAG_GETREST,
			    &channels, &keys))
		return;

	/* keys shouldn't contain space */
	space = strchr(keys, ' ');
	if (space != NULL) {
		*space = '\0';
	}

        chanlist = g_strsplit(channels, ",", -1);
	keylist = g_strsplit(keys, ",", -1);

	outchans = g_string_new(NULL);
	outkeys = g_string_new(NULL);

	use_keys = *keys != '\0';
	tmpkey = keylist;
	tmp = chanlist;
	for (;; tmp++) {
		if (*tmp !=  NULL) {
			channel = ischannel(**tmp) ? g_strdup(*tmp) :
			g_strdup_printf("#%s", *tmp);

			chanrec = irc_channel_find(server, channel);
			if (chanrec == NULL) {
				schannel = channel_setup_find(channel, server->connrec->chatnet);

				g_string_sprintfa(outchans, "%s,", channel);
				if (*tmpkey != NULL && **tmpkey != '\0')
                        		key = *tmpkey;
	                        else if (schannel != NULL && schannel->password != NULL) {
					/* get password from setup record */
                	                use_keys = TRUE;
					key = schannel->password;
				} else key = NULL;
				
				g_string_sprintfa(outkeys, "%s,", get_join_key(key));
				channame = channel + (channel[0] == '!' &&
						      channel[1] == '!');
				chanrec = irc_channel_create(server, channame, NULL,
							     automatic);
				if (key != NULL) chanrec->key = g_strdup(key);
			}
			g_free(channel);

			if (*tmpkey != NULL)
                	        tmpkey++;
	
			tmpstr = tmp;
			tmpstr++;
			cmdlen = outchans->len-1;
			
			if (use_keys)
				cmdlen += outkeys->len;
			if (*tmpstr != NULL)
				cmdlen += ischannel(**tmpstr) ? strlen(*tmpstr) :
					  strlen(*tmpstr)+1;
			if (*tmpkey != NULL)
				cmdlen += strlen(*tmpkey);
				
			/* don't try to send too long lines 
			   make sure it's not longer than 510
			   so 510 - strlen("JOIN ") = 505 */
			if (cmdlen < 505)
				continue;
		}
		if (outchans->len > 0) {
			g_string_truncate(outchans, outchans->len-1);
			g_string_truncate(outkeys, outkeys->len-1);
			irc_send_cmdv(IRC_SERVER(server),
				      use_keys ? "JOIN %s %s" : "JOIN %s",
				      outchans->str, outkeys->str);
		}
		cmdlen = 0;
		g_string_truncate(outchans,0);
		g_string_truncate(outkeys,0);
		if (*tmp == NULL || tmp[1] == NULL)
			break;
	}
	g_string_free(outchans, TRUE);
	g_string_free(outkeys, TRUE);

	g_strfreev(chanlist);
	g_strfreev(keylist);

	cmd_params_free(free_arg);
}