ko4life-net / ko

Open source development of the game Knight Online. This is a reversed engineered old version of the game aiming to replicate the nostalgic experience we all once had <3
MIT License
48 stars 21 forks source link

Ensure socket ID list is guarded consistently #224

Closed twostars closed 1 month ago

twostars commented 1 month ago

Your checklist for this pull request

🚨Please review the guidelines for contributing to this repository.

Description

This prevents race conditions where the ID is removed from the list but not restored (causing a reduced number of available socket IDs in the list), or if especially unlucky, crashes.

The socket ID list is guarded more consistently in ReceiveWorkerThread() implementations, which we essentially follow here.

Ideally I'd have an implementation to better enforce scoping for these, but for consistency with the existing code I just continue to call EnterCriticalSection() & LeaveCriticalSection() manually.

💔Thank you!