static int msg_mode(const char *replyto, struct userlist *user, char *data) { char *channel, *modes ; if (data == NULL) { msgreply(user, replyto, "Syntax error: mode <channel> <flags>"); return (0); } channel = strtok(data, " "); modes = strtok(NULL, ""); if (channel == NULL || modes == NULL) { msgreply(user, replyto, "Syntax error: mode <channel> <flags>"); return (0); } if (GetChannelAccess(user, channel) < 0) { return (access_too_low(user, replyto)); } info_log("Mode change %s on %s by %s\n", modes, channel, unick(user)); msgreply(user, replyto, "Changing mode on %s to %s", channel, modes); irc_sprintf(usinfo(user), "MODE %s %s\n", channel, modes); return (0); }
static int msg_topic(const char *replyto, struct userlist *user, char *data) { char *channel, *topic ; if (data == NULL) { msgreply(user, replyto, "Syntax error: topic <channel> <text>"); return (0); } channel = strtok(data, " "); topic = strtok(NULL, ""); if (channel == NULL || topic == NULL) { msgreply(user, replyto, "Syntax error: topic <channel> <text>"); return (0); } if (GetChannelAccess(user, channel) < 0) { return (access_too_low(user, replyto)); } info_log("Topic on %s set to %s by %s\n", channel, topic, unick(user)); msgreply(user, replyto, "Changing topic on %s", channel); irc_sprintf(usinfo(user), "TOPIC %s :%s\n", channel, topic); return (0); }
static int msg_autoop(const char *replyto, struct userlist *user, char *data) { if (data == NULL) { if (botinfo->autoop == 1) { msgreply(user, replyto, "Autoop ON"); } else { msgreply(user, replyto, "Autoop OFF"); } return (0); } if (strcaseeq("off", data)) { botinfo->autoop = 0; msgreply(user, replyto, "Autoop OFF"); return (0); } if (strcaseeq("on", data)) { botinfo->autoop = 1; msgreply(user, replyto, "Autoop ON"); return (0); } msgreply(user, replyto, "Syntax error: Autoop <on/off>"); return (0); }
static int msg_join(const char *replyto, struct userlist *user, char *data) { char *channel, *key ; if (data == NULL) { msgreply(user, replyto, "Syntax error: join <channel> <key>"); return (0); } channel = strtok(data, " "); key = strtok(NULL, ""); if (channel == NULL) { msgreply(user, replyto, "Syntax error: join <channel> <key>"); return (0); } if (EnterChannel(data, key, user->userinfo->server) == -1) { msgreply(user, replyto, "I'm in that channel already"); } else { msgreply(user, replyto, "Joining %s", channel); info_log("Join to %s requested by %s\n", channel, unick(user)) ; } return (0); }
static int msg_botuptime(const char *replyto, struct userlist *user, const char * UNUSED(data)) { time_t now; int min; int hour; int day; time_t uptime; time(&now); uptime = now - botinfo->starttime; day = uptime / 86400; if (day > 0) { uptime = uptime - (day * 86400); } hour = uptime / 3600; if (hour > 0) { uptime = uptime - (hour * 3600); } min = uptime / 60; if(day==1) { msgreply(user, replyto, "up %i day, %i:%02i",day, hour, min); return(0); } msgreply(user, replyto, "up %i days %i:%02i",day, hour, min); return(0); }
static int msg_opuser(const char *replyto, struct userlist *user, char *data) { char *channel, *usertoop ; if (data == NULL) { msgreply(user, replyto, "Syntax error: opuser <channel> <user>"); return (0); } channel = strtok(data, " "); usertoop = strtok(NULL, ""); if (user == NULL) { msgreply(user, replyto, "Syntax error: opuser <channel> <user>"); return (0); } if (GetChannelAccess(user, channel) >= 0) { info_log("Opuser %s on %s\n", usertoop, channel); msgreply(user, replyto, "Opping %s on %s", usertoop, channel); irc_sprintf(usinfo(user), "MODE %s +o %s\n", channel, usertoop); } else { msgreply(user, replyto, "Authorization failed!"); } return (0); }
/* needed to shut the compilor up */ return(0); } //admin only command: lists registered bot users static int msg_listusers(const char *replyto, struct userlist *user, const char * UNUSED(data)) { info_log("Requested listusers by %s\n", user->userinfo->nick); int i=0; struct userdata *userdata_curr; userdata_curr=conf_userdata; while(userdata_curr != NULL){ msgreply(user, replyto, " %s",userdata_curr->usernick); userdata_curr=userdata_curr->next; i++; } msgreply(user, replyto, "--- %i users total ---",i); return(0); } static int msg_version(const char *replyto, struct userlist *user, const char * UNUSED(data)) { msgreply(user, replyto, "Version: %s", botinfo->ver); return(0); } static int msg_time(const char *replyto, struct userlist *user, const char * UNUSED(data)) { char timestr[50]; time(&currtime); strftime(timestr, sizeof(timestr), "%a %b %d %H:%M:%Y", localtime(&currtime)); msgreply(user, replyto, "The current time is: %s", timestr); return(0); } static int msg_reload(const char *replyto, struct userlist *user, const char * UNUSED(data)) { info_log("Reload by %s\n", user->userinfo->nick); acid_reload("reloading\n"); //msgreply(user, replyto, "Reload complete."); msgreply(user, replyto, "Professore ho ricaricato Utenti e Log sulla navetta siamo pronti a consegnarli."); return(0); } #if 0 /* too ugly to live */ static int msg_help(const char *replyto, struct userlist *user, const char *data) { char *line; FILE *fp_help; /* This is not ideal.. spending this much time inside a routine will make it hard for the bot to handle outside events in a timely manor */ if ((line = malloc(100)) == NULL) { display_error("execute: Malloc error!\n"); return (-1); } if ((fp_help = fopen("../docs/help", "r")) == NULL) { info_log("Cant open help file! \n"); free(line); msgreply(user, replyto, "Cant open help file! "); return(0); } while (fgets(line, 100, fp_help) != NULL) { if (msgreply(user, replyto, "%s", line) == -1) { free(line); return (-1); } /* give the server time to accept the input */ sleep(1); } free(line); return (0); }
static int msg_kick(const char *replyto, struct userlist *user, char *data) { char *channel, *nick, *message ; struct userlist *target; int user_access; /* syntax: kick <channel> <nick> */ channel = strtok(data, " "); nick = strtok(NULL, " "); message = strtok(NULL, ""); if (channel == NULL || nick == NULL) { msgreply(user, replyto, "Syntax error: kick <channel> <nickname>"); return (0); } if (strcaseeq(nick, user->userinfo->server->nick)) { info_log("%s tried to make me kick myself\n", unick(user)); irc_sprintf(usinfo(user), "KICK %s %s :Try to make me kick myself eh?\n", channel, unick(user)); return (0); } user_access = GetChannelAccess(user, channel); if (user_access < 0) return (access_too_low(user, replyto)); target = GetFromChannel(nick, channel, user->userinfo->server); if (target == NULL) msgreply(user, replyto, "I don't see that user in the channel"); if ((target->access >= 0) && (user_access > target->access)) { privmsg(usinfo(user), unick(target), "%s tried to kick you!", unick(user) ); privmsg(usinfo(user), replyto, "attempt to kick user with higher access denied"); return (0); } info_log("KICK %s %s\n", channel, unick(target)); msgreply(user, replyto, "Kicking %s on %s", nick, channel); if (message == NULL) { irc_sprintf(usinfo(user), "KICK %s %s\n", channel, nick); return (0); } else { irc_sprintf(usinfo(user), "KICK %s %s :%s\n", channel, nick, message); return (0); } }
//admin only command: lists registered bot users static int msg_listusers(const char *replyto, struct userlist *user, const char * UNUSED(data)) { info_log("Requested listusers by %s\n", user->userinfo->nick); int i=0; struct userdata *userdata_curr; userdata_curr=conf_userdata; while(userdata_curr != NULL){ msgreply(user, replyto, " %s",userdata_curr->usernick); userdata_curr=userdata_curr->next; i++; } msgreply(user, replyto, "--- %i users total ---",i); return(0); }
static int msg_utf8(const char *replyto, struct userlist *user, const char *UNUSED(data)) { msgreply(user, replyto, "Per cambiare provvisoriamente il tuo charset in utf-8 digita /charset utf-8 oppure fai mela+S, seleziona il server (Azzurra), fai Show Details e seleziona il charset manualmente per cambiarlo definitivamente."); return(0); }
static int msg_reload(const char *replyto, struct userlist *user, const char * UNUSED(data)) { info_log("Reload by %s\n", user->userinfo->nick); acid_reload("reloading\n"); //msgreply(user, replyto, "Reload complete."); msgreply(user, replyto, "Professore ho ricaricato Utenti e Log sulla navetta siamo pronti a consegnarli."); return(0); }
static int msg_part(const char *replyto, struct userlist *user, const char *data) { if (data == NULL) { msgreply(user, replyto, "Syntax error: part <channel>"); return (0); } if (ExitChannel(data, user->userinfo->server) == -1) { msgreply(user, replyto, "I'm not in channel %s", data); } else { msgreply(user, replyto, "Parting %s", data); info_log("Parted %s by %s\n", data, unick(user)) ; } return (0); }
static int msg_access(const char *replyto, struct userlist *user, const char *UNUSED(data)) { /* syntax: identify <password> */ UpdateAccess(user,NULL); msgreply(user, replyto, "Access level for %s is %i",user->userinfo->nick,user->access); return(0); }
static int msg_nick(const char *replyto, struct userlist *user, const char * data) { struct server_list *server; if (data == NULL) { msgreply(user, replyto, "Syntax error: nick <nickname>"); return(0); } server = user->userinfo->server; info_log("NICK changed from %s to %s by %s\n", server->nick, data, unick(user)); free(server->nick); server->nick = strdup(data); msgreply(user, replyto, "Changing nick to %s", server->nick); irc_sprintf(usinfo(user),"NICK %s\n", server->nick); return(0); }
static int msg_time(const char *replyto, struct userlist *user, const char * UNUSED(data)) { char timestr[50]; time(&currtime); strftime(timestr, sizeof(timestr), "%a %b %d %H:%M:%Y", localtime(&currtime)); msgreply(user, replyto, "The current time is: %s", timestr); return(0); }
static int msg_identify(const char *replyto, struct userlist *user, const char *data) { /* syntax: identify <password> */ if(strcaseeq(data,"help")) { msgreply(user, replyto, "Useage: identify <password>"); return(0); } UpdateAccess(user,data); msguser (user, "Identification complete"); return(0); }
static int msg_shutdown(const char *replyto, struct userlist *user, const char * UNUSED(data)) { info_log("Shutdown by %s\n", user->userinfo->nick); msgreply(user, replyto, "Bacia il mio fondoschiena metallico!!!"); //msgreply(user, replyto, "Shutting down"); irc_sprintf(user->userinfo->server->sinfo, "QUIT :Shutdown requested by %s\n",user->userinfo->nick); sleep(3); acid_shutdown(0); /* needed to shut the compilor up */ return(0); }
static int msg_lista(const char *replyto, struct userlist *user, const char *UNUSED(data)) { struct server_list *server; server = user->userinfo->server; info_log("KICK to %s on %s\n", unick(user), replyto); msgreply(user, replyto, "Il premio 'Ciao sono un imbecille e cerco warez' di oggi va a %s!", unick(user)); irc_sprintf(usinfo(user),"KICK %s %s :Come osi cercare Warez qui, TROLL!\n", replyto, unick(user)); return(0); }
static int msg_raw(const char *replyto, struct userlist *user, const char *data) { if (data == NULL) { msgreply(user, replyto, "Syntax error: raw <command>"); return(0); } if (strcaseeq(data, "QUIT")) { send_notice(user->userinfo->server->sinfo, user->userinfo->nick, "Error: use shutdown instead"); return (0); } info_log("RAW: %s by %s\n", data, unick(user)); msguser(user, "Sending raw message> %s", data); irc_sprintf(usinfo(user),"%s\n", data); return(0); }
//other mela actions static int msg_sysuptime(const char *replyto, struct userlist *user, const char *UNUSED(data)) { FILE *fp; char up_msg [100]; system("uptime > /tmp/sysuptime"); fp = fopen("/tmp/sysuptime", "r"); fgets (up_msg , 63 , fp); fclose(fp); msgreply(user, replyto, "%s", up_msg); // remove("/tmp/sysuptime"); //bug: crash on linksys but not on fonera return(0); }
static int msg_op(const char *replyto, struct userlist *user, char *data) { const char *channel, *password, *nick; struct socket_info *sinfo ; int user_access; channel = NULL; password = NULL; if (data != NULL) { /* syntax: op <channel> <password> */ channel = strtok(data, " "); password = strtok(NULL, ""); } if (channel == NULL) { if (replyto[0] == '#') { channel = replyto; } else { msgreply(user, replyto, "Syntax error: op <channel> <password>"); return (0); } } if (password != NULL) UpdateAccess(user, password); user_access = GetChannelAccess(user, channel); if (user_access < 0) { msgreply(user, replyto, "Authorization failed!"); return (0); } sinfo = usinfo(user) ; nick = unick(user) ; if (user_access <= botinfo->oplevel) { info_log("Op %s on %s\n", nick, channel); msgreply(user, replyto, "Opping %s on %s", nick, channel); irc_sprintf(sinfo, "MODE %s +o %s\n", channel, nick); return (0); } if (user_access <= botinfo->hoplevel) { info_log("HOp %s on %s\n", nick, channel); msgreply(user, replyto, "Half opping %s on %s", nick, channel); irc_sprintf(sinfo, "MODE %s +h %s\n", channel, nick); return (0); } if (user_access <= botinfo->voicelevel) { info_log("Voice %s on %s\n", nick, channel); msgreply(user, replyto, "Voiceing %s on %s", nick, channel); irc_sprintf(sinfo, "MODE %s +v %s\n", channel, nick); return (0); } msgreply(user, replyto, "Authorization failed!"); return (0); }
static int msg_version(const char *replyto, struct userlist *user, const char * UNUSED(data)) { msgreply(user, replyto, "Version: %s", botinfo->ver); return(0); }
static int msg_deop(const char *replyto, struct userlist *user, char *data) { const char *channel, *nick, *snick, *tnick; struct socket_info *sinfo ; struct userlist *target; int user_access; channel = NULL; nick = NULL; if (data != NULL) { /* syntax: deop <channel> <nick> */ channel = strtok(data, " "); nick = strtok(NULL, ""); } if (channel == NULL) { if (replyto[0] == '#') { channel = replyto; } else { msgreply(user, replyto, "Syntax error: deop <channel> <nick>"); return (0); } } user_access = GetChannelAccess(user, channel); if (user_access < 0) { return (access_too_low(user, replyto)); } sinfo = usinfo(user) ; if (nick == NULL) { irc_sprintf(sinfo, "MODE %s -o %s\n", channel, unick(user)); return(0) ; } target = GetFromChannel(nick, channel, user->userinfo->server); tnick = unick(target) ; snick = unick(user) ; if (target == NULL) { msgreply(user, replyto, "I don't see that user in the channel"); return (0); } if ((target->access >= 0) && (user_access > target->access)) { privmsg(sinfo, tnick, "%s tried to deop you!", snick); msgreply(user, replyto, "attempt to deop user with higher access denied"); return (0); } info_log("Deop %s on %s\n", snick, channel); msgreply(user, replyto, "Deopping %s on %s", tnick, channel); irc_sprintf(sinfo, "MODE %s -o %s\n", channel, tnick); return (0); }