Running a Source dedicated server (for Left 4 Dead)

December 26th, 2008

For a while now I have been running some dedicated servers for Source games. Primarily Team Fortress 2. I lately switched those off in favor of Left 4 Dead servers. I was always looking for a way to improve my setup. At some point during my initial googleing I came across this article.
I based my startup script on the one in that article. But we’ll come back to that later. Let’s start with installation.
The initial steps are laid out perfectly on srcds.com. But I’ll list everything important in here as well.

As all of my administration articles (so far) this one is for Ubuntu Server 8.04.1.

Let’s start by adding a new user that will run our servers.

sudo adduser --disabled-login steam

Now to log in with the newly created user to install the servers. We need to switch the user as root as a normal user can not log into this account.

sudo su - steam

No we can install the HLDSUpdateTool.

wget http://www.steampowered.com/download/hldsupdatetool.bin
chmod +x hldsupdatetool.bin
./hldsupdatetool.bin
./steam

In case it will hang at “Checking bootstrapper version…” you can try to set a set of preferred content servers. You do that by creating a file called “steam.cfg” and adding the following line to it:

PreferredContentServerIDs = "id id id"

You can find the ids on http://store.steampowered.com/stats/content/ under “Individual Server Statisistics”. Look for Valve #NN servers and place the number of the servers you want to use inside the quotes. Then retry running steam.

Now we’ll install a game. Let’s start out with Left 4 Dead. If you want to see what games are available, run:

./steam -command list

This will also show you the correct game identifier for Left 4 Dead, which is l4d_full (left4dead was for the demo).

./steam -command update -game l4d_full -dir /home/steam

In case the installation process hangs you can also try setting the preferred content servers as mentioned above. Now, theoretically you’re good to go and you can start your server. But we’re gonna go a step further. I use a start script based on the article mentioned at the start of this article. Now let’s grab it.
But wait, in case you realize that you really don’t want to use any of my shitty scripts and that you just want to get a clean server running, in that case it can stilll be helpful to get the script. You see when you use my script and you start a profile it will print out the command line it used. That way you can build up your desired configuration according to this guide, then run the script and get the correct command line to run your server. Thus I still highly recommend getting the script.

wget http://www.dirty-motherfucker.org/blog/wp-content/uploads/2008/12/steamLauncher.sh
chmod +x steamLauncher.sh

The script allows to easily start and stop Source servers in the background. It also allows for several profiles for several games. So you can start all games through the same interface. I like it, if you don’t then maybe have a look at the original script.

So let’s create a profile for Left 4 Dead.

mkdir profiles
editor profiles/l4d.conf

Now, this is how a profile should look like:

longName                = Left 4 Dead - 1 instance      ; The name of this profile/game
gameName                = left4dead                     ; The name given by steam to the game (equals the foldername ex. cstrike|tf2|left4dead)
daemon                  = /home/steam/l4d/srcds_run     ; Usually srcds_run
updater                 = /home/steam/steam             ; Where is the updater located? (steam binary)
basePath                = /home/steam/l4d               ; The base path of the steam installation (this folder contains tf2/cstrike/left4dead folders)
userName                = steam                         ; What user the server should run as

serverName              = My L4D Server                 ; The name that will appear in the server browser
serverIp                = 11.222.33.111                 ; The IP address to bind the server socket to
serverPort              = 27010                         ; The first port to use for listening (will be treated as base port with forked l4d servers)
serverMap               = l4d_hospital01_apartment      ; The first map to load
serverMaxPlayers        = 4                             ; Maximum number of players allowed on the server
serverPriority          = 0                             ; Renice to set for the server process (-20 is high, 0 is normal, +19 is low)
forkCount               = 0                             ; How many instances to fork
additionalParams        = -nohltv -steamport 27960+## +clientport 25030+## +exec server##.cfg +sv_lan 0 ; Additional params to run the server with

Obviously in that profile you need to adjust at least the serverIp parameter. Now you can run that profile by typing.

./steamLauncher start l4d

