View difference between Paste ID: cW1Jvd2c and jiYE76jD
SHOW: | | - or go back to the newest paste.
1
os.loadAPI("manualQuarry.lua")
2
os.pullEvent = os.pullEventRaw
3
serverID = 0
4
filename = "adminsuccess.txt"
5
cost = 160
6
print("Fuel Level: " .. turtle.getFuelLevel()/20000 .. "%")
7
print("Fuel Amount: " .. turtle.getFuelLevel())
8
9
function openPort()
10
	rednet.open("left")
11
end
12
13
function readAdminPassword()
14
	local file = fs.open(filename, "r")
15
    line = file.readLine()
16
	file.close()
17
    return line
18
end
19
20
function conductTransaction(username, password)
21
  message = "buy " .. username .. " " .. password .. " " .. cost
22
  rednet.send(serverID, message)
23
  id, value = rednet.receive(nil, 3)
24
  os.sleep(1)
25
  return value
26
end
27
28
function checkCredentials(username, password)
29
  message = "search " .. username .. " " .. password
30
  rednet.send(serverID, message)
31
  id, value = rednet.receive(nil, 3)
32
  os.sleep(1)
33
  return value
34
end
35
36
status, err = pcall(function() openPort() end)
37
if not status then
38
	turtle.select(1)
39
	turtle.equipLeft()
40
	status, err = pcall(function() openPort() end)
41
	if not status then
42
		print("Modem not found in first slot or left hand, stopping")
43
		os.shutdown()
44
	end
45
end
46
47
print("Mining Turtle Rental - $" .. cost)
48
print("Please Login to Rent")
49
print("Username: ")
50
username = read()
51
print("Password: ")
52
password = read("*")
53
if username == "admin" and password == readAdminPassword() then
54
	os.exit(1)
55
end
56
success = conductTransaction(username, password)
57
if success == nil then
58
    print("Transaction Connection to Server Failed")
59
    os.sleep(3)
60
	os.shutdown()
61
elseif success == "false" then
62
    print("Transaction Failed")
63
    print("Account Value: " .. checkCredentials(username, password))
64
    os.sleep(5)
65
	os.shutdown()
66
else
67
    print("Success!")
68
	turtle.equipLeft()
69
	print("Warning: Stopping the Turtle Will Complete Current Transaction (also the turtle will slightly break if it cannot break certain blocks in area)")
70
	manualQuarry.mine()
71
	os.shutdown()
72
end
73
74
75