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

Several variables with Rednet ?

Started by valentinp72, 08 April 2013 - 01:01 AM
valentinp72 #1
Posted 08 April 2013 - 03:01 AM
Hello !

For my server, i'm creating a bank system. I search how to send (by rednet) several variables. I test :

http://www.computerc...rednet-message/
http://www.computerc...rednet-message/
and

local send = pseudo .. password
rednet.send(32, send)
and that not's working, that write : rednet:11: string expected. Where is the problem ? :(/>

I'm very sorry for my bad english, i'm french.
SadKingBilly #2
Posted 08 April 2013 - 03:09 AM
For some reason, the send variable is not a string. Without seeing the rest of your code (that is, where you declare pseudo and password), I don't know how to help you.
valentinp72 #3
Posted 08 April 2013 - 03:15 AM

version = "BIM - Banque Internationale MineCube - Version 1.0"
term.clear()
term.setCursorPos(1,1)
term.setTextColor(colors.lime)
print("		    ########  #### ##	 ## ")
print("		    ##	 ##  ##  ###   ### ")
print("		    ##	 ##  ##  #### #### ")
print("		    ########   ##  ## ### ## ")
print("		    ##	 ##  ##  ##	 ## ")
print("		    ##	 ##  ##  ##	 ## ")
print("		    ########  #### ##	 ## ")
term.setTextColor(colors.orange)
print("  ")
print("	 + - - - - - - - - - - - - - - - - - - - - +")
print("	 I	  Connexion - Espace sécurisé	    I")
print("	 I										 I")
print("	 I  Identifiant :						  I")
print("	 I  Mot de passe :						 I")
print("	 I										 I")
print("	 + - - - - - - - - - - - - - - - - - - - - +")
print("  ")
term.setTextColor(colors.lime)
print(version)
term.setCursorPos(24,12)
   pseudo = read()
term.setCursorPos(24,13)
  password = read("*")
rednet.open(top)
local send = pseudo .. password
rednet.send(32, send)

sleep(2)
os.shutdown()

For the moment, I have not installing a security system (sha1). Thank you ;)/>
1lann #4
Posted 08 April 2013 - 03:47 AM
rednet.open(top) should be rednet.open("top")
SadKingBilly #5
Posted 08 April 2013 - 04:32 AM
Yeah, looks like I was wrong about what was causing the problem. 1lann has it right.
PixelToast #6
Posted 08 April 2013 - 04:49 AM
soooo, your effectively broadcasting the password
valentinp72 #7
Posted 08 April 2013 - 06:52 AM
Thank you ! I have an other problem, how I can save in the server computer (fs) several informations (username (name of the file), password, the money, and, maybe the "logs") ?
I want to read the first line of the file to find the true password, and on the second line the money currently, it's possible ?

Thanks you ;)/>
mark332 #8
Posted 08 April 2013 - 09:58 AM
use the fs-API

for example:


z = "USERNAME"
y = "USERPASS"
local file = fs.open("<YOURFILE>", "w") -- open File in write mode
file.writeLine(z)  ---writing the variable "z" in the first Line
file.writeLine(y)  ---writing the variable "y" in the second Line

Now the File looks like this:

USERNAME
USERPASS


To read the information you can use:

local file = fs.open("<YOURFILE>","r") --open File in read mode
userdata = {}   ---clear the table "userdata"
local line = file.readLine() --read the first Line of the File

repeat --repeat the following
table.insert(userdata, line) --insert the line into the table
local line = file.readLine()  --read the next line of the file
until line == nil --stop reading the file, if there're no more lines

local username = userdata[1] --Take the username from the table
local password = userdata[2] ---Take the userpassword from the table

the rest should be known ;)/>
PixelToast #9
Posted 08 April 2013 - 10:16 AM
more compact (and fixed) version:

local file = io.open("<YOURFILE>","r") -- open File in read mode (use io API instead)
local userdata = {}   -- make and localize the table "userdata"
for line in file:lines() do --repeat the following
table.insert(userdata, line) --insert the line into the table
end --stop reading the file, if there're no more lines
-- dont need to close the handle because lines does it for us
local username = userdata[1] --Take the username from the table
local password = userdata[2] ---Take the password from the table
valentinp72 #10
Posted 09 April 2013 - 07:32 AM
Hum ..