Keep in mind though, this is not a state that we want to be comfortable with just yet. Nevertheless start it up and check if there is any trouble. If it comes up, attach to the screen session as the script tells you to.
In case you get an error saying “Cannot open terminal ‘/dev/pts/0′”, you can run “script /dev/null” and then attach to the session. There are other ways to resolve it. If you wanna find out about those they’re easy to find in Google ;)

Now, in the profile of Left 4 Dead in the additionParameters we also tell the server to execute a certain config file. Let’s create that one now.

editor l4d/left4dead/cfg/server01.cfg

In here we can now override the default map, difficulty and whatnot. For example:

hostname        My L4D Server - No Mercy - Normal Difficulty
map             l4d_hospital01_apartment
m_difficulty    normal

Setting the difficulty and map is almost pointless though as they can be changed by vote anyway. But I’m sure you can think of some other server variables that you might want to set. And this is the place to do it.

Now might be a good time to talk about forking with Left 4 Dead servers. Given that there are only 4 or 8 players on a Left 4 Dead server it’s almost a waste only running a single instance. That’s why you can fork multiple instances of servers. Let’s have a look at a Left 4 Dead profile modified to run 4 servers.

longName                = Left 4 Dead - 4 instances     ; The name of this profile/game
gameName                = left4dead                     ; The name given by steam to the game (equals the foldername ex. cstrike|tf2|left4dead)
daemon                  = /home/steam/l4d/srcds_run     ; Usually srcds_run
updater                 = /home/steam/steam             ; Where is the updater located? (steam binary)
basePath                = /home/steam/l4d               ; The base path of the steam installation (this folder contains tf2/cstrike/left4dead folders)
userName                = steam                         ; What user the server should run as

serverName              = My L4D Server                 ; The name that will appear in the server browser
serverIp                = 11.222.33.111                 ; The IP address to bind the server socket to
serverPort              = 27010                         ; The first port to use for listening (will be treated as base port with forked l4d servers)
serverMap               = l4d_hospital01_apartment      ; The first map to load
serverMaxPlayers        = 4                             ; Maximum number of players allowed on the server
serverPriority          = 0                             ; Renice to set for the server process (-20 is high, 0 is normal, +19 is low)
forkCount               = 4                             ; How many instances to fork
additionalParams        = -nohltv -steamport 27960+## +clientport 25030+## +exec server##.cfg +sv_lan 0 ; Additional params to run the server with

You can now also create server02.cfg, server03.cfg and server04.cfg in the l4d folder. This way you can start up each instance with a different map, difficulty, key, …
It remains a mystery to me how to properly send commands to the console with forked instances though. Although from what I read there are ways, but I just never had any luck with those. I also never had any luck with rcon. So basically when I play on my own servers I can’t do shit when someone is getting on my nerves. And we sure don’t want that!
So what do we do? We install SourceMod. It gives us a nice and easy way to kick players when they get on our balls. And we can be happy little server admins. During the installation of SourceMod it may be helpful to run only a single instance profile of Left 4 Dead so you can easily attach to the screen session and send of some commands to test your installation.
So let’s get to it!

First of all we require MetaMod. A very straight-forward guide can be found on the MetaMod Wiki. For completeness sake I’ll replicate the required information here though.

  1. Download MetaMod at http://www.metamodsource.net/
  2. Put it into the left4dead folder. (cd l4d/left4dead)
  3. tar xvzf mmsource-1.7.0.tar.gz (Filename might differ)
  4. In l4d/left4dead/addons create a file metamod.vdf and put the following into it:
    "Plugin"
    {
            "file"  "../left4dead/addons/metamod/bin/server_i486.so"
    }
    
  5. Go back into your home directory and restart your server (./steamLauncher restart l4d)
  6. Attach to the screen session and type “meta version”. Everything other than “Unknown command” is a good sign.

If the installation of MetaMod fails, refer to the MetaMod Wiki or bug me about it.

