Skip to content

Skip a UTF-8 byte order mark at the start of multi.cfg - #7881

Open
dustinspace217 wants to merge 1 commit into
scp-fs2open:masterfrom
dustinspace217:multi/standalone-cfg-first-option
Open

dustinspace217 wants to merge 1 commit into
scp-fs2open:masterfrom
dustinspace217:multi/standalone-cfg-first-option

Conversation

@dustinspace217

Copy link
Copy Markdown
Contributor

Fixes #5543

What?

Strips a UTF-8 byte order mark from the first line of multi.cfg before it is parsed.

Why?

Some editors (Notepad, depending on version and settings) save the file with a byte order mark. The reader compares the first word of each line with the option names, so with the mark in front the first option never matches and is silently ignored. That is why adding a dummy first line works around it. The engine never writes multi.cfg, so "works once, then stops" most likely comes from the file being saved again by an editor.

How?

On the first line only, if it starts with EF BB BF, those three bytes are removed before parsing. I didn't reuse util::check_encoding_and_skip_bom: it calls Error() on a file with a mark when Unicode text mode is off, which would make this case fatal instead of fixing it.

Testing?

A standalone server with its own preferences folder, checked through the standalone web API: which login works, which port it listens on, and the server name it reports. Each run used its own port and server name, so every answer came from that run. Master (a1250d7) against this branch, Linux Release builds, retail FS2 data, no mods. 14 multi.cfg variants:

  • No mark (CRLF, LF, port line first): identical on both.
  • Mark, then name / password / port first (4 orderings): master ignores whichever option is on line 1; this branch applies all of them.
  • Mark followed by a blank line, or by a comment line: identical on both.
  • Mark only, empty file, no file: defaults on both.
  • Two bytes of a mark, or the mark twice: line 1 is ignored on both. Editors don't write these.

A normal game launch into SM1-01 on this branch reads multi.cfg at startup and plays as before.

Anything Else?

fs2_open.ini has the same problem in profile_read: a mark before [Default] means the keys under it are dropped, which fits the part of #5543 about the ini. I'll send that as a separate PR. Written with Claude Code; the investigation, review and testing ran on my machine.

Editors such as Notepad can save multi.cfg with a byte order mark. The
reader compared the first word of each line with the option names, so the
mark made the first option silently ignored.
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.

Bug: Standalone server sometimes ignores the first option in multi.cfg

1 participant