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

CC/infrastructure implementation/coding

Started by mistamadd001, 02 May 2014 - 06:11 AM
mistamadd001 #1
Posted 02 May 2014 - 08:11 AM
Hi all,

I am setting up a new server (name undecided) and I am interested in trying to set up towns that have "true" infrastructure.

I have the idea of supplying several items to 'houses' and charging for usage as well as charging for the house itself.

My idea would be, having a 'password protected' house (pwd door, worldguard(major-claim for the house (to prevent the player breaking the system)and a subclaim(inside the house walls(to allow players building/placing of items)))) that you can gain initial access by inserting your 'credit card' (uniquely created floppy disk) once the card has been inserted a 'house server' 'downloads' the player's financial details (account#) and can then start logging charges.

The house server displays the charges on a monitor in the house so the player can keep track of his charges.

Events that must occur at house 'purchase':
  1. Player must be added to worldguard subclaim perms
  2. Door password must be updated to match players credit card pin
  3. House server password must be updated to match players credit card pin
  4. Previous charges displayed must be cleared
After initial setup the player could then access the house server using his credit card pin and add a door password (if he/she wants additional players to live with him/her. Their player names must also be added to the worldguard subclaim.

The charges are sent to a 'banking server' that then a) Checks the player has enough money, B)/> Pays the utilities supplier based on usage.

Charges I am currently considering are: Rent (paid per day), Electricity (paid per kEU), Energy (paid per kMJ)(kEU and kMJ would be charged according to their base production rate eg. 100EU=20MJ), Fuel (Paid per 10000mB (10Buckets), Oil (Paid per 10000mB), Lava (paid per 10000mB).

As far as I can assume/see these are the systems I would need to implement to have this work correctly.
  1. Banking server (Computer & wmodem)
  2. House server (Computer, wmodem & Monitor)
  3. House access terminal (Computer)(House server connected via bundled cable)
  4. Credit card creator (Computer, wmodem & disk drive (autofeed system for blank disks))
  5. scheduling server? (Computer & wmodem)(used to handle the large amount of access to banking server)
and future inclusions
6. ATM
7. Shop

This is a lot of work and I can understand that, and although I am relatively new to Computercraft, I believe (with guidance) I can achieve what I want. I understand what I want to happen, I understand 'how' it happens, I just dont know how to make it happen haha.

If anyone would like to help me with starting out and pointing me in the right direction, perhaps providing some example programs/code snippets to help me better understand how it will all go together.

I am really excited about this and I believe it would be something unique to create an attraction to my server.
mistamadd001 #2
Posted 02 May 2014 - 08:37 AM
All the info I want on the credit card is the players account number (randomly generated) making it that much harder to hack someones account.

I also want to be able to pay interest on players' current funds (calculated daily) based on a percentage eg. billybob has M$1000 and at 12am every day he gains 2% interest resulting in day one as M$1002 day 2 M$1004.004 I would also like it so any equations that result in more than 2 decimal places such as in day 2, to be rounded to the nearest 2 decimals so day 2 would become M$1004.00 but day three would become M$1006.01 (instead of 1006.008)
Edited on 02 May 2014 - 06:37 AM
CoLDarkness #3
Posted 02 May 2014 - 09:42 AM
Imgoodisher has an economy system for CC. I think you might be interested.

http://imgood.zapto.org/ntc/docs.txt
mistamadd001 #4
Posted 02 May 2014 - 01:25 PM
Thats only client side though?

Id prefer to have a completely server based system, rather than going external, I know its less secure (unless your web system is done poorly) but its much easier for me to manage, at this stage, if I see this being more than just a flight of fancy, and I read up on the programming of such a system, then I will implement sql on the serverbox to handle the details. however I would still prefer it to be solely ingame cc
Lyqyd #5
Posted 02 May 2014 - 03:57 PM
Moved to General.
mistamadd001 #6
Posted 02 May 2014 - 04:56 PM
So far I have a server here though I'm getting a concatenation error on line 5 (all to do with marking a serverlog with 'date' and 'time' just for hack log purposes, (though if someone did hack and see how ive coded it they could easily delete the logs)

I also have an account creation/creditcard creation program here that works perfectly as long as you supply it with disks (disks will be uncraftable on my server so as to stop people creating fake disks, although I will be adding disk ID's to accounts as well)

and lastly my seriously WIP client here

there are still MANY things that I need to add in and tidy up as well as several other machines I need to create, but I thought I'd show everyone my first day's progress (BTW, I didn't know how to create a table this morning. So I'm pretty impressed with my learning so far)

comments, critiques, suggestions, etc. always welcome
Bomb Bloke #7
Posted 03 May 2014 - 01:43 AM
So far I have a server here though I'm getting a concatenation error on line 5

At that point you've not defined the "id" variable - did you mean to use "os.getComputerID()"?
mistamadd001 #8
Posted 03 May 2014 - 03:16 AM
So far I have a server here though I'm getting a concatenation error on line 5

At that point you've not defined the "id" variable - did you mean to use "os.getComputerID()"?

yea at about 4am this morning I realised that. I fixed that and proceeded to complete quite an overhaul of the code i already had and added in all of the "client/atm" code.

New Programs:

Server V0.2
Client/ATM V0.2
Card creator V1.1

if you try and run these systems at the moment, the only one that doesn't throw errors is the card creator(hence the release version)
the other 2 are throwing super confusing errors that make no sense at all such as in the Client program I'm getting at line 7: 'then' expected, however the line is a 'while true do' statement so there shouldn't be a 'then' statement, and in the Server program I get at line 88: ')' expected, now as far as I can tell, this line is 100% correct.

If anyone has insight into this I would greatly appreciate it.

NB: The install command in both the server and the client will be removed once implemented, it is simply an easier way of creating multiple legitimate clients
Edited on 03 May 2014 - 01:18 AM
CometWolf #9
Posted 03 May 2014 - 11:16 AM
Actually, this is line 7 of the client

  if disk.hasData(disk) = false
I hope you can spot the 2 reasons it's throwing an error there…

As for line 88 in the server

file.write(date..","..time.."("..id.."): "acc.." Withdraw attempt")
Take a closer look at your concatenation.
Engineer #10
Posted 03 May 2014 - 11:57 AM
Actually, this is line 7 of the client

  if disk.hasData(disk) = false
I hope you can spot the 2 reasons it's throwing an error there…

As for line 88 in the server

file.write(date..","..time.."("..id.."): "acc.." Withdraw attempt")
Take a closer look at your concatenation.

And now the answers:

For a comparison we use ==, because if you use = lua thinks you want to assign something.
So, the fixed code is:

if disk.hasData(disk) == false then

With concatination you are just missing one ..
We all overlook something :)/>

file.write( date .. "," .. time .. "(" .. id .. "): " .. acc .. " Withdraw attempt" )
mistamadd001 #11
Posted 04 May 2014 - 05:20 AM
thanks for that, I didnt even realise about the concatenation, and I found that I'd copied that piece of code right through my program, a few ctrl + f's later and its all working, and I thank you kind sirs
mistamadd001 #12
Posted 04 May 2014 - 08:43 AM
Actually, this is line 7 of the client
 if disk.hasData(disk) = false 
I hope you can spot the 2 reasons it's throwing an error there… As for line 88 in the server
 file.write(date..","..time.."("..id.."): "acc.." Withdraw attempt") 
Take a closer look at your concatenation.
And now the answers: For a comparison we use ==, because if you use = lua thinks you want to assign something. So, the fixed code is:
 if disk.hasData(disk) == false then 
With concatination you are just missing one .. We all overlook something :)/>/>
 file.write( date .. "," .. time .. "(" .. id .. "): " .. acc .. " Withdraw attempt" ) 

