void bot_destroy(BOT_REC *bot) { GNode *node; g_return_if_fail(bot != NULL); node = g_node_find(bot->botnet->bots, 0, G_TRAVERSE_ALL, bot); if (node != NULL) { if (!bot->disconnect) bot_mark_disconnects(node); } bot_disconnect(bot); if (node != NULL) { while (node->children != NULL) bot_destroy(node->children->data); g_node_destroy(node); } if (bot->botnet->uplink == bot) bot->botnet->uplink = NULL; if (bot->botnet->master == bot) bot->botnet->master = NULL; while (bot->ircnets != NULL) bot_ircnet_destroy(bot, bot->ircnets->data); line_split_free(bot->buffer); g_free_not_null(bot->nick); g_free(bot); }
static void botnet_event(BOT_REC *bot, const char *data) { BOT_DOWNLINK_REC *downlink; char *fname; g_return_if_fail(bot != NULL); g_return_if_fail(data != NULL); if (bot->connected) return; signal_stop_by_name("botnet event"); if (bot->uplink) { botnet_connect_event_uplink(bot, data); return; } downlink = bot->link; if (!bot->pass_ok && g_strncasecmp(data, "PASS ", 5) == 0) { /* password sent, check that it matches */ if (strcmp(data+5, downlink->password) == 0) { /* ok, connected! */ bot->pass_ok = TRUE; } else { /* wrong password, disconnect */ bot_disconnect(bot); } return; } if (g_strncasecmp(data, "NICK ", 5) == 0) { /* set bot's nick */ if (!bot->pass_ok) { /* password has to be sent before nick, kill the stupid bot. */ bot_disconnect(bot); return; } if (g_strcasecmp(bot->botnet->nick, data+5) == 0 || bot_find_nick(bot->botnet, data+5) != NULL) { /* nick already exists */ bot_send_cmd(bot, "NICKERROR"); return; } /* set the nick */ bot->nick = g_strdup(data+5); bot->connected = TRUE; bot_send_cmd(bot, "CONNECTED"); /* send info about all the bots that are connected now to this botnet */ botnet_send_botinfo(bot->botnet->bots, bot); botnet_send_links(bot, FALSE); botnet_send_links(bot, TRUE); bot_send_cmdv(bot, "%s - MASTER %s", bot->botnet->nick, bot->botnet->master->nick); /* send our current user configuration */ fname = g_strdup_printf("%s/.irssi/users.temp", g_get_home_dir()); botuser_save(fname); botnet_send_file(bot->botnet, bot->nick, fname); g_free(fname); /* send sync msg */ bot_send_cmdv(bot, "%s - SYNC", bot->botnet->nick); return; } /* pass/nick not sent yet */ bot_send_cmd(bot, "ERROR"); }
void bot_parsemsg(struct bot* b, char* msg) { printf("S> %s <E\n", msg); if(bot_pingpong(b, msg)<0) { /* * TODO: Adjust sizes to something less stupid. */ char host[256]; char nick[64]; char cmd[256]; char channel[64]; char message[512]; if(bot_parsecmd(msg, host, nick, cmd, channel, message)==0) { printf("HOST: %s\nNICK: %s\nCMD: %s\nCHANNEL: %s\nMSG: %s\n", host, nick, cmd, channel, message); if(strcmp(cmd, "PRIVMSG")==0) { int allowedtoexec=0; int hasarguments=0; const char** authedusers = config_getvals(b->conf, "authorized_users"); if(!*authedusers[0] && strcmp(message, "iamyourfather")==0) { #ifdef DEBUG printf("Checking authed users.\n"); #endif config_add(b->conf, "authorized_users", host); CMD(b->conn, "PRIVMSG", nick, "Admin user added."); allowedtoexec=1; } for(int i=0; authedusers[i]; ++i) { if(strcmp(host, authedusers[i])==0) { allowedtoexec=1; break; } } #ifdef DEBUG printf("Allowed to exec: %d\n", allowedtoexec); #endif if(allowedtoexec && is_publiccommand(message, NULL)!=0) { if(is_cbotcommand(message)==0) { char* ccmd = message+6; if(strcmp(ccmd, "DIE")==0) { bot_disconnect(b); return; } else if(strncmp(ccmd, "join", 4)==0) { CMD(b->conn, "JOIN", NULL, ccmd+4); } else CMD(b->conn, cmd, NULL, ccmd); } } else if(is_publiccommand(message, &hasarguments)==0) { if(strncmp(message, "!unicafe", 8)==0) { const char* func; if(hasarguments) { if(strncmp(message+9, "--keskusta", 10)==0 || strncmp(message+9, "-k", 2)==0) func="unicafe_centre"; } else func="unicafe"; #ifdef CBOT_PYTHON struct python_module p; memset(&p, 0, sizeof(p)); char* p1=(char*)python_module_call(&p, "unicafe.py", func); char* p2=p1; int i=0; int len=strlen(p1); while(i<len) { while(*p2!='\n'){++p2;++i;} *p2=0; ++p2; ++i; CMD(b->conn, "PRIVMSG", channel, p1); p1=p2; usleep(500000); } #else fprintf(stderr, "Python module is not compiled.\n"); #endif } } else if(strcmp(channel, *config_getvals(b->conf, "nick"))==0 && !allowedtoexec) CMD(b->conn, "PRIVMSG", nick, "Access denied!"); //bot_execcmd(b, message); } } } }