server/chat_metadata.go (714B)
1 package main 2 3 import "strings" 4 5 func validChatMetadata(data []byte) bool { 6 // Native public messages contain at most one reference, then one voice record. 7 for record := byte(0); record < 2; record++ { 8 if len(data) == 0 { 9 return true 10 } 11 if data[0] != record { 12 continue 13 } 14 length := 13 // Record type and three reference integers. 15 if record == 1 { 16 length = 3 // Record type and two voice bytes. 17 } 18 if len(data) < length { 19 return false 20 } 21 data = data[length:] 22 23 // Both records end in two counted C strings, excluding the terminator. 24 for range 2 { 25 text, ok := readChatString(&data) 26 if !ok || strings.ContainsRune(text, 0) { 27 return false 28 } 29 } 30 } 31 return len(data) == 0 32 }