portfolio / site
This website and kshell
kanetempleton.com is a Go program I run on my own server. It serves these pages, runs the terminal at the top of them, and connects your browser to a game server written in C.
- Built with
- Go, MySQL, JavaScript, HTML and CSS
- Hosting
- A Debian server on AWS, behind Cloudflare
- Earlier versions
- Java (on JBend), then Node.js, then Go
kshell, the terminal at the top
The black box at the top of every page is a shell written in JavaScript. It isn't a decoration. Click it and try these:
help everything it can do
ls the pages of this site, as directories
cd portfolio go to a page without touching the mouse
theme change the colours of the whole site, light or dark
guestbook read the guestbook, or sign it
game start the multiplayer C game
fullscreen give the terminal the whole window
You can register an account from it, and your theme follows you to any device you log in on. Tab completes commands and page names, and the up arrow brings back what you typed before.
How the pages work
Every page is one small HTML fragment. When you click a link, the site fetches just that fragment and swaps it into the page, so the terminal keeps its history and the music keeps playing. If you open the same address directly, the server wraps the same fragment in the full layout, so every link still works on its own and search engines see whole pages.
How the game gets to your browser
your browser my server ┌────────────────────┐ ┌──────────────────────────────────┐ │ C client compiled │ WebSocket│ Go web server TCP C game │ │ to WebAssembly │ ───────► │ (relay) ─────► server │ └────────────────────┘ └──────────────────────────────────┘
The game server only speaks raw TCP and browsers can't, so the Go server carries the bytes between them. The game server itself listens only on the machine it runs on. More about the game is on its development blog.
A second server behind this one
The JBend demo is a separate program: a Java process running JBend, the backend I wrote from scratch, with two more games inside it. It listens only on the machine itself. The Go server passes anything under /JBend/demo/ through to it, WebSockets included, and serves the JBend documentation straight from the repository's files.
your browser ──► Go web server ──► JBend (Java) ──┬── JBGame
│ │ └── bridge ──► 2018 game server
└──── MySQL ──────┘
Both programs keep their data in the same MySQL database, in separate tables.
Running it
- Deploys by git push. A hook on the server checks out the new code, builds it, restarts the service, makes sure it came back up and clears the Cloudflare cache.
- Runs as a service. The web server, the C game server and the JBend demo are systemd services under an ordinary user, and restart themselves if they stop.
- Accounts. Passwords are stored as bcrypt hashes, repeated failed logins from one address are locked out for a while, and session cookies are HTTP-only.