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 = "&w=" .. WIDTH .. "&h=" .. HEIGHT;
for i, obj in ipairs(objects) do
args = args .. "&" .. 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 ^_^/>