void makedir(char* file) { char* ptr; char* remember = NULL; char buffer [MAX_BUFFER], filename[MAX_BUFFER]; buffer[0] = '\0'; if((ptr = m_strtok_r(file, "/\\", &remember)) != NULL) { do { if(buffer[0] != '\0' || file[0] == '/') m_sprintf(filename, MAX_BUFFER, "%s/%s", buffer, ptr); else m_sprintf(filename, MAX_BUFFER, "%s", ptr); m_sprintf(buffer, MAX_BUFFER, "%s", filename); #ifdef WINDOWS CreateDirectoryA(filename, NULL); #else mkdir(filename, S_IRWXU); #endif } while((ptr = m_strtok_r(NULL, "/\\", &remember)) != NULL); } }
void add_to_a_list(char *thestring, int thetype, char *nick, char *channels, char *reason, int shitlevel) { ShitList *sremove = NULL; int scount = 0; switch(thetype) { case SHITLIST_ADD: { if (!(sremove = nickinshit(nick, thestring))) { shit_count++; sremove = (ShitList *) new_malloc(sizeof(ShitList)); sremove->level = shitlevel; sremove->reason = m_strdup(reason); sremove->channels = m_strdup(channels); sremove->filter = m_sprintf("%s!%s", nick, thestring); add_to_list((List **)&shitlist_list, (List *)sremove); sync_whowas_addshit(sremove); sync_shitlist(sremove, 1); if (shitlevel == PERM_IGNORE) ignore_nickname(sremove->filter, IGNORE_ALL, 0); bitchsay("Adding %s!%s to Shitlist", nick, thestring); } else bitchsay ("%s!%s already on my Shitlist", nick, thestring); break; } case SHITLIST_REMOVE: { char *s_str; s_str = m_sprintf("%s!%s", nick, thestring); while ((sremove = (ShitList *)removewild_from_list((List **)&shitlist_list, s_str))) { shit_count--; scount++; if (sremove->level == PERM_IGNORE) ignore_nickname(sremove->filter, IGNORE_ALL, IGNORE_REMOVE); sync_whowas_unshit(sremove); sync_shitlist(sremove, 0); new_free(&sremove->filter); new_free(&sremove->reason); new_free(&sremove->channels); new_free((char **)&sremove); bitchsay("Deleting %s!%s from Shitlist", nick, thestring); } if (!scount) bitchsay("Didnt find %s!%s on the Shitlist", nick, thestring); new_free(&s_str); break; } } }
void ignore_last_nick(char dumb, char *dumber) { NickTab *nick; char *tmp1; if ((nick = gettabkey(1, NULL))) { set_input(empty_str); tmp1 = m_sprintf("%sig %s", get_string_var(CMDCHARS_VAR), nick->nick); set_input(tmp1); new_free(&tmp1); } update_input(UPDATE_ALL); }
static void foreach_count(const char* filename, int is_file, void* unused) { char buffer[MAX_BUFFER]; (void)unused; if(is_file) { m_sprintf( buffer, MAX_BUFFER, DATA_PATH "/" MODELS "%s", filename); if(archive_is_archive(buffer)) model_nb_filenames++; } }
static void foreach_concat(const char* filename, int is_file, void* data) { char*** ptr = (char***)data; char buffer[MAX_BUFFER]; if(is_file) { m_sprintf( buffer, MAX_BUFFER, DATA_PATH "/" MODELS "%s", filename); if(archive_is_archive(buffer)) { **ptr = m_strdup(filename); *ptr += 1; } } }
int opengl_font_build( font_t* font, const char* file, int size) { opengl_font_t* o; if((o = (opengl_font_t*)malloc(sizeof(opengl_font_t))) == NULL) return 0; font->size = size; font->data = (void*)o; m_sprintf(o->name, MAX_BUFFER, DATA_PATH "/" FONTS "/%s", file); o->atlas = texture_atlas_new(512, 512, 1); o->font = texture_font_new(o->atlas, o->name, size * window_zoom); texture_font_load_glyphs(o->font, cache); current_font = font; // Set last build to current one. return 1; }
bool SaveAdminList(COutStream& stream) { std::string data; data.reserve(1 << 12); // 4kb for (auto itr = admin::adminList.cbegin(); itr != admin::adminList.cend(); ++itr) { data += itr->second.name + ","; data += itr->second.hash + ","; data += m_sprintf("%i\r\n", itr->second.accessLevel.get_level()); } std::wstring adminPathTmp = adminPath + L".tmp"; CTempFile<COutFile> file; if (!file.Open(adminPathTmp, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ, OPEN_ALWAYS)) { stream << L"can't open admin file : " << adminPath << endl; return false; } DWORD written; if (!file.Write((BYTE*)data.c_str(), data.size(), &written)) { stream << "can't write to new admin file" << endl; return false; } file.Close(); if (!CFile::Move(adminPathTmp, adminPath, true)) { stream << "can't replace old admin file " << adminPath << endl; return false; } file.success(); return true; }
int delay_check_auto (char *channel) { ChannelList *chan = NULL; char *buffer = NULL; NickList *possible; if (!channel || !*channel) return -1; if ((chan = lookup_channel(channel, from_server, CHAN_NOUNLINK)) == NULL) return -1; for (possible = next_nicklist(chan, NULL); possible; possible = next_nicklist(chan, possible)) { if ((possible->shitlist || possible->userlist) && (!(possible->sent_reop < 4) || !(possible->sent_deop < 4))) { malloc_sprintf(&buffer, "%s %s %s %d", channel, possible->nick, possible->host, from_server); add_timer(0, empty_string, 3 * 1000, 1, real_check_auto, buffer, NULL, -1, "check-auto"); } } add_timer(0, empty_string, 5 * 1000, 1, delay_flush_all, m_sprintf("%s %d", channel, from_server), NULL, -1, "check-auto"); return 0; }
int dir_foreach( const char* dirname, void (*first_pass)(const char*, int, void*), int (*process)(void*), void (*second_pass)(const char*, int, void*), void* data) { #ifndef WINDOWS DIR* dir; struct dirent* rem, entry; int err; if((dir = opendir(dirname)) == NULL) return 0; if(first_pass) { for(err = readdir_r(dir, &entry, &rem) ; rem != NULL && err == 0 ; err = readdir_r(dir, &entry, &rem)) { // Only list regular filed and directories. if(entry.d_type & DT_REG) first_pass(entry.d_name, 1, data); else if(entry.d_type & DT_DIR) first_pass(entry.d_name, 0, data); } rewinddir(dir); } if(process) process(data); if(second_pass) { for(err = readdir_r(dir, &entry, &rem) ; rem != NULL && err == 0 ; err = readdir_r(dir, &entry, &rem)) { // Only list regular filed and directories. if(entry.d_type & DT_REG) second_pass(entry.d_name, 1, data); else if(entry.d_type & DT_DIR) second_pass(entry.d_name, 0, data); } } closedir(dir); return 1; #else HANDLE h; WIN32_FIND_DATA fd; char buffer[MAX_BUFFER]; // We need to add a * to get all files in the // current directory. m_sprintf( buffer, MAX_BUFFER, "%s*", dirname); if(first_pass) { if((h = FindFirstFileA(buffer, &fd)) == INVALID_HANDLE_VALUE) return 0; do { int is_file = !(fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY); first_pass(fd.cFileName, is_file, data); } while(FindNextFileA(h, &fd)); FindClose(h); } if(process) process(data); // Apparently there's no way to rewind with Windows :( if(second_pass) { if((h = FindFirstFileA(buffer, &fd)) == INVALID_HANDLE_VALUE) return 0; do { int is_file = !(fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY); second_pass(fd.cFileName, is_file, data); } while(FindNextFileA(h, &fd)); FindClose(h); } return 1; #endif }
CSetList *create_csets_for_channel(char *channel) { CSetList *tmp; #ifdef VAR_DEBUG int i; for (i = 1; i < NUMBER_OF_CSETS - 1; i++) if (strcmp(cset_array[i-1].name, cset_array[i].name) >= 0) ircpanic("Variable [%d] (%s) is out of order.", i, cset_array[i].name); #endif if (check_cset_queue(channel, 0)) { if ((tmp = (CSetList *)find_in_list((List **)&cset_queue, channel, 0))) return tmp; for (tmp = cset_queue; tmp; tmp = tmp->next) if (!my_stricmp(tmp->channel, channel) || wild_match(tmp->channel, channel)) return tmp; } tmp = (CSetList *) new_malloc(sizeof(CSetList)); /* use default settings. */ tmp->set_aop = get_int_var(AOP_VAR); tmp->set_annoy_kick = get_int_var(ANNOY_KICK_VAR); tmp->set_ainv = get_int_var(AINV_VAR); tmp->set_auto_join_on_invite = get_int_var(AUTO_JOIN_ON_INVITE_VAR); tmp->set_auto_rejoin = get_int_var(AUTO_REJOIN_VAR); tmp->set_bantime = get_int_var(BANTIME_VAR); tmp->compress_modes = get_int_var(COMPRESS_MODES_VAR); tmp->bitch_mode = get_int_var(BITCH_VAR); tmp->channel_log = 0; tmp->log_level = m_strdup("ALL"); set_msglog_channel_level(cset_array, tmp); #if defined(WINNT) || defined(__EMX__) tmp->channel_log_file = m_sprintf("~/bx-conf/%s.log", channel+1); #else tmp->channel_log_file = m_sprintf("~/.BitchX/%s.log", channel+1); #endif tmp->set_joinflood = get_int_var(JOINFLOOD_VAR); tmp->set_joinflood_time = get_int_var(JOINFLOOD_TIME_VAR); tmp->set_ctcp_flood_ban = get_int_var(CTCP_FLOOD_BAN_VAR); tmp->set_deop_on_deopflood = get_int_var(DEOP_ON_DEOPFLOOD_VAR); tmp->set_deop_on_kickflood = get_int_var(DEOP_ON_KICKFLOOD_VAR); tmp->set_deopflood = get_int_var(DEOPFLOOD_VAR); tmp->set_deopflood_time = get_int_var(DEOPFLOOD_TIME_VAR); tmp->set_hacking = get_int_var(HACKING_VAR); tmp->set_kick_on_deopflood = get_int_var(KICK_ON_DEOPFLOOD_VAR); tmp->set_kick_on_joinflood = get_int_var(KICK_ON_JOINFLOOD_VAR); tmp->set_kick_on_kickflood = get_int_var(KICK_ON_KICKFLOOD_VAR); tmp->set_kick_on_nickflood = get_int_var(KICK_ON_NICKFLOOD_VAR); tmp->set_kick_on_pubflood = get_int_var(KICK_ON_PUBFLOOD_VAR); tmp->set_kickflood = get_int_var(KICKFLOOD_VAR); tmp->set_kickflood_time = get_int_var(KICKFLOOD_TIME_VAR); tmp->set_kick_ops = get_int_var(KICK_OPS_VAR); tmp->set_nickflood = get_int_var(NICKFLOOD_VAR); tmp->set_nickflood_time = get_int_var(NICKFLOOD_TIME_VAR); tmp->set_pubflood = get_int_var(PUBFLOOD_VAR); tmp->set_pubflood_time = get_int_var(PUBFLOOD_TIME_VAR); tmp->set_pubflood_ignore = 60; tmp->set_userlist = get_int_var(USERLIST_VAR); tmp->set_shitlist = get_int_var(SHITLIST_VAR); tmp->set_lamelist = get_int_var(LAMELIST_VAR); tmp->set_lame_ident = get_int_var(LAMEIDENT_VAR); tmp->set_kick_if_banned = get_int_var(KICK_IF_BANNED_VAR); tmp->set_auto_limit = get_int_var(AUTO_LIMIT_VAR); malloc_strcpy(&tmp->chanmode, get_string_var(CHANMODE_VAR)); malloc_strcpy(&tmp->channel, channel); return tmp; }
void prepare_adduser(UserhostItem *stuff, char *nick, char *args) { int thetype = 0; unsigned long flags = 0; int ppp = 0; UserList *uptr = NULL; char *channels = NULL, *passwd = NULL, *p = NULL, *uh, *e_host, *host; if (!stuff || !stuff->nick || !nick || !strcmp(stuff->user, "<UNKNOWN>") || my_stricmp(stuff->nick, nick)) { bitchsay("No such nick [%s] found", nick); return; } thetype = my_atol(args); next_arg(args, &args); ppp = my_atol(args); next_arg(args, &args); channels = next_arg(args, &args); p = next_arg(args, &args); flags = convert_str_to_flags(p); passwd = next_arg(args, &args); uh = clear_server_flags(stuff->user); if (*stuff->user == '~' || *stuff->user == '^') { while ((strlen(uh) > 8)) uh++; host = m_sprintf("*%s@%s", uh, ppp ? cluster(stuff->host) : stuff->host); } else host = m_sprintf("%s@%s", uh, ppp ? cluster(stuff->host) : stuff->host); e_host = m_sprintf("%s@%s", stuff->user, stuff->host); if (thetype == USERLIST_ADD) { char *e_pass = NULL; if (passwd) e_pass = cryptit(passwd); if (!(uptr = lookup_userlevelc(stuff->nick, e_host, channels, NULL))) { add_userhost_to_userlist(stuff->nick, host, channels, e_pass, flags); send_to_server("NOTICE %s :You have been added to my Userlist as *!%s with [%s]", nick, host, convert_flags_to_str(flags)); send_to_server("NOTICE %s :You are allowed on channels [%s]", nick, channels); if (passwd) send_to_server("NOTICE %s :Your password is [%s]", nick, passwd); put_it("%s", convert_output_format("$G Added [*!$0] on $1. Password is [$2] and flags are [$3-]", "%s %s %s %s", host, channels, passwd?passwd:"None", convert_flags_to_str(flags))); } else if (passwd) { send_to_server("NOTICE %s :Your password is %s[%s]", nick, uptr->password ? "changed to " : "", passwd); malloc_strcpy(&uptr->password, e_pass); } } else { if (!(remove_userhost_from_userlist(host, channels))) bitchsay("User not found on the userlist"); else put_it("%s", convert_output_format("$G Removed [$0] on $1 from userlist", "%s %s", host, channels)); } new_free(&e_host); new_free(&host); }
/* * Protection levels * 1 Reop if de-oped * 2 De-op offender * 3 Kick offender * 4 KickBan offender */ int check_prot(char *from, char *person, ChannelList *chan, BanList *thisban, NickList *n) { NickList *tmp = NULL; NickList *kicker; char *tmp_ban = NULL; char *nick = NULL, *userhost = NULL, *p; if (!from || !*from || !person || !*person || !chan) return 0; if (!my_stricmp(person, from)) return 0; tmp_ban = LOCAL_COPY(person); if ((p = strchr(tmp_ban, '!'))) { nick = tmp_ban; *p++ = 0; userhost = p; } else nick = person; if (!n) { if (!(tmp = find_nicklist_in_channellist(person, chan, 0))) { for (tmp = next_nicklist(chan, NULL); tmp; tmp = next_nicklist(chan, tmp)) { if (wild_match(nick, tmp->nick) && wild_match(userhost, tmp->host) && tmp->userlist) { n = tmp; break; } } } } if (get_cset_int_var(chan->csets, USERLIST_CSET) && chan->chop && ((n && n->userlist) || (tmp && tmp->userlist))) { UserList *user = NULL; time_t current = now; if (n) user = n->userlist; else user = tmp->userlist; if (!user || (user && !check_channel_match(user->channels, chan->channel))) return 0; if (!(kicker = find_nicklist_in_channellist(from, chan, 0))) return 0; if ((user->flags & (PROT_DEOP | PROT_INVITE | PROT_BAN | PROT_KICK | PROT_REOP))) { int do_reop = 0; if (user->flags & PROT_DEOP) { if (!kicker->sent_deop) { if (!kicker->userlist || (kicker->userlist && !(kicker->userlist->flags & PROT_DEOP))) send_to_server("MODE %s -o %s", chan->channel, from); kicker->sent_deop++; } do_reop = 1; } if (user->flags & PROT_INVITE) { if (thisban && !thisban->sent_unban) { thisban->sent_unban++; thisban->sent_unban_time = current; send_to_server("MODE %s -b %s", chan->channel, thisban->ban); send_to_server("INVITE %s %s", n?n->nick:tmp->nick, chan->channel); } } if (user->flags & PROT_BAN) { /* do_reop = 1; */ if (kicker->userlist) send_to_server("MODE %s -o %s", chan->channel, from); else { char *h, *u; u = LOCAL_COPY(kicker->host); h = strchr(u, '@'); *h++ = 0; send_to_server("MODE %s -o+b %s %s", chan->channel, kicker->nick, ban_it(kicker->nick, u, h, kicker->ip)); if (get_int_var(AUTO_UNBAN_VAR)) add_timer(0, empty_string, get_int_var(AUTO_UNBAN_VAR) * 1000, 1, timer_unban, m_sprintf("%d %s %s", from_server, chan->channel, ban_it(kicker->nick, u, h, kicker->ip)), NULL, -1, "auto-unban"); } } if (user->flags & PROT_KICK) { if (kicker && (!kicker->userlist || (kicker->userlist && !(kicker->userlist->flags & PROT_KICK)))) send_to_server("KICK %s %s :\002BitchX\002 Protected User", chan->channel, kicker->nick); } if ((user->flags & PROT_REOP) || do_reop) { /* added by Sergs [email protected] */ if (thisban) { if (thisban->sent_unban_time - current > 30) { thisban->sent_unban++; thisban->sent_unban_time = current; send_to_server("MODE %s -b %s", chan->channel, thisban->ban); } else if (thisban->sent_unban < 3) { thisban->sent_unban++; thisban->sent_unban_time = current; send_to_server("MODE %s -b %s", chan->channel, thisban->ban); } } if (n && (!n->sent_reop || (n->sent_reop_time && (current - n->sent_reop_time > 60)))) { char *u = NULL; malloc_sprintf(&u, "%s %s %s %s %d", chan->channel, n->nick, n->host, "o", from_server); add_timer(0, empty_string, 10 * 1000, 1, delay_opz, u, NULL, -1, "delay-ops"); n->sent_reop++; n->sent_reop_time = current; } } } if ((user->flags & USER_FLAG_PROT) && (p = get_string_var(USER_FLAG_PROT_VAR))) run_user_flag("USER_FLAG_PROT", p, n, kicker); return 1; } return 0; }
NickList *check_auto(char *channel, NickList *nicklist, ChannelList *chan) { ShitList *shitptr = NULL; UserList *userptr = NULL; ChannelList *chan_ptr = NULL; char *ban; if (!channel || !*channel || !nicklist) return NULL; if (!chan) { ChannelList *chan2; chan2 = get_server_channels(from_server); chan_ptr = (ChannelList *) find_in_list((List **)&chan2, channel, 0); } else chan_ptr = chan; if (!chan_ptr) return NULL; if (!chan_ptr->chop) return nicklist; userptr = nicklist->userlist; shitptr = nicklist->shitlist; if (userptr && !check_channel_match(userptr->channels, channel)) userptr = NULL; if (shitptr && (!check_channel_match(shitptr->channels, channel) || isme(nicklist->nick))) shitptr = NULL; if (get_cset_int_var(chan_ptr->csets, SHITLIST_CSET) && shitptr != NULL && userptr == NULL) { char *theshit; time_t current = now; theshit = get_string_var(SHITLIST_REASON_VAR); switch(shitptr->level) { case 0: return nicklist; break; case 1:/* never give opz */ if (nicklist->sent_deop < 4 && nick_isop(nicklist)) { add_mode(chan_ptr, "o", 0, nicklist->nick, NULL, get_int_var(NUM_OPMODES_VAR)); nicklist->sent_deop++; nicklist->sent_deop_time = current; } break; case 2: /* Auto Kick offender */ add_mode(chan_ptr, NULL, 0, nicklist->nick, shitptr->reason?shitptr->reason:theshit, 0); break; case 3: /* kick ban the offender */ case 4: /* perm ban on offender */ if (nicklist->sent_deop < 4 || (nicklist->sent_deop < 4 && shitptr->level == 4)) { send_to_server("MODE %s -o+b %s %s", channel, nicklist->nick, shitptr->filter); nicklist->sent_deop++; nicklist->sent_deop_time = current; if (get_int_var(AUTO_UNBAN_VAR) && shitptr->level != 4) add_timer(0, empty_string, get_int_var(AUTO_UNBAN_VAR) * 1000, 1, timer_unban, m_sprintf("%d %s %s", from_server, channel, shitptr->filter), NULL, -1, "auto-unban"); } if (get_cset_int_var(chan_ptr->csets, KICK_IF_BANNED_CSET)) send_to_server("KICK %s %s :%s", channel, nicklist->nick, (shitptr->reason && *shitptr->reason) ? shitptr->reason : theshit); default: break; } return nicklist; } if (userptr && get_cset_int_var(chan_ptr->csets, USERLIST_CSET)) { char *buffer = NULL; time_t current = now; int done = 0; char *p = NULL; if (get_cset_int_var(chan_ptr->csets, AOP_CSET)) { if ((userptr->flags & ADD_OPS)) { done++; if (!userptr->password && !nicklist->sent_reop && !nick_isop(nicklist)) { nicklist->sent_reop++; nicklist->sent_reop_time = current; if (!(userptr->flags & ADD_IOPS)) { malloc_sprintf(&buffer, "%s %s %s %s %d", channel, nicklist->nick, nicklist->host, "o", from_server); add_timer(0, empty_string, 10 * 1000, 1, delay_opz, buffer, NULL, -1, "delay-ops"); } else send_to_server("MODE %s +o %s", chan_ptr->channel, nicklist->nick); } } else if ((userptr->flags & ADD_VOICE)) { done++; if (!nicklist->sent_voice && !nick_isvoice(nicklist)) { nicklist->sent_voice++; nicklist->sent_voice_time = current; if (!(userptr->flags & ADD_IOPS)) { malloc_sprintf(&buffer, "%s %s %s %s %d", channel, nicklist->nick, nicklist->host, "v", from_server); add_timer(0, empty_string, 10 * 1000, 1, delay_opz, buffer, NULL, -1, "delay-ops"); } else send_to_server("MODE %s +v %s", chan_ptr->channel, nicklist->nick); } } } if ((userptr->flags & USER_FLAG_OPS) && (p = get_string_var(USER_FLAG_OPS_VAR))) { done++; run_user_flag("USER_FLAG_OPS", p, nicklist, NULL); } if (done) return nicklist; } if (get_cset_int_var(chan_ptr->csets, KICK_IF_BANNED_CSET) && check_channel_match(get_string_var(PROTECT_CHANNELS_VAR), chan_ptr->channel)) { char *ipban = NULL; char *u = NULL; if (!nicklist->host) return nicklist; ban = m_3dup(nicklist->nick, "!", nicklist->host); if (nicklist->ip && nicklist->host) { char *user = alloca(strlen(nicklist->host)+1); strcpy(user, nicklist->host); if ((u = strchr(user, '@'))) *u = 0; ipban = m_opendup(nicklist->nick, "!", user, "@", nicklist->ip, NULL); } if (!isme(nicklist->nick) && (!eban_is_on_channel(ban, chan_ptr) && (ban_is_on_channel(ban, chan_ptr) || (ipban && ban_is_on_channel(ipban, chan_ptr)))) ) { new_free(&ban); new_free(&ipban); if (nick_isop(nicklist) && !get_cset_int_var(chan_ptr->csets, KICK_OPS_CSET)) return nicklist; my_send_to_server(from_server, "KICK %s %s :Banned", chan_ptr->channel, nicklist->nick); } new_free(&ban); new_free(&ipban); } return nicklist; }