void event_channel (irc_session_t * session, const char * event, const char * origin, const char ** params, unsigned int count)
{
	char nickbuf[128];

	if ( count != 2 )
		return;

	printf ("'%s' said in channel %s: %s\n", 
		origin ? origin : "someone",
		params[0], params[1] );

	if ( !origin )
		return;

	irc_target_get_nick (origin, nickbuf, sizeof(nickbuf));

	if ( !strcmp (params[1], "quit") )
		irc_cmd_quit (session, "of course, Master!");

	if ( !strcmp (params[1], "help") )
	{
		irc_cmd_msg (session, params[0], "quit, help, dcc chat, dcc send, ctcp");
	}

	if ( !strcmp (params[1], "ctcp") )
	{
		irc_cmd_ctcp_request (session, nickbuf, "PING 223");
		irc_cmd_ctcp_request (session, nickbuf, "FINGER");
		irc_cmd_ctcp_request (session, nickbuf, "VERSION");
		irc_cmd_ctcp_request (session, nickbuf, "TIME");
	}

	if ( !strcmp (params[1], "dcc chat") )
	{
		irc_dcc_t dccid;
		irc_dcc_chat (session, 0, nickbuf, dcc_recv_callback, &dccid);
		printf ("DCC chat ID: %d\n", dccid);
	}

	if ( !strcmp (params[1], "dcc send") )
	{
		irc_dcc_t dccid;
		irc_dcc_sendfile (session, 0, nickbuf, "irctest.c", dcc_file_recv_callback, &dccid);
		printf ("DCC send ID: %d\n", dccid);
	}

	if ( !strcmp (params[1], "topic") )
		irc_cmd_topic (session, params[0], 0);
	else if ( strstr (params[1], "topic ") == params[1] )
		irc_cmd_topic (session, params[0], params[1] + 6);

	if ( strstr (params[1], "mode ") == params[1] )
		irc_cmd_channel_mode (session, params[0], params[1] + 5);

	if ( strstr (params[1], "nick ") == params[1] )
		irc_cmd_nick (session, params[1] + 5);

	if ( strstr (params[1], "whois ") == params[1] )
		irc_cmd_whois (session, params[1] + 5);
}
Exemple #2
0
/*
void botcmd_clones(irc_session_t* session, const char* send_to, const char* sender) {
    bool* checked;
    unsigned int i;
    unsigned int j;
    char buf[256];
    bool found;

    printf("Clones query requested by %s\n", sender);
    checked = malloc(name_count * sizeof(bool));

    for (i = 0; i < name_count; i++) {
        for (j = i + 1; j < name_count; j++) {
            strcpy(buf, "");
            sprintf(buf, "%s is clone of: ", name_list[i]);
            found = false;

            if (strcmp(host_list[i], host_list[j]) == 0) {
                strcat(buf, " ");
                strcat(buf, name_list[i]);
                checked[j] = true;
            }
        }
    
        if (found) {
            printf("Clone Results: %s", buf);
            irc_cmd_notice(session, send_to, buf);
        }

        checked[i] = true;
    }

    free(checked);
}
*/
void botcmd_quit(irc_session_t* session) {
    bot_exiting = true;

    if (session != NULL) {
        irc_cmd_quit(session, BOT_QUIT_MSG);
    }
}
Exemple #3
0
static void irc_close(GaimConnection *gc)
{
	struct irc_conn *irc = gc->proto_data;

	if (irc == NULL)
		return;

	if (irc->gsc || (irc->fd >= 0))
		irc_cmd_quit(irc, "quit", NULL, NULL);

	if (gc->inpa)
		gaim_input_remove(gc->inpa);

	g_free(irc->inbuf);
	if (irc->gsc) {
		gaim_ssl_close(irc->gsc);
	} else if (irc->fd >= 0) {
		close(irc->fd);
	}
	if (irc->timer)
		gaim_timeout_remove(irc->timer);
	g_hash_table_destroy(irc->cmds);
	g_hash_table_destroy(irc->msgs);
	g_hash_table_destroy(irc->buddies);
	if (irc->motd)
		g_string_free(irc->motd, TRUE);
	g_free(irc->server);

	if (irc->writeh)
		gaim_input_remove(irc->writeh);

	gaim_circ_buffer_destroy(irc->outbuf);

	g_free(irc);
}
Exemple #4
0
void cmd_quit(irc_session_t* session, const char* cmd, const char* origin, char* args) {
    if(!strcmp(origin, master_origin)) {
        if(args[0] == '\0') {
            irc_cmd_msg(session, channel, "bien sûr, Maître !");
            irc_cmd_quit(session, NULL);
        }
    } else {
        char nick[20];
        irc_target_get_nick(origin, nick, 20);
        char msg[100];
        sprintf(msg, "%s: bien essayé :>", nick);
        irc_cmd_msg(session, channel, msg);
    }
}
void irc_auto_rename_nick(irc_session_t *session)
{
    static int tries=0;
    CslIrcContext *context=(CslIrcContext*)irc_get_ctx(session);

    if (++tries<2)
    {
        //context->Server->Network->Nick+=wxT("'");
        context->Server->Network->Nick=context->Server->Network->AltNick;
        irc_cmd_nick(session,U2A(context->Server->Network->AltNick));
    }
    else
        irc_cmd_quit(session,NULL);
}
Exemple #6
0
static void irc_close(PurpleConnection *gc)
{
	struct irc_conn *irc = gc->proto_data;

	if (irc == NULL)
		return;

	if (irc->gsc || (irc->fd >= 0))
		irc_cmd_quit(irc, "quit", NULL, NULL);

	if (gc->inpa)
		purple_input_remove(gc->inpa);

	g_free(irc->inbuf);
	if (irc->gsc) {
		purple_ssl_close(irc->gsc);
	} else if (irc->fd >= 0) {
		close(irc->fd);
	}
	if (irc->timer)
		purple_timeout_remove(irc->timer);
	g_hash_table_destroy(irc->cmds);
	g_hash_table_destroy(irc->msgs);
	g_hash_table_destroy(irc->buddies);
	if (irc->motd)
		g_string_free(irc->motd, TRUE);
	g_free(irc->server);

	if (irc->writeh)
		purple_input_remove(irc->writeh);

	purple_circ_buffer_destroy(irc->outbuf);

	g_free(irc->mode_chars);
	g_free(irc->reqnick);

#ifdef HAVE_CYRUS_SASL
	if (irc->sasl_conn) {
		sasl_dispose(&irc->sasl_conn);
		irc->sasl_conn = NULL;
	}
	g_free(irc->sasl_cb);
	if(irc->sasl_mechs)
		g_string_free(irc->sasl_mechs, TRUE);
#endif


	g_free(irc);
}
Exemple #7
0
/*
====================
IRC_DisconnectSession

Disconnects from the IRC server.
====================
*/
void IRC_DisconnectSession(int handle, const char *reason) {
    irc_session_t *s;
    char fmtmsg[MAX_INPUTLINE];
    if(!IRC_SessionIsConnected(handle)) {
        IRC_Printf("Attempted to disconnect an unconnected session %i\n", handle);
        return;
    }
    
    s = &irc_sessions[handle];
    IRC_Translate_DP2IRC(reason, fmtmsg, sizeof(fmtmsg));
    irc_cmd_quit(s->session, fmtmsg);
    
    //if(IRC_SessionIsConnected(handle))
    //    irc_disconnect(s->session);
        
    IRC_Printf("Session %i disconnected\n", handle);
}
bool CslIrcSession::Disconnect(const wxString& message)
{
    if (!CslIrcEngine::GetThread() || m_state==STATE_DISCONNECTED)
        return false;

    wxString s;

    if (message.IsEmpty())
        s<<CSL_NAME_STR<<wxT(" ")<<CSL_VERSION_LONG_STR<<CSL_WEBADDRFULL_STR;
    else
        s=message;

    m_state=STATE_DISCONNECTED;

    irc_cmd_quit(m_context.Session,U2A(s));

    CslIrcEngine::GetThread()->Disconnect(m_context);

    return true;
}
Exemple #9
0
void ircCommands(irc_session_t * session,const char * origin,const char ** params,unsigned int settings)
{
	
	if (settings & QUIT && !strcmp (params[1], "!quit") )
		irc_cmd_quit (session, "Bot wird beendet...");
		
	if(strstr(params[1],botnick))
	{
		irc_cmd_msg(session, params[0][0] =='#' ? params[0] : origin ,"me?");
	}
	
	if (settings & NICK_CHANGE && strstr (params[1], "!nick") == params[1] )
	{
		sprintf(botnick,"%s",params[1] + 6);
		irc_cmd_nick (session, params[1] + 6);
	}

	if(settings & JOIN_PART)
	{	
		if(currentChannelCount < MAX_CHANNELS)
			if (strstr (params[1], "!join") == params[1] )
			{
				irc_cmd_join (session, params[1] + 6,0);
				currentChannelCount++;
			}

		if (strstr (params[1], "!part") == params[1] )
		{
			if(strstr(params[0],ctx.channel) == 0)
			{
				irc_cmd_part (session, params[0]);
				rmChannel(params[0]);
				currentChannelCount--;
			}
			else
			{
				irc_cmd_msg(session,params[0],"Hier geh ich net raus");
			}	
		
		}
	}

	if(settings & GET_TIME && strstr(params[1],"!time"))
	{	
		char tmp[60];
		time ( &rawtime );
		ptm = gmtime ( &rawtime );
	
		sprintf(tmp,"Es ist %2d:%02d\n", (ptm->tm_hour+GMT)%24, ptm->tm_min);
		irc_cmd_msg(session, params[0][0] =='#' ? params[0] : origin ,tmp);
	}

	if(settings & TOPIC_CHANGE)
	{
		if ( !strcmp (params[1], "!topic") )
			irc_cmd_topic (session, params[0], 0);
		else if ( strstr (params[1], "!topic ") == params[1] )
			irc_cmd_topic (session, params[0], params[1] + 7);
	}


	if(strstr(params[1],"!status"))
	{
		char tmp[80];
		sprintf(tmp,"Channelsettings = %d",getChannelSettings(params[0]));
		irc_cmd_msg(session,params[0],tmp);
	}

	if(strstr(params[1],"!set"))
	{
		int settings;
		char line[200];
		char parts[32][32];
		int i = 0;
		
		strcpy(line,params[1]);

		char *ptr =strtok(line," ");

		while(ptr !=NULL)
		{
			sprintf(parts[i],"%s",ptr);
			ptr = strtok(NULL, " ");
			i++;
		}
		
		settings = atoi(parts[2]);

		if(strstr(parts[2],"privmsg"))
		{		
			privmsg_settings = settings;	
		}
		else
		{
			setChannelSettings(parts[1],settings);
		}
	}

	if(strstr(params[1],"!debug"))
	{	
		int i;
		for(i=0;i<MAX_CHANNELS;i++)
			printf("%d=%s=%d\n",i,chansettings[i].channel,chansettings[i].settings);
	}
}
Exemple #10
0
/**
* @brief Private Message Event
* Diese Funktion wird aufgerufen, wenn der Bot eine Private Message erhält.
* Loggt das Event.
* Überprüft ob die geschickte Nachricht ein Befehl ist, wenn ja wird dieser ausgeführt.
* Reagiert auf quit, help, topic <text>, nick <name>, log, logon, logoff, time, lastseen <name>, mode, whois.
* @param session ein Pointer von irc_session_t, Session von der ein Event erzeugt wird.
* @param event ein konstanter char Pointer, Event Name
* @param origin ein konstanter char Pointer, Herkunfts Name (Person die die Private Nachricht geschickt hat)
* @param params const char, Liste der Parameter (0 - Eigener Nick, 1 - Message Text)
* @param count ein unsigned int, Anzahl der Parameter
*/
void event_privmsg (irc_session_t * session, const char * event, const char * origin, const char ** params, unsigned int count)
{

	printf ("'%s' said me (%s): %s\n", 
		origin ? origin : "someone",
		params[0], params[1] );
	
	if ( !origin )
		return;
	
	char nickbuf[128];
	irc_target_get_nick (origin, nickbuf, sizeof(nickbuf));
	
	if(logging==1)
	{
		char theTime[100];
		struct tm * clock;
		time_t sec;
		time(&sec);
		clock = localtime(&sec);
		strftime(theTime, sizeof(theTime), "%Y-%m-%d %H:%M:%S", clock);
	
		char message[1024];
		sprintf(message, "INSERT INTO log (name, chan, message, date) VALUES ('%s', 'said me (%s):', '%s', '%s');", nickbuf, params[0], params[1], theTime);
		logSQL(message);
	}
	
	if ( !strcmp (params[1], "quit") )
		irc_cmd_quit (session, "of course, Master!");

	if ( !strcmp (params[1], "help") )
	{
		irc_cmd_msg (session, nickbuf, "quit, help, topic <text>, nick <name>, log, logon, logoff, time, lastseen <name>");
	}
	
	if ( !strcmp (params[1], "time") )
	{
		char theTime[100];
		struct tm * clock;
		time_t sec;
		time(&sec);
		clock = localtime(&sec);
		strftime(theTime, sizeof(theTime), "%Y-%m-%d %H:%M:%S", clock);
		
		irc_cmd_msg (session, nickbuf, theTime);
	}
	
	if ( !strcmp (params[1], "logon") )
	{
		logging = 1;
		irc_cmd_msg (session, nickbuf, "Logging eingeschaltet");
	}
	
	if ( !strcmp (params[1], "logoff") )
	{
		logging = 0;
		irc_cmd_msg (session, nickbuf, "Logging ausgeschaltet");
	}
	if ( !strcmp (params[1], "log") )
	{
		sqlite3_stmt *vm;
		sqlite3_open(DB_FILE, &dbhandle);
	
		sqlite3_prepare(dbhandle, "SELECT * FROM log", -1, &vm, NULL);
		while (sqlite3_step(vm) != SQLITE_DONE)
		{
			char text[1024];
			sprintf(text, "(%s) %s %s %s", sqlite3_column_text(vm, 4), sqlite3_column_text(vm, 1),sqlite3_column_text(vm, 2),sqlite3_column_text(vm, 3));
			irc_cmd_msg (session, nickbuf, text);
		}
	
		sqlite3_finalize(vm);
		sqlite3_close(dbhandle);
	}

	if ( strstr (params[1], "lastseen ") == params[1] )
	{
		sqlite3_stmt *vm;
		sqlite3_open(DB_FILE, &dbhandle);
		
		char search[50];
		char name[50];
		sprintf(name, "%s", params[1] + 9);
		if(name[(strlen(name)-1)] == ' ')
		{
			name[(strlen(name)-1)] = '\0';
		}
		sprintf(search, "SELECT * FROM log WHERE name = '%s'  ORDER BY id DESC LIMIT 1", name);
		
		sqlite3_prepare(dbhandle, search, -1, &vm, NULL);
		sqlite3_step(vm);
		
		char text[1024];
		if(sqlite3_column_text(vm, 1)!=NULL)
		{
			sprintf(text, "%s last seen %s", sqlite3_column_text(vm, 1), sqlite3_column_text(vm, 4));
		}
		else
		{
			sprintf(text, "%s never seen", params[1]+9);
		}
		irc_cmd_msg (session, nickbuf, text);
		
		sqlite3_finalize(vm);
		sqlite3_close(dbhandle);
	}

	if ( !strcmp (params[1], "topic") )
		irc_cmd_topic (session, params[0], 0);
	else if ( strstr (params[1], "topic ") == params[1] )
		irc_cmd_topic (session, params[0], params[1] + 6);

	if ( strstr (params[1], "mode ") == params[1] )
		irc_cmd_channel_mode (session, params[0], params[1] + 5);

	if ( strstr (params[1], "nick ") == params[1] )
	{
		irc_cmd_nick (session, params[1] + 5);
	}

	if ( strstr (params[1], "whois ") == params[1] )
		irc_cmd_whois (session, params[1] + 5);
}
Exemple #11
0
void dazeus::Server::quit( const std::string &reason ) {
	irc_cmd_quit(IRC, reason.c_str());
}
Exemple #12
0
void event_channel (irc_session_t * session, const char * event, const char * origin, const char ** params, unsigned int count)
{
    printf ("<%s> sagt in %s: %s\n", origin ? origin : "someone", params[0], params[1] );
    snprintf(textbuf, sizeof(textbuf), "<%s>  %s", origin, params[1]);
    dlop(textbuf,false);

    if ( !strcmp (params[1], "-h") || !strcmp (params[1], "-help") )
    {
        char * str = irc_color_convert_to_mirc ("[B]bold[/B], [I]reverse[/I], [U]underline[/U], [COLOR=RED]red[/COLOR], [COLOR=YELLOW/BLACK]black[/COLOR]");
        irc_cmd_msg (session, params[0], str);
        free (str);
        irc_cmd_msg (session, params[0], "[B]bold[/B], [I]reverse[/I], [U]underline[/U], [COLOR=RED]red[/COLOR], [COLOR=YELLOW/BLACK]black[/COLOR]");
        irc_cmd_msg (session, params[0], " ");
        irc_cmd_msg (session, params[0], "-l nickname   | Abfrage, wann ein Nutzer das letzte Mal im Raum war.");
        irc_cmd_msg (session, params[0], "-e [email protected]  | Verschicken des irc-Log an eine Mailadresse");
        irc_cmd_msg (session, params[0], "-bot          | Abfrage, ob ein irc-Bot da ist.");
        irc_cmd_msg (session, params[0], "-q xxxxxx     | Bot wird geschlossen, z.B.: -q 123532");
    }

    if ( !strcmp (params[1], "-bot") )
    {
        char * str = irc_color_convert_to_mirc ("Hallo! Yes, I'm Bot. =)");
        irc_cmd_msg (session, params[0], str);
        free (str);
    }

    if ( strstr(params[1], "-l"))
    {
        char par[100];
        size_t len;
        strcpy(par, params[1]+3);

        char cdata[255];

        len = strlen(par);

        if(len > 0 )
        {
            strcpy(cdata, par);
            ssqlsv(cdata, false);
            snprintf (textbuf, sizeof(textbuf), "%s",cdata);
        }
        else snprintf (textbuf, sizeof(textbuf), "Hast du vergessen, einen Nickname einzugeben?");

        irc_cmd_msg (session, params[0], textbuf);
        printf("Rueckmeldung: %s\n",textbuf);

        snprintf(cdata, sizeof(cdata), " ");
    }

    if ( strstr(params[1], "-e") )
    {
        size_t lin2;
        lin2 = strlen(params[1]);
        if(lin2>3)
        {
            char cemail[50];
            strcpy(cemail, params[1]+3);
            irc_cmd_msg (session, params[0], "An deiner email-Adresse wurde log.txt geschickt");
            char system_str[256];

            FILE * datei;
            size_t len;
            char text[100];

            datei = fopen("/etc/ircbotF/confi.cfg", "r");

            if( datei != NULL)
            {
                fgets(text,100,datei);
                len = strlen(text);
                text[len-1] = '\0';
                fclose(datei);
            }
            char pfad[255];
            snprintf(pfad, sizeof(pfad),"%slog/log.txt",text);

            snprintf( system_str, sizeof(system_str), "mail -s \"IRC-LOG\" %s < %s", cemail, pfad );
            system(system_str);
        }
        else irc_cmd_msg (session, params[0], "ohne email-Adresse geht es nicht");

    }

    if(strstr(params[1], "-q"))
    {
        if ( !strcmp (params[1], "-q 123456") && !strcmp(origin,"Xdmin"))
        {

            char * str = irc_color_convert_to_mirc ("Bye bye!");
            irc_cmd_msg (session, params[0], str);
            free (str);
            if(irc_cmd_quit(session,params[0]))
            {
                syslog(LOG_ERR, "QUIT IRC command closed");
                exit(irc_errno(session));
            }
        }
        else
        {
            char * str = irc_color_convert_to_mirc ("sorry, dein Passwort ist falsch oder es funktioniert nur als Admin");
            irc_cmd_msg (session, params[0], str);
            free (str);
        }
    }

}
Exemple #13
0
void event_channel (irc_session_t * irc_session, const char * event, const char * origin, const char ** params, unsigned int count) {
	char buffer[512];
	char nickbuf[128];
	char md5sum[MD5_HASHSUM_SIZE];
	ConfigArrayPtr setting;
	SessionPtr session;

if ( count != 2 )
	return;

params[1] = irc_color_strip_from_mirc( params[1] );
addlog ("'%s' said in channel %s: %s", origin ? origin : "someone", params[0], params[1] );

if ( !origin )
	return;

irc_target_get_nick( origin, nickbuf, sizeof(nickbuf) );

md5_string( origin, md5sum );
session = get_session( SESSION_IRC, md5sum );


if ( !strcmp (params[1], "help") ) {
	if( ( session->dbuser ) && ( session->dbuser->level >= LEVEL_MODERATOR ) )
		snprintf(buffer, sizeof(buffer), "%s", irc_color_convert_to_mirc( "[B]Usage[/B] - quit, help, dcc send, topic, mode, whois, nick" ) );
	else
		snprintf(buffer, sizeof(buffer), "%s", irc_color_convert_to_mirc( "[B]Usage[/B] - help, dcc send, login" ) );
	irc_cmd_notice( irc_session, params[0], buffer );
}

if ( !strcmp (params[1], "ctcp") ) {
	irc_cmd_ctcp_request (irc_session, nickbuf, "PING 223");
	irc_cmd_ctcp_request (irc_session, nickbuf, "FINGER");
	irc_cmd_ctcp_request (irc_session, nickbuf, "VERSION");
	irc_cmd_ctcp_request (irc_session, nickbuf, "TIME");
}

if ( !strcmp (params[1], "dcc chat") ) {
		irc_dcc_t dccid;
	
	irc_dcc_chat (irc_session, 0, nickbuf, dcc_recv_callback, &dccid);
	addlog ("DCC chat ID: %d", dccid);
}

if ( !strcmp (params[1], "dcc send") ) {
		irc_dcc_t dccid;
	setting = GetSetting( "HTTP Images" );
	snprintf(buffer, sizeof(buffer), "%s/cookie.gif", setting->string_value );
	irc_dcc_sendfile (irc_session, 0, nickbuf, buffer, dcc_file_send_callback, &dccid);
	addlog ("DCC send ID: %d", dccid);
}


if( ( session->dbuser ) && ( session->dbuser->level >= LEVEL_MODERATOR ) ) {

if ( !strcmp (params[1], "quit") ) {
		irc_cmd_quit (irc_session, "of course, Master!");
}

if ( !strcmp (params[1], "topic") ) {
	irc_cmd_topic (irc_session, params[0], 0);
} else if ( strstr (params[1], "topic ") == params[1] ) {
	irc_cmd_topic (irc_session, params[0], params[1] + 6);
}

if ( strstr (params[1], "mode ") == params[1] )
	irc_cmd_channel_mode (irc_session, params[0], params[1] + 5);

if ( strstr (params[1], "nick ") == params[1] )
	irc_cmd_nick (irc_session, params[1] + 5);

if ( strstr (params[1], "whois ") == params[1] )
	irc_cmd_whois (irc_session, params[1] + 5);

}

return;
}