Jump to content


albrat's Content

There have been 159 items by albrat (Search limited from 10-February 22)


By content type

See this member's


Sort by                Order  

#178455 Program Security

Posted by albrat on 14 May 2014 - 10:04 AM in Ask a Pro

I would say the best way to prevent a random computer from password finding on your server... Would be to list all your client computers in your server program.

eg.

serid = { 12,15,17,19,23,25 }
Then when you get a rednet message you run a little check on the list.

eg.

onlist = false
for chk, #serid, 1 do
  if serid(chk) = p1 then onlist = true break
end

if onlist == false then rednet.send(p1, "not on access list") end

if onlist == true then -- Check if our request is from a pc on our list.
  if p2 == pass then
	rednet.send(p1, true)
  else
	rednet.send(p1, false)
  end
end



I also have a log on the server that records failed attempts to login and the password they tried. (only on failed attempts) it also logs the Id of the computer, so I can ban the id from the server.



#173258 CC For Minecraft Server

Posted by albrat on 13 April 2014 - 10:50 PM in Ask a Pro

By the way you describe this... You installed ComputerCraft into your server and client... Did your friend install CC and forge on their client? (just have to be sure.)

If they have not installed or they have installed it incorrectly then this could cause the problem you are seeing.



#162588 Searching for 2 Programs

Posted by albrat on 30 January 2014 - 03:27 AM in General

I would also suggest not using the DW20 button API. It is basically designed to open sub menu's etc. and for single press buttons.

Sadly I do not have any programs that currently do anything like you are looking for. But i think there is a button program in the tutorials section. (that is better than the Direwolf20 version).



#161672 How to gracefully exit a script?

Posted by albrat on 23 January 2014 - 05:58 AM in Ask a Pro

I would use the following to exit a script with a message of completion.
printError("Program Complete") --// sets the error message for the error
error()
I was just checking with bios.lua on the 1.58 version of CC .
error("Program Complete")
Should achieve the same effect looking at the way this is handled (I have not tested this method of exiting.)



#160820 Reading information on disks

Posted by albrat on 16 January 2014 - 01:44 PM in Ask a Pro

The table has already done half the job for you. You are calling the filenames from a table and inserting them into buttons...

you already know that the first button is entry 1 in the list table. (buttons on a screen you have to insert a co-ordinate system and names into a table... Just add an additional data element with the program name as well. )

eg. button[1] = { 5, 1, 10, 3, "ButtonsAPI" } --// we have a range of clicking ( x,y 5 pixels in and 1 from the top By 10 pixels and 3 from the top ) and then we store the program name. ( we know this program is on /disk/ so we don't need to store that information. )
The click registers a match on button[1] so we can catch 1 from that and know that button[1][5] is the program that was clicked.



#160615 Rednet id

Posted by albrat on 14 January 2014 - 01:55 PM in Ask a Pro

View PostGreatShooter, on 11 January 2014 - 02:13 PM, said:

And my computer's code:
local names = {
  [20] = "Water bottler",

}

local monitor = peripheral.wrap("back")
os.startTimer(600)
while true do
  rednet.open("right")
  event, id, text = os.pullEvent()
  if event == "rednet_message"  then
	local name
	if names[id] then name = names[id] else name = id end
	  term.redirect(monitor)
	  print(name.." says:"..text)
	  term.restore()
	  print(os.pullEvent())
	
	   local executetime = os.time()
	
	  local executetime = executetime + 12
	  while executetime == os.time() do
		term.redirect(monitor)
		term.clear()
		term.restore()  
  
  
	   end
  
	 end
	end

Do you think they are ok/ need tweaking?
The server code here will not work correctly. There is only a fraction of a tick where executetime and os.time() will match, the timer updates faster than the tick on the program so it could actually pass the matching time before it activates, hence I used >= in my check system.

Also due to the fact that our turtle is only sending a message once 10 minutes passes, you should have the server running on the os.pullEvent() as a wait and not the os.time() way. as waiting on os.time() will only trigger on one event.

local names = {
  [20] = "Water bottler",

}

local monitor = peripheral.wrap("back")
os.startTimer(600)
while true do
  rednet.open("right")
  event, id, text = os.pullEvent()
  if event == "rednet_message"  then
	local name
	if names[id] then name = names[id] else name = id end
	  term.redirect(monitor)
	  print(name.." says:"..text)
	  term.restore()
	  print(event)  --// print(os.pullEvent()) will make the system pause for a event to print, not print the captured event.

--// Removed the section that paused script for 10 minutes, this would have errored as well, because there was no yielding events.
  
	end
