Jump to content




Computercraft Virtual Currency

help

  • You cannot reply to this topic
28 replies to this topic

#1 pauliuskas05

  • Members
  • 12 posts

Posted 05 July 2014 - 02:42 PM

Hi, I am a noob on ComputerCraft. I really want to make a Virtual Currency on my server. So that it use floppy disks as Credit Cards, but only keep account name in them. Everything else (password, balance) would be on a server computer.

#2 AssossaGPB

  • Members
  • 126 posts
  • LocationFlorida, USA

Posted 05 July 2014 - 04:45 PM

Well, if your new to ComputerCraft and Lua I would NOT recommend a virtual currency system as your first project. First, go read some tutorials on Lua, and some on the ComputerCraft apis. Then, you should make some simple programs and learn rednet. But, if you think your ready then read on:

First, you'll want to have some encryption system. I recommend using my Encryption Api for the key exchange and StrUtils for the actual encryption.
Next, you want to set up a packet protocol, this involves parsing rednet messages and doing the corresponding action.
Finally, you want to make sure you hash your passwords when sending them to the server for extra security.

That's all there is to it, kinda complicated, but kinda simple with the right apis. If you need anymore help, I check the forums twice a day and am often on the irc, just shout my name!

PS: I don't recommend using disks for credit cards as they can easily be cloned.

#3 pauliuskas05

  • Members
  • 12 posts

Posted 05 July 2014 - 04:59 PM

View PostAssossaGPB, on 05 July 2014 - 04:45 PM, said:

PS: I don't recommend using disks for credit cards as they can easily be cloned.

Why not ? On them there is going to be only account name that can only be accessed with password.

#4 AssossaGPB

  • Members
  • 126 posts
  • LocationFlorida, USA

Posted 06 July 2014 - 12:16 AM

View Postpauliuskas05, on 05 July 2014 - 04:59 PM, said:

View PostAssossaGPB, on 05 July 2014 - 04:45 PM, said:

PS: I don't recommend using disks for credit cards as they can easily be cloned.

Why not ? On them there is going to be only account name that can only be accessed with password.
Oh, ok. I thought you were gonna store the password on the card as well.

#5 TheOddByte

    Lazy Coder

  • Members
  • 1,607 posts
  • LocationSweden

Posted 06 July 2014 - 12:18 AM

View PostAssossaGPB, on 06 July 2014 - 12:16 AM, said:

View Postpauliuskas05, on 05 July 2014 - 04:59 PM, said:

View PostAssossaGPB, on 05 July 2014 - 04:45 PM, said:

PS: I don't recommend using disks for credit cards as they can easily be cloned.

Why not ? On them there is going to be only account name that can only be accessed with password.
Oh, ok. I thought you were gonna store the password on the card as well.
Well if he was going to then he could hash them :P

#6 Bomb Bloke

    Hobbyist Coder

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

Posted 06 July 2014 - 01:19 AM

It's easy enough to copy a disk's contents. It's nearly impossible to clone a disk's ID number. There doesn't need to be anything on a disk at all if you purely want to use it for identification - in fact, done properly, use of disks would also negate any need to even ask for a password... So long as the disks themselves aren't stealable...

#7 AssossaGPB

  • Members
  • 126 posts
  • LocationFlorida, USA

Posted 06 July 2014 - 01:52 AM

View PostTheOddByte, on 06 July 2014 - 12:18 AM, said:

View PostAssossaGPB, on 06 July 2014 - 12:16 AM, said:

View Postpauliuskas05, on 05 July 2014 - 04:59 PM, said:

View PostAssossaGPB, on 05 July 2014 - 04:45 PM, said:

PS: I don't recommend using disks for credit cards as they can easily be cloned.

Why not ? On them there is going to be only account name that can only be accessed with password.
Oh, ok. I thought you were gonna store the password on the card as well.
Well if he was going to then he could hash them :P
But then someone could just copy the hash

View PostBomb Bloke, on 06 July 2014 - 01:19 AM, said:

