Posted 18 September 2015 - 04:53 AM
I'll try to be as thorough as I can explaining this. I'm reinventing the wheel a bit here with this API but I need it for something else I'm working on: http://pastebin.com/kjKrUP41 Most of it works perfectly fine. The problem I'm dealing with is in the function "receiveEvents" at line 643, or more specifically, the point where it overrides the "os.pullEventRaw" function at line 654. The idea here is that the event receivers and senders can be passed a table of strings indexed to strings. The functions will then take any event which matches an index in those tables and convert the event to the value of that index. For example {["foo"]="bar"} will convert all "foo" events into "bar" events. On the sender side, this happens just before the event is sent. On the receiving side, this happens in the "os.pullEventRaw" function so that both events received over rednet, and events fired by that computer will be converted according to the tables mentioned earlier. The purpose I had in mind for this is to have it send all events from the sender as "remote_eventName", which would then be converted back to "eventName" on the receiving computer. This works just fine, the trouble comes in when I take it to the next step. I want to convert all local events from "eventName" to "void_eventName". The final result being that the sending computer can fire events on the receiving computer, while the receiving computer can not. The problem is, when working with the parallel system, os.pullEventRaw will be called multiple times, so the event ends up getting modified more than once. "remote_eventName" becomes "eventName" becomes "void_eventName". This of course breaks the sending computer's ability to control the receiving computer. I thought the work around would be simple enough, just add and extra flag to the event saying "event has been modified" so that no other "pullEventRaw"s try to mess with it. This works for most events, but for whatever reason one of the coroutines removes the flag from all mouse events resulting in them being modified more than once. I can type, but not click. Basically, I need help either fixing this workaround, or finding another workaround. I'll post the testing code below, to set up the environment, place down two advanced computers and attach wireless modems to the top of each. Set the label of both and install TRoR on them. Modify the following code where needed to match the credentials of your computers.
--"sender" refers to the computer which will be sending events, not the computer which will be sending its screen
rednet.open("top")
if os.getComputerID() == [sender ID] then
parallel.waitForAny(
function()
sendEvents(asPacketDataS(
"test",
"all",
rednet.CHANNEL_BROADCAST
),
genWhitelistTable(
"terminate",
"key",
"char",
"key_up",
"mouse_click",
"mouse_up",
"mouse_scroll",
"mouse_drag"
),
{
["terminate"]="remote_terminate",
["key"]="remote_key",
["char"]="remote_char",
["key_up"]="remote_key_up",
["mouse_click"]="remote_mouse_click",
["mouse_up"]="remote_mouse_up",
["mouse_scroll"]="remote_mouse_scroll",
["mouse_drag"]="remote_mouse_drag"
}, true)
end,
function()
receiveScreen(asPacketData(
"test",
nil,
[receiver ID],
nil,
rednet.CHANNEL_BROADCAST
))
if term.termRediected then
term.resetTerm()
end
end
)
else
parallel.waitForAny(
function()
receiveEvents(nil,
asPacketData(
"test",
nil,
[sender ID],
nil,
rednet.CHANNEL_BROADCAST
),
{
["remote_terminate"]="terminate",
["remote_key"]="key",
["remote_char"]="char",
["remote_key_up"]="key_up",
["remote_mouse_click"]="mouse_click",
["remote_mouse_up"]="mouse_up",
["remote_mouse_scroll"]="mouse_scroll",
["remote_mouse_drag"]="mouse_drag",
["terminate"]="void_terminate",
["key"]="void_key",
["char"]="void_char",
["key_up"]="void_key_up",
["mouse_click"]="void_mouse_click",
["mouse_up"]="void_mouse_up",
["mouse_scroll"]="void_mouse_scroll",
["mouse_drag"]="void_mouse_drag"
}
)
end,
function()
sendScreen(function()
shell.run("shell")
if os.pullEventRawOverriden then
os.resetOsTable()
end
end,
asPacketDataS(
"test",
"all",
rednet.CHANNEL_BROADCAST
), true
)
end
)
end