A quick question for you, in the Client program how would I make it recognise if the disk has been removed (effectively cancelling the transaction and therefore returning to requesting a card)?
mistamadd001 #13
Posted 04 May 2014 - 02:18 PM
OK, so I'm getting really frustrated at the moment, for some reason my client program wont talk to my server program, I get to entering my password on the client and I hit enter, it prints that the message has been sent but my server (which records every message received) doesn't seem to be receiving the message. Neither the client or the server are throwing an error. Anyone got any ideas??

Server v0.2.1 here
Client v0.2.1 here
Bomb Bloke #14
Posted 06 May 2014 - 03:30 AM
Assuming the ID is correct (yeah, I know, but check it again - and don't confuse the client/server IDs!), are the two systems in range of each other? Are they able to communicate if you manually send a basic message via the Lua prompt?
mistamadd001 #15
Posted 06 May 2014 - 03:50 AM
Assuming the ID is correct (yeah, I know, but check it again - and don't confuse the client/server IDs!), are the two systems in range of each other? Are they able to communicate if you manually send a basic message via the Lua prompt?

yea, just tried, sent a test msg thru and it was received
Edited on 06 May 2014 - 01:55 AM
Bomb Bloke #16
Posted 06 May 2014 - 06:49 AM
The "end" on line 195 should be sitting below line 75, where you first broke indentation.
mistamadd001 #17
Posted 06 May 2014 - 11:11 AM
The "end" on line 195 should be sitting below line 75, where you first broke indentation.

Thank you, I have fixed that, I'm now having other issues, I should really fix the issues I'm already having before writing new code lol.
mistamadd001 #18
Posted 08 May 2014 - 03:10 AM
I have the "banking" programs/computers working as close to how I want as I reckon I'll get them with the amount of knowledge of CC and Lua. So without further ado

All client/server communication is handled by rednet.send, no broadcasting (any interception attempts will be more difficult, I would suggest banning the creation of computers and disks)

Server v1.0

Client Authentication - No transactions will be processed unless the client computer is registered on the server prior.
User authentication - Transaction options will not be processed unless the users password is confirmed
All balance equations are computed centrally in the server.
All interactions are written to a serverlog.

Client v1.0

All sensitive information is handled internally and offsite, no passwords or balance information is held on the bankCard.
Balance enquiries, Withdrawals from CC to economy plugins (requires commandBlocks), Deposits from economy plugins to CC (requires commandBlocks) and transfers are all available directly from the client and are handled by the internal system.

Creator v 1.1

Account and disk creation, No sensitive information stored on bankCards

As always, suggestions, comments, etc. are welcome.

I will be trying to start the infrastructure systems now. If anyone has any idea how to continually update a variable from the nuclear information readers data table. (Using NIR's to receive how much fluid/energy are being transferred from the central system to any private properties) I would love to hear them. (I have already tried setting the peripheral.get() inside a while loop to no avail)