Server Talk > Scripting Releases

Soldat Shell - Shell (Bash and Csh) scripts for Soldat dedicated servers.

(1/3) > >>

BlackFire533:
Script name: Soldat Shell
Script description: Collection of shell (Bash and Csh) scripts for Soldat dedicated servers.
Original author(s): Myself.
License: GNU Affero General Public License Version 3
Full description:
Although I only wrote four scripts, more is to come; thus, a collection. They're supposed to replace Soldat's Pascal scripts. All of them work, except not perfectly, at least not (yet) for the rcon_kills and rcon_balancer scripts.

rcon_kills script: Count the kills for each player and display a message after each defined row has been reached.
rcon_announce script: Periodically display a set of three messages after five minutes + two other messages, after 30 seconds, counted from the five minutes.
rcon_commands script: Execute commands requested by a player; currently, the commands are: !date (date Unix command), !info (uname -a Unix command), !script (script information; credits), !red or !1 (change the player's team to Alpha), !blue or !2 (change the player's team to Bravo), !spec or !5 (spectate; become a spectator).
(NEW!) rcon_balancer script: Check for inconsistency in Alpha and Bravo teams and automatically switch the team of the last player who joined.

Since I made them on GNU/Linux, it is unlikely that Unix or other Unix-like operating systems (including macOS) be able to run them, because GNU programs tend to be and act different than these found in Unix and other Unix-like operating systems. However, *BSD and illumos users may already have or can install GNU programs, so they just need to adapt their environment.
Windows users may use Cygwin to run the scripts.
NOTE: Even though GNU programs are different than these found in Unix and other Unix-like operating systems, I'm writing the scripts with POSIX in mind.

The scripts can be found in my GitHub repository.

jrgp:
Wow.

It's clear you put a lot of effort into this and I don't think I've seen something like this before.

Maybe the closest to this I've seen before may have been back before pascal scripts where people did similar functionality with mIRC scripts.

Few questions:

- In cases like https://github.com/Krush206/soldat-shell/blob/main/rcon_balancer#L91 why not use $( $( ) ) type nested shell execution as opposed to backticks which you had to escape?

- It seems like /tmp is hard coded in various places, might be helpful to make that customizable

- Have you considered the possibility for shell injection, eg if a player has malicious characters in their names?

jrgp:
Just read this some more, some more thoughts:

It looks like the main loop of these scripts is an infinite busy-wait where you check for recognizable commands in /tmp/cmds, and if there are any you take action and immediately wipe the file. I have a few concerns with this approach:

- with each iteration of the while loop (numerous per second as there are no sleeps) you'll be spawning off numerous `grep` processes, especially if none of them match (each elif). This would consume excessive resources

- if there are many incoming messages at once, some of them will get dropped/ignored as the relevant `grep` might miss them

Instead, why not find a way to pass netcat's stdin and stdout to your script's stdin and stdout, and operate on incoming lines as you receive them, using `while read line` or similar? That way you aren't busy waiting (as each loop iteration will block on reading an incoming message), won't drop messages, and will consume far fewer resources.


Furai:
When writing Bash script I cannot recommend ShellCheck enough. It checks your code for best practices and errors. There's command line version and many text editors support it, at the very least I know for sure that Visual Studio Code does support it.

BlackFire533:

--- Quote from: jrgp on June 10, 2021, 01:11:22 am ---- In cases like https://github.com/Krush206/soldat-shell/blob/main/rcon_balancer#L91 why not use $( $( ) ) type nested shell execution as opposed to backticks which you had to escape?

--- End quote ---
I have always been used to backticks, but I will consider to replace them.

--- Quote from: jrgp on June 10, 2021, 01:11:22 am ---- It seems like /tmp is hard coded in various places, might be helpful to make that customizable

--- End quote ---
Since this is the default directory for temporary files, I did not really want to use something random/unknown. Regardless, I may implement custom variables. However, the recommendation to have a tmpfs mount will always remain.

--- Quote from: jrgp on June 10, 2021, 01:11:22 am ---- Have you considered the possibility for shell injection, eg if a player has malicious characters in their names?

--- End quote ---
Not really, but I'm making a note of and considering this, too.

--- Quote from: jrgp on June 10, 2021, 01:28:22 am ---It looks like the main loop of these scripts is an infinite busy-wait where you check for recognizable commands in /tmp/cmds, and if there are any you take action and immediately wipe the file. I have a few concerns with this approach:

- with each iteration of the while loop (numerous per second as there are no sleeps) you'll be spawning off numerous `grep` processes, especially if none of them match (each elif). This would consume excessive resources

- if there are many incoming messages at once, some of them will get dropped/ignored as the relevant `grep` might miss them

Instead, why not find a way to pass netcat's stdin and stdout to your script's stdin and stdout, and operate on incoming lines as you receive them, using `while read line` or similar? That way you aren't busy waiting (as each loop iteration will block on reading an incoming message), won't drop messages, and will consume far fewer resources.

--- End quote ---
You are right. I have always been concerned of the same reasons, too. Thanks for the input, I will replace the loop statement and implement netcat within the script.

--- Quote from: Furai on June 10, 2021, 01:38:10 am ---When writing Bash script I cannot recommend ShellCheck enough. It checks your code for best practices and errors. There's command line version and many text editors support it, at the very least I know for sure that Visual Studio Code does support it.

--- End quote ---
This may come handy. Thanks.

Navigation

[0] Message Index

[#] Next page

Go to full version