Now we’re gonna install SourceMod. Again a proper guide can be found at http://wiki.alliedmods.net/Installing_SourceMod.

  1. Grab one of the latest snapshots of SourceMod from http://www.sourcemod.net/snapshots-1.2.php
  2. Just like we did with MetaMod, put it into the l4d/left4dead folder.
  3. Extract it via tar xvzf sourcemod-1.2.0-hg2469.tar.gz (Filename may differ again)
  4. Go back into your home directory and restart your server (./steamLauncher restart l4d)
  5. Attach to the screen session and type “meta list”. You should see that SourceMod is loaded.

Now last but not least we need to set ourself up as an admin in SourceMod. We do that by editing

l4d/left4dead/addons/sourcemod/configs/admins_simple.ini

Right at the bottom we will now put the following line:

"STEAM_YOURID" "99:z"

If you’re like me then you’ll have no clue what your Steam ID is. So open up steam and connect to any server in any game. Then open up the console and type “status”. In the list that appears there should be your nick somewhere. And close to it, you’ll find your Steam ID.

Now you should be an admin on your Left 4 Dead servers. You can join your own servers easily by invoking “openserverbrowser” in the Left 4 Dead console. To enjoy being an admin it helps to bind “sm_admin” to some key. Then you can open the admin menu and kick those pesky players who just can’t stop running ahead to get themselves killed.

In case this isn’t clear. You’ll have to forward some ports for your servers to work. Which can easily be accomplished by adding two lines to your /etc/ufw/after.rules file. Similar to these two:

# Steam TF2 Server
-A ufw-after-input -d 11.222.33.111 -m udp -p udp --dport 26900:27040 -m conntrack --ctstate NEW,RELATED,ESTABLISHED -j ACCEPT
-A ufw-after-input -d 11.222.33.111 -m tcp -p tcp --dport 27000:27020 -m conntrack --ctstate NEW,RELATED,ESTABLISHED -j ACCEPT

I hope I haven’t left any open questions. In case I did, please let me know ;)

Substrate in 25 lines

December 15th, 2008

As soon as I heard of the 25-Line ActionScript Contest I knew I’d have to take part. So I tried re-implementing Substrate in 25 lines. I ended up with a pretty limited version but it runs fine and looks nice.

But, oh well, I didn’t make the finals :( And I don’t plan on entering it again. Although after seeing the source of the finalists I assume I would even be able to add more features. Which would be using techniques that I assumed were frowned upon ;)

So, because of the length of some lines, no code in this post, only a link to the source.
And this is the resulting swf file.

I hope someone gets something out of this, cause I sure didn’t :D

Flash Player version in AWStats – Revised

November 20th, 2008

My first implementation of this idea may have been sufficient for general use. For inclusion in WordPress however it was problematic at best.
Now that I have revised (and tested) it, I thought I’d share this updated WordPress plugin.

<?php
/*
Plugin Name: Flash version Detection
Plugin URI: http://www.dirty-motherfucker.org/
Description: Detects flash version
Version: 0.1
Author: gencha
Author URI: http://www.dirty-motherfucker.org
*/

$plugin_root = get_settings('siteurl') . '/wp-content/plugins/'.dirname(plugin_basename(__FILE__));

if( preg_match("/(\/\?feed=|\/feed)/i",$_SERVER['REQUEST_URI']) ) {
        // RSS Feeds
        // do nothing
} else {
        add_action('wp_head', 'add_head');
}

function add_head() {
	global $plugin_root;
	echo '
	<!-- Flash player version detection -->
	<script src="' . $plugin_root . '/swfobject.js" type="text/javascript"></script>
	<script type="text/javascript">
		window.onload = function() {
			var version = deconcept.SWFObjectUtil.getPlayerVersion();
			if( document.getElementById && version["major"]> 0 ) {
				var flash_version = version["major"] +"."+ version["minor"] +"."+ version["rev"];
				document.getElementById("flashversion").innerHTML = "<iframe src=\"' . get_settings("siteurl") . '/flash_player_version.php?version=" + flash_version + "\" style=\"display: none;\"></iframe>";
			}
		}
	</script>
	';
}
?>

In this version I put the JavaScript code inline. Although I’m not a big fan of that, it’s reasonable in this case and I have all the code in one place. This made it easier to fix the second bug. Which was that the whole concept only worked on the main page. On other pages the browser couldn’t find the flash_version.php file. Which resulted in nasty 404 errors. Now I can simply put the blogs base path into the JavaScript code and everything is well.

Furry Blog Logo

November 13th, 2008

Update: I updated the .swf files. So hopefully now those pesky Flash Player errors are gone :( Shame on me for bad coding.

I had a little fun with particles in AS3 the past days. I wrote a small piece based on my Processing port framework that traces the paths of particles. The particles pick up color from a given input texture. As they move, they plot their color onto the canvas. Although i added the condition that the color is only plotted if the target pixel is darker than the particle color. This results in a nice glowing effect around the outline of the image.
I built the swf files against Flash Player 10 this time. There is actually no need at all to do so, but i just couldn’t resist Vector. Arrays are so dirty :(

Here is the larger version with the complete blog logo. ;)

And here’s some source to go with it. Although it’ll hardly compile outside of the Processing Port framework ;D But since i moved servers my SVN repository isn’t publicly available anymore. So if anyone has any interest in the complete source, i’ll wrap it up and put it online ;)

Particle.as

package org.dirty_dirtymotherfucker.tracer {
  import flash.display.BitmapData;
  import flash.geom.Point;
  import flash.geom.Rectangle;
  import org.dirty_dirtymotherfucker.processing.*;

  public class Particle {

    public var position_x:Number;
    public var position_y:Number;
    public var direction_x:Number;
    public var direction_y:Number;
    public var color:uint;
    public var life:Number;
    public var source:BitmapData;
    public var randomSource:BitmapData;

    public function Particle( source:BitmapData, randomSource:BitmapData, sourceOffset:uint ) {
      this.source = source;
      if( Tracer.USE_PERLIN_NOISE ) {
        this.randomSource = new BitmapData( randomSource.width, 1, false );
        this.randomSource.copyPixels( randomSource, new Rectangle( 0, sourceOffset, randomSource.width, 1 ), new Point( 0, 0 ) );
      }
      birth();
    }

    public function birth( ):void {
      life        = Tracer.MAX_PARTICLE_LIFE;
      position_x  = MathHelper.randomRange( -Tracer.CANVAS_SIZE_X, Tracer.CANVAS_SIZE_X );
      position_y  = MathHelper.randomRange( -Tracer.CANVAS_SIZE_Y, Tracer.CANVAS_SIZE_Y );
      direction_x = MathHelper.randomRange( -1.0, 1.0 );
      direction_y = MathHelper.randomRange( -1.0, 1.0 );
      color       = source.getPixel32( position_x, position_y );
    }

    public function travel( source:BitmapData, canvas:BitmapData, blend:Number ):void {
      if( Tracer.USE_PERLIN_NOISE ) {
        direction_x += ( ColorHelper.getR( randomSource.getPixel( life * 10, 0 ) ) - 128 ) / 256;
        direction_y += ( ColorHelper.getG( randomSource.getPixel( life * 10, 0 ) ) - 128 ) / 256;
      } else {
        direction_x += MathHelper.randomRange( -0.1, 0.1 );
        direction_y += MathHelper.randomRange( -0.1, 0.1 );
      }

      // normalize direction
      var len:Number = Math.sqrt( direction_x * direction_x + direction_y * direction_y );
      direction_x /= len;
      direction_y /= len;

      position_x += direction_x;
      position_y += direction_y;
      life -= 0.1;
      //if( 0 == color ) life = 0;

      var sourceColor:uint = source.getPixel32( position_x, position_y );
      var canvasColor:uint = canvas.getPixel32( position_x, position_y );

      if( sourceColor != canvasColor ) {
        color = ColorHelper.blend( color, sourceColor, blend );

        var colorFit:Boolean = ColorHelper.getR( ColorHelper.toGrayScale( color ) ) > ColorHelper.getR( ColorHelper.toGrayScale( canvasColor ) );
        if( 0 != ColorHelper.getA( color ) && colorFit ) {
          canvas.setPixel32( position_x, position_y, ColorHelper.blend( color, canvasColor, 25 ) );
          //canvas.setPixel32( position.x, position.y, color );
        }
      }

      if( 0 > position_x || position_x > Tracer.CANVAS_SIZE_X || 0 > position_y || position_y > Tracer.CANVAS_SIZE_Y || 0 >= life ) birth();
    }

  }

}

