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

Rabbit Browser

Started by ErwinOlie, 06 November 2015 - 12:15 AM
ErwinOlie #1
Posted 06 November 2015 - 01:15 AM
[Closed because of disinterest]

This morning, i had the idea and motivation to create a cross-server-public-internet-protocol and browser for computercraft,
and… to keep this thing going and to stay motivated, this is the progress =)

Description of 'Rabbit'? >
- Webbrowser!
- Free domain registration for everyone!
- Free website hosting! (or host them at your own pc/host)
- Make your website accessible to everyone who's using Rabbit anywhere!

How does it work? >
Long story short, your request goes to a dns server, the dns server selects the matching host, the host selects the matching website, the website converts to the display of the computer.

Do you like to have your own domainname? Post or PM the requested domain and your host it will be redirected to, and i'll add it to the dns :)/>
Sooner or later you'll be able todo this your own, by a simple account registration on a website.

Working on now >
PHP api - |||||||||||||||||||| 30%
Monitor-sizes support - |||||||||||||||||||| 30%
Search engine - |||||||||||||||||||| 0%
Website for DNS registration - |||||||||||||||||||| 0%
Website for Rabbithosting - |||||||||||||||||||| 0%


Screenshot >
Spoiler

Code (alpha 1.2.4) (06-11-15 14:00) >
Spoiler
local WIDTH, HEIGHT = term.getSize();
local RABBIT_SERVER = "http://direct.erwinolie.nl/rabbit.php";
local HOMEPAGE = "rbt://www.rabbithome.com/";

local matrix = "";
local objects = {};

-- start [CLASS Object] --
local Object = {};
Object.__index = Object;

setmetatable(Object, {
  __call = function (class, ...)
	local self = setmetatable({}, class);
	self:_init(...);
	return self;
  end,
})

function Object:_init(name, value, x, y)
  self.name = name;
  self.value = value;
  self.x = x;
  self.y = y;
  self.w = 1;
  self.h = 1;
end
-- end [CLASS Object] --

-- start [CLASS TextBox] --
local TextBox = {};
TextBox.__index = TextBox;

setmetatable(TextBox, {
  __index = Object,
  __call = function (class, ...)
	local self = setmetatable({}, class);
	self:_init(...);
	return self;
  end,
})

function TextBox:_init(name, value, x, y, w)
  Object._init(self, name, value, x, y);
  self.w = w;
  self.f = false;
  self.ptr = 1;
end

function TextBox:invoke(key, c)
  if c == false then
	if key == "backspace" and self.ptr > -1 then
	  self.value = string.sub(self.value, 1, self.ptr) .. string.sub(self.value, self.ptr + 2);
self.ptr = self.ptr - 1;
elseif key == "left" and self.ptr > -1 then
self.ptr = self.ptr - 1;
elseif key == "right" and self.ptr < #self.value - 1 then
self.ptr = self.ptr + 1;
end
  else
	self.value = string.sub(self.value, 1, self.ptr + 1) .. key .. string.sub(self.value, self.ptr + 2);
self.ptr = self.ptr + 1;
  end
end

function TextBox:focus(flag, x, y)
  if flag then
	self.f = flag;
	self.ptr = x - self.x - 1;
  end
  self.f = flag;
end

function TextBox:draw()
  term.setTextColor(1);
  term.setBackgroundColor(32768);
  term.setCursorPos(self.x, self.y);
  local text = self.value;
  if self.f then
	text = string.sub(text, 1, self.ptr + 1) .. "_" .. string.sub(text, self.ptr + 2);
  end
  for x = #text + 1, self.w, 1 do
	text = text .. " ";
  end
  write(string.sub(text, -self.w));
end
-- end [CLASS TextBox] --

-- start [CLASS Button] --
local Button = {};
Button.__index = Button;

setmetatable(Button, {
  __index = Object,
  __call = function (class, ...)
	local self = setmetatable({}, class);
	self:_init(...);
	return self;
  end,
})

function Button:_init(name, value, x, y, w, url)
  Object._init(self, name, value, x, y);
  self.w = w;
  self.url = url;
end

function Button:focus(flag)
  if flag then
	if self.name == "send" then
	  for i, obj in ipairs(objects) do
   if obj.name == "url" then
loadPage(obj.value);
end
	  end
else
	  loadPage(self.url);
end
  end
end

function Button:draw()
  term.setTextColor(32768);
  term.setBackgroundColor(256);
  term.setCursorPos(self.x, self.y);
  local text = self.value;
  for x = #text + 1, self.w, 1 do
	text = text .. " ";
  end
  write(string.sub(text, 1, self.w));
