mirror of
https://github.com/zenith391/OCEmu.git
synced 2025-09-28 07:24:22 -04:00
More fixes
trim the url string when doing a request Check the protocol to make sure it's valid or supported Add in another patch to http to actually preform http requests when asked, the hack however prevents you from doing HTTP on 443, but it's much better Add in the SDL2 scancode to cprint debugging Ignore Escape key Artificially generate various characters for various keys Also default to 0 in key_up Add in a secondary list for the artificial characters: Backspaces Tabs Enter Delete
This commit is contained in:
parent
2fc29e6f8d
commit
b6aeb90d67
@ -7,8 +7,8 @@ if not okay then
|
||||
end
|
||||
require("support.http_patch")
|
||||
local url = require("socket.url")
|
||||
local okay, http = pcall(require, "ssl.https")
|
||||
if not okay then
|
||||
local httpsok, http = pcall(require, "ssl.https")
|
||||
if not httpsok then
|
||||
cprint("Cannot use HTTPS: " .. http)
|
||||
http = require("socket.http")
|
||||
end
|
||||
@ -17,6 +17,11 @@ component.connect("filesystem",gen_uuid(),nil,"lua/component/internet",true)
|
||||
|
||||
local obj = {}
|
||||
|
||||
local function string_trim(s)
|
||||
local from = s:match"^%s*()"
|
||||
return from > #s and "" or s:match(".*%S", from)
|
||||
end
|
||||
|
||||
local function checkUri(address, port)
|
||||
local parsed = url.parse(address)
|
||||
if parsed ~= nil and parsed.host ~= nil and (parsed.port ~= nil or port > -1) then
|
||||
@ -117,6 +122,19 @@ function obj.request(url, postData) -- Starts an HTTP request. If this returns t
|
||||
return nil, "http requests are unavailable"
|
||||
end
|
||||
-- TODO: Check for too many connections
|
||||
url = string_trim(url)
|
||||
-- TODO: Use url.parse
|
||||
local protocol = url:match("(.-):")
|
||||
if protocol == "http" then
|
||||
elseif protocol == "https" then
|
||||
if not httpsok then
|
||||
return nil, "unsupported protocol"
|
||||
end
|
||||
elseif protocol == "ftp" or protocol == "mailto" then
|
||||
return nil, "unsupported protocol"
|
||||
else
|
||||
return nil, "invalid address"
|
||||
end
|
||||
if type(postData) ~= "string" then
|
||||
postData = nil
|
||||
end
|
||||
|
@ -5,7 +5,7 @@ local lua_utf8 = require("utf8")
|
||||
local SDL = elsa.SDL
|
||||
|
||||
-- Conversion table for SDL2 keys to LWJGL key codes
|
||||
local keys = require("support.sdl_to_lwjgl")
|
||||
local keys,codes = elsa.filesystem.load("support/sdl_to_lwjgl.lua")()
|
||||
|
||||
local code2char = {}
|
||||
|
||||
@ -24,15 +24,16 @@ end
|
||||
function elsa.keydown(event)
|
||||
local keyevent = ffi.cast("SDL_KeyboardEvent", event)
|
||||
local key = keyevent.keysym.scancode
|
||||
cprint("keydown",keys[key])
|
||||
table.insert(kbdcodes,{type="key_down",addr=address,code=keys[key] or 0})
|
||||
local lwjgl = keys[key]
|
||||
cprint("keydown",keyevent.keysym.scancode,lwjgl)
|
||||
-- TODO: Lovely SDL Hacks
|
||||
if keys[key] == 15 then
|
||||
setLatest(9)
|
||||
elseif keys[key] == 28 or keys[key] == 156 then
|
||||
setLatest(13)
|
||||
if lwjgl ~= 1 then -- Escape
|
||||
table.insert(kbdcodes,{type="key_down",addr=address,code=lwjgl or 0})
|
||||
end
|
||||
if keys[key] == 210 then
|
||||
if lwjgl ~= nil and codes[lwjgl] ~= nil then
|
||||
setLatest(codes[lwjgl])
|
||||
end
|
||||
if lwjgl == 210 then
|
||||
if SDL.hasClipboardText() > 0 then
|
||||
table.insert(machine.signals,{"clipboard",address,ffi.string(SDL.getClipboardText())})
|
||||
end
|
||||
@ -42,8 +43,11 @@ end
|
||||
function elsa.keyup(event)
|
||||
local keyevent = ffi.cast("SDL_KeyboardEvent", event)
|
||||
local key = keyevent.keysym.scancode
|
||||
cprint("keydown",keys[key])
|
||||
table.insert(kbdcodes,{type="key_up",addr=address,code=keys[key],char=code2char[keys[key]]})
|
||||
local lwjgl = keys[key]
|
||||
cprint("keydown",keyevent.keysym.scancode,lwjgl)
|
||||
if key ~= 41 then -- Escape
|
||||
table.insert(kbdcodes,{type="key_up",addr=address,code=lwjgl or 0,char=code2char[lwjgl]})
|
||||
end
|
||||
end
|
||||
|
||||
-- keyboard component
|
||||
|
@ -7,6 +7,7 @@ cprint("http_patch start")
|
||||
-- Patch data
|
||||
local patches = {
|
||||
{[[if headers[name] then headers[name] = headers[name] .. ", " .. value]],[[if headers[name] then if type(headers[name]) == "string" then headers[name] = {headers[name]} end headers[name][#headers[name]+1] = value]]},
|
||||
{[[local nreqt = adjustrequest(reqt)]],[[local nreqt = adjustrequest(reqt) if nreqt.scheme == "http" then nreqt.create = nil if nreqt.port == "443" then nreqt.port = "80" end end]]},
|
||||
}
|
||||
package.loaded["socket.http"] = nil
|
||||
local path = package.searchpath("socket.http",package.path)
|
||||
|
@ -36,6 +36,7 @@ return {
|
||||
[38]=10,
|
||||
[39]=11,
|
||||
[40]=28,
|
||||
[41]=1,
|
||||
[42]=14,
|
||||
[43]=15,
|
||||
[44]=57,
|
||||
@ -96,4 +97,10 @@ return {
|
||||
[228]=157,
|
||||
[229]=54,
|
||||
[230]=184,
|
||||
},{
|
||||
[14]=8,
|
||||
[15]=9,
|
||||
[28]=13,
|
||||
[156]=13,
|
||||
[211]=127,
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user