An attempt to "refactor" VC:MP Blank Server

Started by DMWarrior, Aug 20, 2019, 12:25 PM

Previous topic - Next topic

DMWarrior

Hello.

I just found VC:MP 0.4 Blank Server and decided to take a look at how to setup a VC:MP server. But while it's good enough for running locally and see if everything runs fine, I felt annoyed with some parts when I was trying to get started. Some of my thoughts:

  • All functions are listed, but there's no description of what they do or what type you expect the arguments to be;
  • I don't like Allman style indentation;
  • I don't like spaces between function arguments either;
  • Some functions are quite hard to understand. SendDataToClient(), for example, may look almost like "magic code" for beginners because of it's indentation issues and excessive use of one-liners;

I also feel that reading documentation in portuguese instead of english would be more comfortable for me, so I decided to look through all the code and try to document, comment and explain the best I could with this language in mind.

And here's my result:
Download Link (reupload)

Here are some of my changes:
  • All functions have documentation written above them. That includes @event tags (to tell what is an event and what isn't),  descriptions (some are vague, some are detailed) and a list of arguments (including it's types);
  • Code has been reindented to Ratliff/K&R style;
  • No more spaces between brackets;
  • I did my best to try understand how some of functions work and decided to comment everything;
  • Portuguese documentation is available in Markdown and HTML on "docs" folder;
  • /pos command added, because why not? It can be used initially to take some positions and play around with XML, learning how to spawn cars, objects, teleport functions, etc;
  • 80 columns per line;

There were at least 3 things I wanted to do, but didn't:
  • Change return 1 to return true;
  • Clean up argument types (some are IDs, some are instances... is hard to describe exactly unless when you try to use the function and find by yourself; not even the Wiki itself explains that very well);
  • Move all color codes to a property list. Color.Yellow seems way easier to understand than "[#FFFF81]";

Everything is written in portuguese, but I encourage anyone else to do the same in english as well. I know there's nothing special about adding a bunch of vague descriptions on top of functions, but it does help, specially for actual working code like SendDataToClient() and SendDataToServer(). When they're commented that way, people can see what everything does straight away. Some functions may also be confusing to differentiate, like onGameResize() and GUI::gameResize().

Some of my thoughs on Blank Server are mostly opinion-based. This is also  basically the same code, just commented out (and in another language).

Even though you don't understand portuguese, please give a look. I hope you like my try on "refactoring" Blank Server's code (more like "rewriting everything specifically for me to understand", but yeah...).

Blank Server is great for what's intended to be: a quick and easy way to test and start a server. It's just a little messy, but good enough to get you started. So thanks to Sebastian for providing it.

NicusorN5

I was thinking of doing something like this, but you nailed it! Great one!

MatheuS

Very good!


Portuguese: isso vai ser bom pra ajudar alguns novatos que ainda não sabem como montar um servidor para o VCMP.
if( !sucess ) tryAgain();
Thanks to the VCMP community. It was the happiest period of my life.

Sebastian

That's one great thing you have done here.

I used to know what every event is for, so never thought of explaining them.
Seems like newer players didn't need them either, even if they do haha. It is a good add-on.

KingDark

#4

The link does not work, it takes you to the page, but the file you want to download has been deleted
#NULL

Mursaleen5544

#5
I needed this one please upload asap.

DMWarrior

#6
Reuploaded the file and updated the download link:
Download Link (reupload)