end
-- end [CLASS Button] --

-- start [CLASS _main] --
function split(generic)
  local result = {};
  local str = "";
  for i = 1, #generic, 1 do
	if string.sub(generic, i, i) == "," then
table.insert(result, str);
str = "";
else
str = str .. string.sub(generic, i, i);
end
  end
  table.insert(result, str);
  return result;
end

function loadPage(page)
  local args = "&amp;w=" .. WIDTH .. "&amp;h=" .. HEIGHT;
  for i, obj in ipairs(objects) do
	args = args .. "&amp;" .. obj.name .. "=" .. obj.value;
objects[i] = nil;
  end
  matrix = http.get(RABBIT_SERVER .. "?page=" .. page .. args).readAll();
  matrix = string.gsub(string.gsub(matrix, "\n", ""), "\r", "");
  local generic = split(string.sub(matrix, WIDTH*HEIGHT*3+1));
  local ptr = 1;
  while ptr < #generic do
	if generic[ptr] == "TextBox" then
table.insert(objects, TextBox(generic[ptr+1], generic[ptr+2], tonumber(generic[ptr+3]), tonumber(generic[ptr+4]), tonumber(generic[ptr+5])));
ptr = ptr + 6;
elseif generic[ptr] == "Button" then
table.insert(objects, Button(generic[ptr+1], generic[ptr+2], tonumber(generic[ptr+3]), tonumber(generic[ptr+4]), tonumber(generic[ptr+5]), generic[ptr+6]));
ptr = ptr + 7;
end
  end
  term.clear();
  update();
end

function update()
  for y = 1, HEIGHT, 1 do
	for x = 1, WIDTH, 1 do
	  term.setTextColor(math.pow(2, tonumber(string.sub(matrix, WIDTH*HEIGHT+(y-1)*WIDTH+x, WIDTH*HEIGHT+(y-1)*WIDTH+x), 16)));
	  term.setBackgroundColor(math.pow(2, tonumber(string.sub(matrix, WIDTH*HEIGHT*2+(y-1)*WIDTH+x, WIDTH*HEIGHT*2+(y-1)*WIDTH+x), 16)));
	  term.setCursorPos(x, y);
	  write(string.sub(matrix, (y-1)*WIDTH+x, (y-1)*WIDTH+x));
	end
  end
  updateobj();
end

function updateobj()
  for i, obj in ipairs(objects) do
	obj:draw();
  end
end

loadPage(HOMEPAGE);
while true do
  local event, param1, param2, param3 = os.pullEvent();
  if event == "char" then
	for i, obj in ipairs(objects) do
if obj.f then
   obj:invoke(param1, true);
end
end
updateobj();
  elseif event == "key" then
	for i, obj in ipairs(objects) do
if obj.f then
   obj:invoke(keys.getName(param1), false);
end
end
updateobj();
  elseif event == "mouse_click" then
	for i, obj in ipairs(objects) do
	  obj:focus(false);
if obj.x <= param2 and obj.x + obj.w > param2 and obj.y <= param3 and obj.y + obj.h > param3 then
   obj:focus(true, param2, param3);
end
	end
updateobj();
  end
end
-- end [CLASS _main] --

Suggestions and feedback are always welcome ^_^/>
Edited on 25 November 2015 - 05:51 PM
Creator #2
Posted 06 November 2015 - 08:37 AM
Well good luck with the project and stay motivated.
Edited on 06 November 2015 - 08:23 AM
Lego Stax #3
Posted 08 November 2015 - 02:53 PM
Is that Windows 10 I spy in the screenshot?
RoD #4
Posted 23 November 2015 - 10:33 PM
Getting attempting to index ? (a nil value) at 157
ErwinOlie #5
Posted 25 November 2015 - 06:50 PM
Getting attempting to index ? (a nil value) at 157

After 3 weeks, only 2 persons has checked out a single webpage, and I was not able to find any contributors, which results in a shutdown ;x [closed]
Creator #6
Posted 25 November 2015 - 09:40 PM
You shouldn't lose motivation so fast. Maybe that is because people don't know where the project stands. Try posting updates on the code and additional features every few days. Maybe goals, bugs. I am sure that'll help.
LDDestroier #7
Posted 26 November 2015 - 02:38 PM
Hey, lotsa people make programs by themselves. I personally try to do as much as I can by myself with no personal help whatsoever, until I'm totally stuck.

Oh, and I usually focus on a single program until it's polished into perfection, so I can use it as bragging material. :D/>
RoD #8
Posted 26 November 2015 - 06:41 PM
This has a lot of potential / pretty interesting, if your problem is paying for the hosts you can try free web hosts like 00webhost.