View difference between Paste ID: SPqm0PaC and AFqwwJAr
SHOW: | | - or go back to the newest paste.
1
-- rec.lua
2-
local id,message = rednet.receive()
2+
local id, message, lock, name, mode
3-
local lock = message[4]
3+
local info, num, val
4-
local name = message[2]..".lua"
4+
5-
if lock == "greenblock" then
5+
6-
local mode = message[1]
6+
	id, message = rednet.receive()
7-
 if (mode == "read") then
7+
	lock = message[4]
8-
  if (fs.exists("Accounts/"..name)) then
8+
	name = message[2] .. ".lua"
9-
  local info = fs.open("Accounts/"..name,"r")
9+
10-
  local num = info.readLine()
10+
	if lock == "greenblock" then
11-
  rednet.send(id,num)
11+
		mode = message[1]
12-
  info.close()
12+
13-
  elseif (fs.exists("Accounts/"..name) == false) then
13+
		if (mode == "read") then
14-
  local info = fs.open("Accounts/"..name,"w")
14+
			if fs.exists("Accounts/" .. name) then
15-
  info.writeLine("0.00")
15+
				info = fs.open("Accounts/" .. name, "r")
16-
  rednet.send(id,"0.00")
16+
				num = info.readLine()
17-
  info.close()
17+
				rednet.send(id, num)
18-
  end
18+
				info.close()
19-
 elseif (mode == "write") then
19+
20-
 local val = message[3]
20+
			elseif fs.exists("Accounts/" .. name) == false then
21-
 local info = fs.open("Accounts/"..name,"w")
21+
				info = fs.open("Accounts/" .. name, "w")
22-
 info.writeLine(val)
22+
				info.writeLine("0.00")
23-
 info.close()
23+
				rednet.send(id, "0.00")
24-
 end
24+
				info.close()
25-
else
25+
			end
26
27-
end
27+
		elseif mode == "write" then
28
			val = message[3]
29
			info = fs.open("Accounts/" .. name, "w")
30
			info.writeLine(val)
31
			info.close()
32
33
		end
34
	end
35
end