It's easy enough to copy a disk's contents. It's nearly impossible to clone a disk's ID number. There doesn't need to be anything on a disk at all if you purely want to use it for identification - in fact, done properly, use of disks would also negate any need to even ask for a password... So long as the disks themselves aren't stealable...
Hm, never thought of that, how do you read the disk's id from the computer?

#8 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 06 July 2014 - 02:30 AM

Well if you do it right, it doesn't matter if people can see the hash, 'cause they need to enter the password, not the hashed password.

Take a look into the Disk API for how to get info about disks.

#9 AlkamlBan

  • Members
  • 64 posts
  • LocationGreece

Posted 07 July 2014 - 03:30 PM

This (in my opinion at least) is a great idea. A currency that can be used in computercraft servers! Finally we will have something else to try and hack other than computers! Just kiddin (not really) but I think it is a great idea!

#10 pauliuskas05

  • Members
  • 12 posts

Posted 07 July 2014 - 08:50 PM

I writed some code, but it doesn't seems to work. When I will get home i will post it...

Edited by pauliuskas05, 07 July 2014 - 08:53 PM.


#11 AlkamlBan

  • Members
  • 64 posts
  • LocationGreece

Posted 08 July 2014 - 09:07 AM

View Postpauliuskas05, on 07 July 2014 - 08:50 PM, said:

I writed some code, but it doesn't seems to work. When I will get home i will post it...

I worked on something aswell but it also didn't seem to work. Well...I will check it out today after all I wrote the program in 2am yesterday so I couldn't make out any mistakes in the code

#12 AlkamlBan

  • Members
  • 64 posts
  • LocationGreece

Posted 08 July 2014 - 09:25 AM

The problem with this is that there can be a big freakin' problem. What will happen if someone kills you and steals your "credit card"? Well one possibility would be to make checks every now and then. So for example every fifth purchase you ask the user to input his code or else they block the card. Also checks can be make where the server has a countdown. Once the countdown is over for the next purchase the user needs his code. There is a problem with both...First with the first one the thief would go to a store and buy a lot of things all in once and it would be on you to pay them! The second idea also has a problem because the thief can buy anything he wants before the check is up. But supposing you are not in a hardcore server (so you don't get kicked when you die) the user of the card can go to the bank and say that his card was stolen so they can instantly block it the point is that the thief is still given some time to buy whatever he wants. So...I guess that we will have to find a way of tightening security

#13 pauliuskas05

  • Members
  • 12 posts

Posted 09 July 2014 - 09:55 AM

ATM Code:
local modem_side = "back"
local server = 6
local d_side = "bottom"
local pin_check = nil
local exists = nil
function cls()
term.clear()
term.setCursorPos(1,1)
print("BANK")
term.setCursorPos(1,2)
end
function dej()
disk.eject(d_side)
end
rednet.open(modem_side)
cls()
print("		 Please insert your Credit Card")
local event, isDisk = os.pullEvent("disk")
if fs.exists("disk/bank") then
local ccid = disk.getID(d_side)
rednet.send(server, ccid)
senderId, exists, distance= rednet.receive()
if exists == "yes" then
  cls()
  write("		   PIN: ")
  local pin = read("*")
  rednet.send(server, pin)
  senderId, pin_check, distance = rednet.receive()
   if pin_check == "good" then
    pin = nil
    pin_check = nil
    senderId, money, distance = rednet.receive()
    print("You have: "..money)
   elseif pin_check == "bad" then
    cls()
    print("Wrong PIN !")
   end
elseif exists == "no" then
  cls()
  print("	  Account doesn't exists")
end
else
cls()
print("		 This is not a credit card")
dej()
sleep(1.5)
os.shutdown()
end

Server Code:
term.clear()
term.setCursorPos(1,1)
local modem_side = "top"
local srv_id = os.getComputerID()
print("Running BANK server on "..srv_id)
rednet.open(modem_side)
while true do
senderId, id, distance = rednet.receive()
if fs.exists("acc/"..id) then
rednet.send(senderId, "yes")
config.load("acc",id)
local real_pass = config.readVal("pass")
senderId, pass, distance = rednet.receive()
  if pass == real_pass then
   rednet.send(senderId, "good")
   local money = config.readVal("money")
   rednet.send(senderId, money)
   break
  elseif pass ~= real_pass then
   rednet.send(senderId, "bad")
   break
  end