Tracer.as

package org.dirty_dirtymotherfucker.tracer {

  import flash.display.*;
  import flash.events.*;
  import flash.geom.Matrix;
  import flash.geom.Point;
  import flash.geom.Rectangle;
  import flash.net.URLLoader;
  import flash.net.URLRequest;

  import org.dirty_dirtymotherfucker.processing.*;

  /**
   * The main implementation of the Tracer project
   */
  public class Tracer extends BlogSprite {

    // Main application settings

    public static const CANVAS_BACKGROUND_COLOR:uint  = 0xFF000000;

    public static const UPDATES_PER_SECOND:uint       = 1200;

    public static const ITERATIONS_PER_UPDATE:uint    = 10;

    public static const CANVAS_SIZE_X:uint            = 466;// 840;
    public static const CANVAS_SIZE_Y:uint            = 220;

    public static const ADDITIVE_BLENDING:Boolean     = true;
    public static const SUBTRACTIVE_BLENDING:Boolean  = false;
    private static const MAX_ITERATIONS:uint          = 0;// 120 * 20;

    public static const MAX_PARTICLE_LIFE:Number      = 100;
    public static const NUM_PARTICLES:int             = 1000;

    public static const USE_PERLIN_NOISE:Boolean      = false;

    private var iterationCount:int = 0;

    private var loader:Loader;
    private var source:BitmapData;
    private var randomSeed:BitmapData;

    private var particles:Vector.<Particle>;

    private var blend:Number;

    public function Tracer():void {
      ColorHelper.loadPalette( );

      super( CANVAS_SIZE_X, CANVAS_SIZE_Y, CANVAS_BACKGROUND_COLOR );

      loader = new Loader();
      //loader.load( new URLRequest( "map.png" ) );
      loader.load( new URLRequest( "http://www.dirty-motherfucker.org/blog/wp-content/uploads/2008/11/motherfucking.png" ) );

      loader.contentLoaderInfo.addEventListener( Event.COMPLETE, drawMap );
    }

    override protected function onDraw( event:TimerEvent ):void {
      canvas.lock();
      for( var iteration:uint = 0; iteration < ITERATIONS_PER_UPDATE; ++iteration ) {
        // draw
        if( null == loader.content ) break;
        for each( var particle:Particle in particles ) {
          particle.travel( source, canvas, blend );
        }

        blend += 0.06;
        if( blend >= 255 ) stopApp();

        // cycle limiter
        if( MAX_ITERATIONS > 0 && ++iterationCount > MAX_ITERATIONS ) {
          restart();
        }
      }
      canvas.unlock();

    }

    override protected function startApp( updatesPerSecond:uint = 0 ):void {
      super.startApp( UPDATES_PER_SECOND );

      particles = new Vector.<Particle>();

      blend = 10;

      iterationCount = 0;

      canvas.fillRect( new Rectangle( 0, 0, CANVAS_SIZE_X, CANVAS_SIZE_Y ), CANVAS_BACKGROUND_COLOR );

      initContent();
    }

    private function drawMap( e:Event ):void {
      loader.removeEventListener( Event.COMPLETE, drawMap );

      initContent();
    }

    private function initContent():void {
      if( null == loader ) return;
      source = new BitmapData( CANVAS_SIZE_X, CANVAS_SIZE_Y, true, 0x00000000 );
      var matrix:Matrix = new Matrix();
      matrix.translate( 0, CANVAS_SIZE_Y / 2 - loader.height / 2 );
      source.draw( loader, matrix );

      if( USE_PERLIN_NOISE ) {
        randomSeed = new BitmapData( MAX_PARTICLE_LIFE * 10, NUM_PARTICLES, false, 0x000000 );
        randomSeed.perlinNoise( MAX_PARTICLE_LIFE * 10, NUM_PARTICLES, 8, Math.random() * uint.MAX_VALUE, true, true, BitmapDataChannel.GREEN | BitmapDataChannel.RED, false );
      }

      for( var i:uint = 0; i < NUM_PARTICLES; ++i ) {
        particles.push( new Particle( source, randomSeed, i ) );
      }

    }

  }

}

Including Flash Player version in AWStats

November 12th, 2008

I was interested in what Flash Player version people are using when visiting my site. So i looked around the web for a solution including AWStats. At first i was out of luck until i noticed that AWStats has a discussion forum on sourceforge as well.
Someone there came up with a solution which was almost perfect for me.

First of all you’re gonna want to put this in your awstats config file for your site:

ExtraSectionName1="Flash Player Version"
ExtraSectionCodeFilter1="200 304"
ExtraSectionCondition1="URL,\/flash_player_version\.php"
ExtraSectionFirstColumnTitle1="Version"
ExtraSectionFirstColumnValues1="QUERY_STRING,version=([^&]+)"
ExtraSectionFirstColumnFormat1="%s"
ExtraSectionStatTypes1=PL
ExtraSectionAddAverageRow1=0
ExtraSectionAddSumRow1=1
MaxNbOfExtra1=100
MinHitExtra1=1

Note that i made some slight adjustments to some strings compared to the original version.
Now you need to add some JavaScript to make appropriate URL requests that AWStats can read from.
Note that this is the original code, not the one i finally ended up with.

<script language="javascript" type="text/javascript" src="../swfobject/swfobject.js"></script> 

<script type="text/javascript">
var version = deconcept.SWFObjectUtil.getPlayerVersion();
if (document.getElementById && version["major"] > 0) {
var flash_version = version['major'] +"."+ version['minor'] +"."+ version['rev'];
document.getElementById('flashversion').innerHTML = "<iframe src=\"../version.php?version=" + flash_version + "\" style=\"display: none;\"></iframe>";
}
</script>

As i did not want to just jam this into my theme files, i wrote a little WordPress plugin to do the above task.

<?php
/*
Plugin Name: Flash Player Version Detection
Plugin URI: http://www.dirty-motherfucker.org/
Description: Detects flash version
Version: 0.1
Author: gencha
Author URI: http://www.dirty-motherfucker.org
*/

$plugin_root = get_settings('siteurl') . '/wp-content/plugins/'.dirname(plugin_basename(__FILE__));

if( preg_match("/(\/\?feed=|\/feed)/i",$_SERVER['REQUEST_URI']) ) {
        // RSS Feeds
        // do nothing
} else {
        add_action('wp_head', 'add_head');
}

function add_head() {
	global $plugin_root;
	echo '
        <!-- Flash player version detection -->
        <script src="' . $plugin_root . '/swfobject.js" type="text/javascript"></script>
        <script src="' . $plugin_root . '/flash_version.js" type="text/javascript"></script>
	';
}
?>

I took some small bits from the KML Flash Embed plugin. This will include the appropriate JavaScript files in your blog. Obviously, if you’re not using WordPress, this is of no use to you. You can just directly include SWFObject in the head section of your site.

Now the important bit is the JavaScript file that actually performs the URL request which AWStats will later see.

window.onload = function() {
	var version = deconcept.SWFObjectUtil.getPlayerVersion();
	if( document.getElementById && version["major"] > 0 ) {
		var flash_version = version['major'] +"."+ version['minor'] +"."+ version['rev'];
		document.getElementById("flashversion").innerHTML = "<iframe src=\"../flash_player_version.php?version=" + flash_version + "\" style=\"display: none;\"></iframe>";
	}
}

