int32_t next_system_reg(int16_t ts) { BbsListNet b = BbsListNet::ReadBbsDataNet(session()->current_net().dir); const auto& r = b.reg_number(); if (r.find(ts) != r.end()) { return r.at(ts); } return 0; }
net_system_list_rec *next_system(int ts) { static net_system_list_rec csne; BbsListNet b = BbsListNet::ReadBbsDataNet(session()->current_net().dir); auto c = b.node_config_for(ts); if (c == nullptr) { csne = {}; return nullptr; } csne = *c; return &csne; }
int main(int argc, char** argv) { Logger::Init(argc, argv); try { ScopeExit at_exit(Logger::ExitLogger); CommandLine cmdline(argc, argv, "net"); NetworkCommandLine net_cmdline(cmdline); if (!net_cmdline.IsInitialized() || cmdline.help_requested()) { ShowHelp(cmdline); return 1; } const auto& net = net_cmdline.network(); LOG(INFO) << "NETWORKF for network: " << net.name; if (net.type != network_type_t::ftn) { LOG(ERROR) << "NETWORKF is only for use on FTN type networks."; return 1; } VLOG(1) << "Reading BBSDATA.NET.."; BbsListNet b = BbsListNet::ReadBbsDataNet(net.dir); if (b.empty()) { LOG(ERROR) << "ERROR: Unable to read BBSDATA.NET."; LOG(ERROR) << " Do you need to run network3?"; return 3; } const net_system_list_rec* fake_ftn_node = b.node_config_for(FTN_FAKE_OUTBOUND_NODE); if (!fake_ftn_node) { LOG(ERROR) << "Can not find node for outbound FTN address."; LOG(ERROR) << " Do you need to run network3?"; return 3; } FidoCallout fido_callout(net_cmdline.config(), net); if (!fido_callout.IsInitialized()) { LOG(ERROR) << "Unable to initialize fido_callout."; return 1; } auto cmds = cmdline.remaining(); if (cmds.empty()) { LOG(ERROR) << "No command specified. Exiting."; return 1; } const string cmd = cmds.front(); cmds.erase(cmds.begin()); LOG(INFO) << "Command: " << cmd; LOG(INFO) << "Args: "; for (const auto& r : cmds) { LOG(INFO) << r << endl; } if (cmd == "import") { const std::vector<string> extensions{"su?", "mo?", "tu?", "we?", "th?", "fr?", "sa?", "pkt"}; auto net_dir = File::MakeAbsolutePath(net_cmdline.config().root_directory(), net.dir); auto inbounddir = File::MakeAbsolutePath(net_dir, net.fido.inbound_dir); for (const auto& ext : extensions) { import_bundles(net_cmdline.config(), fido_callout, net, inbounddir, StrCat("*.", ext)); #ifndef _WIN32 import_bundles(net_cmdline.config(), fido_callout, net, inbounddir, StrCat("*.", ToStringUpperCase(ext))); #endif } } else if (cmd == "export") { const string sfilename = StrCat("s", FTN_FAKE_OUTBOUND_NODE, ".net"); if (!File::Exists(net.dir, sfilename)) { LOG(INFO) << "No file '" << sfilename << "' exists to be exported to a FTN packet."; return 1; } // Packet file is created by us for sure. File f(net.dir, sfilename); if (!f.Open(File::modeBinary | File::modeReadOnly)) { LOG(ERROR) << "Unable to open file: " << net.dir << sfilename; return 1; } bool done = false; std::set<std::string> bundles; while (!done) { Packet p; wwiv::net::ReadPacketResponse response = read_packet(f, p, true); if (response == wwiv::net::ReadPacketResponse::END_OF_FILE) { // Delete the packet. f.Close(); f.Delete(); break; } else if (response == wwiv::net::ReadPacketResponse::ERROR) { return 1; } if (p.nh.main_type == main_type_new_post) { if (!export_main_type_new_post(net_cmdline, net, fido_callout, bundles, p)) { LOG(ERROR) << "Error exporting post."; } } else if (p.nh.main_type == main_type_email_name) { if (!export_main_type_email_name(net_cmdline, net, fido_callout, bundles, p)) { LOG(ERROR) << "Error exporting email."; } } else { LOG(ERROR) << "Unhandled type: " << main_type_name(p.nh.main_type); // Let's write it to dead.net if (!write_wwivnet_packet(DEAD_NET, net, p)) { LOG(ERROR) << "Error writing to DEAD.NET"; } } } } else { LOG(ERROR) << "Unknown command: " << cmd; return 1; } return 0; } catch (const std::exception& e) { LOG(ERROR) << "ERROR: [networkf]: " << e.what(); } return 2; }