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

Toraktu - A Server Template [ Automated ]

Started by TorakTu, 15 August 2013 - 08:30 PM
TorakTu #1
Posted 15 August 2013 - 10:30 PM
A Server Template




NOTICE ( November 27th, 2014 ): I came back to find a ComputerCraft version for 1.8.1 and I see it still hasn't gotten to that point yet. I'm afraid that I will not bother with this site any longer since its dead. Sorry to see it go. It was the best mod around.

WHAT IT IS
This is a server template. It fully automates itself in the sense of finding all peripherals it needs… if you have them attached. It works on regular computers and advanced computers. Touch screen as well. This is the basic template I will be using for TorNet. You can add your own ideas into this template for your massive server projects.



MY DREAM OF COMPUTERCRAFT
Call me crazy, but I feel that TorNet could be better used if multiple servers all over the world that host minecraft, And they could display their websites right inside of computercraft. Think about it. Simple HTML websites FROM ANY TO ANY minecraft server. Well, its a dream that is VERY possible. With the PHP and the parsing of those files, you could literally have one server talk to another through a website. Of course you must setup a PHP website, but you technically could use this server template to do so. It's a dream of mine to make this happen. Who knows… :)/>



SERVER TEMPLATE ( Recommended ! )
Here is the pastebin for the template with a server locking mechanism built in so that if it sees another server with the same identification it will shut the newer server down.

NEWEST VERSION - 8.26.2013 ( Build 1531 )
pastebin get EeWG5PW3 template

Older Version
pastebin get W1UjG6ac template



SERVER TEMPLATE - NO LOCKING MECHANISM
Use this pastebin for the template if you do not want a locking mechanism.
pastebin get msun8KDc template