end



#160223 sorting system

Posted by albrat on 11 January 2014 - 09:33 AM in Ask a Pro

It is a good way to do it, but I used a table system that used the id's as an index. eg table([7]) would give me the value 3. it does mean that every id would have to have a value. (not good for memory) But it means that checking the table for a id is easier on the programmer. But you could also store more information in the table. (table inside a table) ...

I had a table setup of items(), items had a table inside each entry that had the quantity, name, max stack size. (not all items stack to 64) This meant if I wanted a Wooden Door, (324 or 64 item id.) I would check id 64, items([64](1)) -- this would return eg. 32 (our stored quantity). items([64](2)) -- This would return "Wooden Door", and items([64](3)) would return 16 as our max stack size.

** warning my information on how to do tables and the terminology may be wrong, I haven't worked with CC and tables for a while. (I've been on a hardmode server and its taken a month to setup a safe ish house.)

items = { [1] = { 0, "Stone" , 64 } ; [2] = { 0, "Grass" , 64 } ;
}



#160220 Rednet id

Posted by albrat on 11 January 2014 - 09:14 AM in Ask a Pro

The sleep function pauses the script, which is what GreatShooter here is trying to avoid.

I guess another way would be to record the system time, then add a line of check code.
Here is a little sample I wrote to do just that on a basic check.
while true do --// loop here for ever.

local executetime = os.time()
local executetime = executetime + 12 --// This is 10 minutes in os.time

while executetime >= os.time() do --// Loop untill our 10 minutes have gone.
sleep(0.1) --// my current prevention for yielding during testing
term.setCursorPos(1,5)
print(executetime)
print(os.time)
end

tenminjob() --// call the 10 minute function

end

Currently this will print the time and time that the counter will trigger. To make it run your normal programs just call your normal programs inside the 10 minute loop. Once it finishes the last task and the 10 minutes have passed it will exit the loop and then continue with the command you wish to run after 10 minutes.



#160213 Rednet id

Posted by albrat on 11 January 2014 - 08:16 AM in Ask a Pro

@ GreatShooter -- I would use a os.startTimer(600) then just have a check in your code that uses an if statement to trigger that event.

os.startTimer(600)
while true do
event,id,message,sender = os.pullEvent()

if event == "timer" then
  -- your 10 minute code here
end

if event == "rednet_message" then
  -- Your rednet message code here
end
end
That is a simple piece of code that would do what you ask, even if the turtle performs other tasks.

There is another way that is simply a "event = os.pullEvent(1) " This will pause your script for 1 second pulling the next event from the stack. (0.1 would work too ) -- I think this is wrong.



#160210 sorting system

Posted by albrat on 11 January 2014 - 07:57 AM in Ask a Pro

I would have a seperate computer that handles just the incoming items. Simply put send a message to the server computer that says "R 32 1" then have the server computer recieve the message, and store it in a table then send a "ack" response, to let the counter know that the message was recieved.

Where "R" is recieve. "32" is the count of items and "1" is the item number.

But I would store all incoming in a table, then just read from the table like a stack. That way you could send the information and store multiple entries before sending. fx. batch process several items then if idle for 2 seconds... Send data burst to the server.

I know I am not suggesting code but I hope this helps more with the idea stage. :)



#147206 multiple computers on the same set of cables

Posted by albrat on 29 September 2013 - 02:44 PM in Ask a Pro

The way that I would do it... Is you have 3 computers with rednet / wireless modems... Then have one computer connected to the door that is the lock computer, the other two computers basically send a signal to the door computer to tell it to open.

That way you can send a signal from either computer to open the door.



#144460 Countdown Timer For A Spawner

Posted by albrat on 12 September 2013 - 07:17 AM in Ask a Pro

the local current = count is basically assigning current to the function itself. (bad way of writing the program with a function and a varible using the same name.)

Change local count = 300 (at the start of the program) to "counter = 300"

