Fix legacy client detection

This commit is contained in:
Trevor Slocum 2024-08-30 14:00:42 -07:00
parent dc5e2bfea5
commit ef40f1443a
2 changed files with 19 additions and 5 deletions

View file

@ -22,11 +22,11 @@ Clients must send a register command, reset command or login command before send
- Register an account. A valid email address must be provided.
- Usernames must contain at least one non-numeric character.
- `registerjson <client name> <email> <username> <password>`
- `registerjson <client> <email> <username> <password>`
- Register an account and enable JSON formatted responses.
- All client applications should use the `registerjson` command to register, as JSON
formatted responses are more easily parsed by computers.
- The name of the client must be specified.
- The client field is specified as follows: `example-client-v1.2.3/en`
- Aliases: `rj`
- `resetpassword <email>`
@ -37,11 +37,11 @@ formatted responses are more easily parsed by computers.
- Log in. A random username is assigned when none is provided.
- Usernames must contain at least one non-numeric character.
- `loginjson <client name> [username] [password]`
- `loginjson <client> [username] [password]`
- Log in and enable JSON formatted responses.
- All client applications should use the `loginjson` command to log in, as JSON
formatted responses are more easily parsed by computers.
- The name of the client must be specified.
- The client field is specified as follows: `example-client-v1.2.3/en`
- Aliases: `lj`
- `password <old> <new>`

View file

@ -347,18 +347,32 @@ func logClientRead(msg []byte) {
}
func legacyClient(clientName []byte) bool {
// Strip language.
slash := bytes.IndexByte(clientName, '/')
if slash != -1 {
clientName = clientName[:slash]
}
// Split by hyphens.
split := bytes.Split(clientName, []byte("-"))
if len(split) == 0 {
return true
} else if !bytes.Equal(split[0], []byte("boxcars")) {
}
// Only Boxcars requires legacy support.
if !bytes.Equal(split[0], []byte("boxcars")) {
return false
}
// Parse version information.
last := split[len(split)-1]
lastSplit := bytes.Split(last, []byte("."))
if len(lastSplit) != 3 {
return true
}
major, minor := parseInt(lastSplit[0]), parseInt(lastSplit[1])
// Boxcars releases before v1.4.0 require legacy support.
return major < 1 || (major == 1 && minor < 4)
}