Jump to content
Sign in to follow this  
bazik_

Script for limiting number of allowed sound files

Recommended Posts

Hi,

as we all know, the soundfiles can cause a lot of lag. Thats not while a player uploads them to the server, but when the server uploads them to the connecting players. Limiting the custom file size isnt a solution because with a 20k limit, one can still connect with 20 sound files having < 20k each.

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

#! /bin/sh

# File : soundfilter.sh

# Autor : bazik <bazik at 0x1337 dot net>

# Homepage : http://0x1337.net

#

# Written for Suicide Euro Squad - http://suicidesquad.co.uk

BASEDIR=/home/ses/ofpserver

while true;

do

find $BASEDIR/tmp*/players -name sound | while read DIRS;

do

ls -1 $DIRS | sed -n "2,$ p" | while read SOUNDS;

do

rm -f "$DIRS/$SOUNDS"

done

done

done

The above simple script scans the servers tmp folder and deletes all sound files but one in a players sound folder. You can adjust the number of allowed files by changing the number in the sed command to the number of allowed sound files + 1.

So if you want to allow 5 sound files per player, change the line to:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

[...]

ls -1 $DIRS | sed -n "6,$ p" | while read SOUNDS;

[...]

To use the script, change the BASDIR variable to the root folder of your flashpoint server. Change into that folder and run the script with the following command:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

nohup ./soundfilter.sh &

That will execute the script and put it into background so you can just close your shell and it will remain running.

If you fear that infinite loop in there, look at the cpu usage:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

PID USER PRI NI SIZE RSS SHARE STAT %CPU %MEM TIME COMMAND

8427 ses 20 5 988 988 848 S N 0.0 0.0 0:05 soundfilter.sh

Short overview what the script does:

- search for "sound" folder in the player temp directory

- list all files in the "sound" folder

- delete all files but the (alphabetical) first N where N is the number you set - 1

- start over again smile_o.gif

If you now connect to our server with 10 soundfiles, they get uploaded to the server by you and all but the first uploaded get deleted directly.

If anyone connects now, he only gets that first file from the server. If you play your 3rd or 4th file via the action menu, others will see the text, but wont hear anything (as the file does not exist in their local tmp folder).

Oh and if you want to delete all files and deny sounds at all just remove the sed instruction:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

[...]

ls -1 $DIRS | while read SOUNDS;

[...]

I think that should explain it enough smile_o.gif Hope its of use for someone.

Regards,

bazik

P.S.: Before someone asks: Thats for a Linux server of course ;)

Share this post


Link to post
Share on other sites

You might want to add a little delay into that infinite loop, as without a delay it causes alot needless cpu load. One second delay should be good (ie add "sleep 1" before the find command)

Share this post


Link to post
Share on other sites

I did have a delay with "sleep 1" in there, but sometimes that caused sound files to get through the script and to the client. That happend a few times during the test, so I removed the "sleep".

The used load of the script is that small that it didnt change anything on the performance side.

Share this post


Link to post
Share on other sites

thats cool. I should try and write a windows equivalent. Dunno if I can emulate that using DOS batch language though.

Share this post


Link to post
Share on other sites

Doesn't work when there are spaces in the name of the player. Either use xargs or write it in perl so it will work with any kind of playername and with unix and windows. Guess i'll do that in the next few days...

Otherwise, a cool idea biggrin_o.gif

Share this post


Link to post
Share on other sites
Doesn't work when there are spaces in the name of the player. Either use xargs or write it in perl so it will work with any kind of playername and with unix and windows. Guess i'll do that in the next few days...

Otherwise, a cool idea biggrin_o.gif

>> Doesn't work when there are spaces in the name of the player.

Oooops! Thanks for finding that bug smile_o.gif Fixed version:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

#! /bin/sh

# File : soundfilter.sh

# Autor : bazik <bazik at 0x1337 dot net>

# Homepage : http://0x1337.net

#

# Written for Suicide Euro Squad - http://suicidesquad.co.uk

BASEDIR=/home/ses/ofpserver

while true;

do

find $BASEDIR/tmp*/players -name sound | while read DIRS;

do

ls -1 "$DIRS" | sed -n "2,$ p" | while read SOUNDS;

do

rm -f "$DIRS/$SOUNDS"

done

done

done

Share this post


Link to post
Share on other sites

Works fine, we asked Bazik to do this on our server after the tmp folder had a habit of growing to around 2Mb at peak times (with 22000 byte limit on all custom files).

Thanks, hope others benifit too.

Share this post


Link to post
Share on other sites

bazik: maybe i'm blind, but what exactly is different in the new version? I made a crude perlscript for the same purpose and am running that now for testing purposes on my server.

Share this post


Link to post
Share on other sites
bazik: maybe i'm blind, but what exactly is different in the new version? I made a crude perlscript for the same purpose and am running that now for testing purposes on my server.

I added quotes around the "$DIRS" variable.

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×