Coerce pilot names to lowercase on startup
Mako88 reports that using `-pilot Mixed` on Windows causes crashes during multiplayer setup, but `-pilot mixed` does not crash. This is not reproducible on case sensitive filesystems, probably because case sensitive systems recognize that `Mixed.plr` and `mixed.plr` are not the same file. In both cases, the underlying plr file name was all lowercase. Coerce the pilot name to lowercase when it is converted to a plr file name. This also fixes a minor bug where the check for a user-specified extension of `.plr` would recognize `-pilot alice.plr`, but not recognize `-pilot alice.PLR`. This is a workaround for a bug in the network code, which becomes confused and crashes when the player's callsign contains mixed case. Reported-by: Mako88 <https://github.com/dxx-rebirth/dxx-rebirth/issues/188>
This commit is contained in:
parent
4d483ca88f
commit
d67ada45ef
|
@ -50,6 +50,7 @@ char copyright[] = "DESCENT II COPYRIGHT (C) 1994-1996 PARALLAX SOFTWARE CORPOR
|
|||
#include <sys/types.h>
|
||||
#endif
|
||||
|
||||
#include <cctype>
|
||||
#include "pstypes.h"
|
||||
#include "strutil.h"
|
||||
#include "console.h"
|
||||
|
@ -534,16 +535,17 @@ static int main(int argc, char *argv[])
|
|||
if (!CGameArg.SysPilot.empty())
|
||||
{
|
||||
char filename[sizeof(PLAYER_DIRECTORY_TEXT) + CALLSIGN_LEN + 4];
|
||||
unsigned j;
|
||||
|
||||
snprintf(filename, sizeof(filename), PLAYER_DIRECTORY_STRING("%.12s"), CGameArg.SysPilot.c_str());
|
||||
/* The pilot name is never used after this. Clear it to
|
||||
* free the allocated memory, if any.
|
||||
*/
|
||||
CGameArg.SysPilot.clear();
|
||||
const uintptr_t SysUsePlayersDir = CGameArg.SysUsePlayersDir;
|
||||
for (j = SysUsePlayersDir; filename[j]; ++j)
|
||||
auto j = SysUsePlayersDir;
|
||||
for (const auto &facet = std::use_facet<std::ctype<char>>(std::locale::classic()); char &c = filename[j]; ++j)
|
||||
{
|
||||
switch (filename[j]) {
|
||||
case ' ':
|
||||
filename[j] = '\0';
|
||||
}
|
||||
c = facet.tolower(static_cast<uint8_t>(c));
|
||||
}
|
||||
if (j < sizeof(filename) - 4 && (j <= 4 || strcmp(&filename[j - 4], ".plr"))) // if player hasn't specified .plr extension in argument, add it
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue