void dazeus::Server::connectToServer() { printf("Connecting to server: %s\n", toString(this).c_str()); assert( !config_->network->nickName.length() == 0 ); irc_callbacks_t callbacks; memset(&callbacks, 0, sizeof(irc_callbacks_t)); callbacks.event_connect = irc_callback; callbacks.event_nick = irc_callback; callbacks.event_quit = irc_callback; callbacks.event_join = irc_callback; callbacks.event_part = irc_callback; callbacks.event_mode = irc_callback; callbacks.event_umode = irc_callback; callbacks.event_topic = irc_callback; callbacks.event_kick = irc_callback; callbacks.event_channel = irc_callback; #if LIBIRC_VERSION_HIGH > 1 || LIBIRC_VERSION_LOW >= 6 callbacks.event_channel_notice = irc_callback; #endif callbacks.event_privmsg = irc_callback; callbacks.event_notice = irc_callback; callbacks.event_invite = irc_callback; callbacks.event_ctcp_req = irc_callback; callbacks.event_ctcp_rep = irc_callback; callbacks.event_ctcp_action = irc_callback; callbacks.event_unknown = irc_callback; callbacks.event_numeric = irc_eventcode_callback; irc_ = (void*)irc_create_session(&callbacks); if(!irc_) { std::cerr << "Couldn't create IRC session in Server."; abort(); } irc_set_ctx(IRC, this); assert( config_->network->nickName.length() != 0 ); std::string host = config_->host; if(config_->ssl) { #if defined(LIBIRC_OPTION_SSL_NO_VERIFY) host = "#" + host; if(!config_->ssl_verify) { std::cerr << "Warning: connecting without SSL certificate verification." << std::endl; irc_option_set(IRC, LIBIRC_OPTION_SSL_NO_VERIFY); } #else std::cerr << "Error: Your version of libircclient does not support SSL. Failing connection." << std::endl; slotDisconnected(); return; #endif } irc_connect(IRC, host.c_str(), config_->port, config_->network->password.c_str(), config_->network->nickName.c_str(), config_->network->userName.c_str(), config_->network->fullName.c_str()); }
void Kommunikater::commitServer() { callbacks.event_connect = event_connect; callbacks.event_channel = event_channel; session = irc_create_session (&callbacks); irc_set_ctx (session, &ctx); irc_option_set (session, LIBIRC_OPTION_STRIPNICKS); irc_connect (session, iam.server, 6667, 0, iam.nick, 0, 0); state.session = session; if(irc_run (session) && !state.stop) printf ("Could not connect or I/O error"); }
IRCSession::IRCSession(char const* servername, unsigned int port, char const* password, const char* nick, const char* username, const char* realname) : session{nullptr} { session = irc_create_session(&IRC::callbacks); if (session == nullptr) throw std::runtime_error{"Could not create IRC session."}; irc_option_set( session, LIBIRC_OPTION_STRIPNICKS ); if (irc_connect(session, servername, port, password, nick, username, realname)) throw std::runtime_error{"Could not initiate connection to server."}; IRC::session_map[session] = this; }
module_t * irc_new() { irc_t *irc = calloc(1, sizeof(irc_t)); if (!irc) { perror("calloc"); return NULL; } irc->module.type = "irc"; irc->module.name = NULL; irc->module.connect = module_connect; irc->module.config = config; irc->module.process_select_descriptors = process_select; irc->module.add_select_descriptors = add_select; irc->module.send = send; irc->module.get_nicks = get_nicks; irc->server = ""; irc->ssl = 0; irc->ipv6 = 0; irc->port = 6667; irc->password = NULL; irc->nick = "guest"; irc->username = "******"; irc->realname = "noname"; irc->channels = NULL; // Add this module to the global linked list irc->next = modules; modules = irc; irc->session = irc_create_session(&callbacks); if (!irc->session) { fprintf(stderr, "irc: %s\n", irc_strerror(irc_errno(irc->session))); } irc_option_set(irc->session, LIBIRC_OPTION_STRIPNICKS); return (module_t *)irc; }
bool CslIrcSession::InitContext(CslIrcContext *context) { irc_callbacks_t callbacks; memset(&callbacks,0,sizeof(callbacks)); callbacks.event_connect=event_connect; callbacks.event_join=event_join; callbacks.event_nick=event_nick; callbacks.event_quit=event_quit; callbacks.event_part=event_part; callbacks.event_mode=event_mode; callbacks.event_topic=event_topic; callbacks.event_kick=event_kick; callbacks.event_channel=event_chanmsg; callbacks.event_privmsg=event_privmsg; callbacks.event_notice=event_notice; //callbacks.event_invite //callbacks.event_umode callbacks.event_ctcp_req=event_ctcp_request; //callbacks.event_ctcp_rep; callbacks.event_ctcp_action=event_ctcp_action; //callbacks.event_unknown callbacks.event_numeric=event_numeric; //callbacks.event_dcc_chat_req //callbacks.event_dcc_send_req if (!(context->Session=irc_create_session(&callbacks))) return false; //nicknames only, strip them from nick!host. irc_option_set(context->Session,LIBIRC_OPTION_STRIPNICKS); context->EvtHandler=this; SetNextHandler(context->Target); return true; }
void IRC::initSessions() { IRC::_sessionServerMap.clear(); irc_callbacks_t callbacks = initCallbacks(); std::vector<ConfigHandler::IRCOptions_Server>::iterator it; for(it = _options->serverVector.begin(); it != _options->serverVector.end(); it++) { irc_session_t* s = irc_create_session(&callbacks); if(!s) { std::cerr << "IRC::initSessions() can't creat session for " << it->address << std::endl; continue; } else std::cout << "IRC::initSessions() created session for " << it->address << std::endl; irc_option_set(s, LIBIRC_OPTION_STRIPNICKS); IRC::_sessionServerMap[s] = *it; } }
std::thread Twitch::Connect( const std::string &user, const std::string &password ) { return std::thread( [this, user, password] { this->user = user; this->channel = "#" + user; irc_callbacks_t callbacks; memset( &callbacks, 0, sizeof( callbacks ) ); callbacks.event_connect = event_connect; callbacks.event_channel = event_channel; callbacks.event_numeric = event_numeric; session = irc_create_session( &callbacks ); if ( !session ) { OnError( -1, "Failed to create IRC session" ); return; } TwitchContext *ctx = new TwitchContext(); ctx->twitch = this; irc_set_ctx( session, ctx ); irc_option_set( session, LIBIRC_OPTION_STRIPNICKS ); status = TWITCH_CONNECTING; if ( irc_connect( session, "irc.chat.twitch.tv", 6667, password.c_str(), user.c_str(), user.c_str(), user.c_str() ) ) { OnError( irc_errno( session ), irc_strerror( irc_errno( session ) ) ); status = TWITCH_DISCONNECTED; return; } if ( irc_run( session ) ) { OnError( irc_errno( session ), irc_strerror( irc_errno( session ) ) ); status = TWITCH_DISCONNECTED; return; } } ); }
int main (int argc, char **argv) { irc_callbacks_t callbacks; irc_ctx_t ctx; irc_session_t * s; unsigned short port = 6667; if ( argc != 4 ) { printf ("Usage: %s <server> <nick> <channel>\n", argv[0]); return 1; } memset (&callbacks, 0, sizeof(callbacks)); callbacks.event_connect = event_connect; callbacks.event_join = event_join; callbacks.event_channel = event_channel; callbacks.event_numeric = event_numeric; s = irc_create_session (&callbacks); if ( !s ) { printf ("Could not create session\n"); return 1; } ctx.channel = argv[3]; ctx.nick = argv[2]; printf("nick:%s and channel:%s\n",ctx.nick,ctx.channel); irc_set_ctx (s, &ctx); // If the port number is specified in the server string, use the port 0 so it gets parsed if ( strchr( argv[1], ':' ) != 0 ) port = 0; // To handle the "SSL certificate verify failed" from command line we allow passing ## in front // of the server name, and in this case tell libircclient not to verify the cert if ( argv[1][0] == '#' && argv[1][1] == '#' ) { // Skip the first character as libircclient needs only one # for SSL support, i.e. #irc.freenode.net argv[1]++; irc_option_set( s, LIBIRC_OPTION_SSL_NO_VERIFY ); } // Initiate the IRC server connection if ( irc_connect (s, argv[1], port, 0, argv[2], 0, 0) ) { printf ("Could not connect: %s\n", irc_strerror (irc_errno(s))); return 1; } // and run into forever loop, generating events if ( irc_run (s) ) { printf ("Could not connect or I/O error: %s\n", irc_strerror (irc_errno(s))); return 1; } return 1; }
int main(int argc, char** argv) { irc_callbacks_t callbacks; irc_session_t *s; //Time init time ( &rawtime ); ptm = gmtime ( &rawtime ); printf(" : - Bot wird gestartet...\n"); //-- SQLite Init printf(" : - SQLite wird initialisiert...\n"); sqlite3_open(SQLITEFILE, &sqlitedb); sql_createtables(); switch(argc) { case 2: { int tmp = -1; tmp = configfileLaden(argv[1]); if(tmp==0) { return 1; } printf(" : - Bot Configfile geladen \n"); }break; case 4: ctx.channel = argv[3]; ctx.nick = argv[2]; server = argv[1]; printf(" : - Bot configuriert (Parameter) \n"); break; default: printf ("!: - Parameter fehlen\n"); printf ("!: - %s <server> <nick> '<#channel>' \n",argv[0]); printf ("!: - %s <configfile> \n",argv[0]); return 1; } printf(" : - Server: %s \n",server); printf(" : - Nick: %s \n",ctx.nick); printf(" : - Channel: %s \n",ctx.channel); memset(&callbacks, 0, sizeof(callbacks)); //-- Events -- callbacks.event_connect = event_connect; callbacks.event_join = event_join; callbacks.event_channel = event_channel; callbacks.event_privmsg = event_privmsg; //-- // ctx.channel = "#Bot"; // ctx.nick = "FH-BoT"; if(server == NULL) { printf("?: - setzt Standartserver\n"); server = "localhost"; } s = irc_create_session(&callbacks); if(!s) { printf("X: - Konnte keine IRC Session aufbauen...\n"); return 1; } irc_set_ctx (s,&ctx); irc_option_set (s, LIBIRC_OPTION_STRIPNICKS); if( irc_connect (s, server,port, 0,ctx.nick,0,0)) { printf("X: - Konnte keine Verbindung zum Server aufbauen...\n"); return 1; } if( irc_run (s) ) { printf (" : - SQLite wird geschlossen. \n"); sqlite3_close(sqlitedb); printf (" : - Bot wurde beendet. \n"); return 1; } sqlite3_close(sqlitedb); return 1; }
/** * @brief Main Funktion * Setzt die Callback Funktionen. * Initialisiert und Startet den IRC Bot * @param argc ein Integer, Anzahl der Argumente * @param argv ein Char, beinhaltet Argumente * @return int */ int main (int argc, char **argv) { irc_callbacks_t callbacks; irc_ctx_t ctx; irc_session_t * s; unsigned short port; if ( argc != 5 ) { printf ("Usage: %s <server> <nick> <'#channel'> <daemon:yes/no>\n", argv[0]); return 1; } if ( !strcmp (argv[4], "yes") ) { daemonize(); } else if ( !( !strcmp (argv[4], "no") )) { printf ("Usage: %s <server> <nick> <'#channel'> <daemon:yes/no>\n", argv[0]); return 1; //Beispiel // ./irc_bot irc.twice-irc.de:6667 test_bot328 '#qaywsx999' no } memset (&callbacks, 0, sizeof(callbacks)); callbacks.event_connect = event_connect; callbacks.event_join = event_join; callbacks.event_nick = event_nick_change; callbacks.event_quit = event_quit; callbacks.event_channel = event_channel; callbacks.event_privmsg = event_privmsg; s = irc_create_session (&callbacks); if ( !s ) { printf ("Could not create session\n"); return 1; } ctx.channel = argv[3]; ctx.nick = argv[2]; bot_name = ctx.nick; irc_set_ctx (s, &ctx); createSQLDB(); // If the port number is specified in the server string, use the port 0 so it gets parsed if ( strchr( argv[1], ':' ) != 0 ) port = 0; // To handle the "SSL certificate verify failed" from command line we allow passing ## in front // of the server name, and in this case tell libircclient not to verify the cert if ( argv[1][0] == '#' && argv[1][1] == '#' ) { // Skip the first character as libircclient needs only one # for SSL support, i.e. #irc.freenode.net argv[1]++; irc_option_set( s, LIBIRC_OPTION_SSL_NO_VERIFY ); } // Initiate the IRC server connection if ( irc_connect (s, argv[1], port, 0, argv[2], 0, 0) ) { printf ("Could not connect: %s\n", irc_strerror (irc_errno(s))); return 1; } // and run into forever loop, generating events if ( irc_run (s) ) { printf ("Could not connect or I/O error: %s\n", irc_strerror (irc_errno(s))); return 1; } return 1; }
void ChatNetworkingIRC::createConnection( const ChatConnectionConfig& conf ) throw ( ChatExpection ) { if ( conf._port == 0 ) { throw ChatExpection( "Invalid Port" ); } if ( !conf._serverURL.length() ) { throw ChatExpection( "Invalid Server URL" ); } if ( !conf._channel.length() ) { throw ChatExpection( "Invalid Channel" ); } #ifdef WIN32 // start up winsock WORD version; WSADATA data; int err; version = MAKEWORD( 2, 2 ); err = WSAStartup( version, &data ); if ( err != 0 ) { throw ChatExpection( "Cannot setup ms winsock" ); } #endif irc_callbacks_t callbacks; memset( &callbacks, 0, sizeof( callbacks ) ); // set up the callbacks callbacks.event_connect = event_connect; callbacks.event_nick = event_nick; callbacks.event_join = event_join; callbacks.event_numeric = event_numeric; callbacks.event_channel = event_channel; callbacks.event_kick = event_kick; callbacks.event_part = event_part; irc_session_t* p_session = NULL; p_session = irc_create_session( &callbacks ); if ( !p_session ) { throw ChatExpection( "Could not create networking session" ); } // store the context information IRCSessionContext* p_ctx = new IRCSessionContext; p_ctx->_p_handler = this; p_ctx->_channel = conf._channel; irc_set_ctx( p_session, p_ctx ); _p_session = p_session; irc_option_set( p_session, LIBIRC_OPTION_STRIPNICKS ); // initiate the IRC server connection if ( irc_connect( p_session, conf._serverURL.c_str(), conf._port, conf._password.length() ? conf._password.c_str() : NULL, conf._nickname.c_str(), conf._username.length() ? conf._username.c_str() : NULL, conf._realname.length() ? conf._realname.c_str() : NULL ) ) { throw ChatExpection( std::string( irc_strerror( irc_errno( p_session ) ) ) ); } // store the configuration _p_config = new ChatConnectionConfig; *_p_config = conf; _p_config->_p_protocolHandler = this; // start the thread -- the method run() below is called in a new created thread start(); }
// Main function int main(int argc, char** argv){ irc_callbacks_t irc_callbacks; char* host_str; int host_len, ssl; I = 0; if(argc != 2) error(1, "Error: config file must be specified on comand line\n"); // load config from ini conf_file = argv[1]; C = iniparser_load(conf_file); // parse server config and generate a string to give to libircclient ssl = iniparser_getboolean(C, "server:ssl", 0); host_len = strlen(iniparser_getstring(C, "server:host", "")) + (ssl ? 1 : 0); host_str = malloc(host_len + 1); host_str[0] = '#'; host_str[host_len] = '\0'; strcpy(&host_str[ssl ? 1 : 0], iniparser_getstring(C, "server:host", "")); // init local data structures mem_init(); cbtable_init(); // init mysql S = mysql_init(NULL); if(mysql_real_connect(S, iniparser_getstring(C, "mysql:host", "localhost"), iniparser_getstring(C, "mysql:user", "root"), iniparser_getstring(C, "mysql:pass", ""), iniparser_getstring(C, "mysql:database", ""), iniparser_getint(C, "mysql:port", 0), 0, 0) == NULL) error(1, "Unable to connect to mysql: %s\n", mysql_error(S)); // init lua L = luaL_newstate(); luaL_openlibs(L); register_lua_functions(); if(luaL_dofile(L, iniparser_getstring(C,"bot:file","/dev/null"))){ size_t lua_errlen = 0; const char* lua_error = luaL_checklstring(L, -1, &lua_errlen); error(1, "Error processing Lua script:\n%s\n", lua_error); } // init libircclient memset(&irc_callbacks, 0, sizeof(irc_callbacks)); irc_callbacks.event_connect = event_generic; irc_callbacks.event_nick = event_generic; irc_callbacks.event_quit = event_generic; irc_callbacks.event_join = event_generic; irc_callbacks.event_part = event_generic; irc_callbacks.event_mode = event_generic; irc_callbacks.event_umode = event_generic; irc_callbacks.event_topic = event_generic; irc_callbacks.event_kick = event_generic; irc_callbacks.event_channel = event_command; irc_callbacks.event_privmsg = event_command; irc_callbacks.event_notice = event_generic; irc_callbacks.event_unknown = event_generic; irc_callbacks.event_invite = event_generic; irc_callbacks.event_ctcp_req = event_generic; irc_callbacks.event_ctcp_rep = event_generic; irc_callbacks.event_ctcp_action = event_generic; irc_callbacks.event_channel_notice = event_generic; irc_callbacks.event_numeric = event_numeric; do_quit = 0; while(!do_quit){ if(I) irc_destroy_session(I); I = irc_create_session(&irc_callbacks); if(!I) error(1, "Unable to create IRC session... probably out of memory\n"); irc_option_set(I, LIBIRC_OPTION_STRIPNICKS); irc_option_set(I, LIBIRC_OPTION_SSL_NO_VERIFY); //irc_option_set(I, LIBIRC_OPTION_DEBUG); // initialize irc server connection if(irc_connect(I, host_str, iniparser_getint(C,"server:port",6667), 0, iniparser_getstring(C,"bot:nick","bot"), iniparser_getstring(C,"bot:user","bot"), "libircclient" )) irc_error(I,1); // not sure why we need to sleep here, but if we don't, we can't connect sleep(1); // run the irc client loop if(irc_run(I)) irc_error(I,0); } // clean up mysql_close(S); irc_destroy_session(I); lua_close(L); cbtable_destroy(); iniparser_freedict(C); free(host_str); return EXIT_SUCCESS; }
int main (int argc, char **argv) { bool daemon_deaktiv = false; bool btipp = false; int is=1, in=2, ic=3; int i=1; for(; i < argc; i++) { if ( !strncmp(argv[i], "-d",3) || !strncmp(argv[i], "-D",3) ) { if(argc > 4) btipp = true; daemon_deaktiv = true; printf("\n--------------------------------------------------\n"); printf("Daemon wird deaktiviert."); if(i<2) { is = 2; in = 3; ic = 4; } } else if ( !strncmp(argv[i], "-h",3) || !strncmp(argv[i], "-help",6) ) { btipp = true; printf("TEST: HELP ist da\n"); system("nroff -mandoc ./man/iman.pod | less"); } } if(btipp == false && argc != 4 ) { printf("\nUsage: %s [options]\n", argv[0]); printf("\n [ -h | -help ] Anleitung"); printf("\n [ <server> <nick> <#channel> ] Ircbot startet"); printf("\n [ -d .......... ] startet und Daemon wird deaktiviert\n\n"); exit(EXIT_SUCCESS); } irc_callbacks_t callbacks; irc_ctx_t ctx; irc_session_t * s; memset (&callbacks, 0, sizeof(callbacks)); callbacks.event_connect = event_connect; callbacks.event_join = event_join; callbacks.event_channel = event_channel; callbacks.event_quit = event_quit; s = irc_create_session (&callbacks); if ( !s ) { printf ("Could not create session\n"); return 1; } ctx.channel = argv[ic]; ichanel = argv[ic]; ctx.nick = argv[in]; mynick = argv[in]; irc_set_ctx (s, &ctx); irc_option_set(s, LIBIRC_OPTION_STRIPNICKS); if ( irc_connect (s, argv[is], 6667, 0, argv[in], 0, 0) ) { printf ("Es kann nicht verbinden: %s\n", irc_strerror (irc_errno(s))); return 1; } else { if(daemon_deaktiv == false) { printf("\n--------------------------------------------------\n"); printf("Daemon wird aktiviert."); } printf("\nBot-Nickname: '%s'",argv[in]); printf("\nChannel : '%s'",argv[ic]); printf("\nEs verbindet: '%s'....\n", argv[is]); } if(daemon_deaktiv == false) { openlog (daemon_name, LOG_CONS | LOG_PID | LOG_NDELAY, LOG_DAEMON); syslog (LOG_INFO, "Ircbot: Starting...."); start_daemon(daemon_name, LOG_USER); } irc_run (s); syslog (LOG_INFO, "Ircbot: Terminating..."); closelog(); return 1; }