H-uru / Plasma

Cyan Worlds's Plasma game engine
http://h-uru.github.io/Plasma/
GNU General Public License v3.0
205 stars 80 forks source link

Fix potentially catastrophic Age init errors related to being alone. #1303

Closed Hoikas closed 1 year ago

Hoikas commented 1 year ago

A common anti-pattern for determining whether or not we are the only person in an Age is to check the player list returned by PtGetPlayerList(). Generally, if this list is empty, some initialization to a default state is done or some restoration work is done if it is not empty. What the gameplay programmers seem to have not realized, though, is that the list returned by PtGetPlayerList() omits any players that are in your ignore list. Therefore, the wrong initialization path may be executed if there are players in the Age, but all of them are in your ignore list. This could have consequences that range from odd but amusing to catastrophic, depending on the script in question.

Therefore, we fix this problem by introducing PtIsSolo(), which tells us whether or not we are the only player in the Age. This function is not vulnerable to ignore shennanigans, and we avoid creating lots of temporary ptPlayer objects that we don't actually care about.