Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local pkg = {
- money = "local tempAmt = 0!@#&local tempPass = 0!@#&!@#&function split(str, pat)!@#& local t = { }!@#& local fpat = '(.-)'..pat!@#& local last_end = 1!@#& local s, e, cap = str:find(fpat, 1)!@#& while s do!@#& if s ~= 1 or cap ~= '' then!@#& table.insert(t,cap)!@#& end!@#& last_end = e+1!@#& s, e, cap = str:find(fpat, last_end)!@#& end!@#& if last_end <= #str then!@#& cap = str:sub(last_end)!@#& table.insert(t, cap)!@#& end!@#& return t!@#&end!@#&!@#&local tArgs = { ... }!@#&if #tArgs<1 then!@#& print(\"No arguments! Usage: mailserver <serverid> <modemside>\")!@#& return!@#&end!@#&if #tArgs~=2 then side = \"top\"!@#&else side = tArgs[2] end!@#&term.write(\"Enter ComputerID of Master Server: \")!@#&master = tonumber(tArgs[1])!@#&if master == -1 then!@#& print(\"Bad ID! Check ID of master server and update startup.\");!@#& return!@#&end!@#&!@#&term.clear()!@#&term.setCursorPos(1,1)!@#&rednet.open(side)!@#&!@#&local id, msg;!@#&while true do!@#& print(\"Requesting admission on \"..master)!@#& rednet.send(master, \"$MASTER$ADDSERVER-\"..os.getComputerID()..\"-MONEY\")!@#& id, msg = rednet.receive(5)!@#& if msg==\"$ACK\" then!@#& print(\"Confirmed.\")!@#& break;!@#& end!@#&end!@#&!@#&function readFromFile(accountName)!@#& if(fs.exists(accountName)) then!@#& local file = io.open(accountName, \"r\")!@#& local fline = file:read()!@#& file:close()!@#& local finfo = split(fline, \"-\")!@#& tempAmt = finfo[2]!@#& tempPass = finfo[1]!@#& end!@#&end!@#&!@#&function writeToFile(accountName, txt, pass)!@#& local file = io.open(accountName, \"w\")!@#& if file then!@#& file:flush()!@#& file:write(pass..\"-\"..txt)!@#& file:close()!@#& end!@#&end!@#&!@#&function transfer(info)!@#& readFromFile(info[1])!@#& if tempPass == info[2] then!@#& tempAmt = tempAmt - info[4]!@#& writeToFile(info[1], tempAmt, tempPass)!@#& readFromFile(info[3])!@#& tempAmt = tempAmt + info[4]!@#& writeToFile(info[3], tempAmt, tempPass)!@#& tempAmt = 0!@#& end!@#&end!@#&!@#&function newAccount(info)!@#& file = io.open(info[1], \"w\")!@#& file:write(info[2]..\"-0\")!@#& file:close()!@#&end!@#&!@#&function getAccountBalance(info)!@#& readFromFile(info[1])!@#& resp=\"$CLIENT-\"..info[2]..\"-\"..tempAmt!@#& rednet.send(master, resp)!@#&end!@#&!@#&term.clear()!@#&term.setCursorPos(1,1)!@#&print(\"Deathman Money Server\")!@#&print(\"Designed by KeeganDeathman\")!@#&print(string.rep(\"-\", 50))!@#&!@#&while true do!@#& local sender,msg = rednet.receive()!@#& if string.find(msg, \"$REQUEST\") then!@#& print(\"Message received!\")!@#& print(\"Request received: Responding...\")!@#& msg = string.gsub(msg, \"$REQUEST\", \"\")!@#& -- The master server is always the sender, but it must be replaced with the actual recipient!@#& sender = tonumber(msg)!@#& dispatchRequest(sender)!@#& print(\"Complete.\")!@#& elseif string.find(msg, \"$MONEY\") then!@#& print(\"Message received!\")!@#& print(msg)!@#& print(\"Money Order Received: Applying\")!@#& msg = string.gsub(msg, \"$MONEY\", \"\")!@#& if string.find(msg, \"$TRANSFER\") then!@#& msg = string.gsub(msg, \"$TRANSFER\", \"\")!@#& local info = split(msg, \"-\")!@#& transfer(info)!@#& elseif string.find(msg, \"$NEWACCOUNT\") then!@#& msg = string.gsub(msg, \"$NEWACCOUNT\", \"\")!@#& msg = split(msg, \"-\")!@#& newAccount(msg)!@#& elseif string.find(msg, \"$GETBALANCE\") then!@#& msg = string.gsub(msg, \"$GETBALANCE\", \"\")!@#& info = split(msg, \"-\")!@#& getAccountBalance(info)!@#& end!@#& print(\"Complete.\")!@#& end!@#&end!@#&!@#&!@#&--Transfer will take (account1Name, account1Pass, account2Name, amt), and will subtract amt from account1, and add amt to account2!@#&--New Account needs a password and a name. Default money value is 0!@#&--Get Account Balance requires account name and client ID",
- PkgMake = "sPackage = \"local pkg = %@1 local function makeFile(_path, _content) local file = fs.open(_path, \\\"w\\\") _content = _content:gsub(\\\"\\!@\\\"..\\\"#&\\\", \\\"%\\\\n\\\") _content = textutils.unserialize(_content) file.write(_content) file.close() end local function makeFolder(_path, _content) fs.makeDir(_path) for k,v in pairs(_content) do if type(v) == \\\"table\\\" then makeFolder(_path .. \\\"/\\\" .. k, v) else makeFile(_path .. \\\"/\\\" .. k, v) end end end local sDest = shell.resolve( \\\"%@2\\\" ) or \\\"/\\\" if sDest == \\\"root\\\" then sDest = \\\"/\\\" end local tPackage = pkg makeFolder(sDest, tPackage) print(\\\"Package Extracted to '\\\" .. sDest .. \\\"'!\\\")\"!@#&!@#&function addFile(_package, _path)!@#& if fs.getName(_path) == \".DS_Store\" then!@#& return _package!@#& end!@#& local file, err = fs.open(_path, \"r\")!@#& local content = file.readAll()!@#& content = content:gsub(\"%\\n\", \"\\!@\"..\"#&\")!@#& content = content:gsub(\"%%\", \"%%%%\")!@#& _package[fs.getName(_path)] = content!@#& file.close()!@#& print(\"Added file '\".._path..\"'\")!@#& return _package!@#&end!@#&!@#&function addFolder(_package, _path)!@#& if string.sub(_path,1,string.len(\"rom\"))==\"rom\" or string.sub(_path,1,string.len(\"/rom\"))==\"/rom\" then!@#& print(\"Ignored 'rom' folder. (\".._path..\")\")!@#& return!@#& end!@#& _package = _package or {}!@#& for _,f in ipairs(fs.list(_path)) do!@#& local path = _path..\"/\"..f!@#& if fs.isDir(path) then!@#& _package[fs.getName(f)] = addFolder(_package[fs.getName(f)], path)!@#& else!@#& _package = addFile(_package, path)!@#& end!@#& end!@#& return _package!@#&end!@#&!@#&local tArgs = { ... }!@#&if #tArgs < 2 then!@#& print( \"Usage: PkgMake <source> <destination>\" )!@#& return!@#&end!@#&!@#&local sSource = shell.resolve( tArgs[1] )!@#&local sDest = shell.resolve( tArgs[2] )!@#&!@#&if fs.isDir( sDest ) then!@#& error(\"Destination must not be a folder.\")!@#&end!@#&!@#&if sSource == sDest then!@#& error(\"Source can not be equal to destination.\")!@#&end!@#&!@#&if fs.exists( sSource ) and fs.isDir( sSource ) then!@#& tPackage = {}!@#& tPackage = addFolder(tPackage, sSource)!@#& fPackage = fs.open(sDest,\"w\")!@#&!@#& sPackage = string.gsub(sPackage, \"%%@2\", fs.getName(sSource))!@#& sPackage = string.gsub(sPackage, \"%%@1\", textutils.serialize(tPackage))!@#& fPackage.write(sPackage)!@#& fPackage.close()!@#& print(\"Package Done! ('\" .. sDest .. \"')\")!@#& print(\"Type '\" .. sDest .. \"' to run it.\")!@#&else!@#& error(\"Source does not exist or is not a folder.\")!@#&end",
- } local function makeFile(_path, _content) local file = fs.open(_path, "w") _content = _content:gsub("!@".."#&", "%\n") _content = textutils.unserialize(_content) file.write(_content) file.close() end local function makeFolder(_path, _content) fs.makeDir(_path) for k,v in pairs(_content) do if type(v) == "table" then makeFolder(_path .. "/" .. k, v) else makeFile(_path .. "/" .. k, v) end end end local sDest = shell.resolve( "root" ) or "/" if sDest == "root" then sDest = "/" end local tPackage = pkg makeFolder(sDest, tPackage) print("Package Extracted to '" .. sDest .. "'!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement