class_topic::class_topic() { //Already loaded, do not load again if (this->topiclist.IsHeadLoaded == true) return; std::ifstream topicfile_stream(prefs_get_topicfile()); if (!topicfile_stream) { eventlog(eventlog_level_error, __FUNCTION__, "couldn't open topic file"); return; } std::string strLine; std::smatch match; const std::regex rgx("(.*)\t(.*)"); // tab character separates the channel name and topic //loop through each line in topic file while (std::getline(topicfile_stream, strLine)) { //obtain channel name and topic string pair from current line if (std::regex_search(strLine, match, rgx)) this->topiclist.add(match[1].str(), match[2].str(), true); else eventlog(eventlog_level_error, __FUNCTION__, "Invalid line in topic file (%s)", strLine.c_str()); } this->topiclist.IsHeadLoaded = true; }
//Saves data from Head vector to topic file int class_topic::class_topiclist::save() { std::ofstream topicfile_stream(prefs_get_topicfile(), std::ofstream::trunc); //FIXME: optimize this if (!topicfile_stream) { eventlog(eventlog_level_error, __FUNCTION__, "couldn't open topic file"); return -1; } for (auto topic : this->Head) { if (topic->save == true) topicfile_stream << topic->channel_name << "\t" << topic->topicstr << std::endl; // tab character separates the channel name and topic } return 0; }
int channel_set_topic(char const * channel_name, char const * topic_text, int do_save) { t_topic * topic; if (!(channel_name)) { eventlog(eventlog_level_error, __FUNCTION__, "got NULL channel_name"); return -1; } if (!(topic_text)) { eventlog(eventlog_level_error, __FUNCTION__, "got NULL topic"); return -1; } if ((topic = get_topic(channel_name))) { xfree((void *)topic->topic); topic->topic = xstrdup(topic_text); } else { topiclist_add_topic(channel_name, topic_text, do_save); } if (do_save == DO_SAVE_TOPIC) { if (topiclist_save(prefs_get_topicfile()) < 0) { eventlog(eventlog_level_error, __FUNCTION__, "error saving topic list"); return -1; } } return 0; }
int pre_server_startup(void) { pvpgn_greeting(); if (oom_setup() < 0) { eventlog(eventlog_level_error, __FUNCTION__, "OOM init failed"); return STATUS_OOM_FAILURE; } if (storage_init(prefs_get_storage_path()) < 0) { eventlog(eventlog_level_error, "pre_server_startup", "storage init failed"); return STATUS_STORAGE_FAILURE; } if (psock_init() < 0) { eventlog(eventlog_level_error, __FUNCTION__, "could not initialize socket functions"); return STATUS_PSOCK_FAILURE; } if (support_check_files(prefs_get_supportfile()) < 0) { eventlog(eventlog_level_error, "pre_server_startup","some needed files are missing"); eventlog(eventlog_level_error, "pre_server_startup","please make sure you installed the supportfiles in %s",prefs_get_filedir()); return STATUS_SUPPORT_FAILURE; } if (anongame_maplists_create() < 0) { eventlog(eventlog_level_error, "pre_server_startup", "could not load maps"); return STATUS_MAPLISTS_FAILURE; } if (anongame_matchlists_create() < 0) { eventlog(eventlog_level_error, "pre_server_startup", "could not create matchlists"); return STATUS_MATCHLISTS_FAILURE; } if (fdwatch_init(prefs_get_max_connections())) { eventlog(eventlog_level_error, __FUNCTION__, "error initilizing fdwatch"); return STATUS_FDWATCH_FAILURE; } connlist_create(); gamelist_create(); timerlist_create(); server_set_hostname(); channellist_create(); if (helpfile_init(prefs_get_helpfile())<0) eventlog(eventlog_level_error,__FUNCTION__,"could not load helpfile"); ipbanlist_create(); if (ipbanlist_load(prefs_get_ipbanfile())<0) eventlog(eventlog_level_error,__FUNCTION__,"could not load IP ban list"); if (adbannerlist_create(prefs_get_adfile())<0) eventlog(eventlog_level_error,__FUNCTION__,"could not load adbanner list"); if (autoupdate_load(prefs_get_mpqfile())<0) eventlog(eventlog_level_error,__FUNCTION__,"could not load autoupdate list"); if (versioncheck_load(prefs_get_versioncheck_file())<0) eventlog(eventlog_level_error,__FUNCTION__,"could not load versioncheck list"); if (news_load(prefs_get_newsfile())<0) eventlog(eventlog_level_error,__FUNCTION__,"could not load news list"); watchlist_create(); output_init(); attrlayer_init(); accountlist_create(); if (ladder_createxptable(prefs_get_xplevel_file(),prefs_get_xpcalc_file())<0) { eventlog(eventlog_level_error, "pre_server_startup", "could not load WAR3 xp calc tables"); return STATUS_WAR3XPTABLES_FAILURE; } ladders_init(); ladders_load_accounts_to_ladderlists(); ladder_update_all_accounts(); if (characterlist_create("")<0) eventlog(eventlog_level_error,__FUNCTION__,"could not load character list"); if (prefs_get_track()) /* setup the tracking mechanism */ tracker_set_servers(prefs_get_trackserv_addrs()); if (command_groups_load(prefs_get_command_groups_file())<0) eventlog(eventlog_level_error,__FUNCTION__,"could not load command_groups list"); aliasfile_load(prefs_get_aliasfile()); if (trans_load(prefs_get_transfile(),TRANS_BNETD)<0) eventlog(eventlog_level_error,__FUNCTION__,"could not load trans list"); tournament_init(prefs_get_tournament_file()); anongame_infos_load(prefs_get_anongame_infos_file()); clanlist_load(); teamlist_load(); if (realmlist_create(prefs_get_realmfile())<0) eventlog(eventlog_level_error,__FUNCTION__,"could not load realm list"); topiclist_load(prefs_get_topicfile()); return 0; }