Posted 24 November 2012 - 10:22 AM
Hey…
ehm.. i am making a server for passwords… (when a computer client asks for password, it sends the input to this server, and receives "Correct" or "False") but it seems like i got an error:
MikkAPI:414: attempt to call nil
Code?
its right here:
Full code[huge(its a API)]:
Pastebin code [full code]:
Thanks in advance :-P
____________________________
-Mikk809h
ComputerCraft is awesome
ehm.. i am making a server for passwords… (when a computer client asks for password, it sends the input to this server, and receives "Correct" or "False") but it seems like i got an error:
MikkAPI:414: attempt to call nil
Code?
its right here:
Spoiler
only the server code:Spoiler
function PassServer()
local oldDog = os.pullEvent
os.pullEvent = os.pullEventRaw
local runningP = true
Passwords = {}
IdS = {}
if not fs.exists("PdsWaid") then
fileCheck = fs.open("PdsWaid", "w")
for i, k in ipairs(Passwords) do
fileCheck.writeLine(Passwords[k])
end
fileCheck.close()
elseif fs.exists("PdsWaid") then
local fileRead = fs.open("PdsWaid", "r") -- here is the error LINE... i dont understand why?
local lines1 = fileRead.readLine()
repeat
table.insert(Passwords, lines1)
lines1 = fileRead.readLine()
until lines1 == nil
fileRead.close()
end
if not fs.exists("PdsPaid") then
fileChecks = fs.open("PdsPaid", "w")
for h, g in ipairs(IdS) do
fileChecks.writeLine(IdS[k])
end
fileChecks.close()
else
fileReads = fs.open("PsdsPaid", "r")
lines2 = fileReads.readLine()
repeat
table.insert(IdS, lines2)
lines2 = fileReads.readLine()
until lines2 == nil
fileReads.close()
end
function checkInput()
while running do
event, key = os.pullEvent("key")
if event == "key" then
if key == keys.Q then
running = false
end
end
end
end
function Server()
while runningServer do
id, msg = rednet.receive()
for i, v in ipairs(IdS) do
if id == IdS[v] then
for k, f in ipairs(Passwords) do
if msg == Passwords[f] then
rednet.send(id, "ValidPassword")
end
end
end
end
end
end
function LoadServer()
clear(1,1)
TSP("Loading Password Server v. 2.3")
sleep(1)
TSP("Loaded... Ready to Go...")
clear(1,10)
TSP("Type "Q" to exit")
sleep(2)
for i = 1, 9 do
term.setCursorPos(1, i)
term.clearLine()
end
parallel.waitForAny(Server, checkInput)
end
while runningP do
clear(1,1)
TSP("Welcome.....")
p("-----------------")
sleep(2)
TSP("Loading components...")
p("-----------------")
sleep(3)
TSP("Done!")
sleep(0.5)
clear(1,1)
TSP("Enter Password to boot server...")
sleep(1)
TSW("Password > ")
PassInput = read("#")
if PassInput == "ServerBootAccess_Key" then
clear(1,1)
runningP = false
LoadServer()
else
clear(1,1)
TSP("Wrong password ?")
sleep(4)
os.shutdown()
end
end
os.pullEvent = oldDog
end
Full code[huge(its a API)]:
Spoiler
function TSW( text )
textutils.slowPrint(text)
end
function TSP( text )
textutils.slowPrint(text)
end
function p( text )
print( text )
end
function w( text )
write( text )
end
function printCentered( PosY, text )
local x, y = term.getSize()
term.setCursorPos(x, PosY)
p(text)
end
function clear(x,a)
term.clear()
term.setCursorPos(x,a)
end
function goForward()
while not turtle.forward() do
turtle.dig()
sleep(1)
end
end
function goBack()
while not turtle.back() do
turtle.turnRight()
turtle.turnRight()
turtle.dig()
turtle.attack()
turtle.turnRight()
turtle.turnRight()
sleep(1)
end
end
function goUp()
while not turtle.up() do
turtle.digUp()
sleep(1)
end
end
function goDown()
while not turtle.down() do
turtle.digDown()
sleep(1)
end
end
function moveUp(x1)
BootSystematics_MikkAPIAPIS("goUp")
FuelLevel()
p("Starting API...")
for a3 = 1, x1 do
MikkTurtleAPI.goUp()
end
end
function moveDown(x2)
BootSystematics_MikkAPIAPIS("goDown")
FuelLevel()
p("Starting API...")
for a3 = 1, x2 do
MikkTurtleAPI.goDown()
end
end
function moveForward(x3)
BootSystematics_MikkAPIAPIS("goForward")
FuelLevel()
p("Starting API...")
for a3 = 1, x3 do
MikkTurtleAPI.goForward()
end
end
function turn(Bolean)
if Bolean == right or Bolean == "right" or Bolean == Right or Bolean == "Right" then
while not turtle.turnRight() do
sleep(1)
end
elseif Bolean == left or Bolean == "left" or Bolean == Left or Bolean == "Left" then
while not turtle.turnLeft() do
sleep(1)
end
end
end
function FuelLevel()
while turtle.getFuelLevel() < 100 do
clear(1,1)
p("I need fuel in slot number "1"")
turtle.select(1)
while not turtle.refuel() do
clear(1,1)
p("I need fuel.. put fuel in slot "1"")
end
end
end
--[Calling In-Game-Action IGA]--
function BootSystematics_MikkAPIAPIS( ApiChoose )
os.loadAPI("MikkTurtleAPI")
os.loadAPI("MikkConsoleAPI")
os.loadAPI("turtle")
clear(1,1)
printCentered( 7, "The Following API, has been entered: ""..ApiChoose..""")
sleep(0.7)
printCentered( 1, "Please Wait, while booting ""..ApiChoose..""")
sleep(2)
clear(1,1)
printCentered( 3, "Starting ""..ApiChoose..""")
end
--[In-Game Functions...]--
function doWall( high, length, SlotNum )
function placeDown()
while not turtle.placeDown() do
if SlotNum < 16 then
turtle.select(SlotNum+1)
SlotNum = SlotNum + 1
else
turtle.select(1)
SlotNum = 1
end
clear(1,1)
turtle.digDown()
sleep(1)
end
end
function place()
while not turtle.place() do
if SlotNum < 16 then
turtle.select(SlotNum+1)
else
turtle.select(1)
end
clear(1,1)
turtle.dig()
sleep(1)
end
end
function placeUp()
while not turtle.placeUp() do
if SlotNum < 16 then
turtle.select(SlotNum+1)
else
turtle.select(1)
end
clear(1,1)
turtle.digUp()
sleep(1)
end
end
function NextRow()
goForward()
for a0 = 1, high do
goDown()
end
end
function Build()
FuelLevel()
p("Starting API...")
for a1 = 1, length do
for a2 = 1, high do
goUp()
placeDown()
end
NextRow()
end
end
BootSystematics_MikkAPIAPIS( "doWall" )
turtle.select(SlotNum)
Build()
end
function doQuarry()
x = 1
xx = 1
xxx = 1
function NextRow1()
turtle.turnRight()
goForward()
turtle.turnLeft()
end
function NextLvl1()
if xx == 0 then
turtle.turnLeft()
for wid = 1, widTT2 - 1 do
goForward()
end
turtle.turnRight()
goForward()
xx = 1
else
turtle.turnLeft()
for wid = 1, widTT2 - 1 do
goForward()
end
turtle.turnRight()
goForward()
for ad = 1, heiTT2 - 1 do
goDown()
end
xx = 1
end
end
function NextRow2()
if x == 1 then
turtle.turnRight()
goForward()
turtle.turnRight()
x = 0
else
turtle.turnLeft()
goForward()
turtle.turnLeft()
x = 1
end
end
function NextLvl2()
if x == 1 then
turtle.turnLeft()
for wid0 = 1, widTT1 - 1 do
goForward()
end
turtle.turnRight()
goDown()
for i = 1, lenTT1 - 1 do
goBack()
end
x = 1
else
turtle.turnRight()
for wid0 = 1, widTT1 - 1 do
goForward()
end
turtle.turnRight()
goDown()
x = 1
end
end
--[verticalised tunnel/hole]--
function QuarryVert1()
for hei2 = 1, heiTT1 do
for wid2 = 1, widTT1 do
for len2 = 1, lenTT1 do
turtle.digDown()
local lenv = tonumber(len2)
if lenv < lenTT1 then
goForward()
end
sleep(0.5)
end
local widv = tonumber(wid2)
if widv < widTT1 then
NextRow2()
end
end
NextLvl2()
end
for heiUp = 1, heiTT1 do
goUp()
end
end
--[horisontial tunnel]--
function QuarryHori1()
for len1 = 1, lenTT2 do
for wid1 = 1, widTT2 do
for hei1 = 1, heiTT2 do
turtle.dig()
local heic = tonumber(hei1)
if heic < heiTT2 then
if xx == 1 then
goUp()
else
goDown()
end
end
end
local widc = tonumber(wid1)
if widc < widTT2 then
NextRow1()
if xx == 1 then
xx = 0
else
xx = 1
end
end
end
NextLvl1()
end
for heiBack = 1, lenTT2 do
goBack()
end
end
function QuarryVert()
clear(1,1)
w("Width? > ")
WiTe1 = read()
widTT1 = tonumber(WiTe1)
clear(1,1)
w("Length? > ")
LeTe1 = read()
lenTT1 = tonumber(LeTe1)
clear(1,1)
w("size? (how many rows it will dig down) > ")
HeTe1 = read()
heiTT1 = tonumber(HeTe1)
FuelLevel()
QuarryVert1()
end
function QuarryHori()
clear(1,1)
w("Width? > ")
WiTe2 = read()
widTT2 = tonumber(WiTe2)
clear(1,1)
w("Height? > ")
HeTe2 = read()
heiTT2 = tonumber(HeTe2)
clear(1,1)
w("Length? (the length of the tunnel) > ")
LeTe2 = read()
lenTT2 = tonumber(LeTe2)
FuelLevel()
QuarryHori1()
end
BootSystematics_MikkAPIAPIS("doQuarry")
verHor = true
while verHor do
clear(1,1)
p("Do you want the quarry, Vertical or Horisontial? Vertical is downwards, Horisontial is straight ahead...")
w(" Answer >>---> ")
VH1 = read()
if VH1 == "Vertical" or VH1 == "vertical" or VH1 == Vertical or VH1 == vertical then
verHor = false
QuarryVert()
elseif VH1 == "Horisontial" or VH1 == "horisontial" or VH1 == Horisontial or VH1 == horisontial then
verHor = false
QuarryHori()
else
verHor = true
clear(1,1)
p("Your answer does not match to Horisontial or Vertical ... Try again")
end
end
end
function PassServer()
local oldDog = os.pullEvent
os.pullEvent = os.pullEventRaw
local runningP = true
Passwords = {}
IdS = {}
if not fs.exists("PdsWaid") then
fileCheck = fs.open("PdsWaid", "w")
for i, k in ipairs(Passwords) do
fileCheck.writeLine(Passwords[k])
end
fileCheck.close()
elseif fs.exists("PdsWaid") then
local fileRead = fs.open("PdsWaid", "r") -- Error here...
local lines1 = fileRead.readLine()
repeat
table.insert(Passwords, lines1)
lines1 = fileRead.readLine()
until lines1 == nil
fileRead.close()
end
if not fs.exists("PdsPaid") then
fileChecks = fs.open("PdsPaid", "w")
for h, g in ipairs(IdS) do
fileChecks.writeLine(IdS[k])
end
fileChecks.close()
else
fileReads = fs.open("PsdsPaid", "r")
lines2 = fileReads.readLine()
repeat
table.insert(IdS, lines2)
lines2 = fileReads.readLine()
until lines2 == nil
fileReads.close()
end
function checkInput()
while running do
event, key = os.pullEvent("key")
if event == "key" then
if key == keys.Q then
running = false
end
end
end
end
function Server()
while runningServer do
id, msg = rednet.receive()
for i, v in ipairs(IdS) do
if id == IdS[v] then
for k, f in ipairs(Passwords) do
if msg == Passwords[f] then
rednet.send(id, "ValidPassword")
end
end
end
end
end
end
function LoadServer()
clear(1,1)
TSP("Loading Password Server v. 2.3")
sleep(1)
TSP("Loaded... Ready to Go...")
clear(1,10)
TSP("Type "Q" to exit")
sleep(2)
for i = 1, 9 do
term.setCursorPos(1, i)
term.clearLine()
end
parallel.waitForAny(Server, checkInput)
end
while runningP do
clear(1,1)
TSP("Welcome.....")
p("-----------------")
sleep(2)
TSP("Loading components...")
p("-----------------")
sleep(3)
TSP("Done!")
sleep(0.5)
clear(1,1)
TSP("Enter Password to boot server...")
sleep(1)
TSW("Password > ")
PassInput = read("#")
if PassInput == "ServerBootAccess_Key" then
clear(1,1)
runningP = false
LoadServer()
else
clear(1,1)
TSP("Wrong password ?")
sleep(4)
os.shutdown()
end
end
os.pullEvent = oldDog
end
Spoiler
http://pastebin.com/huQQYWLcThanks in advance :-P
____________________________
-Mikk809h
ComputerCraft is awesome