Login Server Protocol - kukfa/mmoserver GitHub Wiki
The login server uses an old version of the Lineage II login server protocols, version 785a. Some of the details (e.g. error messages) have been adapted to fit the game.
Packets to and from the login server are encrypted using the Blowfish algorithm in ECB mode with a static key ([;'.]94-31==-%&@!^+]). Additionally, usernames and passwords are encrypted using the DES algorithm in ECB mode with a static key (TEST followed by 4 null-bytes). A checksum algorithm is used to check message integrity.
Each packet begins with a 2-byte field for the packet length, in little-endian order. This is followed by an encrypted blob containing the packet data. Once decrypted, the data consists of a single byte identifying the packet type, followed by the corresponding data for that packet, and the checksum of the data at the end.
Packet Structure Summary
[Length] Description
- [2] Packet length (little-endian)
- [Rest of packet] Blowfish-encrypted data blob, comprised of: 1. [1] Packet type 2. [Variable] Packet data 3. [8] Checksum
Typical Login Sequence
[Sender] Packet type
- (Client initiates TCP connection)
- [S] Init
- [C] RequestAuthLogin
- [S] LoginOK -or- LoginFail
- [C] RequestServerList
- [S] ServerList
- [C] RequestServerLogin
- [S] PlayOK -or- PlayFail
- (Client disconnects from login server and connects to game server)
Client Packets
The following packets are used by the client:
RequestAuthLogin
Used to send the username and password to the server. Expects either LoginOK or LoginFail in response.
Note: Game HTML-encodes the & and < characters, which takes extra space. Credentials are ASCII-only, not Unicode.
Packet structure:
- [1] Packet type (00)
- [30] Credentials, comprised of:
1. [24] DES encrypted credentials
- [14] Username
- [10] Password 2. [6] Unencrypted password bytes that spill over 8-byte block size for encryption (sigh)
- Note: Need to combine these with the 8 decrypted password bytes above
RequestServerList
Requests the list of game servers.
Packet structure:
- [1] Packet type (05)
- [8] Session key
- [7] Null bytes
RequestServerLogin
Request to connect to a game server. Expects either PlayOK or PlayFail in response.
Packet structure:
- [1] Packet type (02)
- [8] Session key
- [1] Server ID
Server Packets
The following packets are used by the server:
InitPacket
Sends a session ID (?) and the protocol version (785a) to the client. Note: This is a special packet that does not use a checksum.
Packet structure:
- [1] Packet type (00)
- [4] Session ID (?)
- [4] Protocol version, little-endian
LoginOK
Approves the client's login request and allows it to move to the next stage.
Packet structure:
- [1] Packet type (03)
- [8] Session key
- [24] Unknown data
* Note: This data takes a specific form
*
00 00 00 00 00 00 00 00 EA 03 00 00 00 00 00 00 00 00 00 00 02 00 00 00
LoginFail
Denies the client's login request.
Reasons:
- 01 -> Cancels login with "Error connecting to server" message
- 02 -> Invalid username or password
- 03 -> Invalid username or password
- 04 -> Cancels login with "Error connecting to server" message
- 05 -> Cancels login with "Error connecting to server" message
- 07 -> Account is already logged in
- 09 -> Cancels login with "Error connecting to server" message
- 10 -> Cancels login with "Error connecting to server" message
- 12 -> Cancels login with "Error connecting to server" message
- 13 -> Cancels login with "Error connecting to server" message
Packet structure:
- [1] Packet type (01)
- [1] Reason
- [6] Null bytes
ServerList
Returns the list of game servers and their status.
Packet structure:
- [1] Packet type (04)
- [1] Total number of game servers
- [1] Last game server used
- [16 * # servers] The following is repeated for each server: 1. [1] Server ID 2. [4] Game server IP address, big-endian order 3. [4] Game server port, little-endian order 4. [1] Age limit (?) 5. [1] PvP (1 if PvP server, 0 otherwise) 6. [2] Current number of players 7. [2] Max number of players 8. [1] Online (1 if server should be listed, 0 otherwise)
- [Variable] Enough null-bytes to bring the total packet size to a multiple of 8
PlayOK
Approves the client's request to connect to a game server.
Packet structure:
- [1] Packet type (07)
- [8] Session key
- [7]
01followed by 6 null-bytes
PlayFail
Denies the client's request to connect to a game server.
Reasons:
- 01 -> Cancels with "Error connecting to server" message
- 02 -> Cancels with "Error connecting to server" message
- 03 -> Cancels with "Error connecting to server" message
- 04 -> Cancels with "Error connecting to server" message
- 0f -> Cancels with "Error connecting to server" message
Packet structure:
- [1] Packet type (06)
- [1] Reason
AccountKicked
Notifies the client their account has been banned.
Reasons:
- 01 -> Access denied (prints message about beta access timeframes)
- 08 -> Blocked
- 10 -> Blocked
- 20 -> Blocked
Packet structure:
- [1] Packet type (02)
- [1] Reason
- [6] Null-bytes