mirror of
https://github.com/zenith391/OCEmu.git
synced 2025-09-29 07:53:29 -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
|
end
|
||||||
require("support.http_patch")
|
require("support.http_patch")
|
||||||
local url = require("socket.url")
|
local url = require("socket.url")
|
||||||
local okay, http = pcall(require, "ssl.https")
|
local httpsok, http = pcall(require, "ssl.https")
|
||||||
if not okay then
|
if not httpsok then
|
||||||
cprint("Cannot use HTTPS: " .. http)
|
cprint("Cannot use HTTPS: " .. http)
|
||||||
http = require("socket.http")
|
http = require("socket.http")
|
||||||
end
|
end
|
||||||
@ -17,6 +17,11 @@ component.connect("filesystem",gen_uuid(),nil,"lua/component/internet",true)
|
|||||||
|
|
||||||
local obj = {}
|
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 function checkUri(address, port)
|
||||||
local parsed = url.parse(address)
|
local parsed = url.parse(address)
|
||||||
if parsed ~= nil and parsed.host ~= nil and (parsed.port ~= nil or port > -1) then
|
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"
|
return nil, "http requests are unavailable"
|
||||||
end
|
end
|
||||||
-- TODO: Check for too many connections
|
-- 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
|
if type(postData) ~= "string" then
|
||||||
postData = nil
|
postData = nil
|
||||||
end
|
end
|
||||||
|
@ -5,7 +5,7 @@ local lua_utf8 = require("utf8")
|
|||||||
local SDL = elsa.SDL
|
local SDL = elsa.SDL
|
||||||
|
|
||||||
-- Conversion table for SDL2 keys to LWJGL key codes
|
-- 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 = {}
|
local code2char = {}
|
||||||
|
|
||||||
@ -24,15 +24,16 @@ end
|
|||||||
function elsa.keydown(event)
|
function elsa.keydown(event)
|
||||||
local keyevent = ffi.cast("SDL_KeyboardEvent", event)
|
local keyevent = ffi.cast("SDL_KeyboardEvent", event)
|
||||||
local key = keyevent.keysym.scancode
|
local key = keyevent.keysym.scancode
|
||||||
cprint("keydown",keys[key])
|
local lwjgl = keys[key]
|
||||||
table.insert(kbdcodes,{type="key_down",addr=address,code=keys[key] or 0})
|
cprint("keydown",keyevent.keysym.scancode,lwjgl)
|
||||||
-- TODO: Lovely SDL Hacks
|
-- TODO: Lovely SDL Hacks
|
||||||
if keys[key] == 15 then
|
if lwjgl ~= 1 then -- Escape
|
||||||
setLatest(9)
|
table.insert(kbdcodes,{type="key_down",addr=address,code=lwjgl or 0})
|
||||||
elseif keys[key] == 28 or keys[key] == 156 then
|
|
||||||
setLatest(13)
|
|
||||||
end
|
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
|
if SDL.hasClipboardText() > 0 then
|
||||||
table.insert(machine.signals,{"clipboard",address,ffi.string(SDL.getClipboardText())})
|
table.insert(machine.signals,{"clipboard",address,ffi.string(SDL.getClipboardText())})
|
||||||
end
|
end
|
||||||
@ -42,8 +43,11 @@ end
|
|||||||
function elsa.keyup(event)
|
function elsa.keyup(event)
|
||||||
local keyevent = ffi.cast("SDL_KeyboardEvent", event)
|
local keyevent = ffi.cast("SDL_KeyboardEvent", event)
|
||||||
local key = keyevent.keysym.scancode
|
local key = keyevent.keysym.scancode
|
||||||
cprint("keydown",keys[key])
|
local lwjgl = keys[key]
|
||||||
table.insert(kbdcodes,{type="key_up",addr=address,code=keys[key],char=code2char[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
|
end
|
||||||
|
|
||||||
-- keyboard component
|
-- keyboard component
|
||||||
|
@ -7,6 +7,7 @@ cprint("http_patch start")
|
|||||||
-- Patch data
|
-- Patch data
|
||||||
local patches = {
|
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]]},
|
{[[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
|
package.loaded["socket.http"] = nil
|
||||||
local path = package.searchpath("socket.http",package.path)
|
local path = package.searchpath("socket.http",package.path)
|
||||||
|
@ -36,6 +36,7 @@ return {
|
|||||||
[38]=10,
|
[38]=10,
|
||||||
[39]=11,
|
[39]=11,
|
||||||
[40]=28,
|
[40]=28,
|
||||||
|
[41]=1,
|
||||||
[42]=14,
|
[42]=14,
|
||||||
[43]=15,
|
[43]=15,
|
||||||
[44]=57,
|
[44]=57,
|
||||||
@ -96,4 +97,10 @@ return {
|
|||||||
[228]=157,
|
[228]=157,
|
||||||
[229]=54,
|
[229]=54,
|
||||||
[230]=184,
|
[230]=184,
|
||||||
|
},{
|
||||||
|
[14]=8,
|
||||||
|
[15]=9,
|
||||||
|
[28]=13,
|
||||||
|
[156]=13,
|
||||||
|
[211]=127,
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user