summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorraven <citrons@mondecitronne.com>2026-03-22 00:46:17 -0500
committerraven <citrons@mondecitronne.com>2026-03-22 00:46:17 -0500
commit19c6461ef30974f1c8dfc10051842bac17cbbf60 (patch)
tree3ef5f6bdec26b0e2d1e827dc45e248db847bdb29
parentce89fa4d1d9c6b16e7e5abf9c2417bc104750727 (diff)
fix chat
-rw-r--r--server/chat.go77
1 files changed, 41 insertions, 36 deletions
diff --git a/server/chat.go b/server/chat.go
index d91ca55..4206d66 100644
--- a/server/chat.go
+++ b/server/chat.go
@@ -13,42 +13,9 @@ func processChatMessage(message string) []classic.Packet {
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()
- }
+ endLine := func() {
+ if line.Len() == 0 {
+ return
}
packet := &classic.Message {
Message: classic.PadString(line.String()),
@@ -57,5 +24,43 @@ func processChatMessage(message string) []classic.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
}