CHANGELOG
- 8.26.2013 ( Build 1531 )
– Added Server Identity Generation ( No need to edit the server file manually to change the server's identity. Still allows for custom identity, by editing the Ident File that is created. )
– Fixed setTextColor now has the appropriate Capital letter C.

- 8.16.2013 ( Build 840 )
– Fixed setTextColor now has the appropriate Capital letter C.
– Original version



DEMO
SERVER TEMPLATE DEMO - NO LOCKING MECHANISM ( Not recommended as your default. This is for demonstration purposes only ! )
Test my demo template example below on three different wireless computers and you will see them all communicate with each other. To initiate it, just hit the G key in one of the computers. The transmit and receive lights will go green.. on the black and white screen it shows 0 and 1.
The full code here
Spoiler

-- TorakTu - Template [ 8.15.2013.2006 ]
os.pullEvent = os.pullEventRaw
local mainName = "Template"
local em = "NONE"
local sides = {"left","right","top","bottom","back"}
local mSide = { }
local mtotal = 0
local isModem = 0
local off = 0
local mon = ""
local advancedornot = false
local currPath = shell.resolve(".")
local timer
local theSwitch = 0
local theTime = 0
local menu_options = 0
local trans = 0
local mScaleSize = 0.5
local setMonScale = 0
local tr = 0
if currPath == "disk" then currPath = "/disk/" end
for _,v in pairs(sides) do
   if peripheral.getType(v) == "modem" then
	  mtotal = mtotal + 1
	  mSide[mtotal] = v
	  isModem = 1
   end
   if peripheral.getType(v) == "monitor" then
	  em = v
   end
end
if isModem == 0 then
   term.clear()
   term.setCursorPos(1,1)
   print(" ")
   print(" WARNING ! No modem attached !")
   print(" ")
   print(" PROGRAM TERMINATED !")
   print(" ")
   return
end
local modem = peripheral.wrap(mSide[1])
if em ~= "NONE" or em == "bottom" or em == "top" or em == "left" or em == "right" or em == "back" then
   mon = peripheral.wrap(em)
   mon.setTextScale(0.5)
else
   mon = "NONE"
end
if term.isColor() then
   advancedornot = true
end
function mtprint(theString,x,y,fg,bg)
   if mon ~= "NONE" then
	  if advancedornot then
		 if f ~= 0 then
			mon.setTextColor(fg)
			term.setTextColor(fg)
		 end
		 if b ~= 0 then
			mon.setBackgroundColor(bg)
			term.setBackgroundColor(bg)
		 end
	  end
		 mon.setCursorPos(x,y)
		 mon.write(theString)
		 term.setCursorPos(x,y)
		 term.write(theString)
   else
	  if advancedornot then
		 if f ~= 0 then
			term.setTextcolor(fg)
		 end
		 if b ~= 0 then
			term.setBackgroundColor(bg)
		 end
	  end
	  term.setCursorPos(x,y)
	  term.write(theString)
   end
end
function clearMe()
   if mon ~= "NONE" then
	  if advancedornot then
		 term.setBackgroundColor(colors.black)
		 term.setTextColor(colors.white)
		 mon.setBackgroundColor(colors.black)
		 mon.setTextColor(colors.white)
	  end
	  mon.clear()
	  mon.setCursorPos(1,1)
	  term.clear()
	  term.setCursorPos(1,1)
   else
	  if advancedornot then
		 term.setTextColor(colors.white)
		 term.setBackgroundColor(colors.black)
	  end
	  term.clear()
	  term.setCursorPos(1,1)
   end
end
local settings			 = { }
settings.isonline		  = "offline"
function pscreen()
   if settings.isonline == "online" then
	  mtprint(settings.isonline.." ",26,3,colors.green,colors.black)
   else
	  mtprint(settings.isonline.." ",26,3,colors.red,colors.black)
   end
   mtprint(tostring(mSide[1]).." ",26,4,colors.cyan,colors.black)
end
function saveFile( file, data )
   local f = fs.open( file, "w" )
   f.write( data )
   f.close()
end
function readFile( file )
   if not fs.exists( file ) then return end
   local f = fs.open( file, "r" )
   local loadInfo = f.readAll()
   f.close()
   return loadInfo
end
function emodem()
   if off == 0 then
	  settings.isonline = "offline"
	  modem.close(1)
   end
   if off == 1 then
	  settings.isonline = "online"
	  modem.open(1)
   end
end
function mDraw()
   mtprint(" ---------- ",3,7,colors.black,colors.brown)
   mtprint("| Q - QUIT |",3,8,colors.black,colors.brown)
   mtprint(" ---------- ",3,9,colors.black,colors.brown)
   mtprint(" ---------- ",16,7,colors.black,colors.brown)
   mtprint("|E - ENABLE|",16,8,colors.black,colors.brown)
   mtprint(" ---------- ",16,9,colors.black,colors.brown)
end
function transmissions()
	  if trans == 0 then
		 tr = 0
		 mtprint("0",35,7,colors.gray,colors.gray)
		 mtprint("0",35,9,colors.gray,colors.gray)
	  end
	  if trans == 1 then
		 tr = 1
		 timer = os.startTimer(0.1)
		 mtprint("1",35,7,colors.green,colors.green)
	  end
	  if trans == 2 then
		 tr = 1
		 timer = os.startTimer(0.1)
		 mtprint("1",35,9,colors.green,colors.green)
	  end
end
clearMe()
mtprint(mainName,10,1,colors.red,colors.black)
mtprint("Server Status	  : ",5,3,colors.white,colors.black)
mtprint("Modem Side		 : ",5,4,colors.white,colors.black)
mtprint("Tx : ",30,7,colors.white,colors.black)
mtprint("Rx : ",30,9,colors.white,colors.black)
emodem()
pscreen()
mDraw()
while true do
   if theTime == 1 then
	  timer = os.startTimer(0.1)
	  if theSwitch >= 1 then theSwitch = theSwitch - 1 end
	  if theSwitch <= 0 then
		 theSwitch = 0
		 theTime = 0
	  end
   end
   if off > 2 then off = 0 end
   if theTime == 0 and theSwitch >= 1 then theSwitch = theSwitch - 1 end
   if theSwitch <= 0 then
	  theSwitch = 0
	  theTime = 0
   end
  
  if tr >= 1 then
	 tr = tr - 1
  else
	 if trans > 0 then
		 tr = 0
		 trans = 0
		 transmissions()
	  end
   end
  
   local evt, arg, xPos, yPos, message = os.pullEvent()
   if evt == "timer" then
	  if tr > 0 then timer = os.startTimer(0.1) end
   end
   if evt == "modem_message" then
	  if settings.isonline == "online" then
		 if message == "test" then
			trans = 1
			transmissions()
			modem.transmit(1,1,"test")
			trans = 2
			transmissions()
		 end
	  end
   end
   if evt == "char" then
	  local c = string.lower(arg)
	  if c == "g" then
		 modem.transmit(1,1,"test")
		 trans = 1
		 transmissions()
	  end
	  if c == "q" then
		 if off == 0 then
			break
		 else
		 end
	  end
	  if c == "e" then
		 if theSwitch == 0 then
			theTime = 1
			theSwitch = 1
			off = off + 1
			if off >= 2 then off = 0 end
			emodem()
			pscreen()
		 end
	  end
   end
   if evt == "mouse_click" or evt == "monitor_touch" then
	  menu_options = 0
	  setMonScale = 0
	  if evt == "monitor_touch" then setMonScale = 1 end
	  if xPos >= 3 + setMonScale and xPos <= 14 + setMonScale and yPos >= 7 and yPos <= 9 then
		 menu_options = 1
	  end
	  if xPos >= 16 + (setMonScale / 2) and xPos <= 27 + setMonScale and yPos >= 7 and yPos <= 9 + (setMonScale / 2) then
		 menu_options = 2
	  end
	  if menu_options == 1 and off == 0 then
		 break
	  else
	  end
	  if menu_options == 2 then
		 off = off + 1
		 if off >= 2 then off = 0 end
		 emodem()
		 pscreen()
	  end
   end
end
clearMe()
print(" ")
print("Program Terminated")
print(" ")


Enjoy…

Edited on 28 November 2014 - 02:07 AM
lifewcody #2
Posted 15 August 2013 - 10:56 PM
Amazing! Simply Amazing!
TorakTu #3
Posted 16 August 2013 - 08:06 AM
Amazing! Simply Amazing!

Thanks bro. Yea when you run it, it doesn't seem to do much. But it does. And keep in mind, this is a demonstration. I will have to clean up the pastebin version so that it truly is a skeleton / template. The code on this thread is a demonstration of all the servers talking to each other. Where I messed up is I put this version in the pastebin. So I'll have to fix that. I come home from vacation tomorrow. But won't get into full swing of things until monday.

Cheers

EDIT UPDATE : Fixed. Now the pastebin is the actual template without the code of the demo in it. Now it can be used for whatever purpose you need. You would just need to understand how the code works. If you know CC well enough, you should be able to figure out what you can do with this. :)/>

