Exemple #1
0
static void quote_forget(irc_t *irc, const char *channel, const char *user, list_t *list) {
    char *quotenick    = list_shift(list);
    char *quotemessage = list_shift(list);

    if (!quotenick || !quotemessage)
        return;
    if (!quote_access_check(irc, user))
        return;

    quote_nick_stripspecial(&quotenick);

    if (!quote_find(quotenick, quotemessage))
        return irc_write(irc, channel, "%s: Sorry, could not find any quotes like \"%s %s\"",
            user,
            quotenick,
            quotemessage
        );

    database_statement_t *statement = database_statement_create("DELETE FROM QUOTES WHERE NAME = ? AND CONTENT = ?");
    if (!database_statement_bind(statement, "ss", quotenick, quotemessage))
        return;
    if (!database_statement_complete(statement))
        return;

    irc_write(irc, channel, "%s: Ok, removed - \"%s %s..\" - from the quote db",
        user,
        quotenick,
        quotemessage
    );
}
Exemple #2
0
void popMsg()
{
	if(bytets < time(NULL) - 1)
	{
		bytets = time(NULL);
		if(bper >= 75) 
			bper -= 75;
	}
//	printf("Debug: %d bytes\n", bper);
	
	if(bper > CLIENT_FLOOD_AUX)
		return;

	if(sendQ.highSize == 0)
	{
		if((sendQ.lowSize > 0) && (lastMsg < time(0) - LOWMSG_DELAY))
		{
			bper += strlen(sendQ.low[0].message);
			irc_write(sendQ.low[0].message);
			free(sendQ.low[0].message);
			memcpy(sendQ.low, &sendQ.low[1], --sendQ.lowSize * sizeof(struct nodeQ) );
		}
	} else if( (lastMsg < time(0) - HIGHMSG_DELAY) || (bper < CLIENT_FLOOD_LOW) ) {
		bper += strlen(sendQ.high[0].message);
		irc_write(sendQ.high[0].message);
		free(sendQ.high[0].message);
		memcpy(sendQ.high, &sendQ.high[1], --sendQ.highSize * sizeof(struct nodeQ) );
	}
	return;
}
Exemple #3
0
int public_userlistcmd(nick *np, channel *cp, int argc, char **argv) {
    account *tmp, **list;
    nicklist *nlp;
    bucket *bp;
    chanlevel *clp;
    char buffer[512], formatspace[512];
    int i, j, x, count, state, nicks;
    
    i = j = x = count = state = 0;
    
    if (!argc && CAtleastVoice(np->account->dbuser)) /* So the user can safely request the global userlist too */
        cp = NULL;
    
    if (!cp && !CAtleastVoice(np->account->dbuser)) {
        irc_write(QUEUE_NORMAL, "NOTICE %s :try userlist <#channel>", np->name);
        return 0;
    } else if (cp && (((clp = findchanlevel(cp, np->account)) && CAtleastKnown(clp)) || (CAtleastOp(np->account->dbuser)))) {
        /* View the userlist for a channel */
        printlog("Userlist - channel %s", cp->name);
        for (i = DBF_OWNER; i; i >>= 1) {

            buffer[0] = '\0';
            count = 0;
            for (clp = cp->chanlevels; clp; clp = clp->nextbychan) {
                if ((clp->flags & i) && !(clp->account->status & USTAT_ISMARKED)) {
                    if (clp->account->loggedin) {
                        nicks = 0;
                        for (nlp = clp->account->nicks; nlp; nlp = nlp->next) {
                            snprintf(formatspace, sizeof(formatspace), "%s%s%s%s%s", (count++ && !nicks) ? " " : "", !nicks ? "[" : "", nicks ? ", " : "", nlp->nick->name, (nlp->next == NULL) ? "]" : "");
                            strcat(buffer, formatspace);
                        }
                    } else {
                        snprintf(formatspace, sizeof(formatspace), "%s[#%s]", count++ ? " " : "", clp->account->name);
                        strcat(buffer, formatspace);
                    }
                    clp->account->status |= USTAT_ISMARKED;
                }
                
                if ((count > 10) || (count && strlen(buffer))) {
                    if (!state) {
                        irc_write(QUEUE_SLOW, "NOTICE %s :userlist for %s:", np->name, cp->name);
                        state = 1;
                    }
                    irc_write(QUEUE_SLOW, "NOTICE %s :channel %s%s: %s", np->name, findtype(i), (count == 1) ? "" : "s", buffer);
                    count = 0;
                }
            }

        }

        for (clp = cp->chanlevels; clp; clp = clp->nextbychan)
            clp->account->status &= ~USTAT_ISMARKED;
    } else {
Exemple #4
0
static void mod_load(irc_t *irc, const char *channel, const char *user, const char *module) {
    switch (irc_modules_add(irc, module)) {
        case MODULE_STATUS_FAILURE:
            return irc_write(irc, channel, "%s: failed to load module %s", user, module);
        case MODULE_STATUS_SUCCESS:
            return irc_write(irc, channel, "%s: module %s loaded", user, module);
        case MODULE_STATUS_ALREADY:
            return irc_write(irc, channel, "%s: modules %s is already loaded", user, module);
        default:
            break;
    }
}
Exemple #5
0
int irc_autorejoin(session_t *s, int when, char *chan) {
	irc_private_t *j;
	string_t st;
	window_t *w;
	char *chanprefix;
	int rejoin;

#if 1	/* there's no need of doing it, already checked by irc_onkick_handler() or if it goes through irc_c_init() it's even better. */
	if (!s || !(j = s->priv) || (s->plugin != &irc_plugin))
		return -1;
#endif
	chanprefix = SOP(_005_CHANTYPES);
	rejoin = session_int_get(s, "REJOIN");

	if (!(rejoin&(1<<(when))))
		return -1;

	switch (when) {
		case IRC_REJOIN_CONNECT:
			st = string_init(NULL);
			for (w = windows; w; w = w->next) {
				if (!w->target || w->session != s)			/* check if sessions match and has w->target */
					continue;

				if (valid_plugin_uid(s->plugin, w->target) != 1)	/* check if window is correct for irc: */
					continue;

				if (!xstrchr(chanprefix, (w->target)[4]))		/* check if this is channel.. */
					continue;

				if (st->len)
					string_append_c(st, ',');
				if ((w->target)[4] == '!') {
					string_append_c(st, '!');
					string_append(st, w->target + 10);
				} else {
					string_append(st, w->target + 4);
				}
			}
			if (st->len)
				irc_write(s, "JOIN %s\r\n", st->str);
			string_free(st, 1);
			break;

		case IRC_REJOIN_KICK:
			irc_write(s, "JOIN %s\r\n", chan);
			break;

		default:
			return -1;
	}
	return 0;
}
Exemple #6
0
static void mod_reload(irc_t *irc, const char *channel, const char *user, const char *module) {
    if (!mod_check(irc, channel, user, module, "reload"))
        return;

    switch (irc_modules_reload(irc, module)) {
        case MODULE_STATUS_FAILURE:
            return irc_write(irc, channel, "%s: failed to reload module %s", user, module);
        case MODULE_STATUS_SUCCESS:
            return irc_write(irc, channel, "%s: Ok, module %s reloaded", user, module);
        default:
            break;
    }
}
Exemple #7
0
void irc_init(void)
{
    /*****************************************
     * Now connected, start sending commands *
     *****************************************/
        irc_write(bformat("PASS %s", bdata(config.password))); /* PASS password */
        irc_write(bformat("NICK %s", bdata(config.nickname))); /* NICK nickname */
        irc_write(bformat("USER %s %s %s :%s", bdata(config.ident), bdata(config.host), bdata(config.server_address), bdata(config.name))); /* USER ident host server :name */
    /**********************************
     * Read socket and stay connected *
     **********************************/
    irc_read();
}
Exemple #8
0
/*
 * Replay quicklog data.
 */
void
qlog_replay(connection_type *client, time_t oldest)
{
    list_type *iter;
#ifdef QLOGSTAMP
    char qlogbuf[IRC_MSGLEN];
#endif /* QLOGSTAMP */

    if (client == NULL) {
#ifdef ENDUSERDEBUG
        enduserdebug("qlog_replay(NULL, oldest)");
#endif /* ifdef ENDUSERDEBUG */
        return;
    }

    if (oldest != 0) {
        oldest = time(NULL) - oldest;
    }

    /* Walk through quicklog. */
    for (iter = qlog; iter != NULL; iter = iter->next) {
        qlogentry *entry;
        entry = (qlogentry *) iter->data;

        /* also skip too old entries */
        if (entry->timestamp < oldest) {
            continue;
        }

        if (cfg.qlog_no_my_quit == 1) {
            if (is_my_quit(entry->text) == 1) {
                continue;
            }
        }

#ifdef QLOGSTAMP
        if (cfg.timestamp != TS_NONE) {
            const char *out;
            out = qlog_add_timestamp(entry, qlogbuf, IRC_MSGLEN);
            irc_write(client, "%s", out);
        } else {
            irc_write(client, "%s", entry->text);
        }
#else /* ifdef QLOGSTAMP */
        irc_write(client, "%s", entry->text);
#endif /* ifdef else QLOGSTAMP */
    }
} /* void qlog_replay(connection_type *client, time_t oldest) */
Exemple #9
0
/* immed=1 makes this function pretty much equal to irc_free(), except that
   this one will "log". In case the connection is already broken and we
   shouldn't try to write to it. */
void irc_abort(irc_t *irc, int immed, char *format, ...)
{
	char *reason = NULL;

	if (format != NULL) {
		va_list params;

		va_start(params, format);
		reason = g_strdup_vprintf(format, params);
		va_end(params);
	}

	if (reason) {
		irc_write(irc, "ERROR :Closing link: %s", reason);
	}

	ipc_to_master_str("OPERMSG :Client exiting: %s@%s [%s]\r\n",
	                  irc->user->nick ? irc->user->nick : "(NONE)",
	                  irc->user->host, reason ? : "");

	g_free(reason);

	irc_flush(irc);
	if (immed) {
		irc_free(irc);
	} else {
		b_event_remove(irc->ping_source_id);
		irc->ping_source_id = b_timeout_add(1, (b_event_handler) irc_free, irc);
	}
}
Exemple #10
0
Fichier : irc.c Projet : csko/yaosp
static int irc_handle_connect_finish( event_t* event ) {
    int error;
    socklen_t len;
    size_t length;
    char buffer[ 256 ];

    event_manager_remove_event( &irc_connect );

    /* Check if connect() was successful or not. */

    len = sizeof(int);
    getsockopt( sock, SOL_SOCKET, SO_ERROR, &error, &len );

    if ( error != 0 ) {
        ui_error_message( "Failed to connect to the server.\n" );
        return 0;
    }

    ui_error_message( "Connected to the server.\n" );

    event_init( &irc_read );
    irc_read.fd = sock;
    irc_read.events[ EVENT_READ ].interested = 1;
    irc_read.events[ EVENT_READ ].callback = irc_handle_incoming;

    event_manager_add_event( &irc_read );

    length = snprintf( buffer, sizeof( buffer ),
        "NICK %s\r\nUSER %s SERVER \"elte.irc.hu\" :yaOSp IRC client\r\n", my_nick, my_nick
    );
    irc_write( sock, buffer, length );

    return 0;
}
Exemple #11
0
Fichier : irc.c Projet : csko/yaosp
int irc_handle_ping(const char* params){
    char buf[256];
    int length;

    length = snprintf(buf, sizeof(buf), "PONG %s\n", params);

    return irc_write(sock, buf, length);
}
Exemple #12
0
void quickMsg(char *message)
{
	if(bper > CLIENT_FLOOD)
		highMsg(message);
	else
		irc_write(message);
	return;
}
Exemple #13
0
static void ipc_child_cmd_wallops( irc_t *irc, char **cmd )
{
	if( !( irc->status & USTATUS_LOGGED_IN ) )
		return;
	
	if( strchr( irc->umode, 'w' ) )
		irc_write( irc, ":%s WALLOPS :%s", irc->root->host, cmd[1] );
}
Exemple #14
0
static void ipc_child_cmd_opermsg( irc_t *irc, char **cmd )
{
	if( !( irc->status & USTATUS_LOGGED_IN ) )
		return;
	
	if( strchr( irc->umode, 'o' ) )
		irc_write( irc, ":%s NOTICE %s :*** OperMsg *** %s", irc->root->host, irc->user->nick, cmd[1] );
}
Exemple #15
0
void irc_send_join(irc_channel_t *ic, irc_user_t *iu)
{
	irc_t *irc = ic->irc;

	if (irc->caps & CAP_EXTENDED_JOIN) {
		irc_write(irc, ":%s!%s@%s JOIN %s * :%s", iu->nick, iu->user, iu->host, ic->name, iu->fullname);
	} else {
		irc_write(irc, ":%s!%s@%s JOIN :%s", iu->nick, iu->user, iu->host, ic->name);
	}

	if (iu == irc->user) {
		if (ic->topic && *ic->topic) {
			irc_send_topic(ic, FALSE);
		}
		irc_send_names(ic);
	}
}
Exemple #16
0
Fichier : irc.c Projet : csko/yaosp
int irc_join_channel( const char* channel ) {
    char buf[ 128 ];
    size_t length;

    length = snprintf( buf, sizeof( buf ), "JOIN %s\r\n", channel );
    irc_write( sock, buf, length );

    return 0;
}
Exemple #17
0
Fichier : irc.c Projet : csko/yaosp
int irc_part_channel( const char* channel, const char* message ) {
    char buf[ 256 ];
    size_t length;

    length = snprintf( buf, sizeof( buf ), "PART %s :%s\r\n", channel, message );
    irc_write( sock, buf, length );

    return 0;
}
Exemple #18
0
static bool quote_access_check(irc_t *irc, const char *user) {
    if (access_range(irc, user, ACCESS))
        return true;

    int access = 0;
    access_level(irc, user, &access);
    irc_write(irc, user, "Sorry, you have level %d but need level %d to do that", access, ACCESS);
    return false;
}
Exemple #19
0
Fichier : irc.c Projet : csko/yaosp
int irc_send_privmsg( const char* channel, const char* message ) {
    char buf[ 256 ];
    size_t length;

    length = snprintf( buf, sizeof( buf ), "PRIVMSG %s :%s\r\n", channel, message );
    irc_write( sock, buf, length );

    return 0;
}
Exemple #20
0
Fichier : irc.c Projet : csko/yaosp
int irc_raw_command( const char* command ) {
    char buf[ 256 ];
    size_t length;

    length = snprintf( buf, sizeof( buf ), "%s\r\n", command );
    irc_write( sock, buf, length );

    return 0;
}
Exemple #21
0
/* quote <nick> */
static void quote_entry(irc_t *irc, const char *channel, const char *user, const char *nick) {
    database_statement_t *statement = database_statement_create("SELECT * FROM QUOTES WHERE NAME = ? ORDER BY RANDOM() LIMIT 1");
    if (!database_statement_bind(statement, "s", nick))
        return;
    database_row_t *row = database_row_extract(statement, "ss");
    if (!row)
        return irc_write(irc, channel, "%s: Sorry, could not find any quotes like \"%s\"", user, nick);

    const char *quotenick    = database_row_pop_string(row);
    const char *quotemessage = database_row_pop_string(row);

    if (!database_statement_complete(statement))
        return;

    database_request(irc, "QUOTES");

    irc_write(irc, channel, "%s: <%s> %s", user, quotenick, quotemessage);
}
Exemple #22
0
static int
iprintf(const char *fmt, ...)
{
	char buf[1024];
	va_list l;
	va_start(l, fmt);
	int r = vsnprintf(buf, sizeof buf, fmt, l);
	va_end(l);
	return !irc_write(g_irc, buf) ? -1 : r;
}
Exemple #23
0
static bool mod_check(irc_t *irc, const char *channel, const char *user, const char *module, const char *from) {
    for (size_t i = 0; i < sizeof(mod_mask)/sizeof(*mod_mask); i++) {
        if (!strcmp(module, mod_mask[i])) {
            if (from)
                irc_write(irc, channel, "%s: module %s cannot be %sed", user, module, from);
            return false;
        }
    }
    return true;
}
Exemple #24
0
static void quote_stats(irc_t *irc, const char *channel, const char *user, list_t *list) {
    const char *who = list_shift(list);
    if (!who) {
        int count   = quote_length();
        int request = database_request_count(irc, "QUOTES");

        return irc_write(irc, channel, "%s: quote stats -> %d quotes -> requested %d times", user, count, request);
    }

    int count = 0;
    if (!quote_count(who, &count))
        return irc_write(irc, channel, "%s: %s has no quotes", user, who);

    const char *plural = (count > 1) ? "quotes" : "quote";
    if (strcmp(user, who))
        irc_write(irc, channel, "%s: %s has %d %s", user, who, count, plural);
    else
        irc_write(irc, channel, "%s: you have %d %s", user, count, plural);
}
Exemple #25
0
static void ipc_child_cmd_kill( irc_t *irc, char **cmd )
{
	if( !( irc->status & USTATUS_LOGGED_IN ) )
		return;
	
	if( nick_cmp( NULL, cmd[1], irc->user->nick ) != 0 )
		return;		/* It's not for us. */
	
	irc_write( irc, ":%s!%s@%s KILL %s :%s", irc->root->nick, irc->root->nick, irc->root->host, irc->user->nick, cmd[2] );
	irc_abort( irc, 0, "Killed by operator: %s", cmd[2] );
}
Exemple #26
0
char *set_eval_ops( set_t *set, char *value )
{
	irc_t *irc = set->data;
	
	if( g_strcasecmp( value, "user" ) == 0 )
		irc_write( irc, ":%s!%s@%s MODE %s %s %s %s", irc->mynick, irc->mynick, irc->myhost,
		                                              irc->channel, "+o-o", irc->nick, irc->mynick );
	else if( g_strcasecmp( value, "root" ) == 0 )
		irc_write( irc, ":%s!%s@%s MODE %s %s %s %s", irc->mynick, irc->mynick, irc->myhost,
		                                              irc->channel, "-o+o", irc->nick, irc->mynick );
	else if( g_strcasecmp( value, "both" ) == 0 )
		irc_write( irc, ":%s!%s@%s MODE %s %s %s %s", irc->mynick, irc->mynick, irc->myhost,
		                                              irc->channel, "+oo", irc->nick, irc->mynick );
	else if( g_strcasecmp( value, "none" ) == 0 )
		irc_write( irc, ":%s!%s@%s MODE %s %s %s %s", irc->mynick, irc->mynick, irc->myhost,
		                                              irc->channel, "-oo", irc->nick, irc->mynick );
	else
		return SET_INVALID;
	
	return value;
}
Exemple #27
0
static void quote_add(irc_t *irc, const char *channel, const char *user, list_t *list) {
    char *quotenick    = list_shift(list);
    char *quotemessage = list_shift(list);

    if (!quotenick || !quotemessage)
        return;
    if (!quote_access_check(irc, user))
        return;

    quote_nick_stripspecial(&quotenick);

    if (quote_find(quotenick, quotemessage))
        return irc_write(irc, channel, "%s: Quote already exists.", user);

    database_statement_t *statement = database_statement_create("INSERT INTO QUOTES (NAME, CONTENT) VALUES ( ?, ? )");
    if (!database_statement_bind(statement, "ss", quotenick, quotemessage))
        return;
    if (!database_statement_complete(statement))
        return;

    irc_write(irc, channel, "%s: Ok, added quote: <%s> %s", user, quotenick, quotemessage);
}
Exemple #28
0
Fichier : irc.c Projet : csko/yaosp
int irc_quit_server( const char* reason ) {
    char buf[ 256 ];
    size_t length;

    if ( reason == NULL ) {
        length = snprintf( buf, sizeof( buf ), "QUIT :Leaving...\r\n" );
    } else {
        length = snprintf( buf, sizeof( buf ), "QUIT :%s\r\n", reason );
    }

    irc_write( sock, buf, length );

    return 0;
}
Exemple #29
0
static void quote_reauthor(irc_t *irc, const char *channel, const char *user, list_t *list) {
    char *from = list_shift(list);
    char *to   = list_shift(list);

    if (!from || !to)
        return quote_help(irc, channel, user);
    if (!quote_access_check(irc, user))
        return;

    quote_nick_stripspecial(&from);
    quote_nick_stripspecial(&to);

    int count = 0;
    if (!quote_count(from, &count))
        return irc_write(irc, channel, "%s: Sorry, could not find any quotes by \"%s\"", user, from);

    database_statement_t *statement = database_statement_create("UPDATE QUOTES SET NAME=? WHERE NAME=?");
    if (!database_statement_bind(statement, "ss", to, from))
        return;
    if (!database_statement_complete(statement))
        return;

    irc_write(irc, channel, "%s: Ok, reauthored %d %s from %s to %s", user, count, count > 1 ? "quotes" : "quote", from, to);
}
Exemple #30
0
int establish_connection() {
    /* For connecting */
    char *hostname, *port;
    /* For introduction purposes */
    char *nickname, *username, *realname;

    hostname = getconf("server", NULL);
    port     = getconf("port", "6667");

    nickname = getconf("nickname", NULL);
    username = getconf("username", NULL);
    realname = getconf("realname", NULL);

    if (!hostname || !nickname || !username || !realname) {
        printlog("You are missing some variables from the configuration file, "
               "please check the configuration file for the missing values of: %s%s%s%s%s%s%s",
               !hostname ? "server" : "", !hostname ? " " : "", !nickname ? "nickname" : "", 
               !nickname ? " " : "", !username ? "username" : "", !username ? " " : "", 
               !realname ? "realname" : "");
        exit(1);
    }

    if (irc_connect(hostname, atoi(port))) {
        /* If we connected, lets introduce ourselves to the server */
        
        /* Only copy the nickname until we use USERHOST on the server to find out our real host */
        bi.botuser = addtouser(NULL, nickname, NULL, NULL);
        
        irc_write(QUEUE_SERVER, "USER %s 127.0.0.1 localhost :%s", username, realname);
        irc_write(QUEUE_SERVER, "NICK %s", nickname);

        return 1;
    }

    return 0;
}