Skip to content

Instantly share code, notes, and snippets.

@TrueBrain
TrueBrain / change_x_to_u.py
Last active December 14, 2020 18:49
Replace \x escape in C-strings to \u escape
import re
import sys
def replace_utf8(match):
char = match.group(0)
char = chr(int(char[2:4], 16)) + chr(int(char[6:8], 16))
char = char.encode("raw_unicode_escape").decode()
char = char.encode("unicode_escape").decode()
char = char.replace("\\x", "\\u00")
@TrueBrain
TrueBrain / proposal-milek7.md
Last active December 19, 2020 22:10
OpenTTD multiplayer

Decentralized local authentication

Use a public key (pubkey) / secret key (secret) to authenticate yourself with the server. At login, you authenticate yourself to the server. If you protect your company, this is done based on your pubkey. This means that only you with the correct secret can still join that company.

A server stores this pubkey in the savegame, to make company protections survive restarts.

Server sharing pubkeys

@TrueBrain
TrueBrain / network-improvements.md
Last active December 23, 2020 14:04
OpenTTD Network Improvements

Phase 1 - Add crypto

  • Add crypto library to OpenTTD
  • Generate a single crypto-based unique identifier on clients
  • On joining the server, the client gives the server his crypto-based unique identifier
  • The server challenges the client to validate he is the owner of this crypto-based unique identifier
  • On creating a new company, the server adds the unique identifier to the access list of the company
  • On joining a company, before a password is asked, the server checks if you are on the access list of the company, and lets you in passwordless if you are
  • The crypto-based unique identifiers who have access to companies are stored in the savegame
  • Reloading a savegame on the same server keeps the access list intact
@TrueBrain
TrueBrain / extension.md
Last active January 6, 2021 14:57
GameScript identities

This is meant as extension on: https://wiki.openttd.org/en/Development/Design%20Drafts/Scripts/Capability-based%20API

In addition to having capabilities, GS would benefit from being able to instantiate controllers for certain objects.

For example, take a town. Currently either a GS controls all towns or it doesn't. By adding capabilities, as written in the wiki, it can either share all towns with other GSes or keep them all for him self. I would propose a more fine-graned method: instances.

Every GS has a function like: HasInstanceFor(capability). As example: HasInstanceFor(TownGrowth). The GS either returns 0 if it has nothing for this capability, or N with N > 0 for how many different forms it has for this instance. Next, OpenTTD adds up all the Ns, picks a random number in range, and selects that GS + index to handle that town now forths. For example: GetInstanceFor(TownGrowth, 2).

@TrueBrain
TrueBrain / workflow.md
Last active February 2, 2021 18:44
Title game competition
  • Organiser announces title game competition, and give an end-date for entries.
  • After end-date, organiser adds all savegames + metadata to git repo (say, OpenTTD/title-game-competition).
  • GitHub Actions generates the required screenshots + Markdown for it, and publishes this in another branch (say, "output"), which is published via GitHub Pages (read: available via https).

  • Organiser creates a "QA" Discussion thread for Title Game Competition.
  • Each entry will be its own reply.
  • People can upvote the reply if they like it.
  • After closing, we have a winner.
[SDT_OMANY]
var = game_creation.landscape
type = SLE_UINT8
from = SLV_97
guiflags = SGF_MULTISTRING | SGF_NEWGAME_ONLY
def = 0
max = 3
full.LT_TEMPERATE = temperate, 0
full.LT_ARCTIC = arctic, 1, subartic
full.LT_TOPIC = tropic, 2, subtropic
@TrueBrain
TrueBrain / network-debug-levels.md
Created July 11, 2021 10:33
Network debug levels

It now follows very simple rules:

  • 0 - Fatal, user should know about this
  • 1 - Error, but we are recovering
  • 2 - Warning, wrong but okay if you don't know
  • 3 - Info, information you might care about
  • 4 -
  • 5 - Debug #1 - High level debug messages
  • 6 - Debug #2 - Low level debug messages
  • 7 - Trace information
@TrueBrain
TrueBrain / quick-howto-guide.md
Last active July 17, 2021 17:39
Quick how-to guide in setting up development setup for game coordinator

This guide is build for WSL2 / Linux. For Windows it is also possible, but I can never remember Powershell syntax.

The beginning (one-time effort)

Get Python3.8+. Create a venv (for Debian, install python3-virtualenv package first):

python3 -m venv venv
@TrueBrain
TrueBrain / checklist.md
Last active July 18, 2021 17:39
Checklist for master -> main

Few things happening for each repository:

  • Rename "master" into "main"
  • Cleanup workflows to use the new centralized versions (instead of custom shell-scripts copied everywhere)
  • Enable the "check annotation" step
  • Ensure "default" branch can be anything configured

Repositories left to do:

  • aws
@TrueBrain
TrueBrain / network-todo.md
Last active August 10, 2021 20:13
Network TODO list

GC = Game Coordinator

Cleanup

  • ✓ Server name not empty (or default to "playername's server"?)

Client Info

  • 9114 Add GAME_INFO to TCP and use it for lobby
  • 9469 Sync NetworkGameInfo from server with all clients, so clients locally know the server they are on (and sync servername changes when they happen); possibly only sync information client doesn't already know via a Command packet.
  • 9469 Show server name in GUI