Feature: Whitelist overhaul
Overhauled the whitelist system to use a new dedicated service. This one is memory-based to optimise lookups, rather than accessing the file at each server join for WL comparison.
Added support for in-file comments, by using # prefix (considered invalid and ignored by parser). Could come in handy for those massive files, or just keeping track of "whose IP is this" cases.
Added support for ranges using CIDR notation, to allow for entire subnets to be whitelisted. Particularly useful for LAN parties.
New default for the whitelist.txt file looks like this :
# Localhost
127.0.0.1
::1
# Uncomment to allow IPs within private ranges
# 10.0.0.0/8
# 172.16.0.0/12
# 192.168.0.0/16
# fe80::/10
# fd00::/8
Resolves #3091.
@ACaiCat if you think the code is good, can you add a code review too?
@ACaiCat if you think the code is good, can you add a code review too?
Maybe you should find someone more professional, but it's not me.
Maybe you should find someone more professional, but it's not me.
You are professional
Also, if the whitelist is blank, I think it would be fine to populate it with the example whitelist instead of leaving it blank. e.g., if whitelist is disabled, and is empty, add the default config to it.
I tested this and after adding 127.0.0.1 to the whitelist and using /reload, I was not able to whitelist myself.
Also, Terraria doesn't support IPv6.
It seems can not be reloaded through /reload command (Need restart whole server)
Other note:
There's a submodule update that actually reverts 57039ed002, probably unwanted.
The include of
.ideafolder?
Oops, indeed unwanted changes. Lemme fix that right away 😅
I test it on my win server, /whitelist command can't work.I am sure that no other process was using whitelist.txt
Log:
2025-05-30 21:28:08 - Utils: INFO: Server execute: /whitelist 221.12.2.1。
2025-05-30 21:28:08 - Command: ERROR: System.IO.IOException: The process cannot access the file 'C:\Users\Administrator\Desktop\a\tshock\whitelist.txt' because it is being used by another process.
at Microsoft.Win32.SafeHandles.SafeFileHandle.CreateFile(String fullPath, FileMode mode, FileAccess access, FileShare share, FileOptions options) in System.Private.CoreLib.dll:token 0x60001ce+0xa7
at Microsoft.Win32.SafeHandles.SafeFileHandle.Open(String fullPath, FileMode mode, FileAccess access, FileShare share, FileOptions options, Int64 preallocationSize, Nullable`1 unixCreateMode) in System.Private.CoreLib.dll:token 0x60001cd+0x6
at System.IO.Strategies.OSFileStreamStrategy..ctor(String path, FileMode mode, FileAccess access, FileShare share, FileOptions options, Int64 preallocationSize, Nullable`1 unixCreateMode) in System.Private.CoreLib.dll:token 0x6008cfe+0x14
at System.IO.Strategies.FileStreamHelpers.ChooseStrategyCore(String path, FileMode mode, FileAccess access, FileShare share, FileOptions options, Int64 preallocationSize, Nullable`1 unixCreateMode) in System.Private.CoreLib.dll:token 0x6008cd5+0xa
at System.IO.FileInfo.OpenRead() in System.Private.CoreLib.dll:token 0x6008742+0x0
at TShockAPI.Whitelist.AddLine(ReadOnlySpan`1 content) in /home/runner/work/TShock/TShock/TShockAPI/Whitelist.cs:line 227
at TShockAPI.Whitelist.AddToWhitelist(IPAddress ip) in /home/runner/work/TShock/TShock/TShockAPI/Whitelist.cs:line 203
at TShockAPI.Whitelist.AddToWhitelist(ReadOnlySpan`1 ip) in /home/runner/work/TShock/TShock/TShockAPI/Whitelist.cs:line 175
at TShockAPI.Commands.Whitelist(CommandArgs args) in /home/runner/work/TShock/TShock/TShockAPI/Commands.cs:line 1747
at TShockAPI.Command.Run(CommandArgs args) in /home/runner/work/TShock/TShock/TShockAPI/Commands.cs:line 158
I test it on my win server,
/whitelistcommand can't work.I am sure that no other process was usingwhitelist.txt
By any chance, would you have the repro steps for this one ? Because I can't repro the issue.
By any chance, would you have the repro steps for this one ? Because I can't repro the issue.
Just try to add a ip through /whitelist 192.168.1.2
@THEXN tested it too and got the same error.
Okay. Seems I derped handling the file streams. Now fixed, give it a go on last commit :)
It works now.