Jump to content




AppliedEnergetics and CC Project

computer networking

10 replies to this topic

#1 want_some

  • Members
  • 6 posts
  • LocationUSA

Posted 12 August 2014 - 01:48 PM

First off, i am kinda new to lua. but i been doing some programming and learning lua for a while now. but just the basics of lua tho. Now i want to learn more and get into more advanced stuff like username/password programming to allow users to access different things.

Second, I been working on a little project on my own server. This project was going to use CC and AE ME system. Basically, program will ask the user for their username/password to gain access to their ME Drive (it will have their own ME storage disks that they will need to make themselves). The login computer will then send a message to the computer that will then run the program to send a redstone signal to the dark ME cable to allow that ME Drive to be apart of the ME system.

Here is the picture of a test setup:
Spoiler

How this (should) work:

The player will need to login (of course!) and the program on the Login Computer will then check the table for the verification. If true, it will then send a message to the computer with the ID (username) the player logged in as. First, the message will send a command to run the "On" program to turn on the redstone output to turn the dark cable on (duh!) The program will then wait for a set time (default of 60 seconds) then will automatically send the command to run the "Off" program to the same computer to turn off the dark cable.

What is going wrong:
The login displays perfectly. Asks for the username (aka ID) and password. After I type in the username 393 then the password player1, the program says the welcome message and sleeps for 2 secs like i coded, but then displays the "error" message and quits the program. I'm not sure if the problem is from the table (i did a quick google on the setup) or the "if" statements (i wrote them myself, still learning about the more complex setups of theses like this one)

I thought about not doing a table setup to store the username and password so later i can add a "Change Password" option to the program in case a player gave the password out to others.

This is my code as of right now.
Spoiler

FYI: i checked the message sending code with a program that will send the message with a "computerID" var equal to the network and it went to the right computer and was able to turn on the dark cabel and then 60 seconds later, turn it off. So i know that portion is good.

Edited by want_some, 12 August 2014 - 04:12 PM.


#2 want_some

  • Members
  • 6 posts
  • LocationUSA

Posted 12 August 2014 - 07:27 PM

I been searching how to fix this but not getting anything. I'm really starting to think the problem is with the "if" statements. Can anyone give me an example of the correct way the if statements should be for this? I been reading the wikis and other pages on the web but not getting anywhere..any help will be great!

#3 hilburn

  • Members
  • 153 posts
  • LocationLondon, England

Posted 12 August 2014 - 07:57 PM

At the beginning of each of your if statements you have made a typo

shell.run("clear") not shell.run"clear"

even better is
term.clear()

Edited by hilburn, 12 August 2014 - 07:58 PM.


#4 0099

  • Members
  • 52 posts

Posted 12 August 2014 - 08:41 PM

1. The mistake is that read() always returns a string, even if it is a string of digits, so convert it to a number with tonumer(). Also (what a coincidence!) { 393 = "player1" } makes a field with a string key, to make the key a number, you need { [393] = "player1" }.

2. Keep in mind, that when the key is a string, its concatenation with message "Welcome! Here is your items, " is wrong, so you will need a reverse conversion with tostring().

3. Instead of using so many ifs and identical chunks of code, when your ID is a number, you can just write rednet.send(ID, message).

4. Speaking of messages, you will need to use "On" and "Off" words in quotes, because they are strings.

5. hilburn, it isn't a typo. If a function requires only 1 argument and this argument is a string or a table, you can write it without parentheses.

#5 want_some

  • Members
  • 6 posts
  • LocationUSA

Posted 12 August 2014 - 09:20 PM

ok, i updated the code.

1. the table was updated to {[393] = "player1"} for all "users"

2. the welcome message works fine, why would i change it? the number is the ID, and the "player1" is the password. Later on, i will change this to be a set user name in later updates.

3. i know there is repeated code, this is just a rough draft of the program and i will go back later to shorten it up. Right now i just want to get things working first so i can learn from this.

