# Introducing a KOTH server!

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:

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


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


## Configuration

I maintain the list of current/active KOTHs in this settings file. The template for each entry is:

koth [KOTH-repo-name]
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


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.

# The Website

• Wouldn't Python 2.7.2 make more sense than Python 2.6.6? Or maybe Python 3.4? – mbomb007 Oct 19 '15 at 20:17
• @mbomb007 2.7 would make more sense, it's just that 2.6 came "pre-installed" and I would have to figure out how to update it. – PhiNotPi Oct 19 '15 at 22:04
• I think it'd actually be better if Python 2.7.8, and Python 3.5.x were supported. – Ethan Bierlein Oct 20 '15 at 18:55
• I'm planning a real-time KotH now. I'll take a look at the project in the next couple days and let you know if I see deficiencies there. – Geobits Nov 19 '15 at 15:52
• Are you planning to open-source the project? I've got a few ideas for a server, but I'd like to try them first to see if they're feasible. – user2428118 Jul 9 '16 at 16:46
• Website doesn't work. :/ – Erik the Outgolfer Feb 11 '18 at 13:19
• @EriktheOutgolfer Yeah, unfortunately RedHat recently shut down the particular service that I was using to host the website. They do have some other hosting options, or I could look elsewhere. But I haven't maintained the website because nobody ever requested to use it for anything since I made it in 2015. – PhiNotPi Feb 12 '18 at 12:02
• I had no idea this was a thing – Christopher Feb 15 '18 at 17:33
• Maybe, when the TIO API comes out, you can use any language from there – MilkyWay90 Mar 2 '19 at 17:03
• Is this going anywhere? I got all excited when I saw it, but it's been down for a few years it looks like... – Artemis still doesn't trust SE Apr 9 '19 at 2:03