Athanatos

  • Hero Member
  • Throwing random words to increase my post counter
  • Posts: 1,023
Whitelist plugin
«  »Last edited
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/

Developer of RCNR, Zombie Survival, VLSM(C++) and Infected City Survival

habi

  • Sr. Member
  • Posts: 389
Re: Whitelist plugin
« Reply #1,  »Last edited
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.

Xmair

  • Wiki Contributor
  • Posts: 959

Credits to Boystang!

VU Full Member | VCDC 6 Coordinator & Scripter | EG A/D Contributor | Developer of VCCNR | Developer of KTB | Ex-Scripter of EAD

habi

  • Sr. Member
  • Posts: 389
Re: Whitelist plugin
« Reply #3,  »
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!..

Athanatos

  • Hero Member
  • Throwing random words to increase my post counter
  • Posts: 1,023
Re: Whitelist plugin
« Reply #4,  »
I honestly don't remember, This compiles though.

What not null terminated C-strings are you talking about though?
Developer of RCNR, Zombie Survival, VLSM(C++) and Infected City Survival

habi

  • Sr. Member
  • Posts: 389
Re: Whitelist plugin
« Reply #5,  »
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];

Athanatos

  • Hero Member
  • Throwing random words to increase my post counter
  • Posts: 1,023
Re: Whitelist plugin
« Reply #6,  »
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)
Developer of RCNR, Zombie Survival, VLSM(C++) and Infected City Survival

.

  • VC:MP Beta Tester
  • .
  • Posts: 1,808
Re: Whitelist plugin
« Reply #7,  »Last edited
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.
.

Athanatos

  • Hero Member
  • Throwing random words to increase my post counter
  • Posts: 1,023
Re: Whitelist plugin
« Reply #8,  »
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
Developer of RCNR, Zombie Survival, VLSM(C++) and Infected City Survival