static void edit_net(const Config& config, Networks& networks, int nn) { static const vector<pair<network_type_t, string>> nettypes = { {network_type_t::wwivnet, "WWIVnet "}, {network_type_t::ftn, "Fido "}, {network_type_t::internet, "Internet"} }; Subs subs(syscfg.datadir, networks.networks()); bool subs_loaded = subs.Load(); net_networks_rec& n = networks.at(nn); const string orig_network_name(n.name); const int COL1_POSITION = 14; int y = 1; EditItems items{ new ToggleEditItem<network_type_t>(out, COL1_POSITION, y++, nettypes, &n.type), new StringEditItem<char*>(COL1_POSITION, y++, 15, n.name, false), new NumberEditItem<uint16_t>(COL1_POSITION, y++, &n.sysnum), new StringFilePathItem(COL1_POSITION, y++, 60, config.root_directory(), n.dir) }; if (n.type == network_type_t::ftn) { auto net_dir = File::MakeAbsolutePath(config.root_directory(), n.dir); items.add(new FidoNetworkConfigSubDialog(net_dir, COL1_POSITION, y++, "Network Settings", 76, n)); items.add(new FidoPacketConfigSubDialog(net_dir, COL1_POSITION, y++, "Node Settings", 76, config, n)); } const string title = StrCat("Network Configuration; Net #", nn); unique_ptr<CursesWindow> window(out->CreateBoxedWindow(title, items.size() + 2, 76)); items.set_curses_io(out, window.get()); y = 1; window->PutsXY(2, y++, "Net Type :"); window->PutsXY(2, y++, "Net Name :"); window->PutsXY(2, y++, "Node # :"); window->PutsXY(2, y++, "Directory :"); if (n.type == network_type_t::ftn) { window->PutsXY(2, y++, "Settings :"); window->PutsXY(2, y++, "Addresses :"); } items.Run(); if (subs_loaded && orig_network_name != n.name) { subs.Save(); } networks.Save(); }
BinkConfig::BinkConfig(const std::string& callout_network_name, const Config& config, const Networks& networks) : config_(config), callout_network_name_(callout_network_name), networks_(networks) { // network names will alwyas be compared lower case. StringLowerCase(&callout_network_name_); system_name_ = config.config()->systemname; if (system_name_.empty()) { system_name_ = "Unnamed WWIV BBS"; } sysop_name_ = config.config()->sysopname; if (sysop_name_.empty()) { sysop_name_ = "Unknown WWIV SysOp"; } gfiles_directory_ = config.config()->gfilesdir; if (networks.contains(callout_network_name)) { const net_networks_rec& net = networks[callout_network_name]; if (net.type == network_type_t::wwivnet) { callout_wwivnet_node_ = net.sysnum; if (callout_wwivnet_node_ == 0) { throw config_error(StringPrintf("NODE not specified for network: '%s'", callout_network_name.c_str())); } binkp_.reset(new Binkp(net.dir)); } else if (net.type == network_type_t::ftn) { callout_fido_node_ = net.fido.fido_address; if (callout_fido_node_.empty()) { throw config_error(StringPrintf("NODE not specified for network: '%s'", callout_network_name.c_str())); } } else { throw config_error("BinkP is not supported for this network type."); } // TODO(rushfan): This needs to be a shim binkp that reads from the nodelist // or overrides. binkp_.reset(new Binkp(net.dir)); } }
static bool del_net( Networks& networks, int nn) { wwiv::sdk::Subs subs(syscfg.datadir, networks.networks()); if (!subs.Load()) { return false; } if (subs.subs().empty()) { return false; } // TODO(rushfan): Ensure that no subs are using it. for (size_t i = 0; i < subs.subs().size(); i++) { size_t i2; for (i2 = 0; i2 < i; i2++) { if (subs.sub(i).filename == subs.sub(i2).filename) { break; } } if (i2 >= i) { iscan1(i, subs); open_sub(true); for (int i1 = 1; i1 <= GetNumMessagesInCurrentMessageArea(); i1++) { postrec* p = get_post(i1); if (p->status & status_post_new_net) { if (p->network.network_msg.net_number == nn) { p->network.network_msg.net_number = static_cast<uint8_t>('\xff'); write_post(i1, p); } else if (p->network.network_msg.net_number > nn) { p->network.network_msg.net_number--; write_post(i1, p); } } } close_sub(); } } // Now we update the email. File emailfile(syscfg.datadir, EMAIL_DAT); if (emailfile.Open(File::modeBinary|File::modeReadWrite)) { auto t = emailfile.GetLength() / sizeof(mailrec); for (size_t r = 0; r < t; r++) { mailrec m = {}; emailfile.Seek(r * sizeof(mailrec), File::Whence::begin); emailfile.Read(&m, sizeof(mailrec)); if (((m.tosys != 0) || (m.touser != 0)) && m.fromsys) { if (strlen(m.title) >= WWIV_MESSAGE_TITLE_LENGTH) { // always trim to WWIV_MESSAGE_TITLE_LENGTH now. m.title[WWIV_MESSAGE_TITLE_LENGTH] = 0; } m.status |= status_new_net; if (m.status & status_source_verified) { if (m.network.src_verified_msg.net_number == nn) { m.network.src_verified_msg.net_number = static_cast<uint8_t>('\xff'); } else if (m.network.src_verified_msg.net_number > nn) { m.network.src_verified_msg.net_number--; } } else { if (m.network.network_msg.net_number == nn) { m.network.network_msg.net_number = static_cast<uint8_t>('\xff'); } else if (m.network.network_msg.net_number > nn) { m.network.network_msg.net_number--; } } emailfile.Seek(r * sizeof(mailrec), File::Whence::begin); emailfile.Write(&m, sizeof(mailrec)); } } } // Update the user unique_ptr<char[]> u(new char[syscfg.userreclen]); read_user(1, reinterpret_cast<userrec*>(u.get())); int nu = number_userrecs(); for (int i = 1; i <= nu; i++) { read_user(i, reinterpret_cast<userrec*>(u.get())); if (UINT(u.get(), syscfg.fsoffset)) { if (UCHAR(u.get(), syscfg.fnoffset) == nn) { UINT(u.get(), syscfg.fsoffset) = UINT(u.get(), syscfg.fuoffset) = UCHAR(u.get(), syscfg.fnoffset) = 0; write_user(i, reinterpret_cast<userrec*>(u.get())); } else if (UCHAR(u.get(), syscfg.fnoffset) > nn) { UCHAR(u.get(), syscfg.fnoffset)--; write_user(i, reinterpret_cast<userrec*>(u.get())); } } } // Finally delete it from networks.dat networks.erase(nn); return networks.Save(); }
static bool insert_net(const Config& config, Networks& networks, int nn) { wwiv::sdk::Subs subs(syscfg.datadir, networks.networks()); if (!subs.Load()) { return false; } if (subs.subs().empty()) { return false; } for (size_t i = 0; i < subs.subs().size(); i++) { size_t i2 = 0; for (i2 = 0; i2 < i; i2++) { if (subs.sub(i).filename == subs.sub(i2).filename) { break; } } if (i2 >= i) { iscan1(i, subs); open_sub(true); for (int i1 = 1; i1 <= GetNumMessagesInCurrentMessageArea(); i1++) { postrec* p = get_post(i1); if (p->status & status_post_new_net) { if (p->network.network_msg.net_number >= nn) { p->network.network_msg.net_number++; write_post(i1, p); } } } close_sub(); } } // same as del_net, don't think we need to do this here. // wwiv::sdk::write_subs(syscfg.datadir, subboards); File emailfile(syscfg.datadir, EMAIL_DAT); if (emailfile.Open(File::modeBinary|File::modeReadWrite)) { auto t = emailfile.GetLength() / sizeof(mailrec); for (size_t r = 0; r < t; r++) { mailrec m; emailfile.Seek(sizeof(mailrec) * r, File::Whence::begin); emailfile.Read(&m, sizeof(mailrec)); if (((m.tosys != 0) || (m.touser != 0)) && m.fromsys) { if (strlen(m.title) >= WWIV_MESSAGE_TITLE_LENGTH) { // always trim to WWIV_MESSAGE_TITLE_LENGTH now. m.title[71] = 0; } m.status |= status_new_net; if (m.status & status_source_verified) { if (m.network.src_verified_msg.net_number >= nn) { m.network.src_verified_msg.net_number++; } } else { if (m.network.network_msg.net_number >= nn) { m.network.network_msg.net_number++; } } emailfile.Seek(sizeof(mailrec) * r, File::Whence::begin); emailfile.Write(&m, sizeof(mailrec)); } } } unique_ptr<char[]> u(new char[syscfg.userreclen]); read_user(1, reinterpret_cast<userrec*>(u.get())); int nu = number_userrecs(); for (int i = 1; i <= nu; i++) { read_user(i, reinterpret_cast<userrec*>(u.get())); if (UINT(u.get(), syscfg.fsoffset)) { if (UCHAR(u.get(), syscfg.fnoffset) >= nn) { UCHAR(u.get(), syscfg.fnoffset)++; write_user(i, reinterpret_cast<userrec*>(u.get())); } } } { net_networks_rec n{}; strcpy(n.name, "NetNet"); n.dir = StrCat("newnet.dir", File::pathSeparatorChar); networks.insert(nn, n); } edit_net(config, networks, nn); return true; }
static void edit_net(Networks& networks, int nn) { static const vector<string> nettypes = { "WWIVnet ", "Fido ", "Internet", }; out->Cls(ACS_CKBOARD); unique_ptr<CursesWindow> window(out->CreateBoxedWindow("Network Configuration", 6, 76)); net_networks_rec& n = networks.at(nn); char szOldNetworkName[20]; strcpy(szOldNetworkName, n.name); if (n.type >= nettypes.size()) { n.type = 0; } const int COL1_POSITION = 14; EditItems items{ new ToggleEditItem<uint8_t>(COL1_POSITION, 1, nettypes, &n.type), new StringEditItem<char*>(COL1_POSITION, 2, 15, n.name, false), new NumberEditItem<uint16_t>(COL1_POSITION, 3, &n.sysnum), new FilePathItem(COL1_POSITION, 4, 60, n.dir), }; items.set_curses_io(out, window.get()); int y = 1; window->PutsXY(2, y++, "Net Type :"); window->PutsXY(2, y++, "Net Name :"); window->PutsXY(2, y++, "Node # :"); window->PutsXY(2, y++, "Directory :"); items.Run(); if (strcmp(szOldNetworkName, n.name)) { const string input_filename = StringPrintf("%ssubs.xtr", syscfg.datadir); const string output_filename = StringPrintf("%ssubsxtr.new", syscfg.datadir); FILE *pInputFile = fopen(input_filename.c_str(), "r"); if (pInputFile) { FILE *pOutputFile = fopen(output_filename.c_str(), "w"); if (pOutputFile) { char buffer[255]; while (fgets(buffer, 80, pInputFile)) { if (buffer[0] == '$') { char* ss = strchr(buffer, ' '); if (ss) { *ss = 0; if (strcasecmp(szOldNetworkName, buffer + 1) == 0) { fprintf(pOutputFile, "$%s %s", n.name, ss + 1); } else { fprintf(pOutputFile, "%s %s", buffer, ss + 1); } } else { fprintf(pOutputFile, "%s", buffer); } } else { fprintf(pOutputFile, "%s", buffer); } } fclose(pOutputFile); fclose(pInputFile); const string old_filename = StringPrintf("%ssubsxtr.old", syscfg.datadir); File::Remove(old_filename); File::Rename(input_filename, old_filename); File::Remove(input_filename); File::Rename(output_filename, input_filename); } else { fclose(pInputFile); } } } networks.Save(); }