This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Punisher482's profile picture

Login with Roaming Profiles

Started by Punisher482, 19 May 2013 - 01:15 PM
Punisher482 #1
Posted 19 May 2013 - 03:15 PM
Hello everyone!
I started playing with mods when a friend introduced me to the FeedTheBeast modpacks, and among the mods in the pack I play I found computercraft, and really enjoyed it, and I've been trying to learn more of how LUA works, while also putting the computers to good use.

A few weeks ago I decided I wanted a login system, so that anyone accessing the computers in my base would have to log in, but it would be best if it were controlled from a central server, so that it would be easier to update with new passwords and username.

So I created a test server in order to experiment with how to get this done. This led me to the following wikipage:
http://computercraft...oaming_Profiles

So i tried those codes, unfortunately it doesn't work. The initial [1] & [2] (Login or Shutdown) works fine, but once I've written the username and password, the computer sleeps waiting for the confirmation from the server, but doesn't recieve it, and declare invalid username or password due to timeout. I searched around trying to find other with similar problems, when I realized that all posts related to roaming profiles were several months or years old, and probably an older CC version.

I then started looking more into the wireless modems on the wiki (Yes, I were using wireless the whole time), and wondered if the standard rednet codes didn't work in favor of the new wireless codes, so I tried redesigning the program from the wiki to use the wireless codes (peripheral.wrap, modem.open etc. instead of the rednet codes (rednet.open, rednet.recieve etc.), only to realize I were a little over my head here, and got no idea what I were doing. So now I'm stuck with two different versions of the program that doesn't work.

So my question #1: Are the wiki codes outdated, or are they supposed to still work? If they're supposed to still work, then what is wrong with my programing?

Question #2: If version one is outdated, then what do I need to do to fix it? Are my own version #2 complete rubbish, or am I close to a logical solution?


Thanks in advance!

Regards
Joe


My own programs:

Version 1 (Original Rednet)

Server (ID #0):
Spoiler

term.clear()
term.setCursorPos(1,1)
print("This is a password server. There is no user interaction here.")
print("Please find a computer and login there.")
local firstCycle = true
local validSender = false
local modemSide = "left"
local valid = false
users = {"test", "JVN2", "JAH1" }
password = {"test", "Ost", "Test2" }
senders = { "1", "2", "3", "4" }
function bootUp()
rednet.open(modemSide)
end
while true do
validSender = false
if firstCycle then
  bootUp()
  firstCycle = false
end
senderId, message, distance = rednet.receive()
for i,v in ipairs(senders) do
  if v == senderId then
   validSender = true
   break
  end
end
if validSender then
  for i,v in ipairs(users) do
   if message == v then
	valid = true
	password = passwords[i]
	break
   else
	valid = false
   end
  end
  if valid then
  rednet.send(senderId, password, true)
  else
   rednet.send(senderId, "Not Valid", true)
  end
end
end

Client: (ID #2)
Spoiler

local locker = true
local failed = true
local attempted_login = true
local password_server = 0
rednet.open("left")
while locker do
attempted_login = false
term.clear()
term.setCursorPos(1,1)
print("Welcome to a USERS PC : Roaming Profile Enabled")
print("What would you like to do?")
print("[1] Login(*)")
print("[2] Shutdown")
write("> ")
local input = read()
if input == "2" then
  os.shutdown()
elseif input == "1" then
  attempted_login = true
  print("Please login...")
  write("Username: ")
  local username = read()
  write("Password: ")
  local password = read("*")
  rednet.send(password_server, username, true)
  senderID, message, distance = rednet.receive(5)
  if password == message then
   failed = false
   locker = false
   term.clear()
   term.setCursorPos(1,1)
   print("Welcome ", username)
  else
   print("Invalid Username or Password.")
   sleep(3)
  end
else
  print("Command not recoqnies...")
  sleep(2)
end
end


Version 2 (Wireless codes)

Server (ID: #9)
Spoiler

term.clear()
term.setCursorPos(1,1)
print("This is a password server. There is no user interaction here.")
print("Please find a computer and login there.")
local firstCycle = true
local validSender = false
local modem = peripheral.wrap("left")
local valid = false
users = {"test", "JVN1" }
passwords = {"test", "4370" }
senders = { 10, 11, 12 }
modem.open(500)
while true do
senderId, message, distance = os.pullEvent("modem_message")
for i,v in ipairs(senders) do
  if v == senderId then
   validSender = true
   break
  end
end
if validSender then
  for i,v in ipairs(users) do
   if message == v then
	valid = true
	password = passwords[i]
	break
   else
	valid = false
   end
  end
  if valid then
   modem.transmit(500, 500, senderId, password, true)
  else
   modem.transmit(500, 500, "Not Valid", true)
  end
end
end

Client (ID: #10)
Spoiler

local locker = true
local failed = true
local attempted_login = true
local password_server = 9
local modem = peripheral.wrap("left")
modem.open(500)
while locker do
attempted_login = false
term.clear()
term.setCursorPos(1,1)
print("Welcome to a USERS PC : Roaming Profile Enabled")
print("What would you like to do?")
print("[1] Login (*)")
print("[2] Shutdown")
write("> ")
local input = read()
if input == "2" then
  os.shutdown()
elseif input == "1" then
  attempted_login = true
  print("Please login...")
  write("Username= ")
  local username = read()
  write ("Password: ")
  local password = read("*")
  modem.transmit(500, 500, password_server, username, true)
  senderId, message, distance = os.pullEvent("modem_message")
  if password == modem.message then
   failed = false
   locker = false
   term.clear()
   term.setCursorPos(1,1)
   print("Welcome ", username)
  else
   print("Invalid Username or Password.")
   sleep(3)
  end
else
  print("Command not recognised...")
  sleep(2)
end
end
Lyqyd #2
Posted 20 May 2013 - 12:26 AM
Split into new topic.
Appleeater #3
Posted 23 May 2013 - 03:16 AM
How far away are the terminals from each other?
Zudo #4
Posted 23 May 2013 - 03:29 AM
I made my own script, after discovering this one didnt work :P/>

Just read the whole topic, and you have tried…!