Server must-haves
#1

Introduction

Let's face it, as well as a coder as you are you can't do everything yourself. At one point your gamemode will require additional includes, plugins and filterscripts. I made this discussion so we can elaborate on the things any server should at least have. I know of a couple any server needs--depending on the server type--and you are free to add more.

Command processors

Any and all servers need a command processor. Sure you can write every command under OnPlayerCommandText using strcmp() and strok but this method is very outdated, unorganized and gets exponentially slower as you add more commands. You are better of using one of the very fast command processors available.
  • y_cmd - The fastest (arguably) and most flexible processor, also features a "help" parameter so you can easily add help messages to any command
  • zcmd - Around the same speed as y_cmd but more widely used although this processor is less flexible
  • dcmd - To date still the most widely used command processor, although this still uses strcmp(), dcmd will get slower as you add more commands
There are other processors available, I will not go over them as they are in one way or another based on the ones listed above.

Streamers

There is (to me) only 1 correct option here. Incognito's Streamer Plugin is written entirely in C++ and therefore skips a lot of overhead (PAWN uses more resources than C++), making it the fastest streamer available. A lot faster than any streamer written in PAWN.

ISP can stream a variety of things such as objects, (racing)checkpoints, pickups, ...

String scanners and modifiers

There are a few you can use depending on what you can to do.
  • sscanf(2) - Scanning a string (for anything really, sscanf features a ton of variable types aswel as enums, arrays, ...) Highly recommended for commands, mysql loading and saving, etc...
  • explode - Splitting a string into an array based on a delimiter, sscanf can do this aswel although I understand some people find this harder
  • split - Similar to explode, split will split up (obviously) a string into parts depending on a delimiter
  • strtok - Anyone using this should be bitchslapped, don't use as it's slow and outdated and anything you may be able to do with strtok sscanf can do aswel
  • Regular expressions (regex plugin) - Reading a string for a specific format, validating a string (for perhaps length or wether or not it's a roleplay name), case checking, ... You name it, regular expressions can do it. Regular Expressions is a more advanced technique of reading and checking strings but definitely worth learning since it's THE most commonly used way to check strings in most programming languages. You can learn more about them here (wikipedia) or ****** them.
Looping

For extremely fast and efficient looping though players, vehicles or custom arrays you made yourself, use foreach(). There are as far as I know no alternatives that give comparable speed.

__
TBC, feel free to add to it. Template:
Code:
Subject

Explanation
Reply
#2

YSI Server Includes as a base framework and modules system such as PAWN-Boilerplate by Slice(which also includes YSI and some other cool stuff.)
Reply
#3

Actually, strtok in most of cases (using with zcmd-based command processor) is faster than sscanf and is almost the same as explode. Not to mention it's a better practice.
Reply
#4

https://sampforum.blast.hk/showthread.php?tid=216730

Slice is now officially my new idol.
Reply
#5

You forgot split.
Reply
#6

Quote:
Originally Posted by Stewie`
View Post
Actually, strtok in most of cases (using with zcmd-based command processor) is faster than sscanf and is almost the same as explode. Not to mention it's a better practice.
False.
Reply
#7

Quote:
Originally Posted by SuperViper
View Post
You forgot split.
Quote:

I know of a couple any server needs--depending on the server type--and you are free to add more.

And yes, thank you I will add it to the topic.
Reply
#8

People think of optimisation so much that one of the most important libraries has been forgotten :


https://sampforum.blast.hk/showthread.php?tid=292813



I hope that I have helped .
Reply
#9

Quote:
Originally Posted by Sinner
View Post
Command processors

Any and all servers need a command processor. Sure you can write every command under OnPlayerCommandText using strcmp() and strok but this method is very outdated, unorganized and gets exponentially slower as you add more commands. You are better of using one of the very fast command processors available.
I know that using the default string compare function slows down the server when the strings to compare are a lot, but I'm too used to that, I actually use this: #define Command(%0) !strcmp(cmd, %0, true). I never figured out how ycmd works.
Reply
#10

To elaborate on strcmp() based command processors

strcmp() itself is actually very fast. The problem is that as you add more commands, the if-else structure gets larger and larger. Eventually the server will need to go through all the if-else blocks, checking wether or not the player typed the command, which will be slower as you make more commands.

The y_cmds topic features a chart that visualized the speed difference between strcmp() based commands and command systems that call the function directly.



© Y_Less
Reply
#11

That's not a second for 170 commands, that is for several thousand runs combined.
Reply
#12

Quote:
Originally Posted by Y_Less
Посмотреть сообщение
That's not a second for 170 commands, that is for several thousand runs combined.
My apologies I must have read over that, I'll edit my post.
Reply
#13

To be fair, I'm not sure how clear I actually made that in the original post - I'm not very good at highlighting important points.
Reply
#14

The fundamental workings of y_commands and zcmd are actually simple and quite reasonable.
If you have a command named "testcmd" its faster to call a function with that name directly(actually all functions that handle commands have common prefix for faster searches), so it's basically amortized constant time; O(1), than doing strcmp compares(let's say that's basic operation) is O(n)(where "n" is number of commands) i.e. linear time. That is clearly shown with the graph above.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)