-
-
Notifications
You must be signed in to change notification settings - Fork 813
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
preleminary work on avm1 XMLSocket #5160
preleminary work on avm1 XMLSocket #5160
Conversation
316cebd
to
2087400
Compare
2087400
to
c23128b
Compare
@@ -388,4 +418,16 @@ impl NavigatorBackend for NullNavigatorBackend { | |||
fn pre_process_url(&self, url: Url) -> Url { | |||
url | |||
} | |||
|
|||
fn xmlsocket_connect(&mut self, _: u64, _: ConnectOptions) { | |||
unimplemented!() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Functions that are unimplemented should log an error or do nothing instead of panicking using this macro. NullNavigatorBackend
is used in several places where it would be inappropriate to panic (such as the movie scanner).
The test harness also uses this implementation of NavigatorBackend
. If we created a TestNavigatorBackend
then we could have it simulate specific XML Socket behaviors that we could then test against in test SWFs.
@@ -224,4 +225,16 @@ impl NavigatorBackend for WebNavigatorBackend { | |||
} | |||
url | |||
} | |||
|
|||
fn xmlsocket_connect(&mut self, _: u64, _: ConnectOptions) { | |||
unimplemented!() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This shouldn't panic either.
I'm also going to have to warn you that XMLSockets are not going to be implementable on web. WebSockets are not actually sockets, because you can't enforce same-origin policy on TCP. (The concept of "origin" is very much HTTP-specific.) The way Flash dealt with the obvious security problems of implementing their own custom protocols was to require policy files for any use of XML sockets. (This also applied to other Flash-specific cross-origin request mechanisms.) But browsers don't respect Flash policy files, so there's no way to get a raw socket to an ostensibly consenting domain.
We could hypothetically allow XML sockets on the extension version of Ruffle, but this would require a lot of additional code to, in a background page, validate policy files and authorize socket requests for content processes. Even then, I'm iffy about even supporting that on modern web browsers which have to worry about things like side-channel attacks that Flash never did.
@@ -175,6 +189,22 @@ pub trait NavigatorBackend { | |||
/// Fetch data at a given URL and return it some time in the future. | |||
fn fetch(&self, url: &str, request_options: RequestOptions) -> OwnedFuture<Vec<u8>, Error>; | |||
|
|||
/// XMLSocket::connect | |||
fn xmlsocket_connect(&mut self, socket_id: u64, connection_options: ConnectOptions); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function should allocate and return socket IDs instead of accepting a pre-numbered socket ID.
The way other backends handle this is to use the generational-arena
crate; it provides a stable Index
type which can be handed back to the caller and used to refer to objects owned by the backend later on. The advantage is that old connections can be deallocated without invalidating already-returned indicies.
(This is usually also pub type
'd as Handle
instead of Index
; the sound machinery does a lot of that.)
Side question: do we know any specific games which we suspect will start working with this PR? |
@adrian17 Yes, I tried with the mmo dofus retro. See this video |
Horse Isle client may start working with this.. |
This was added in #12489. Thank you so much for your work on it regardless! |
This PR introduce basic avm1 XMLSocket operations; new, connect, onConnect, onData, close, send
The implementation is supporting Desktop only for now as I don't know how to handle it in web (perhaps websockets as @EmperorBale mentioned here ?).
Disclaimer; I am not familiar with the codebase nor I am familier with how Flash Player is working under the hood. I pretty much hacked ruffle based on this documentation http://demo.ligams.free.fr/AS2LR/XMLSocket.html to check whether or not we could run Dofus Retro with ruffle.
It ended up 'working' (requiring a bit more work, not part of this PR, as there was some issues with SWF imports).
Related to #905 #288