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

[Adhoc] Fix multiplayer issue on MGS:PW due to detecting an incorrect source port on incoming data #14140

Merged
merged 6 commits into from
Feb 21, 2021

Conversation

anr2me
Copy link
Collaborator

@anr2me anr2me commented Feb 14, 2021

Fix multiplayer issue on MGS:PW due to detecting an incorrect source port on incoming data
May not be the best solution since i haven't really figured out what actually happening, but fix #14130 most of the time, although i'm still getting a wrong port detected once but seems to happen very rarely now.

PS: In the case AdhocMatching detecting an incorrect port, players will see an orange message on screen saying "Data from incorrect Port detected [MAC address]: SourcePort -> DestPort" where SourcePort is the wrong one and supposed to be the same with DestPort.

If this message appeared, players just need to wait until the port detected correctly and this message no longer appeared (may takes a few seconds or more before it gets detected correctly), otherwise progressing any further will cause communication issue.

This issue may also happened on other games too, since many games are using PDP/UDP.

Test builds:
Win32&64: https://www.dropbox.com/s/2t3mtdhb0f045cn/PPSSPP_1.11-testbuild_Win32x64.zip?dl=0
Android(ARMv7): https://www.dropbox.com/s/b41bm43mtn1gpnn/PPSSPP_1.11-testbuild_ARMv7.apk?dl=0

@ghost
Copy link

ghost commented Feb 14, 2021

Won't all the delays and giving more time in the code cause more desyncs?
Because its already happening even in localhost with some games if you play for some time.

@anr2me
Copy link
Collaborator Author

anr2me commented Feb 14, 2021

It's only delayed when creating the socket, most games doesn't create new socket during game play,
and desync could happen when the game detecting incoming data from a wrong source port, because it will reply to that wrong port where nobody is listening, thus ended unable to communicate.

@@ -7263,6 +7283,10 @@ int matchingInputThread(int matchingId) // TODO: The MatchingInput thread is usi

// Ignore Incoming Trash Data
}
else if (recvresult == 0 && rxbuflen > 0) {
WARN_LOG(SCENET, "InputLoop[%d]: Unknown Port[%s:%u] (Recved=%i, Length=%i)", matchingId, mac2str(&sendermac).c_str(), senderport, recvresult, rxbuflen);
host->NotifyUserMessage(std::string("Data from incorrect Port detected [") + mac2str(&sendermac) + std::string("]:") + std::to_string(senderport) + std::string(" -> ") + std::to_string(context->port), 1.0, 0x0080ff);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add translate of "Data from incorrect Port detected"

@anr2me
Copy link
Collaborator Author

anr2me commented Feb 15, 2021

Updated with translate

@anr2me anr2me marked this pull request as draft February 16, 2021 09:09
@anr2me
Copy link
Collaborator Author

anr2me commented Feb 16, 2021

Looks like MGS:PW versus mode still have the incorrect port issue :(
image
And it doesn't seems to be disappearing over time :(

13:05:966 idle0        D[SCENET]: HLE\sceNetAdhoc.cpp:1579 sceNetAdhocPdpSend[1:9099](BC): Sent 1 bytes to 192.168.8.102:9099

13:05:977 idle0        D[SCENET]: HLE\sceNetAdhoc.cpp:1753 sceNetAdhocPdpRecv[1:9099]: Received 36 bytes from 192.168.8.102:1024

13:05:977 idle0        W[SCENET]: HLE\sceNetAdhoc.cpp:7287 InputLoop[1]: Unknown Port[70:7b:67:74:51:21:61560] (Recved=0, Length=36)
13:05:988 idle0        D[SCENET]: HLE\sceNetAdhoc.cpp:1753 sceNetAdhocPdpRecv[1:9099]: Received 1 bytes from 192.168.8.102:1024

13:05:988 idle0        W[SCENET]: HLE\sceNetAdhoc.cpp:7287 InputLoop[1]: Unknown Port[70:7b:67:74:51:21:61560] (Recved=0, Length=1)

And according to Wireshark it really came from Source Port 1024 instead of 9099
image

So the issue seems to be between Android or my router,
but when i put breakpoint on Android Studio the port really was binded to the correct port :( which is strange unless Android system need a longer time to actually bind it to the requested port.

PS: Port Offset for this test is 5000

Edit: Apparently changing Port Offset to 10000 doesn't have this issue.. i wondered what happened...

…cause port issue when wrapped to 1024 or lower on android)
@anr2me anr2me marked this pull request as ready for review February 21, 2021 10:26
@anr2me
Copy link
Collaborator Author

anr2me commented Feb 21, 2021

Okay this seems to fix the issue some how... can't find any documentation on such bind behavior tho.

Comment on lines 7261 to 7262
WARN_LOG(SCENET, "InputLoop[%d]: Unknown Port[%s:%u] (Recved=%i, Length=%i)", matchingId, mac2str(&sendermac).c_str(), senderport, recvresult, rxbuflen);
host->NotifyUserMessage(std::string(n->T("Data from incorrect Port")) + std::string(" [") + mac2str(&sendermac) + std::string("]:") + std::to_string(senderport) + std::string(" -> ") + std::to_string(context->port), 1.0, 0x0080ff);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wacky indentation here :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops sorry

…om an incorrect port, progressing any further may ended with connection issue.

Players will need to wait until the port detected correctly before progressing any further (may takes a few more seconds)
@hrydgard
Copy link
Owner

Ready to go?

@anr2me
Copy link
Collaborator Author

anr2me commented Feb 21, 2021

yes, i think so.

@anr2me
Copy link
Collaborator Author

anr2me commented May 10, 2021

Note: Apparently "Data from incorrect port" message can also occurred on Windows vs Windows http://forums.ppsspp.org/showthread.php?tid=27580

@ghost
Copy link

ghost commented Jul 24, 2021

I have one guy on Android that keeps getting me to get the incorrect port error every time.
Every game we tried got this result which is strange because I thought this happens on certain games only.
Strangly no port offset seem to fix the error from happening and I literally tried every one almost lol (even port offset 10k+ yes).
The only game that is not affected is a game that does not use AdhocMatching (Socom Fireteam bravo 3).
A way to overcome it is to use a VPN software like ZeroTier but even then it might happen rarely.
The combination this time was Linux vs Android.

@anr2me
Copy link
Collaborator Author

anr2me commented Jul 24, 2021

The wrong source port issue happened on PDP socket which is connection-less (not sure about PTP, since it connection-oriented it probably didn't matter as long it can get connected), and AdhocMatching is using PDP under-the-hood, so i only shows the error message on games that use AdhocMatching because i know on AdhocMatching both side (host & client) should use the same port for communication.

So games that doesn't use AdhocMatching but use PDP socket might also have similar issue but not being reported/shown, because we don't know which port it supposed to came from as it varies on each game, and not all game use the same port for sending and receiving.

PS: This PR probably didn't solve this issue yet and i'm planning to remove some part of of the code which may not be useful (ie. trying to send an empty data to port 0 hoping for the socket to be bound to the correct interface sooner)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Co-op issue on MGS:PW
4 participants