Jump to content


Windows10User's Content

There have been 60 items by Windows10User (Search limited from 30-March 23)


By content type

See this member's


Sort by                Order  

#277223 ANOTHER problem with my internet system

Posted by Windows10User on 10 May 2018 - 05:58 PM in Ask a Pro

I finally got my DNS and browser to work as they should. However, when the browser sends a request to the web server (to fetch the page), it doesn't work. The server receives the request for the page (the domain name + the name of the page) but doesn't seem to react to it and I know that because the browser won't stop waiting for the request!

Browser:
local modem = peripheral.find("modem")

if modem == nil then
   error("No modem found!", 0)
end

if not modem.isWireless() then
   error("Modem isn't wireless!")
end

print("Type the DNS ID:")
local dnschannel = tonumber(read())
print("Type the domain name:")
local domain = read()
print("Sending request. Press any key to cancel.")

modem.open(dnschannel)
modem.transmit(dnschannel, os.getComputerID(), string.match(domain, "[^/]+"))

local event, mSide, sChannel, rChannel, msg, dist = os.pullEvent("modem_message")
if msg == "FAIL" then
   error("DNS error.", 0)
else
   print(domain)
   modem.transmit(tonumber(msg), os.getComputerID(), domain)
   local event, mSide, sChannel, rChannel, msg, dist = os.pullEvent("modem_message")
   shell.run("clear")
   print("Contents:")
   print(msg)
end

Web server:
local domain = "something.com"

local modem = peripheral.find("modem")

if modem == nil then
	error("No modem found!", 0)
end

if not modem.isWireless() then
   error("Modem isn't wireless!")
end

modem.open(os.getComputerID())

while true do
   local event, mSide, sChannel, rChannel, msg, dist = os.pullEvent("modem_message")
   if fs.exists(string.sub(msg, string.len(domain) + 2)) then
	  print(string.sub(msg, string.len(domain) + 2))
	  local fPage = fs.open(string.sub(msg, string.len(domain) + 2), "r")
	  local page = fPage.readAll()
	  fPage.close()
	  modem.transmit(rChannel, os.getComputerID(), page)
   else
	  modem.transmit(rChannel, os.getComputerID(), "404 - Page Not Found")
   end
end

P. S. automatic code indentation WHEN



#277215 Issues with internet system

Posted by Windows10User on 10 May 2018 - 12:30 PM in Ask a Pro

I think the modem API is too difficult to learn and use in general.



#277213 Interpreter [I have made it but I get an error]

Posted by Windows10User on 10 May 2018 - 12:26 PM in Ask a Pro

I feel like making my own interpreter now!



#277212 http.post() to Pastebin throws "Invalid api_option"

Posted by Windows10User on 10 May 2018 - 12:24 PM in Ask a Pro

Yeah, I literally studied it and the built-in pastebin app.



#277197 Issues with internet system

Posted by Windows10User on 09 May 2018 - 06:53 PM in Ask a Pro

View PostSquidDev, on 09 May 2018 - 06:48 PM, said:

At a guess, the problematic line is for i=1, #ids do. The length of a table only includes the array part, so in this particular case #ids is 0. Consequently, the loop is body never executed and so nothing is sent. You can just delete that loop, as the counter isn't actually used.

So what am I supposed to do?

EDIT: Look, look, removing the for fixes it! Now I just need to try with multiple domains.

EDIT 2: It works!!! Thanks 4 saving my life, Squid.



#277194 Issues with internet system

Posted by Windows10User on 09 May 2018 - 06:33 PM in Ask a Pro

I decided to make an internet system for my OS and CraftOS. I made the browser (so far uses the DNS to resolve a domain to an ID) and the DNS. The DNS nicely receives the request for the ID, but doesn't send it, even though both the domain and ID are present in its ids table.

(BTW, I know that the Rednet API has a small DNS inside of it. Don't mention it. Please.)

Browser (or is it so far?):
rednet.open("top")

print("DNS ID:")
local dns = tonumber(read())
print("URL:")
local url = read()

rednet.send(dns, url, "REQUEST_ID")

local event, id, msg, protocol = os.pullEvent("rednet_message")
if protocol == "ID" then
	print(url.." resolved to "..msg)
end

DNS:
local tArgs = {...}

if #tArgs < 1 then
	error("dns <wireless modem side>", 0)
end

local mSide = tArgs[1]
local modem = nil

if peripheral.getType(mSide) ~= "modem" then
	error("No modem detected on the "..mSide.." side of the computer...", 0)
else
	modem = peripheral.wrap(mSide)
	if not modem.isWireless() then
		error("The modem on the "..mSide.." side of the computer is wired!", 0)
	end
end

local ids = {
["cabbage.com"] = 3
}

rednet.open(mSide)

while true do
	local event, id, msg, protocol = os.pullEvent("rednet_message")
	if protocol == "REQUEST_ID" then
		print("Computer #"..id.." requested ID of "..msg)
		for i=1, #ids do
			if ids[msg] then
				rednet.send(id, ids[msg], "ID")
				print("Replied with "..ids[msg].." to computer #"..id)
			end
		end
	end
end



#277193 http.post() to Pastebin throws "Invalid api_option"

Posted by Windows10User on 09 May 2018 - 06:28 PM in Ask a Pro

View PostEveryOS, on 09 May 2018 - 05:36 PM, said:

View PostWindows10User, on 09 May 2018 - 05:28 PM, said:

BTW, what does the second argument in string.match( sResponse , "[^/]+$") even do?!

It's called a pattern, it is to return part of a string

http://lua-users.org...atternsTutorial

I know it's a pattern, but why random characters?



#277189 http.post() to Pastebin throws "Invalid api_option"

Posted by Windows10User on 09 May 2018 - 05:28 PM in Ask a Pro

BTW, what does the second argument in string.match( sResponse , "[^/]+$") even do?!



#277187 http.post() to Pastebin throws "Invalid api_option"

Posted by Windows10User on 09 May 2018 - 05:07 PM in Ask a Pro

Yeah, I looked at the source code a few times and that clearly slipped past my eyes. Will try it out!

EDIT: Nope, still invalid api_option. The postData from the pastebin program works, tho...



#277182 Terminal Glasses

Posted by Windows10User on 09 May 2018 - 04:10 PM in Ask a Pro

Uhh... maybe write an API that will handle the writing?



#277178 http.post() to Pastebin throws "Invalid api_option"

Posted by Windows10User on 09 May 2018 - 02:37 PM in Ask a Pro

I am working on a Pastebin API (basically the pastebin program, but way better). When I went out to test the upload function, it threw "Bad API request, invalid api_option". I set it to "paste" just like Pastebin says, but I still get that.

Upload function:
function upload(file, title, user, pass)
   if not http then
	  return false, "HTTP required"
   end

   if fs.isDir(file) then
	  return false, "\"file\" is a directory"
   end

   if fs.exists(file) == false then
	  return false, "\"file\" doesn't exist"
   end

   local userkey = ""

   if user and pass then
	  local uresponse = http.post("https://www.pastebin.com/api/api_login.php",
		 "api_dev_key=24eeeaa32fe9c4724e7e4f4f4c601f80&"..
		 "api_user_name="..textutils.urlEncode(user).."&"..
		 "api_user_password="..textutils.urlEncode(pass)
	  )

	  if uresponse then
		 if string.match(uresponse.readAll(), " ") == nil then
			userkey = uresponse.readAll()
		 end
		 uresponse.close()
	  end
   end

   local hdata = fs.open(file, "r")
   local data = hdata.readAll()
   hdata.close()

   local presponse = http.post("https://www.pastebin.com/api/api_post.php",
	  "api_option=paste&"..
	  "api_dev_key=CENSORED&"..
	  "api_paste_code="..data.."&"..
	  "api_user_key="..userkey.."&"..
	  "api_paste_name="..title and title or "".."&"..
	  "api_paste_format=lua&"..
	  "api_paste_expire_date=N&"..
	  "api_paste_private=0"
   )

   if presponse then
	  local presponses = presponse.readAll()
	  presponse.close()
	  return string.sub(presponses, 21)
   end
end



#277079 Cleancut

Posted by Windows10User on 03 May 2018 - 01:04 PM in Operating Systems

View PostTheZipCreator, on 29 April 2018 - 03:25 PM, said:

And about the archiving API: Could you improvise what you mean further?

Something like this: https://pastebin.com/jA4Tjcah.

I successfully compressed rom/programs and rom/apis with this thing.

Feel free to use it, but please at least give me some credit then.



#277032 Cleancut

Posted by Windows10User on 29 April 2018 - 09:45 AM in Operating Systems

You should add an app store and an archiving API. :D



#277031 [SOLVED] Can't load background image

Posted by Windows10User on 29 April 2018 - 08:43 AM in Ask a Pro

OK, I'll try with a more recent copy of CC 1.80.

EDIT: It doesn't do anything. Still the same error.

EDIT 2: Looks like I spelled the image's extension wrong. Sorry 4 wasting your time, everyone.



#277023 [SOLVED] Can't load background image

Posted by Windows10User on 28 April 2018 - 07:05 PM in Ask a Pro

Background images (images as big as the terminal drawed at 1, 1) are also part of my GUI API, Graphics. The paintutils.drawImage() call doesn't seem to work, tho. It gives "graphics:232: bad argument #1 (expected table, got nil)".

Background image part of the API:
backgroundimg = {
   path = "",

   new = function(self)
	  local new = {}
	  setmetatable(new, {__index = self})
	  return new
   end,

   draw = function(self)
	  local image = paintutils.loadImage(self.path)
	  paintutils.drawImage(image, 1, 1) --line 232 AKA the error line
   end
}

Program used:
local fBCD = fs.open("Boot/bcd.ini", "r")
local bcd = textutils.unserialize(fBCD.readAll())
fBCD.close()

os.loadAPI("DoorOS/apis/graphics")

local splash = graphics.backgroundimg:new()
splash.path = "Boot/bootscreen.npf"
splash:draw()
read()



#277021 [SOLVED] Problems with archiving API

Posted by Windows10User on 28 April 2018 - 05:06 PM in Ask a Pro

BTW, tried putting the filehandle.readAll() call into a variable, and it's a nil. So, we have the REAL problem...

EDIT: Found it out, the paths given by fs.list were relative... A dir.."/"..filelist[i] fixed the problem.

EDIT 2: OMG, I completed the API! Both compression and decompression do their thing!



#277020 [SOLVED] Problems with archiving API

Posted by Windows10User on 28 April 2018 - 03:47 PM in Ask a Pro

Doesn't work. Same error but on line 16.

Updated code: (btw had no time 2 indent so sry)
function compress(dir, archive)
if fs.isDir(dir) then
filelist = fs.list(dir)
local archive = {
files = {

},

filedata = {

}
}
for i=1, #filelist do
local filehandle = fs.open(filelist[i], "r")
table.insert(archive.files, filelist[i])
archive.filedata[filelist[i]] = filehandle.readAll() --the erroring line
filehandle.close()
end
local fArchive = fs.open(archive, "w")
fArchive.write(textutils.serialize(archive))
fArchive.close()
return true
else
return false
end
end



#277018 [SOLVED] Problems with archiving API

Posted by Windows10User on 28 April 2018 - 03:21 PM in Ask a Pro

So, for the love of God, I made a decision I never really thought I'd make: making an archiving API (for folders and folders ONLY). Did the basic compression script. Now, the API is supposed to compress in the shape of a table like this (it's serialized):