Now the only thing that is left is that you include an empty div tag with the id “flashversion” somewhere in your site. Now THIS i did just jam into my theme :P
Although i am sure there is some hook i can use in the WordPress plugin architecture. But i’m lazy. So there you have it.

Sketches #5

November 10th, 2008

Postal sketch second round ;)

postal2.png

I hope there’ll be more technical content again soon ;)

Sketches #4

October 30th, 2008

A small sketch i drew during a boring meeting. At least something worth to post. Hope you like it.

postal.png

And maybe you noticed that i re-did the theme of the blog. Thanks to Alien^PDX who inspired me to do it with the background image of his own new website. Be sure to check out his website.

Converting SWF animations to video

October 14th, 2008

If you ever tried to convert a SWF animation to a video you know what a pain it can be. Let’s first look at the solutions at hand:

  • Exporting a movie from Flash
  • Using a SWF to movie converter
  • Screen capture

Now let’s break those down.

  • Exporting a movie from Flash
    - Doesn’t play sub-movieclip animations
  • Using a SWF to video converter
    - Some have limited encoding support
    - Some have really bad encoding quality
    - Some have poor playback performance and the result looks shitty
    - Some also don’t play sub-movieclip animations
  • Screen capture
    - Suffers from the same encoding and playback problems as converters

So, after trying all of the above on a project at hand i was rather disappointed to see that all the solution i tried were basically shit. The animation at hand had 1024×768 dimensions and only in Flash player 10 it played with reasonable speed. So when i added screen capture into the mix the result looked like crap.

So i rolled my own converter. And the goals were clear:

  • I want to capture every single frame of the animation
  • I want the highest quality possible
  • I want to use the vector scaling of flash to achieve my target size to avoid bitmap scaling later on in the process.

Now what i ended up with is a converter that just writes out every single frame as PNG, no sound, no direct video. But capturing the sound is extremely easy and so is converting a PNG sequence into a movie.

So here is how it’s done.
At first i tried to gotoAndStop( ++frame ); in a loop and writing out the frames, but this results in sub-movieclip animations not being played back.
So what you have to do is just play the movie. But you place a listener on it for Event.ENTER_FRAME. If your host application runs at the same frame rate you can also place the listener on the host application (which is what I’ve done in my reference implementation).

Now in the event listener you just .draw into a BitmapData object, encode it to PNG (using the AsPngEncoder from the AsWing project for example) and then write it to disk.
And this is where you get problems. Cause Flash itself won’t let you write to disk. I had 2 solutions to that problem. I used SWFStudio to compile a .exe that could write binaries to disk and i wrote one version in AIR.

Feel free to look at both implementations, but keep in mind that they are basically proof-of-concept, look like shit and are almost unuseable.

The SWFStudio version expects the name of the swf as the first command-line parameter (which can’t include spaces). The second and third parameter are the width and height. The last parameter is the number of frames to write.

The AIR version includes a GUI to set the input movie and output folder.

Have fun!

SWFStudio Version
Adobe AIR Version

Setting up Cacti

October 5th, 2008

So in the process of migrating our company network architecture over the paths months, I had the chance to set up Cacti for server monitoring. I followed some documentation and articles on the net but ended up making some stupid mistakes. So, let’s start with this.

The host system Cacti will be running on, is Ubuntu Server 8.04.1 with no prior modifications. I just installed all pending updates as of today of course. To reproduce this I’m running it in a VMWare virtual machine (just to make sure I’m not missing something important). The configuration of the systems that are being monitored is really not that important. As long as you can run an SNMP deamon on them.

Which brings me to the first thing I didn’t understand from the start. Cacti itself is the tool that is monitoring other servers. Of course you can monitor the machine that Cacti is running on as well, but the main point is, you don’t have to install it on every machine that you want to monitor.

We start off by installing MySQL-Server, as the configure process for Cacti can’t do that on it’s own.