then change the local current = count to "local current = counter"
This will avoid any possible mis-translation of the counter and count (varible and function) by Lua. (also note I changed the counter varible into a global varible by removing local from it's declaration)


I would also say that you really do not need to assign the origional "counter" value as all you are doing is later passing a unchanged value to the program. (wastes memory)...

I suggest you scrap the local count = 300 and just write in the first line of the function "local current = 300" instead. as it is exactly the same but you only assign 300 to current and not to count and current.

function count()
  local current = 300
  ... code stuffs
end



#142191 Help with Stair Mining Program

Posted by albrat on 29 August 2013 - 03:45 AM in Ask a Pro

  if turtle.getItemCount(12) ~=0 then
    turtle.digDown()
    print("Placing Chest...")
    turtle.select(15)
    turtle.placeDown()
    for slots =1,12 do --// we want to select slots 1 to 12
      turtle.select(slots) --// select the slot our for loop is on
      turtle.dropDown() --// Drop the items down
    end
    turtle.select(1) --// select the first slot again now.
  end


That should work for selecting and dropping all items in slots 1 to 12 then reset the slot to start at 1 again.



#141403 Updaters - How Would I Make One?

Posted by albrat on 23 August 2013 - 06:32 PM in Ask a Pro

Have a single file online with a version number... Have each version of your program try and download that file near the beggining of your load up.. run a check against the version of the file and the version of your current program... Voila a quick and easy way of version checking. (do a error handler to set the version to the same as the current version if your online file is not available, just to avoid a value compared to nil... err. )

Doing the single Version file, means you use less bandwidth to check online for new versions and that the program can start running faster instead of downloading everything every time.

I have not played around with online files... But I guess having a patebin account would mean you could update the files there... then just have your check run a program to download from the pastebin links. (all you do is add a new version to your pastebin and use the same link address).

pastebin get .... startup	 -- // for example



#141219 How Did You Learn How To Code?

Posted by albrat on 22 August 2013 - 11:29 AM in General

View Post1lann, on 22 August 2013 - 09:24 AM, said:

I learnt how to code by probably just reading simple explanation of basic functions, then I keep on creating programs that practice the use of them, and once I'm confident I move on. I also frequently make parts of my program, or find out how to make a part of my program by googling, then put it together.
This is basically the approach I took with Lua, plus reading the PiL book.



#141181 Reactor Overheat Protection

Posted by albrat on 22 August 2013 - 06:27 AM in Ask a Pro

View Postimmibis, on 22 August 2013 - 12:42 AM, said:

Why not just use a NOT gate?
Because you have to move your signal away from the reactor to use the not gate. I have played with the same Ideas, but my reactor has a complex redstone circuit to turn itself on and off for set periods of time usnig pistons etc. (the reactor powers all my buildcraft items through an energylink. using a gate plate to detect the flow of power, * if the power is in the pipe it shuts off the MFE * if the MFE is full it shuts the reactors down for 1 minute, to let the power in the MFE drain a bit...)

at the time I made the reactor, I was not using the CC computers. Otherwise I might have used the same system as this to turn on and off the reactor. (gives you more control with different programming).



#141180 How Did You Learn How To Code?

Posted by albrat on 22 August 2013 - 06:17 AM in General

View PostZudoHackz, on 22 August 2013 - 02:30 AM, said:

My first program was "Hello World" in scratch when I was 6!
Scratch is fun :)
My first program was on a ZX Spectrum... (age 5) I had the computer output the factors of 2... 2,4,8,16,32,64,128,256,512.....
I then translated that program to the old BBC computers we had at school. ( and into commodore language for the C64 )
the days of basic ... lol. (The memory limits of 64kb too. ) I made a program back then that tried to use a tape to store a entire screen of text... (wrote a story in a game). I ran out of space on the tape before finishing the program and gave up in the end. hehe. (the 5 1/4 inch disks did not help either I filled one trying to convert the game to disk.) ** it was an adventure book where you were hunting ghosts, every choice you made changed the outcome. Opening and closing some options if you took a train or just waited where you were... for example. (for a 8 year old at that time it was a little much to try and achieve. lol )

I never actually made a "Hello World!" program, this is a little strange really as all tutorials start with this. ( java, C, c++ ) Including Lua. lol... http://www.lua.org/pil/1.html ( and the second part of the first tutorial is basically part of my first ever program. lol )



#141125 Comparing Inventory Question - Basic

Posted by albrat on 21 August 2013 - 07:24 PM in Ask a Pro

I know this is probably a silly comment... But if you have IC2 machines there is an easier way to produce flint, If you use a macerator with gravel it gives flint. :)



#141122 Reactor Overheat Protection

Posted by albrat on 21 August 2013 - 07:18 PM in Ask a Pro

With no redstone signal the reactor does not work. You have to apply a signal to turn on the reactor.

the sensor box that detects the heat emits a redstone signal if the reactor gets too hot.

So we have the computer detect the activation of the overheat signal and make it turn off the redstone to the reactor. ( bit like a "not" switch / Circuit )



#140977 Temporal Slow-Down

Posted by albrat on 20 August 2013 - 05:13 PM in Ask a Pro