Enjoy.
TorakTu #4
Posted 16 August 2013 - 11:07 AM
OP updated with a SERVER LOCK TEMPLATE.

This will allow you to identify a server and it will allow you to prevent your server from running elsewhere.

Also, updated the Tx Rx lights in this one as well.


EDIT UPDATE : I fixed a glitch that if you had more then two servers running with each their own ident, that a third one would crash one of the other two already running servers.
wilcomega #5
Posted 20 August 2013 - 12:30 PM
very nice, i love to see gui's,
because i am the worst at it :P/>
TorakTu #6
Posted 21 August 2013 - 01:49 PM
very nice, i love to see gui's,
because i am the worst at it :P/>

Dude you gave me the inspiration man. Thanks to you I was able to get this far. Kudos to you bro.

Cool part is, you can use the base template in your buenet if you wanted. I tried to make it as simple as I could, but added as many features as I could as well.

Cheers
TorakTu #7
Posted 26 August 2013 - 12:54 PM
Updated the OP.

– Added Server Identity Generation ( No need to edit the server file manually to change the server's identity )
luaCoder #8
Posted 26 August 2013 - 06:10 PM
their is an error on line: 91 because Color does not have a cap C
TorakTu #9
Posted 26 August 2013 - 06:11 PM
their is an error on line: 91 because Color does not have a cap C

If I miss any, let let me know which one. Thanks for reminding me. I had forgotten you mentioned it once before. A lot has been going on lately.. so yea I had forgotten. Thanks again.

Template Server v0.2 – Fixed

Server Template – Fixed

Server Lock Demo – Fixed
TorakTu #10
Posted 26 August 2013 - 06:23 PM
OK.. Trivia.. What does TorNet and the HTTP for ComputerCraft have to do with the future of this Server Template ?

http://www.computerc.&#46;&#46;/HTTP_%28API%29

https://en.wikipedia...TP_status_codes

Well these two links should give you a hint.. read my post above that is titled : MY DREAM OF COMPUTERCRAFT

I hope to work this into TorNet as a seperate Option.

If you do not know what TorNet is, look here : http://www.computercraft.info/forums2/index.php?/topic/14496-tornet-a-basic-http-networking-layer-a-rewritten-version-of-bluenet/page__fromsearch__1
TorakTu #11
Posted 28 August 2013 - 04:57 AM
Guys, I have received messages from a lot of you who submit code to me with "your code" that you put together but you never tested it. Please, test your code before trying to share it with others. And please give credit of where you got your source code if you use code from other people.

I'm not trying to be a dick and I am enjoying your enthusiasm, but I am not going to fix the code your trying to pawn off as your own, especially when I recognize the code from other people. I have read a lot, and I do mean a LOT of code on this forum, so don't treat me as an idiot. I know exactly where your code is coming from and of whom the original code is from.

2 rules that should be on this forum :
1.) Give proper credit to where your "chopped" code came from
2.) Make sure your code works before submitting it if your wanting people to try it out


