Skip to content
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

Closed

Conversation

hussein-aitlahcen
Copy link

@hussein-aitlahcen hussein-aitlahcen commented Aug 28, 2021

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

@hussein-aitlahcen hussein-aitlahcen marked this pull request as draft August 28, 2021 11:08
@hussein-aitlahcen hussein-aitlahcen force-pushed the avm1-xmlsocket branch 4 times, most recently from 316cebd to 2087400 Compare August 28, 2021 15:39
@@ -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!()
Copy link
Member

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!()
Copy link
Member

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);
Copy link
Member

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.)

@adrian17
Copy link
Collaborator

Side question: do we know any specific games which we suspect will start working with this PR?

@hussein-aitlahcen
Copy link
Author

hussein-aitlahcen commented Aug 29, 2021

@adrian17 Yes, I tried with the mmo dofus retro. See this video

@LiEnby
Copy link

LiEnby commented Jan 19, 2022

Horse Isle client may start working with this..

@kmeisthax kmeisthax mentioned this pull request Mar 30, 2022
@ghost ghost mentioned this pull request Sep 11, 2022
@Minigugus Minigugus mentioned this pull request Oct 4, 2022
5 tasks
@Dinnerbone
Copy link
Contributor

This was added in #12489.

Thank you so much for your work on it regardless!

@Dinnerbone Dinnerbone closed this Aug 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants