Tic-tac-toe on DNS

    Initially, I wanted to call this post “a game of 0 lines of HTML, JS and CSS,” inspired by this post , but that would be too loud. Anyway, greatly degrading the UX, I got tic-tac-toe, working exclusively with the power of the DNS protocol.



    For an unprepared user it looks, of course, scary, but even the browser is not needed for the game.

    In order to enter the game, you need to execute the following command, which involves accessing my dns-server:

    $ dig @ns.f1remoon.com game.f1remoon.com. TXT
    

    I also made a small help, which is available in TXT records by domain help.game.f1remoon.com:



    How it works?


    At first I tried to just set up bind9 correctly, but I was very upset: the order of issuing TXT records was random. This, of course, brought some exoticism into the game, but was absolutely unacceptable. I had to drop the idea and look towards the samopisny DNS server. Armed with the desire to learn something new, I took the golang and Go DNS library and it turned out to be a simple server, not much different from the examples.

    The next difficulty was all the combinations of the game. There is a big thanks to Sirion : I took its html-files and translated it in a format that suits me.

    Since the dig command, unlike the browser, does not store the url and does not allow you to poke around the field, you will have to leave it to the user. For the game, the field was marked as numpad:

    7 8 9
    4 5 6
    1 2 3
    

    When requesting a move, you should always give the full history of moves in the reverse, for example, the command for the third move in the cell “9” will look like

    $ dig @ns.f1remoon.com 9.4.5.game.f1remoon.com. TXT
    

    Full withdrawal of three moves
    $ dig @ns.f1remoon.com 5.game.f1remoon.com. TXT
    ; <<>> DiG 9.11.3-1ubuntu1.1-Ubuntu <<>> @ns.f1remoon.com 5.game.f1remoon.com. TXT
    ; (1 server found)
    ;; global options: +cmd
    ;; Got answer:
    ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 12656
    ;; flags: qr rd; QUERY: 1, ANSWER: 3, AUTHORITY: 0, ADDITIONAL: 0
    ;; WARNING: recursion requested but not available
    ;; QUESTION SECTION:
    ;5.game.f1remoon.com.           IN      TXT
    ;; ANSWER SECTION:
    5.game.f1remoon.com.    0       IN      TXT     "o""_""_"
    5.game.f1remoon.com.    0       IN      TXT     "_""x""_"
    5.game.f1remoon.com.    0       IN      TXT     "_""_""_"
    ;; Query time: 135 msec
    ;; SERVER: 159.65.145.145#53(159.65.145.145)
    ;; WHEN: Sun Aug 05 20:16:16 UTC 2018
    ;; MSG SIZE  rcvd: 148
    $ dig @ns.f1remoon.com 4.5.game.f1remoon.com. TXT
    ; <<>> DiG 9.11.3-1ubuntu1.1-Ubuntu <<>> @ns.f1remoon.com 4.5.game.f1remoon.com. TXT
    ; (1 server found)
    ;; global options: +cmd
    ;; Got answer:
    ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 9301
    ;; flags: qr rd; QUERY: 1, ANSWER: 3, AUTHORITY: 0, ADDITIONAL: 0
    ;; WARNING: recursion requested but not available
    ;; QUESTION SECTION:
    ;4.5.game.f1remoon.com.         IN      TXT
    ;; ANSWER SECTION:
    4.5.game.f1remoon.com.  0       IN      TXT     "o""_""_"
    4.5.game.f1remoon.com.  0       IN      TXT     "x""x""o"
    4.5.game.f1remoon.com.  0       IN      TXT     "_""_""_"
    ;; Query time: 131 msec
    ;; SERVER: 159.65.145.145#53(159.65.145.145)
    ;; WHEN: Sun Aug 05 20:16:23 UTC 2018
    ;; MSG SIZE  rcvd: 156
    $ dig @ns.f1remoon.com 9.4.5.game.f1remoon.com. TXT
    ; <<>> DiG 9.11.3-1ubuntu1.1-Ubuntu <<>> @ns.f1remoon.com 9.4.5.game.f1remoon.com. TXT
    ; (1 server found)
    ;; global options: +cmd
    ;; Got answer:
    ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 40450
    ;; flags: qr rd; QUERY: 1, ANSWER: 3, AUTHORITY: 0, ADDITIONAL: 0
    ;; WARNING: recursion requested but not available
    ;; QUESTION SECTION:
    ;9.4.5.game.f1remoon.com.       IN      TXT
    ;; ANSWER SECTION:
    9.4.5.game.f1remoon.com. 0      IN      TXT     "o""_""x"
    9.4.5.game.f1remoon.com. 0      IN      TXT     "x""x""o"
    9.4.5.game.f1remoon.com. 0      IN      TXT     "o""_""_"
    ;; Query time: 131 msec
    ;; SERVER: 159.65.145.145#53(159.65.145.145)
    ;; WHEN: Sun Aug 05 20:16:30 UTC 2018
    ;; MSG SIZE  rcvd: 164
    $
    


    Code repository: github.com/Firemoon777/tic-tac-toe-dns

    UPD: Prototik suggests using the more convenient to play option with the key + short:
    $ dig +short TXT @ns.f1remoon.com 9.4.5.game.f1remoon.com.
    "o""_""x""x""x""o""o""_""_"

    Also popular now: