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

RakNet crash fixes, performance improvements, fix ordering channels for some RPCs #883

Merged
merged 3 commits into from
Mar 22, 2024

Conversation

AmyrAhmady
Copy link
Member

1. RakNet Crashes

There are many places in RakNet you seepacket data being deleted using delete or delete[] and while it works fine, there are cases where double deletion happens, it's very random so the cause isn't clear yet. But finding the actual problem and fixing was easier than reproducing it (Check here: openmultiplayer/RakNet@3efbe1b...7f4f20d#diff-dcf7bd2af9b6ecac1d8af94416ca373c3a6f7a9528852c176dc36ae02e02223f)

2. RakNet related improvements

  1. So for first one, there's 94a43bf , the explanation for this would be how GetRemoteSystemFromPlayerID works internally in RakNet, it loops through all available slots (not taken, not empty, all of them) and tries to search for the same PlayerID and return RemoteSystemStruct ptr for it. A huge improvement can be made by just caching and storing a pointer of RemoteSystemStruct on connect and releasing it on disconnect on open.mp side of the project, to use it for re-implementing GetLastPing for IPlayer::getPing and INetwork::getPing. This also massively helps ScoreAndPingsUpdate RPC since it loops through all players and calls getPing for each of them, resulting a player count * max players loop, for full servers it's 1000 * 1000 iterations for nothing.
  2. Then there's playerIndexes flat hash map used internally in RakNet, for way faster PlayerID and player index lookup and use it in different places in RakNet to, again, improve performance noticeably and get rid of unnecessary overhead of looping through all slots every time you want to find a player index based on their RakNet::PlayerID which is a linear search.

2. Fix chat RPC ordering channels

Almost all chat related RPCs had wrong ordering channels defined, as OrderingChannel_Unordered, while they should be anything ordered, preferably OrderingChannel_SyncRPC.

@Hual
Copy link
Collaborator

Hual commented Mar 9, 2024

There's no PR on the RakNet repo for the commit you linked here

@AmyrAhmady
Copy link
Member Author

Confirmed by people who are actively using this build, works fine and their crashes are gone

@AmyrAhmady AmyrAhmady merged commit 2b6eb99 into master Mar 22, 2024
14 checks passed
@AmyrAhmady AmyrAhmady deleted the amir/net-fixes-and-improvements branch March 22, 2024 16:22
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.

3 participants