Vice City: Multiplayer

Server Development => Community Plugins => Topic started by: Athanatos on September 24th, 2021, 11:59 PM

Title: Whitelist plugin
Post by: Athanatos on September 24th, 2021, 11:59 PM
Hello everyone!

I created a whitelist plugin that will allow only some specified IPs and players into your server.

Purpose


I wrote this plugin just to relax from other demanding projects like my own game engine and game projects. This took me few days to create because of stupid mistakes I made (reading the files, but not copying the data into the containers, as one example).

Now you might say, "passwording servers is enough" -> yes might be. But what if your friend that's scripting his server has a password made of a LaTeX equation? like this one :
Quote
\int e^{x^2} dx = \sum_{n=0}^{\infty}\frac{x^{2n+1}}{n!(2n+1)} + C
or that his password is an entire quote taken from an dubious barely known book? And he can't find the password in his 12k lines of code script that was made from forum snippets? (No one would do that ever (I mean the password thing))

Or maybe you're too lazy to use a single function call in your scripts (i.e SetPassword(string) )

Now again, you might say "I can make this in squirrel too" -> Well this one automatically gets the local IP lol (useless feature probably). Can you do that in Squirrel?

An other reason is that whitelisting is fairly common in multiplayer games like Minecraft, etc.

If you're not convinced f*ck you (/s). (slash s = sarcasm)  (I'm having fun writing this) (Can't wait for the mods to remove the hidden texts)

Well, if you're convinced, here's what you need : this plugin.

Usage


Installation:

Copy the plugin binary compatible with your server into <server root>\plugins\ .
You may need to install the latest MSVC redistributables. Link : https://support.microsoft.com/en-us/topic/the-latest-supported-visual-c-downloads-2647da03-1eea-4433-9aff-95f26a218cc0

First use:

Upon running the server for the first time, the plugin will automatically create 2 files called : allowed_ips.txt and allowed_nicks.txt .

The file allowed_ips is filled with all the local IPs (192.168.1.6 as a example)+ localhost IP (127.0.0.1) and allowed_nicks is filled with 2 example nicknames.

Modifying the whitelist:

Modifying the whitelist requires opening and editing the two created files ( allowed_ips.txt and allowed_nicks.txt ) with your editor of choice(ex. MS Notepad, Notepad++, VS Code, et cetera).

For performance reasons, unlike INIParser, this plugin will keep the whitelists in it's memory instead of continuously reading the files. Therefore modifying the whitelist would require restarting the server after the files are saved!



Future development


If needed Linux support might be taken in consideration. But until then (because probably no one would want this plugin)... That's like the single version that is ever released of this plugin.

Links


Links are here:

Github (source code): https://github.com/NicusorN5/VCMPWhitelistPlugin
Github releases : https://github.com/NicusorN5/VCMPWhitelistPlugin/releases/

Direct download link (x64): https://github.com/NicusorN5/VCMPWhitelistPlugin/releases/download/r1/WhitelistPlugin_x64.dll
Direct download link (x86): https://github.com/NicusorN5/VCMPWhitelistPlugin/releases/download/r1/WhitelistPlugin_x86.dll

And finally... Have a good day y'all.
Title: Re: Whitelist plugin
Post by: habi on February 26th, 2022, 10:56 AM
Nice attempt. with char* and non null terminated strings.
But why do you #include "whitelist.h" in main.h and #include "main.h" in whitelist.h. i feel like laughing.

Include every .h file inside main.h and at last including main.h in every .cpp.
Title: Re: Whitelist plugin
Post by: Xmair on February 26th, 2022, 11:17 AM
Quote from habi on February 26th, 10:56 AM
Include every .h file inside main.h and at last including main.h in every .cpp.
.. what
Title: Re: Whitelist plugin
Post by: habi on February 26th, 2022, 01:49 PM
See  i have main.cpp, game.cpp, functions.cpp and events.cpp and i have main.h, game.h, functions.h and events.h
game.h contains header of functions and classes in game.cpp
functions.h contain that of functions.cpp
And so on.
So in main.h i will
Code: [Select]
#ifndef MAIN_H
#def MAIN_H
#include "game.h"
#include "function.h"
#include "events.h"
//other stuff
#endif
In main.cpp
Code: [Select]
#include "main.h"
In game.cpp,
Code: [Select]
#include "main.h"
In functions.cpp and events.cpp also,
Code: [Select]
#include "main.h"
Problem solved!..
Title: Re: Whitelist plugin
Post by: Athanatos on March 1st, 2022, 06:21 AM
I honestly don't remember, This compiles though.

What not null terminated C-strings are you talking about though?
Title: Re: Whitelist plugin
Post by: habi on March 1st, 2022, 06:31 AM
Code: [Select]
uint8_t CheckPlayer(char* name, size_t name_s, const char* password, const char* ip)
{
//Make a copy of the name, since the size_t parameter tells me this is not a null-terminated string
char* namebuff = new char[name_s + 1];
Title: Re: Whitelist plugin
Post by: Athanatos on March 1st, 2022, 10:41 PM
Ah yes, I wasn't sure if the player name is null terminated or not (when getting it from the VCMP api call).

Also, who says that strings that aren't null terminated are bad? Windows's system (NtCreateFile for example uses UNICODE_STRING that is a struct that contains a char pointer and a size)
Title: Re: Whitelist plugin
Post by: . on March 2nd, 2022, 07:35 PM
Quote from Xmair on February 26th, 11:17 AM
Quote from habi on February 26th, 10:56 AM
Include every .h file inside main.h and at last including main.h in every .cpp.
.. what
He means there's a cyclical header dependency. Header A includes header B and header B includes header A.
Quote from Athanatos on March 1st, 06:21 AM
I honestly don't remember, This compiles though.

What not null terminated C-strings are you talking about though?
You're probably using MSVC to compile. Well, MSVC compiles everything. Even broken or non-standard code. That's why I don't use it much. The moment you try to migrate to other compilers or platforms you'll see what "compiles everything" does to code.
Title: Re: Whitelist plugin
Post by: Athanatos on March 5th, 2022, 01:04 PM
Quote from . on March 2nd, 07:35 PM
You're probably using MSVC to compile. Well, MSVC compiles everything. Even broken or non-standard code.
Ight you caught me