package server import ( "strings" "git.citrons.xyz/metronode/classic" ) func processChatMessage(message string) []classic.Packet { var ( packets []classic.Packet in = strings.NewReader(message) line strings.Builder word strings.Builder color byte = 'f' ) endLine := func() { if line.Len() == 0 { return } packet := &classic.Message { Message: classic.PadString(line.String()), } packets = append(packets, packet) line.Reset() line.WriteString("&7> &" + string([]byte{color})) } endWord := func() { if line.Len() + word.Len() > 64 { endLine() } line.WriteString(word.String()) word.Reset() } for in.Len() > 0 { b, _ := in.ReadByte() if b == '%' { b = '&' } if b == '&' { endWord() word.WriteByte(b) b, _ = in.ReadByte() if (b >= '0' && b <= '9') || (b >= 'a' && b <= 'f') { color = b } word.WriteByte(b) endWord() continue } if b == ' ' { endWord() if line.Len() > 0 { word.WriteByte(b) endWord() } continue } word.WriteByte(b) if word.Len() >= 58 { endWord() } } endWord() endLine() return packets }