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' ) for in.Len() > 0 { for { b, err := in.ReadByte() if b > 127 { b = '?' } if err == nil { if b == '&' || b == '%' { if word.Len() + 1 >= 64 { line.WriteString(word.String()) word.Reset() } next, err := in.ReadByte() in.UnreadByte() if err != nil { word.WriteString("& ") } else if (next >= '0' && next <= '9') || (next >= 'a' && next <= 'f') { b = '&' color = next } } word.WriteByte(b) } if line.Len() + word.Len() > 64 { break } if err != nil { line.WriteString(word.String()) word.Reset() break } if word.Len() >= 64 || b == ' ' { line.WriteString(word.String()) word.Reset() } } packet := &classic.Message { Message: classic.PadString(line.String()), } packets = append(packets, packet) line.Reset() line.WriteString("&7> &" + string([]byte{color})) } return packets }