else
  rednet.send(senderId, "no")
  break
end
end


On ATM I get Error

Quote

startup:23: attempt to call nil

Help me !

EDIT:
BTW I am using "Config API' by ben657

Edited by pauliuskas05, 09 July 2014 - 09:56 PM.


#14 AlkamlBan

  • Members
  • 64 posts
  • LocationGreece

Posted 09 July 2014 - 12:12 PM

View Postpauliuskas05, on 09 July 2014 - 09:55 AM, said:

ATM Code:
local modem_side = "back"
local server = 6
local d_side = "bottom"
local pin_check = nil
local exists = nil
function cls()
term.clear()
term.setCursorPos(1,1)
print("BANK")
term.setCursorPos(1,2)
end
function dej()
disk.eject(d_side)
end
rednet.open(modem_side)
cls()
print("		 Please insert your Credit Card")
local event, isDisk = os.pullEvent("disk")
if fs.exists("disk/bank") then
local ccid = disk.getID(d_side)
rednet.send(server, ccid)
senderId, exists, distance= rednet.receive()
if exists == "yes" then
  cls()
  write("		   PIN: ")
  local pin = read("*")
  rednet.send(server, pin)
  senderId, pin_check, distance = rednet.receive()
   if pin_check == "good" then
	pin = nil
	pin_check = nil
	senderId, money, distance = rednet.receive()
	print("You have: "..money)
   elseif pin_check == "bad" then
	cls()
	print("Wrong PIN !")
   end
elseif exists == "no" then
  cls()
  print("	  Account doesn't exists")
end
else
cls()
print("		 This is not a credit card")
dej()
sleep(1.5)
os.shutdown()
end

Server Code:
term.clear()
term.setCursorPos(1,1)
local modem_side = "top"
local srv_id = os.getComputerID()
print("Running BANK server on "..srv_id)
rednet.open(modem_side)
while true do
senderId, id, distance = rednet.receive()
if fs.exists("acc/"..id) then
rednet.send(senderId, "yes")
config.load("acc",id)
local real_pass = config.readVal("pass")
senderId, pass, distance = rednet.receive()
  if pass == real_pass then
   rednet.send(senderId, "good")
   local money = config.readVal("money")
   rednet.send(senderId, money)
   break
  elseif pass ~= real_pass then
   rednet.send(senderId, "bad")
   break
  end
else
  rednet.send(senderId, "no")
  break
end
end


On ATM I get Error

Quote

startup:23: attempt to call nil

Help me !

Your code is...HUGE (no offence). Btw I am really close to completing it and it reaquires a lot less code(well I did it slightly differently but I also get nearly the same erroe :(

#15 pauliuskas05

  • Members
  • 12 posts

Posted 11 July 2014 - 07:34 PM

Anybody ? I have no idea what causes this error...

#16 flaghacker

  • Members
  • 655 posts

Posted 11 July 2014 - 07:46 PM

Which of your 2 programs errors? The ATM or the server? Also, read this for common errors and how to fix them: http://www.computerc.../#common_errors

Edited by flaghacker, 11 July 2014 - 07:48 PM.


#17 AlkamlBan

  • Members
  • 64 posts
  • LocationGreece

Posted 11 July 2014 - 09:55 PM

All right. Here you go! Got it working:
Bank Server Code:
rednet.open("right")
cards = {{1, 1000}, {2, 550}}
while true do
senderId, ID = rednet.receive("id")
for i = 1, #cards do
    if cards[i][1] == ID then
	    rednet.send(22, "yes", "answer")
	    senderId, amount = rednet.receive("pay")
	    if cards[i][2] >= amount then
		    rednet.send(22, "done", "transaction")
		    cards[i][2] = cards[i][2] - amount
	    else
		    rednet.send(22, "nope", "transaction")
	    end
    else
	    rednet.send(22, "noCustomer", "transaction")
    end
end
end  

And here is the code for the counter of the store:
diskID = disk.getID("bottom")
amount = 100
rednet.open("right")
rednet.send(23, diskID, "id")
repeat
    senderId, message = rednet.receive("answer")
until senderId == 23
if message == "yes" then
    rednet.send(23, amount, "pay")
    senderId, message = rednet.receive("transaction")
    if senderId == 23 and message == "done" then
	    print("Transaction Complete!")
    elseif senderId == 23 and message == "nope" then
	    print("Transaction Failed: Not enough money")
    else
	    print("No such customer")
    end
end

This is how it works:
1)The computer in the store sends a mesage to the bank server containing the cards ID.
2)The server checks in its table to see if the first number of the tables inside the table match the ID
3)If they do the server sends a message to the computer telling it to send it the amount
4)The computer checks the amount and sees if the second number inside the table the ID was found is bigger or equal to the amount
5)If it is it subtracts the amount from the money in the bank and sends a message to the computer saying that the transaction has been completed.