sudo apt-get install mysql-server -y

We input a root password and that’s that with the MySQL-Server.

Now let’s install Cacti itself.

sudo apt-get install cacti -y

I configure it to use Apache2. And I use dbconfig-common for database configuration. Give it the MySQL-Server root password and then a password for the Cacti user. And then Cacti is installed.

Now we configure Cacti via the web interface. For the initial setup process you could just use w3m:

w3m http://localhost/cacti

But sooner or later you better get something with a GUI ;)

When you get to the login screen, give it the default login admin/admin. After that you have to give the admin account a new password. Congratulations, now Cacti is set up and ready to go.

So, when you click the Graphs tab now, you’ll most likely see nothing, or if you already waited for the poller to run for the first time, you see 4 (almost) empty graphs for localhost. These graphs are created by running scripts on the local host. I usually use SNMP to gather the data. So now we create a new device for the local host which is SNMP enabled. But for that, we first need to install the SNMP deamon.

sudo apt-get install snmpd -y;
sudo vi /etc/default/snmpd

What we want to change in /etc/default/snmpd is mainly the logging options. SNMDOPTS includes “-Lsd”, more suitable would be “-LS 0-5 d”. The original setting will log at a debug level and pollute the logfiles. The new one will only log important messages.
At the end of SNMPDOPTS there is also a 127.0.0.1, this is the listening address. To monitor our host system this would be fine. But for additional machines, make sure to either remove it or adjust it to the correct listening address.

sudo vi /etc/snmp/snmpd.conf

In this file look for lines starting with com2sec. What you’re gonna want to do is, comment out the first line (the one for paranoid settings) and enable the second line, which allows read-only access.
Now restart snmpd:

sudo invoke-rc.d snmpd restart

We’re not ready to create our new device.
In Cacti, go to the console tab. Select “create Devices” from the list in the middle. Click Add in the upper right corner.
Give the new device a proper name and supply the ip address. If you didn’t adjust the ip address in /etc/default/snmpd, then make sure to use 127.0.0.1 here.
As the host template select “Generic SNMP-enabled Host” and at the bottom of the form, select “Version 1″ as the SNMP Version.
Now you can select SNMP as the Downed Device Detection as well. And that’s it.

Now, let’s first add a few more data sources. In the “Add data query” dropdown in the lower right, select “SNMP – Get mounted partitions” then click “Add” on the right. Repeat the process for “SNMP – Get Processor Information”.
Now we’re ready to create some graphs.

Make sure that all the data queries have already returned successful results. The status will say “Success” and it will signal that some items have been returned. Especially the Processor information can take a while until valid data is returned. You can click the green circle to refresh the data. When you have proper data, click “Create Graphs for this Host” at the top of the page. Add all data queries for “SNMP – Get Mounted Partitions” and “SNMP – Get Processor Information“. For “SNMP – Interface Statistics“, select the eth interfaces you wanna monitor, then select the graph from the dropdown on the lower right. For example “Traffic (bytes/sec, Total Bandwidth)“. You can come back later to this screen to create more interface related graphs. Confirm the next screen with the “Create” button.

Now select the Devices from the menu on the left. Select your newly created device from the list, select “Place on a Tree (default Tree)” from the dropdown on the bottom right and click “Add”. Confirm by clicking “yes”.

Now go to the “graphs” tab again. As before, you’ll most likely see nothing when looking at your new device, just wait for it ;)

That should be sufficient to get you started. Have fun.

Supernova

August 18th, 2008

While working on a reference implementation in Actionscript for a demo effect, I accidentally ended up with this beauty. It’s based on the lovely City Traveler algorithm by Jared Tarbell with only a few minor adjustments actually. I thought I’d share nevertheless :) Be sure to stop it at some point, otherwise it will go on and on forever, eating up you cpu time.

As always, I also provide a larger version.

You can also dig out the source from the Processing repository, but it’s now buried under the more recent revision of the effect i was actually going for. So if you’re interested, better drop me a line ;)