Since I’ve been busy waiting for Apple’s website to come up, I’ve been working on an overhaul to the CLOT framework. For those who don’t know, CLOT stands for “Custom Ladder or Tournament” and it’s a way for software engineers to create their own WarLight ladders or tournaments. Ladders and tournaments created by CLOT are very flexible, and can do all sorts of things that the built-in ladders and tournaments cannot. See the original blog post for examples of what it can do.
This overhaul was aimed at making CLOTs easier to test via a test mode, making the code simpler and easier to understand, making the app use fewer resources, and implementing many of the commonly needed features, such as hosting multiple tournaments from a single website or handling vote-to-end gracefully.
You can check out the code at github.com/FizzerWL/CLOT.
If you look in api.py, there’s a line that says TestMode = False. By changing this to True, you’ll enable test mode which allows you to test your app offline using fake data.
In test mode, the app won’t hit warlight.net APIs at all, and instead when the code tries to call an API, it will return fake data. This is useful while building your app since you can easily simulate players signing up and see how games get created with them. You can do things like simulate 500 players signing up to your tournament, which would be very time consuming to do by hand.
When you’ve got everything working perfectly, all you have to do is set TestMode back to False and release!
Easier to Understand
The code has been simplified. First, the Django framework was completely removed. Django is a large framework with lots of features, and CLOT hardly used any of them. It was just overkill for our needs.
Instead, it simply uses the webapp2 framework, which is built-in to Google App Engine (GAE) and it’s the same framework that the GAE tutorial walks you through learning. It’s a lightweight framework that’s very simple. It’s much easier to understand than Django.
CLOT was using Django for forms (making it easy to get input from the user). To replace this, I introduced WTForms which is also pretty lightweight and easy to use. CLOT only uses forms in a couple places, such as first-time setup, so you probably won’t need to mess with it much.
The data storage system was upgraded to use “ndb” in place of “db”. This is Google’s upgraded storage system which has a cleaner API and uses automatic caching when getting entities by key. Also, the GamePlayer table was removed for simplicity, and players are now just stored as a list in the Game table.
Uses Fewer Resources
CLOT now uses a caching layer that causes it to use drastically fewer calls to the database. The goal of this is to run a moderately popular CLOT on Google App Engine and not exceed the free quota. I ran a real-time ladder for seven hours, and it used less than 10% of the daily free database quota.
Implements Commonly-Needed Features
The base CLOT code now does a lot more for you. For example, it allows you to run multiple ladders or tournaments from the same website, whereas before you would have had to build that feature yourself. This involved adding a LOT table (Ladder or Tournament) and mapping all of the games to it.
The app now uses authentication instead of requiring players to copy/paste in their invite token. This allows players to securely add or remove themselves from the ladder/tournament.
If players decline a game or fail to join it before a configurable time limit, the app will now automatically delete the game and count it as a loss for the player who didn’t join or declined.
If players vote to end a game, it no longer breaks the ladder.
CLOT in WarLight 2.0
I’ve mentioned a few times that there are going to be some upgrades to the WarLight APIs once WarLight 2.0 launches. I’ll detail here what’s changing.
The membership rule on the CreateGame API (that CLOT uses), is that you can only use features in games that every player you’re inviting can use. This differs from creating games via the UI, where only the game creator needs access to the feature. For example, if you want to use rounding mode or low luck levels, all players in the game need to be a member, since only members can use rounding mode or low luck levels.
In 2.0, it’s possible for non-members to get access to these features, such as low luck levels or rounding mode. Therefore, when inviting players to a game, as long as they have access to those features, you can use them when inviting them via the API.
Technically, this requirement isn’t changing, it just requires expanding your view from a member/non-member to a more granular permission system. If you want to create a 0% luck CLOT, you need to require that everyone joining the CLOT has access to use 0% luck — it doesn’t matter whether they earned that by leveling up or by purchasing a membership.
When someone is joining your CLOT, you call the ValidateInviteToken API. Today, it just tells you if they’re a member or not. In 2.0, it will tell you exactly what they have access to, such as whether they can use 0% luck or alternative rounding modes.
This means that it will be possible to create CLOTs with non-members using all of the features that WarLight offers to non-members, it just might require that players achieve a certain level before they can join your CLOT.
Also, there’s another related change to the CreateGame API. Today, if you try to use a feature that someone doesn’t have access to, it simply reverts back to the default. For example, if you try to make a 0% luck game and a player doesn’t have access to it, it simply creates the game with 75% luck. In 2.0, it won’t do this, and instead will give you an error message if you use something without access.
This is better if you want to ensure that your settings are being used. You won’t have to worry about some games in your tournament using different settings than others. However, this also means you need to be more careful about letting in someone that doesn’t have access to a feature you need to use, otherwise you won’t be able to make the game. For this reason, you need to be sure and check their permissions before letting them join your CLOT.
Check out CLOT’s getting started guide, and feel free to let me know if you have any questions at firstname.lastname@example.org!