I wrote that, and I don't understand, the screen is always black :


term.clear()
term.setCursorPos(1,1)
rednet.open("left")
while true do
  event, senderId, message, distance = os.pullEvent("rednet_message")
   if senderId == 35 then
    table = textutils.unserialize(message)
    pseudo = table[1]
    password = table[2]
    ask1 = table[3]
    ask2 = table[4]
	 if ask1 == "exist" then
	  folder = "/comptes/"
	  extension = ".txt"
	  file = folder..pseudo..extension
	  if fs.exists(file) then
	  
	 local file = io.open(file) -- open File in read mode (use io API instead)
	 local userdata = {}   -- make and localize the table "userdata"
	 for line in file:lines() do --repeat the following
	 table.insert(userdata, line) --insert the line into the table
	 end --stop reading the file, if there're no more lines
	 -- dont need to close the handle because lines does it for us
	 local username = userdata[1] --Take the username from the table
	 local pass = userdata[2] ---Take the password from the table
	 print(username)
	 print(pass)
    end
	 end
   else
    rednet.send(senderId, "Nos machines sont protégées contre le hack.")
   end
end
PixelToast #11
Posted 09 April 2013 - 09:51 AM
change

local file = io.open(file) -- open File in read mode (use io API instead)
to

local file = io.open(file,"r") -- open File in read mode (use io API instead)
and we need to see the program that sends the message
valentinp72 #12
Posted 10 April 2013 - 06:43 AM
I changed the program who check the accounts.

The program that sends the message :

version = "BIM - Banque Internationale MineCube - Version 1.0"
ask1 = "exist"
ask2 = "money"
function Logo()
term.clear()
term.setCursorPos(1,1)
term.setTextColor(colors.lime)
print("			########  #### ##	 ## ")
print("			##	 ##  ##  ###   ### ")
print("			##	 ##  ##  #### #### ")
print("			########   ##  ## ### ## ")
print("			##	 ##  ##  ##	 ## ")
print("			##	 ##  ##  ##	 ## ")
print("			########  #### ##	 ## ")
end
Logo()
term.setTextColor(colors.orange)
print("  ")
print("	 + - - - - - - - - - - - - - - - - - - - - +")
print("	 I	  Connexion - Espace sécurisé		I")
print("	 I										 I")
print("	 I  Identifiant :						  I")
print("	 I  Mot de passe :						 I")
print("	 I										 I")
print("	 + - - - - - - - - - - - - - - - - - - - - +")
print("  ")
term.setTextColor(colors.lime)
print(version)
term.setCursorPos(24,12)
   pseudo = read()
term.setCursorPos(24,13)
  password = read("*")
rednet.open("top")
table = {pseudo, password, ask1, ask2}
message = textutils.serialize(table)
rednet.send(32, message)
Logo()
term.setTextColor(colors.orange)
print("  ")
print("	 + - - - - - - - - - - - - - - - - - - - - +")
print("	 I	  Connexion - Espace sécurisé		I")
print("	 I										 I")
print("	 I	Attente de réponse du serveur ...	I")
print("	 I										 I")
print("	 I										 I")
print("	 + - - - - - - - - - - - - - - - - - - - - +")
print("  ")
sleep(2)
os.shutdown()
valentinp72 #13
Posted 12 April 2013 - 09:17 AM
Up
valentinp72 #14
Posted 21 April 2013 - 07:47 AM
Up please :(/>
theoriginalbit #15
Posted 21 April 2013 - 07:56 AM
Up
Up please :(/>
Uhh what now? Up? are you meaning bump?
What is the latest error?
valentinp72 #16
Posted 08 May 2013 - 06:41 AM
Hum .. I wrote that, and I don't understand, the screen is always black :
Please help me :/
valentinp72 #17
Posted 15 May 2013 - 08:27 AM
Hum .. I wrote that, and I don't understand, the screen is always black :
Please help me :/
valentinp72 #18
Posted 19 May 2013 - 12:04 PM
Why the server computer is always black ?