I have had problems with MC having microlag. But mine was caused by me forgetting to make my programs yeild. It basically started, ran the program. Crashed the CC computer. Then the lag finished. (few tweaks later in my programs and my Mc no longer lagged). * I run Minecraft with 2gb of ram. in the java enviroment. (8gb system ram).

I must admit i have never seen it effect the sky though and I have basically all the mods you have except :-

-OpenCCSensors 0.1.4c
Optifine, CraftGuide.

I have 97 mods in total on my version of minecraft. But it was assembled by my old server admin. ( we closed our server untill Redpower2 is updated to a newer minecraft version now. )



#140931 Reactor Overheat Protection

Posted by albrat on 20 August 2013 - 01:04 PM in Ask a Pro

I know what you are thinking about... it's the insulated cables. You have to run those up to an item and stop. Otherwise the signal doesn't go to the item. (I usually terminate into a normal redstone wire )



#140924 Temporal Slow-Down

Posted by albrat on 20 August 2013 - 12:08 PM in Ask a Pro

inbetween your "while true do" and the end statements you do not allow your script to yeild. Basically it will try to run as fast as possible without giving up processing time to other programs...

You must have a way of making the program yeild... eg sleep(0.1) This may be why you are getting problems with "microlag" while using the computers.



#140921 Reactor Overheat Protection

Posted by albrat on 20 August 2013 - 11:42 AM in Ask a Pro

Confirmed that you can use Redpower2 wires on the front of a monitor.

Attached Image: Untitled.png

Also in screenshot is how to grab the input when it activates.

while true do
if redstone.getIput("front") then
  redstone.setOutput("back", false)
  else redstone.setOutput("back", true)
end
sleep(1)
end



#140681 Railroad layer

Posted by albrat on 18 August 2013 - 07:09 PM in Ask a Pro

--// the following lines allow you to call your program with arguments.
local targs = {...} --// capture the arguments
if targs == nil then --// if no argument handed to program... then 1 iteration
  x = 1
else
  x = targs[1]
end
--// the above code checks and sets value x which is used in our main program loop at the end...

function track1(length)
if length == nil then length = 1 end
for a=1,length do
turtle.turnLeft()
turtle.select(1)
turtle.place()
turtle.turnLeft()
turtle.turnLeft()
turtle.place()
turtle.turnLeft()
turtle.forward()
end
end

function track2(length)  --// captures the varible length as an input.
if length == nil then length = 1 end --// make sure that the input is not nil (error catch)
for b=1,length do --// loop the command for length
turtle.turnLeft()
turtle.select(2)
turtle.place()
turtle.turnLeft()
turtle.turnLeft()
turtle.place()
turtle.turnLeft()
turtle.forward()
turtle.turnLeft()
turtle.turnLeft()
turtle.select(3)
turtle.place()
turtle.turnLeft()
turtle.turnLeft()
end
end

for loop = 1, x do
track1(10) --// hands 10 to function track1()
track2(1) --// hands 1 to function track2()
end

You wrote code that handed values to the functions but your functions did not capture the values / varibles and use them. Instead you had fixed varibles.

These changes make the functions work as adjustable functions. ( eg. You could lay 8 tracks then lay 5 powered rails, then 10 track and 1 powered rail... By sending track1(8) track2(5) track1(10) track2(1) .. )
gives you flexibility in laying of track.

You could also program in a long booster section etc.

Also if you wanted to you could make the turtle run "x" amount of iterations...
(I changed the code already to handle that as a possibility...)

To use your turtle with arguments you would call your program from the turtle like this...


say your program is called "Track"
you would type

Track 10

The program would repeat 10 times and stop.



#140679 How Did You Learn How To Code?

Posted by albrat on 18 August 2013 - 06:49 PM in General

Google is your friend. If you need to do something and have no idea how to do it... Type in your laanguage name, what you want to do. 9/10 times you will get an example that almost does what you want. Try the code examples, change them and modify them to do what you want to do...

Always have a Developers manual for the language you wish to code in... eg Lua - http://www.lua.org/pil/contents.html - This is the online reference manual.

If you are using a custom coding language - eg. ComputerCraft. Then I suggest finding a list of commands and functions that you can use in the program code. (having a list of possible additional commands makes programming in the language easier.) As you use more and more of the available commands you will find that you know what to use more and more as you are writing your programs... By the time you realise it you are writing programs without thinking about how to write them.

(I consider myself a learner, With Lua I have found that you can never be a pro... Because of the way you can expand Lua as you write with lua.)