{
   files = {
	  "1.lua",
	  "2.lua",
	  "3.lua",
   },

   filedata = {
	  "1.lua" = "file 1",
	  "2.lua" = "file 2",
	  "3.lua" = "file 3",
   },
}

stored in an "archive" (just a file containing this table), so I did it. Trying to compress a folder w/ the exact same files, I get this error: "compact:19: attempt to index ? (a nil value)" when inserting the file data into the "filedata" subtable. I inserted a print(textutils.serialize(archive)) (serializes the archive table) and read() (so the code continues execution ONLY when I press enter) to make sure the table is in the right shape for the job. This is the output:

{
   files = {
	  "1.lua",
   },
   filedata = {
	  "1.lua",
   },
}

which looks OK imo, so idk why is it not working. Anyway, the compression function:
function compress(dir, archive)
   if fs.isDir(dir) then
	  filelist = fs.list(dir)
	  local archive = {
		 files = {

		 },

		 filedata = {

		 }
	  }
	  for i=1, #filelist do
		 local filehandle = fs.open(filelist[i], "r")
		 table.insert(archive.files, filelist[i])
		 table.insert(archive.filedata, filelist[i])
		 print(textutils.serialize(archive))
		 read()
		 archive.filedata.filelist[i] = filehandle.readAll() --the erroring line
		 filehandle.close()
	  end
	  local fArchive = fs.open(archive, "w")
	  fArchive.write(textutils.serialize(archive))
	  fArchive.close()
	  return true
   else
	  return false
   end
end

Any help is appreciated!



#277016 Checkboxes don't work quite as they should

Posted by Windows10User on 28 April 2018 - 02:03 PM in Ask a Pro

View PostLupus590, on 27 April 2018 - 04:33 PM, said:

Have a look at what other GUI APIs have and take ideas from those. Also, have a look at real-life GUIs and see if you could mimic them.

OK, by the way should I update the API on my topic in APIs and Utilities?