4. they worked fine when i used it to send the message to each computer manually. the client computer just sends the message basically like a command to run the On and Oft program that i have writen on the other computers.

So far with the updates, nothing worked. I still get the display asking for ID and Password. i enter in the password and ID and i get the password/ID wrong.

#6 0099

  • Members
  • 52 posts

Posted 12 August 2014 - 11:26 PM

View Postwant_some, on 12 August 2014 - 09:20 PM, said:

4. they worked fine when i used it to send the message to each computer manually. the client computer just sends the message basically like a command to run the On and Oft program that i have writen on the other computers.

Let me guess, you then checked them on another computer like if message == On? If so, you just sent non-existing variable (nil) to the other computer and compared it to another non-existing variable. And of course nil == nil returns true, and On == On. But it won't work if you send Off, because Off == nil == nil == On.

Anyway, you forgot to add tonumber(), that's why the welcome message is still working. And, when you do this, please post your updated code.

Edited by 0099, 13 August 2014 - 12:10 AM.


#7 natedogith1

  • Members
  • 110 posts

Posted 13 August 2014 - 01:19 AM

View Post0099, on 12 August 2014 - 11:26 PM, said:

Anyway, you forgot to add tonumber(), that's why the welcome message is still working. And, when you do this, please post your updated code.
Actually, since lua does automatic conversions this shouldn't be an issue

#8 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 13 August 2014 - 03:10 AM

Sometimes. It depends on the situation. It's generally easier from a bug-tracking perspective not to rely on that behaviour, and instead be specific about the types you want.

Edited by Bomb Bloke, 13 August 2014 - 03:14 AM.


#9 Dragon53535

  • Members
  • 973 posts
  • LocationIn the Matrix

Posted 13 August 2014 - 03:10 AM

I decided to look through your code and fix anything that either bugs me, or would cause it not to work correctly. If i get it wrong, well then you should be able to fix the rest of it. Now I will be commenting it as i go through to help you.
Spoiler

I broke your code a little bit so that you can figure the little bits i messed up that would make the computer work correctly just because i'm slightly evil. Look through the code, correct the errors i made, and you should be fine. There are a total of 3 errors, and they should be relatively easy to find if you read it thoroughly

Edited by Dragon53535, 13 August 2014 - 07:52 AM.


#10 want_some

  • Members
  • 6 posts
  • LocationUSA

Posted 13 August 2014 - 11:22 AM

View PostDragon53535, on 13 August 2014 - 03:10 AM, said:

I decided to look through your code and fix anything that either bugs me, or would cause it not to work correctly. If i get it wrong, well then you should be able to fix the rest of it. Now I will be commenting it as i go through to help you.
Spoiler

I broke your code a little bit so that you can figure the little bits i messed up that would make the computer work correctly just because i'm slightly evil. Look through the code, correct the errors i made, and you should be fine. There are a total of 3 errors, and they should be relatively easy to find if you read it thoroughly

Thank you for your help! and i found the errors, two was easy and one was kinda hard.

Errors i found and fixed.

if uTable[ID] === pass then -- you're looking in your table for what you inputed as the ID so if i put in 393 it would look for uTable["393"] which is defined in the table above as the pass being "player1"'
had an extra "=" , removed that.

print("Connection Closed!) -- () needed

missing the end " to finish the string. (was hard to catch before running the code the first time)

  rednet.open("super")

changed "super" to "back". kinda easy to spot after reading the code the second time.


This code worked perfectly! i will save this code and try to change it a bit to add options to let players change the id name and passwords after logging in for the first time. thank you for your help!

#11 Dragon53535

  • Members
  • 973 posts
  • LocationIn the Matrix

Posted 14 August 2014 - 04:54 PM

Well then there you go, now if you want to attempt to have username's and passwords i would look into the fs API, an easy tutorial for it is Here. Eventually if you're wanting to make the passwords more secure i would use GravityScore's SHA-256 CC lua adaptation Here.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users