|
nanoMMO 0.97.8
Building an MMO: The Engineering Series
|
An account has up to four characters in each world (kCharactersPerWorld, in protocol/limits.h), each a row in players with an id and a name of its own, which other players see. A name is unique in its world, and follows an account name's rules, 3 to 16 letters, digits and underscores. players has a unique key on the world and the name, and making a character counts and inserts in one statement, so two requests at once can't take one name, or the last place, between them. A new character has no bag yet, so it gets the starting kit as it first enters its world, and the client's preview dresses it in that kit before then. Deleting one deletes its skills and its bag with it, and deleting an account deletes its characters. The client, reading the same number, has no New character once there are four, and the login server turns a fifth away with "You have 4 characters in Ember already."
A new character comes with the looks its player chose for it (LoginRequest's looks, see Making a character), as four places, in the rig's builds and in the figures file's skins, hair colours and ways to wear the hair, which go into players' build, skin, hair_color and hair, from V16, and a fifth, in the client's six players' colours, for the shirt, which goes into shirt, from V17, all in the statement that makes it. A 0.94.0 client sends no shirt, and its character's shirt stays NULL. The login server reads no content, so it can't count those lists, and keeps any place that fits its column, up to 255 (Characters::kMostLook), and refuses one past that with "That isn't a look there is." Each client wraps each place round to what its own lists have, and every client in a world has the same lists, as the figures and the rig are in ClientHash (see Content), so a place out of range draws as a look there is, the same on every screen (decision 44). The characters' listing has each one's looks (CharacterListing's looks), which the client's preview draws it in. A character made without looks, as the bots and the red-team client make theirs, and every character from before 0.94.0, has NULL in all five, and no looks in its listing, and its id picks how it looks, as before. One with a NULL shirt alone gets its looks without one, and its id picks the shirt's colour. Nothing changes a character's looks once it's made. A new character is in no faction, NULL in faction, from V18, until it swears to one in the world (see Factions).
The world plays a character by its id, so Redis keeps it as player:<world>:<id>, and its skills and bag go by that id (see Saving players). V10 made characters from the players there were, one per account and world, named after the account. Ember's kept their account's id, which their looks come from, and the others' came after the largest account id.
The password, the session and the token go over TLS, so nobody between the client and the servers can read them (see TLS).
The servers find MySQL, Redis and Consul on 127.0.0.1, or wherever NANOMMO_MYSQL_HOST, NANOMMO_REDIS_HOST and NANOMMO_CONSUL_HOST point. The tests that need them skip themselves unless those are set. Run them with those set, or all in Docker.
The world server's test starts a server inside the test, on a port the system picks, and has players join it over TLS, with the protocol tests' certificates. The players see each other until one of them leaves, and a character can't play twice at once. The server and the players run on the test's thread, one handler at a time, until what the test waits for happens, or for five seconds at most.
MySQL keeps its data in the mysql volume, and Redis in the redis volume, so they survive docker compose down. Flyway makes the tables, and changes them, before anything else uses MySQL (see Migrations). docker compose down -v deletes the volumes, and with them all the accounts and players.
Everything the clients and the servers send over TCP goes through TLS 1.3, with OpenSSL, through Asio's ssl::stream. That covers logins on port 7778, and the game's connection on port 7777, with the token, the input and, over TCP, the world. Both ends are ours, so they speak TLS 1.3 and nothing older.
The certificates come from a certificate authority of our own. scripts/certificates.sh makes its key, tls/ca.key, and its certificate, tls/ca.crt. Then a key for the servers, tls/server.key, and a certificate the authority signs for it, tls/server.crt, for localhost, 127.0.0.1, and login and server, their names in Docker Compose. The keys are ECDSA, on the P-256 curve. Names after the folder go on the certificate too, such as a server's domain, or its address, which goes on as an IP name. This one adds a domain and an address.
Run again, it keeps what's there. Given a name the certificate lacks, or once the certificate has expired, it signs a new one for the servers, with every name, from the same authority, so the clients' ca.crt still trusts it, and the servers use it once they start again. Delete tls/*.crt and tls/*.key for a new authority. Git ignores them, so each copy of the repo has an authority of its own. Its first argument is the folder, so it refuses an address or a domain there, which would have made a folder of that name.
Only the authority's key can sign certificates the clients trust, so on a real server, keep it somewhere else, as the servers need server.crt and server.key, and the players' clients ca.crt.
The world over UDP isn't encrypted, as it holds what each player sees in the game anyway. Its first datagram, the hello, carries the login token, which the game server took out of Redis by then, so it can't log anyone in. Someone who can see your traffic could use it to send your world updates elsewhere, which someone in that position could stop anyway, by dropping them.
This shows the handshake and the certificate, with the login server running.