Note: Due to changes with RedHat's hosting service, the website is currently down. There are some (very) early-stage plans to create a bigger, better version. That being said, if you want to see a new KOTH server be built, please voice your support so that we can gauge demand / tailor it to the specific needs of any potential KOTHs to be hosted on it. Here is the official chat room for the project.
The Motivation
The desire for a KOTH server has been around for a while. There have been a couple notable meta discussions about it in the past:
- Creating an official place to become a King of the Hill tester
- How could we run KotHs in a distributed fashion?
By being able to host KOTHs on a server, we can do many things:
- We would no longer need to rely on the OPs machine to perform a run.
- Real-time and massively-multiplayer-online KOTHs are possible.
- The controller can be re-run at any time, with the most recent leaderboard always visible.
- Support for several languages, since it is not based on Stack Snippets.
- Maintain the graphical nature of Stack Snippets, because it's based on a webpage.
The Project
I have created a website http://koth-phinotpi.rhcloud.com/ that is capable of hosting KOTH competitions. It has a couple main features:
- It has a MySQL database to store information. This database is available for KOTH controllers to use.
- It retrieves the KOTH controller files from the author's GitHub repo. I will add support for other locations when the demand arises.
- It allows anyone to view the leaderboard of / run any of the KOTHs.
- The format of the report is highly customizable by the KOTH author.
I am basing my project off of the OpenShift hosting platform by RedHat.
How to Use
Have a repository
Your controller code should be located in a repository for easy cloning by the server. I currently have support for GitHub repositories (which can improve upon demand). Provided your username and repo name, the server clones/pulls the files from that repository to run.
The two parts of a KOTH
In order to function on my server, your KOTH needs to have two commands that can be run. First is the command that runs the main controller. This main controller should be where time-intensive, background-worthy stuff should happen. The controller is run as a daemon in the background, and does not print results directly to the screen. Instead, it should write to results files or the database. Here are two example commands.
perl controller.pl
javac *.java; java Tournament
The second one is what you would do if multiple commands needed to be run, such as compiling all of the entries first.
The second command is a command to return the results to be printed to the screen. These results should be HTML/Javascript which will be shown to the user (as part of the body portion of the web page). Here are some examples:
perl webview.pl
cat leaderboard.txt
The first runs a program that was written by the KOTH author, while the second simply returns a file generated by the main controller.
Ideas for how to use this setup
- Regular KOTHs: The controller is like a regular controller which prints to a file instead of the screen. The report viewing program prints the file.
- Real-time KOTHs: The controller runs (almost) continuously, updating the database with the current information. The viewer uses the database information to create a display for the user to see what is currently happening.
- Stack Snippet-like KOTHs: The controller does very little. The viewer returns the HTML/JavaScript similar to how a Stack Snippet would, so that the user may run it.
Supported Languages
The languages which I believe this site can currently support are:
- Perl (5.10)
- Java
- Ruby
- Python (2.6.6)
- C / C++
- PHP
Using the MySQL Database
Your programs can access the database and use it to store information. The connection details for the database are passed as environmental variables to your program. These are:
OPENSHIFT_MYSQL_DB_HOST
OPENSHIFT_MYSQL_DB_PORT
OPENSHIFT_MYSQL_DB_USERNAME
OPENSHIFT_MYSQL_DB_PASSWORD
Configuration
I maintain the list of current/active KOTHs in this settings file. The template for each entry is:
koth [KOTH-repo-name]
github [github-username]
name [a longer, multi-word name]
description [a description]
controller [command]
webview [command]
Two examples are as follows. The first one is for a Perl KOTH.
koth servertest
github PhiNotPi
name Server Test
description This is an example KOTH for testing.
controller perl {filepath}controller.pl
webview perl {filepath}webview.pl
and this next one is for a Java KOTH.
koth NanoCoreWar
github PhiNotPi
name The Nano Core War
description A core-wars-inspired KOTH with a minimalist instruction set.
controller javac *.java; java Tournament
webview cat leaderboard.txt
The {filepath}
is replaced by my website as the absolute file path to the file created from cloning the repository. It is usually not actually needed because the server changes its working directory to that file path before executing the commands.
This settings file should, theoretically, be the only thing I need to update to add a new KOTH to the server. Deactivating a KOTH should be as easy as removing its name from the top line.
To-Do List
This is a work-in-progress. There are many things that still need to be done.
- Making it look nicer?
- Managing security. Creating a way to limit the power of controllers to only mess around with their own files. I don't anticipate actual malice on the part of PPCG users, but stuff can break accidentally. Right now, I simply set their working directories at the start.
- Better update control. I can manually wipe/re-update any of KOTHs in one fell swoop very easily, but that would usually erase too much stuff. On the other hand, updating may not be a thing we should let every website visitor do.
- It needs more testing/proof-of-concept-ing for real-time KOTHs, since that is a major design goal, but I am unaware of any that currently exist.
- Reduce the downtime involved in updating the site. I think there's actually a feature of the OpenShift platform to help with this, although I will have to look into it.