Jump to content

TheNet:IsWhiteList() does not properly handle files that use CRLF line break


DHC
  • Known Issue

Logs and settings

The returned result of command:

print(TheNet:IsWhiteListed(AllPlayers[1].userid))
[03:49:37]: RemoteCommandInput: "print(TheNet:IsWhiteListed(AllPlayers[1].userid))"
[03:49:37]: false


print(AllPlayers[1].userid)
[03:49:52]: RemoteCommandInput: "print(AllPlayers[1].userid)"
[03:49:52]: OU_76561199142772402

1.thumb.png.916c234dc612826987625a2fb446d187.png

 

And here is my whitelist.txt file's content:

OU_76561199142772402

image.thumb.png.f264efd5684c17b522d2ed02cd185635.png

You can see that the line breaks is CRLF.

 

Analysis

Preface

I can correctly read the whitelist users under Linux operating system, a few days later, someone told me that when he using my mod on his server (OS: Win10), the whitelist user cannot be read correctly, then I debugging on his server use the 'TheNet:IsWhiteListed' API, the above problems occurred. Then I think this may be a bug caused by inconsistent line breaks.

Debugging

I changed the line breaks of his server's whitelist.txt file to LF (like in Linux, \n),The command `TheNet:IsWhiteListed("OU_76561199142772402")` returned true.

Repair suggestions

code

image.thumb.png.ee48fe26bdf0a966a7a5596422f8b721.png

Code logic

  1. Replace all the '\r' to '\n' (The line breaks of MacOS seems to be '\r', so I will replace it with '\n' first)
  2. Replace all the '\n\n' to '\n' (Handle the '\r\n' line break in Windows OS, replace it to Linux OS's line breaks)
  3. Split the lines of the file contents with '\n' and save them in a table

BTW

Is there any other way to get whether a user is in the white list?


Steps to Reproduce

I can correctly read the whitelist users under Linux operating system, a few days later, someone told me that when he using my mod on his server (OS: Win10), the whitelist user cannot be read correctly, then I debugging on his server use the 'TheNet:IsWhiteListed' API, the above problems occurred.

  • Like 1



User Feedback


I had similiar issues but with my blocklist.txt where it uses some weird symbols to separate the information there and it was probably conflicting with the decoding of the file. It was basically reading the whole line instead of just the userid, so the banlist didn't work at all...

I had to fix it using a mod from the Lua side.

Best and most flexible fix would be probably to use pattern matching here and match the Klei ID and Steam ID directly in the line without carryng about the exact positions or the characters around. And that's what I used in the mod as well.

Share this comment


Link to comment
Share on other sites



Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
  • Create New...