#277001 Checkboxes don't work quite as they should

Posted by Windows10User on 27 April 2018 - 11:13 AM in Ask a Pro

Thanks ppl, but by the way, what should I do next speaking of my GUI API (http://www.computerc...ui-drawing-api/)? I have buttons, labels, checkboxes and background images so far, but I didn't update the paste and I need ideas?



#276991 Checkboxes don't work quite as they should

Posted by Windows10User on 26 April 2018 - 12:32 PM in Ask a Pro

View PostDog, on 25 April 2018 - 05:34 PM, said:

One thing you can do that would simply your code a bit. Instead of this...
if self.checked == false then
  self.checked = true
  self:draw()
else
  self.checked = false
  self:draw()
end

Do this instead...
self.checked = not self.checked --# flip the boolean (from true to false or false to true)
self:draw()

I just need a code which will trigger the checkbox even when its text is clicked. At the moment, I need to click the cube.



#276977 Checkboxes don't work quite as they should

Posted by Windows10User on 25 April 2018 - 05:06 PM in Ask a Pro

EDIT: NVM, just found out it only reacts to clicking the actual cube.



#276976 Titanium - Graphical User Interface (GUI) Framework [Beta 1] - XML

Posted by Windows10User on 25 April 2018 - 05:02 PM in APIs and Utilities

It's so good I guess my GUI framework (Graphics) will never see the light of the day. Good luck keeping this boy alive.



#276974 Checkboxes don't work quite as they should

Posted by Windows10User on 25 April 2018 - 04:40 PM in Ask a Pro

I am working on my GUI API (Graphics, if you looked at the APIs subforum of the Programs forum lately). I already done the buttons and labels, so I went like "Hey, why not work on checkboxes?". So I indeed did checkboxes. However, it doesn't work as it should. It nicely accepts all the data it is made to accept and properly uses it when actually drawing the checkbox, but clicking on it doesn't seem to change its state. Thing is, I drawed a checkbox that's not checked by default. When I try to click it so I can check it, it just doesn't do its thing! I even tried making the checkbox checked by default, but it still won't work (while I can't see any sense-making error even after double-checking).

Checkbox part of the API:
checkbox = {
   text = "Check Box",
   x = 2,
   y = 2,
   checked = false,
   w = 0,
   h = 0,

   new = function(self)
	  local new = {}
	  setmetatable(new, {__index = self})
	  return new
   end,

   draw = function(self)
	  local oldBkgColor = term.getBackgroundColor()
	  local text = self.text
	  local x = self.x
	  local y = self.y
	  term.setCursorPos(x, y)
	  if self.checked == false then
		 term.setBackgroundColor(colors.gray)
		 term.write(" ")
	 else
		 term.setBackgroundColor(colors.blue)
		 term.write(" ")
	 end
	 term.setBackgroundColor(oldBkgColor)
	 term.write(" ")
	 term.write(text)
	 w = 2 + string.len(text)
	 h = 1
   end,

   detect = function(self, x, y)
	  if x >= self.x and x <= (self.x + self.w) and y >= self.y and y <= (self.y + self.h) then
		 if checked == false then
			checked = true
			self:draw()
		 else
			checked = false
			self:draw()
		 end
	  end
   end
}

Checkbox program:
term.clear()
term.setCursorPos(1, 1)
os.loadAPI("DoorOS/apis/graphics")
checkbox = graphics.checkbox:new()
checkbox.x = 2
checkbox.y = 2
checkbox.text = "I have read the EULA and accept it."
checkbox:draw()
while true do
   local event, btn, x, y = os.pullEvent("mouse_click")
   checkbox:detect(x, y)
end

Any help is appreciated!



#276957 (v1.1!) Graphics - A GUI-Drawing API

Posted by Windows10User on 24 April 2018 - 02:18 PM in APIs and Utilities

(Admins, if this post gets deleted, please tell me why in PM.)

Hello everyone,

Meet Graphics, a GUI API which right now lets you draw buttons, labels, checkboxes and background images! (and more stuff in the future!)

I will also use Graphics in my upcoming OS (will probably be named DoorOS).

P. S. If you use this API, plz let me know in the replies, means a lot to me!

API download (contact me if Pastebin takes it down):
Spoiler

Button documentation:
Spoiler

Label documentation:
Spoiler

Checkbox documentation:
Spoiler

Background image documentation:
Spoiler

Changelog:
Spoiler

Also yeah, IK Graphics will NEVER stand a chance against Titanium. Still wanted to show it tho.