From: plugd Date: Tue, 6 Aug 2024 04:10:26 +0000 (+0200) Subject: Working on rep file importing. X-Git-Url: https://thelambdalab.xyz/gitweb/index.cgi?a=commitdiff_plain;h=c83d889238d5e4bb3d64772099f3ca5d8a73a32f;p=qwikboard.git Working on rep file importing. --- diff --git a/obbs b/obbs index 6d04b6b..8b524b7 100755 --- a/obbs +++ b/obbs @@ -22,6 +22,8 @@ local usage = [[Usage: obbs [-c config_file] COMMAND [arguments ...] Here COMMAND is one of: newcfg init + qwkout + repin You can also use the -c option to specify an alternative configuration file. (The default is the file "config.lua" in the current directory.)]] @@ -96,7 +98,7 @@ function fs.mktempdir() return posix.mkdtemp("/tmp/obbs-XXXXXX") end ---- Message parsing --- +--- Message database parsing --- local msgs = {} function Message(msg) @@ -186,6 +188,20 @@ function qwk.write_message_blocks(mf, obbs, msg) mf:write(string.rep("\0",padding)) end +function qwk.read_message(archive_dir, obbs, user_name) + + local msg_filename = work_dir .. "/" .. obbs.bbsid .. ".MSG" + + if not fs.exists(msg_filename) then + print("Error: MSG file not found.") + return + end + + local mf = asert(io.open(msg_filename, "r")) + +end + + --- Commands --- local cmd = {} @@ -218,7 +234,6 @@ function cmd.init () load_config() if fs.exists(obbs.path .. "/conferences") or - fs.exists(obbs.path .. "/incoming") or fs.exists(obbs.path .. "/outgoing") then print("One or more OBBS directories already exist. Aborting.") return @@ -229,57 +244,85 @@ function cmd.init () fs.touch(obbs.path .. "conferences/" .. v .. ".msgs") end - fs.mkdir(obbs.path .. "incoming") fs.mkdir(obbs.path .. "outgoing") end --- Pack -function cmd.pack () +-- qwkout: generate QWK file +function cmd.qwkout () load_config() if not arg[1] then - print "Usage: obbs pack USER" + print "Usage: obbs qwkout USER" return end local user_name = arg[1] - local target_dir = fs.mktempdir() + local work_dir = fs.mktempdir() -- CONTROL.DAT - qwk.write_control(target_dir, obbs, user_name) + qwk.write_control(work_dir, obbs, user_name) -- Copy BBS welcome, news and goodbye files if obbs.hello and fs.exists(obbs.hello) then - fs.copy(obbs.hello, target_dir .. "/HELLO") + fs.copy(obbs.hello, work_dir .. "/HELLO") else - fs.touch(target_dir .. "/HELLO") + fs.touch(work_dir .. "/HELLO") end if obbs.news and fs.exists(obbs.news) then - fs.copy(obbs.news, target_dir .. "/NEWS") + fs.copy(obbs.news, work_dir .. "/NEWS") else - fs.touch(target_dir .. "/NEWS") + fs.touch(work_dir .. "/NEWS") end if obbs.news and fs.exists(obbs.goodbye) then - fs.copy(obbs.goodbye, target_dir .. "/GOODBYE") + fs.copy(obbs.goodbye, work_dir .. "/GOODBYE") else - fs.touch(target_dir .. "/GOODBYE") + fs.touch(work_dir .. "/GOODBYE") end -- Pack messages - qwk.write_message(target_dir, obbs) + qwk.write_message(work_dir, obbs) -- Create archive in outgoing os.execute("zip -rj " .. obbs.path .. "/outgoing/" .. obbs.bbsid .. - ".qwk " .. target_dir) + ".qwk " .. work_dir) + + fs.rmdir(work_dir, true) +end + +-- repin: read REP file in - fs.rmdir(target_dir, true) +function cmd.repin() + load_config() + + if not arg[2] then + print "Usage: obbs repin FILE USER" + return + end + + local rep_filename = arg[1] + local user_name = arg[2] + + if not fs.exists(rep_filename) then + print("Error: reply packet file '" .. rep_filename .. "' does not exist.") + return + end + + local work_dir = fs.mktempdir() + + fs.copy(rep_filename, work_dir .. "/repfile.rep") + os.execute("unzip " .. work_dir .. "/repfile.rep -d " .. work_dir) + + qwk.read_message(work_dir, obbs, user_name) + + fs.rmdir(work_dir, true) + end -- Main