gmod_luasocket icon indicating copy to clipboard operation
gmod_luasocket copied to clipboard

Started whitelist code (WIP)

Open thegrb93 opened this issue 6 years ago • 29 comments

Feel free to push modifications or reject if you have a different plan. I'm mostly just experimenting.

Closes: #7

thegrb93 avatar Jan 10 '20 10:01 thegrb93

@danielga couple things I'm unsure about are my LUA->ThrowError usage and the whitelist read location. I'll be testing it out later.

thegrb93 avatar Jan 14 '20 07:01 thegrb93

I think my ThrowError usage looks better now.

thegrb93 avatar Jan 14 '20 07:01 thegrb93

I'll change the whitelist structure to a map of sets instead of vector of pairs.

thegrb93 avatar Jan 14 '20 18:01 thegrb93

It's working. Started a game and it allowed the valid whitelisted address and blocked another valid non-whitelisted address. Switched the port in the whitelist and reloaded the map and the whitelist updated to the new port. Last thing to figure out is where to read the whitelist file from and then to update documentation.

thegrb93 avatar Jan 15 '20 07:01 thegrb93

Anywhere in the base game folder, common/GarrysMod is accessible to lua so maybe AppData? Not sure. Right now it's reading from steamapps/common, idk if that's ideal or not.

thegrb93 avatar Jan 15 '20 07:01 thegrb93

I'd prefer lua to not be able to read the whitelist.

thegrb93 avatar Jan 15 '20 09:01 thegrb93

Also forgot to mention I haven't tested it on Linux since I don't have a linux installation.

thegrb93 avatar Jan 16 '20 01:01 thegrb93

Isn't the executable directory enough to prevent Lua from reading the file? I don't remember any search path that has it. Also, can you give me examples of how the regex helps parsing the file (whitelist examples)?

danielga avatar Jan 16 '20 01:01 danielga

The full list is here https://wiki.garrysmod.com/page/File_Search_Paths . "EXECUTABLE_PATH" lets you get there.

Here's a sample whitelist

google.com:80
       192.168.1.1:27015


whitelist.com:12

//Malformed lines are ignored and can be used as comments

helloworld:100

thegrb93 avatar Jan 16 '20 02:01 thegrb93

Could probably change it to domain:port to be more conventional

thegrb93 avatar Jan 16 '20 02:01 thegrb93

I've tried reading/opening a file with the EXECUTABLE_PATH search path and was unable to do so. And yes, domain:port sounds more convenient.

danielga avatar Jan 16 '20 02:01 danielga

Noticed BASE_PATH and this one actually works.

danielga avatar Jan 16 '20 02:01 danielga

Doesn't look like LUA->ThrowError is working. Any idea what's wrong?

thegrb93 avatar Jan 16 '20 03:01 thegrb93

Ok I just realized my pcall(require is the reason it didn't error. I'll forward the error to ErrorNoHalt and test it tonight.

thegrb93 avatar Jan 16 '20 23:01 thegrb93

I'm also going to add the * wildcard so you can do *.*:80 if you wanted. (maybe)

thegrb93 avatar Jan 16 '20 23:01 thegrb93

Looks like it's working.

thegrb93 avatar Jan 17 '20 03:01 thegrb93

@Python1320 any comments/suggestions?

thegrb93 avatar Jan 17 '20 03:01 thegrb93

Seems to crash on linux atm. Crashes whenever the module is loaded.

thegrb93 avatar Jan 17 '20 06:01 thegrb93

Is there a specific way you have to build it? He just used premake5 gmake, then make -f gmcl_socket.core.make

thegrb93 avatar Jan 17 '20 06:01 thegrb93

Sounds like a bug in the code.

danielga avatar Jan 17 '20 13:01 danielga

It works fine in windows though.

thegrb93 avatar Jan 17 '20 16:01 thegrb93

Maybe garrysmod_common has some issue with Linux? @DaDamRival did you try with a valid whitelist with a valid entry? Would be good to try that and make sure its not the Lua->ThrowError that's crashing it.

thegrb93 avatar Jan 17 '20 16:01 thegrb93

Different compilers have different behavior in undefined behavior situations. You could try executing the code on a Linux VM with a simple executable.

danielga avatar Jan 17 '20 16:01 danielga

I think he only tried loading it without the whitelist to see if it would error as expected but it crashed, but hopefully he'll reply with some more information here soon.

thegrb93 avatar Jan 17 '20 17:01 thegrb93

Seems like that was indeed the issue. Works fine when the whitelist exists.

Sevii77 avatar Jan 17 '20 22:01 Sevii77

@DaDamRival could you try replacing them with this?

		case PARSE_CANT_READ:
			LUA->PushString("Failed to read whitelist file!");
			LUA->Error();
			break;
		case PARSE_NO_ENTRIES:
			LUA->PushString("Didn't find any valid entries in whitelist file!");
			LUA->Error();
			break;

thegrb93 avatar Jan 17 '20 22:01 thegrb93

That doesn't work either unfortunately. Willox says ThrowError works fine for him in Linux, so perhaps its something wrong with garrysmod_common

thegrb93 avatar Jan 17 '20 23:01 thegrb93

Besides a few issues with undefined symbols (I might need to add the whole-archive flag to the lua_shared project on garrysmod_common), the module loaded perfectly fine with a valid whitelist and threw an error properly with an invalid whitelist.

danielga avatar Jan 18 '20 18:01 danielga

Ok, let me know if anything needs to change. I'll have this version deployed on starfall meanwhile.

thegrb93 avatar Jan 19 '20 03:01 thegrb93