diff --git a/protocol/client_query.go b/protocol/client_query.go index a860056..26bfeec 100644 --- a/protocol/client_query.go +++ b/protocol/client_query.go @@ -2,9 +2,29 @@ package protocol import ( "fmt" + "slices" "strings" ) +var supportedClientQueryTypes = buildSupportedClientQueryTypes() + +func buildSupportedClientQueryTypes() []string { + typesList := []string{ + "ATC", "CAPS", "C?", + "RN", "SV", "ATIS", + "IP", "INF", "FP", + "IPC", "BY", "HI", + "HLP", "NOHLP", "WH", + "IT", "HT", "DR", + "FA", "TA", "BC", + "SC", "VT", "ACC", + "NEWINFO", "NEWATIS", "EST", + "GD", "SIMDATA"} + + slices.Sort(typesList) + return typesList +} + type ClientQueryPDU struct { From string `validate:"required,alphanum,max=16"` To string `validate:"required,max=7"` @@ -49,18 +69,7 @@ func (p *ClientQueryPDU) Parse(packet string) error { return err } - switch pdu.QueryType { - case "ATC", "CAPS", "C?", - "RN", "SV", "ATIS", - "IP", "INF", "FP", - "IPC", "BY", "HI", - "HLP", "NOHLP", "WH", - "IT", "HT", "DR", - "FA", "TA", "BC", - "SC", "VT", "ACC", - "NEWINFO", "NEWATIS", "EST", - "GD": - default: + if _, exists := slices.BinarySearch(supportedClientQueryTypes, pdu.QueryType); !exists { return NewGenericFSDError(SyntaxError, fields[2], "invalid query type") } diff --git a/protocol/client_query_response.go b/protocol/client_query_response.go index 685f388..26888b2 100644 --- a/protocol/client_query_response.go +++ b/protocol/client_query_response.go @@ -2,6 +2,7 @@ package protocol import ( "fmt" + "slices" "strings" ) @@ -50,18 +51,7 @@ func (p *ClientQueryResponsePDU) Parse(packet string) error { return err } - switch pdu.QueryType { - case "ATC", "CAPS", "C?", - "RN", "SV", "ATIS", - "IP", "INF", "FP", - "IPC", "BY", "HI", - "HLP", "NOHLP", "WH", - "IT", "HT", "DR", - "FA", "TA", "BC", - "SC", "VT", "ACC", - "NEWINFO", "NEWATIS", "EST", - "GD": - default: + if _, exists := slices.BinarySearch(supportedClientQueryTypes, pdu.QueryType); !exists { return NewGenericFSDError(SyntaxError, fields[2], "invalid query type") }