npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

kotlik

v1.0.5

Published

A state machine system for CTF games

Downloads

100

Readme

Kotlik

Kotlik is a simple API for CTF games (sifrovacky). It is written to be a modular state-machine based API, which can be easily extended and modified.

Setup

You can install the package using npm install kotlik command.

Usage

To use Kotlik, you need to call the createServer function and pass the configuration object to it. The configuration object should contain the following properties:

  • port: The port on which the server should listen
  • sql: MySQL configuration object (host, user, password, database, port)
  • handlers: Message handlers definition
  • dashboard: Dashboard configuration object (password)
  • onCreated: Function that is called when the server is created
  • defaultTeamState: Default team state object
  • defaultAppState: Default app state object
  • additionalAdminInfo: Additional information sent to the admin dashboard

Handlers

Handlers are the core of the Kotlik API. They are used to define the behavior of the server. The handlers are defined in the handlers property of the configuration object. The handlers property should be an object, where the keys are the messages the server should react to and the values are the handler functions. The keys must be in lowercase and without spaces or diactitics. The function takes the following parameters:

  • state - The current team state
  • modules - Server modules for handling different actions
  • server - object containing access to the MySql database and the http server

The function should return a promise that resolves to the new state of the team.

Modules

Modules provide functionality on top of the core server behavior. Currently, the following modules are available:

  • scheduler - Handling scheduled events
  • messenger - Sending messages to the teams
  • events - Storing checkpoint times
  • state - Handling the app state sent to the players

Example

A simple example can be found in the example directory.

import dotenv from "dotenv";
import moment from "moment";
import "moment/locale/cs";
import { createServer } from "kotlik";
dotenv.config();

moment.locale("cs");

type TeamState = {
    pings: number;
};
type AppStateType = {};

createServer<TeamState, AppStateType>({
    port: (process.env.PORT as any) || 3000,
    sql: {
        host: process.env.MYSQL_HOST,
        user: process.env.MYSQL_USER,
        password: process.env.MYSQL_PASSWORD,
        database: process.env.MYSQL_DATABASE,
        port: (process.env.MYSQL_PORT as any) || 3306,
    },
    handlers: {
        ping: async (state, modules, server) => {
            await modules.messenger.message("server", "pong");

            return { ...state, pings: state.pings + 1 };
        },
    },
    onCreated: async (server) => {
        console.log(
            `[server]: Server is running at http://localhost:${
                (process.env.PORT as any) || 3000
            }`
        );
    },
    dashboard: {
        password: process.env.ADMIN_PASSWORD!,
    },
    defaultTeamState: {
        pings: 0,
    },
    defaultAppState: {},
    additionalAdminInfo: {},
});