It’s that time- time to review the results from the OMGWTF2 programming contest.

 var procs = from proc in Process.GetProcesses()
                        where proc.ProcessName == "java"
                        select proc;

foreach (var proc in procs)
{
	proc.Kill();
}

It was this block of code that leapt out to us when we were looking through this entry. Even better was the comment above it:

// Kill any remaining minecraft server apps.  They have a process name of "java",
// whereas the minecraft client uses a process name of "javaw".

Right away, this made jgordon615’s entry a strong candidate for some kind award. But we needed to go deeper, and see exactly how this was implemented.

jgordon615’s entry involves three major architectural elements. First, there’s Web Host, an ASP.NET, WebAPI application. It serves up a Minecraft viewer using WebGL/three.js. This component spins up a Minecraft server process, and tracks a reference from the Application variable.

Inside of the Minecraft server, a redstone circuit does the work of generating a random output. But how, oh how, can IIS communicate with this Minecraft machine?

It sends commands to STDIN, using the weather and the time of day in the Minecraft world to control the behavior of the redstone circuit. But how does it get the output?

STDERR of course! This is, in part, a Minecraft WTF- normal output goes straight to STDERR. The Host.cs file defines the communication “protocol” for both the input and output channels.

Minecraft, of course, is a multiplayer game, and that means none of this works unless someone is actually playing Minecraft. Without a logged in player, in only ever outputs “Yes” Fortunately, there’s a client watcher which uses the filesystem to detect if the WebAPI host is running, and if it is, it launches a client.

There’s much more in the code. jgordon615 did us the favor of providing a WTF summary which outlines all of the tricks he used, including checking the registry for what mime type it should be sending back on its responses, his own “threading” solution, built-in race conditions.

This solution was quite the invention. As we reviewed the code, we all had a sense that jgordon615 implemented it while being held prisoner by ill-defined bad guys, armed with only a Swiss Army Knife, duct-tape, a Minecraft server, and the ability to make explosives out of chewing gum. In honor of that achievement, we’re happy to award jgordon615 the MacGyver Award, for the most unexpected and clever solution.

You can get the full code from GitHub.

There are more winners! Stay tuned as the week goes on.