docs/Login Flow

Login Flow & Authentication

Complete sequence from ENet connect to world entry

Sequence Diagram

Client                          Server
  |                                |
  +- ENet Connect ---------------->|  CONNECT event
  |                                |  allocate Player*
  |<- Welcome (type 1) ------------|  send_(peer, 1, ...)
  |                                |
  +- Login Packet (type 2) ------->|  tankIDName|user
  |   protocol|225                 |  tankIDPass|pass
  |   game_version|5.53            |  requestedName|
  |   fz|...                       |  f|1
  |   klv|...                      |  protocol|225
  |   hash|...                     |  game_version|5.53
  |   mac|...                      |  fz|23314424
  |   rid|...                      |  klv|037fbb...
  |                                |  hash|466084983
  |                                |  mac|9c:12:21:08:xx:xx:xx
  |                                |  country|us
  |                                |  RTENDMARKERBS1001
  |                                |
  |<- OnSuperMainStart (OSM) ------|  Type 4 binary
  |   (world list, user data,      |  NetID, userID,
  |    items, currency, etc.)      |  skin, clothes,
  |                                |  currency, etc.
  |                                |
  +- Join Request (type 3) ------->|  action|join_request
  |   action|join_request|WORLD    |  WORLD_NAME
  |                                |
  |<- World Data ------------------|  Type 4 packets
  |   - World blocks               |  - World header
  |   - Player spawn               |  - Tile data
  |   - Other players              |  - Player spawns
  |                                |
  |<- OnConsoleMessage ------------|  "Welcome to WORLD"
  |                                |
  +- Gameplay begins ------------->|  Type 4 binary packets

Login Packet Fields

FieldExampleDescription
tankIDNameMyUsernameAccount username
tankIDPassMyPasswordAccount password (plaintext)
requestedName""Name change request (usually empty)
f1Platform flag
protocol225Protocol version (must match server)
game_version5.53Client game version
fz23314424Fingerprint/hash
klv037fbb624f...Key lineage value (64-char hex)
hash466084983Account hash
mac9c:12:21:08:xx:xx:xxMAC address
rid026F4146...Device RID (32-char hex)
countryusCountry code
platformID0,1,1Platform identifiers

OnSuperMainStart (OSM) Response

The OSM is the critical response packet sent after successful authentication. It contains all data needed for the client to begin gameplay:

  • Player identity: NetID, userID, skin, clothes, colors
  • Currency: Gems, World Locks, Diamond Locks, Blue Gem Locks
  • Inventory: Full item list with counts
  • World list: Available worlds, last world
  • Social: Friends list, ignored players
  • Flags: VIP, moderator, supporter, roles
  • Playmods: Active effects with timers
  • Settings: Audio, graphics, privacy

The OSM is a type 4 binary packet built via gamepacket_t with structured serialization.

Server-Side Processing

Rate Limiting

// Reset counters every 6.5 seconds
if (Server_Security.login_time + 6500 < now_ms()) {
    Server_Security.login_count = 0;
    Server_Security.update_item_data = 0;
    Server_Security.login_time = now_ms();
}

// Limit concurrent logins per IP
int logged = count_peers_with_same_ip(peer->ip);
if (logged >= 3 || Server_Security.login_count > 40) {
    failed_login(peer, "Too many people logging in");
    return;
}

Server_Security.login_count++;

Authentication

  1. Parse login packet fields
  2. Check RID bans (Server_Security.ridbans)
  3. Load player JSON from players/{name}_.json
  4. Verify password hash
  5. Load inventory, clothes, currency, flags
  6. Apply playmods, check expirations
  7. Build and send OSM response
  8. Set pInfo(peer)->bypass = true for type 3 packets

Join Request & World Entry

// Client sends (type 3):
action|join_request|WORLD_NAME

// Server processes:
1. Load world (get_world) - creates or loads from JSON
2. Send world header (size, weather, locks, etc.)
3. Send tile data (PackBlockType for each tile)
4. Send player spawn (OnSpawn with NetID, position, clothes)
5. Send other players in world (OnSpawn for each)
6. Send OnConsoleMessage "Welcome to WORLD_NAME"

Load Testing Tool

A bundled test tool simulates 60 concurrent clients:

  • Generates unique names: faker{id}_{timestamp}
  • Sends login packet with all required fields
  • Waits for OnSuperMainStart detection
  • Sends action|join_request|START
  • Logs connection metrics (connected, login sent, OSM received, join sent)

Useful for load testing and protocol debugging.