I respect honesty and hard work. If you do both, you got a friend in me. :)/>
theoriginalbit #12
Posted 28 August 2013 - 05:11 AM
-snip-
I had someone try to pass off one of my APIs as their own…….. TO ME! Like, what an idiot! Lol.
wilcomega #13
Posted 28 August 2013 - 06:29 AM
-snip-
I had someone try to pass off one of my APIs as their own…….. TO ME! Like, what an idiot! Lol.
lol
TorakTu #14
Posted 28 August 2013 - 08:45 AM
I had someone try to pass off one of my APIs as their own…….. TO ME! Like, what an idiot! Lol.

I literally have had 7 different people submit my server template BACK TO ME with some alterations.. and some of the alterations were from other code they didn't do. AND.. none of their submissions worked. Guess they all expected me to fix it for them so they can say they did it.
darkrising #15
Posted 31 August 2013 - 10:56 AM
I have been talking and sharing some ideas with TorakTu and have come up with a small prototype called Flare which allows Computercraft computers to communicate across the internet by using PHP scripts attached to a MySQL server. As it currently stands it is quite insecure as any computer can use any ID but I wish to implement a user login later down the line.

I have modified my chat program to work with Flare with send and receiving having a short delay, 1 or 2 seconds locally. I'm sure it could be optimised to work a lot faster but for now it works okay.

My current progress is on my github if you wish to check it out :)/>
TorakTu #16
Posted 31 August 2013 - 10:04 PM
I have been talking and sharing some ideas with TorakTu and have come up with a small prototype called Flare which allows Computercraft computers to communicate across the internet by using PHP scripts attached to a MySQL server. As it currently stands it is quite insecure as any computer can use any ID but I wish to implement a user login later down the line.

I have modified my chat program to work with Flare with send and receiving having a short delay, 1 or 2 seconds locally. I'm sure it could be optimised to work a lot faster but for now it works okay.

My current progress is on my github if you wish to check it out :)/>

My server template is already setup to be automated with peripherals. You could just edit it and use that server to tag the php file every "Nth" timer. Anything from 5 seconds to 1 minute. I had mine set to 10 seconds when I tested this idea in another game. It just means that a response would be delayed roughly 11 seconds. Not bad all things considering.


When the server is setup like this, it should be the ONLY one that is tagging the php website. Everyone else in minecraft ( Meaning the clients that people use to talk to the TorakTu server ) should tag the server in minecraft. This means you would need to add a buffer to allow saving of info back and forth in case the website is slow for some reason.

Think of the possibilities of this though.. you could have a chat with someone from another server somewhere. :)/>
TorakTu #17
Posted 01 September 2013 - 01:22 PM
Do to everything going on in my life ( not that i'm going to explain what it is ) I am putting everything to do with computercraft on hold for a while.

Also, if I could find a way to run computercraft in bukkit, that would make my life a lot easier. -_-/>
MudkipTheEpic #18
Posted 01 September 2013 - 03:39 PM
MCPC+.
TorakTu #19
Posted 02 September 2013 - 08:22 AM
MCPC+.

I had seen MCPC+ but never used it. I have used plain bukkit and vanilla.. Thanks for the info. I was able to set one up. Now I can finally get back to working on a few projects of CC.
TorakTu #20
Posted 20 June 2014 - 02:02 PM
Back guys, i'll try to keep an eye out on this thread more often. Been a long 6 months to a year, so i'm happy things finally slown down for me. Now back to CC code…

Peace
TorakTu #21
Posted 28 November 2014 - 03:08 AM
OP Updated.
Anavrins #22
Posted 28 November 2014 - 05:05 PM
NOTICE ( November 27th, 2014 ): I came back to find a ComputerCraft version for 1.8.1 and I see it still hasn't gotten to that point yet. I'm afraid that I will not bother with this site any longer since its dead. Sorry to see it go. It was the best mod around.
Are you kidding me?
Do you realise there's no Forge version out for 1.8 and it would be impossible for CC to be compatible with 1.8 just yet.
You sure jump to conclusions quickly…
Edited on 28 November 2014 - 04:09 PM
Lyqyd #23
Posted 28 November 2014 - 09:58 PM
Looks like there actually are Forge versions for 1.8, as of a whole two days ago. When he wrote the post, it had only been out for 40 hours or so. Unsurprisingly, there are no recommended builds yet. It's way too early for there to be much point trying to build mods against it.