I will do ATMs tommorow (its already 1am :D ) and post the code

#18 AlkamlBan

  • Members
  • 64 posts
  • LocationGreece

Posted 11 July 2014 - 10:03 PM

View PostAlkamlBan, on 11 July 2014 - 09:55 PM, said:

I will do ATMs tommorow (its already 1am :D ) and post the code

Actually I won't because ATMs dispence virtual currency as real-life money. I don't see the point in making such a thing (I mean its more about redstone thatn computers). Plus why use solid money when you can access your bank account from anywhere? Not that a hacker can't steal your money this way but if you carry real money the thief that will kill you can steal it and you can't retreave it but with this you can go to the bank and report you stolen card and they will stop all transactions happening using that specific card. Plus while an ATM dispences money a guy sitting close can easily pick up some. Both ways have an enemy. So its your call which you will use. If you want I will make an ATM just ask.

#19 pauliuskas05

  • Members
  • 12 posts

Posted 15 July 2014 - 08:40 AM

View PostAlkamlBan, on 11 July 2014 - 10:03 PM, said:

View PostAlkamlBan, on 11 July 2014 - 09:55 PM, said:

I will do ATMs tommorow (its already 1am :D/>/> ) and post the code

Actually I won't because ATMs dispence virtual currency as real-life money. I don't see the point in making such a thing (I mean its more about redstone thatn computers). Plus why use solid money when you can access your bank account from anywhere? Not that a hacker can't steal your money this way but if you carry real money the thief that will kill you can steal it and you can't retreave it but with this you can go to the bank and report you stolen card and they will stop all transactions happening using that specific card. Plus while an ATM dispences money a guy sitting close can easily pick up some. Both ways have an enemy. So its your call which you will use. If you want I will make an ATM just ask.

It's only VIRTAUL, so there is no cash to give out.

EDIT:
BTW I am on vacation. So I won't always be online.

Edited by pauliuskas05, 15 July 2014 - 08:44 AM.


#20 AlkamlBan

  • Members
  • 64 posts
  • LocationGreece

Posted 15 July 2014 - 10:09 AM

View Postpauliuskas05, on 15 July 2014 - 08:40 AM, said:

View PostAlkamlBan, on 11 July 2014 - 10:03 PM, said:

View PostAlkamlBan, on 11 July 2014 - 09:55 PM, said:

I will do ATMs tommorow (its already 1am :D/>/> ) and post the code

Actually I won't because ATMs dispence virtual currency as real-life money. I don't see the point in making such a thing (I mean its more about redstone thatn computers). Plus why use solid money when you can access your bank account from anywhere? Not that a hacker can't steal your money this way but if you carry real money the thief that will kill you can steal it and you can't retreave it but with this you can go to the bank and report you stolen card and they will stop all transactions happening using that specific card. Plus while an ATM dispences money a guy sitting close can easily pick up some. Both ways have an enemy. So its your call which you will use. If you want I will make an ATM just ask.

It's only VIRTAUL, so there is no cash to give out.

EDIT:
BTW I am on vacation. So I won't always be online.

Yes but it would be nice wouldn't it? and btw hackers can do some cool tricks to steal you money from the bank. As I said you are not safe in any of the two ways so its your call. I guess having both would be the best option :)





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users