summaryrefslogtreecommitdiff
path: root/server/chat.go
diff options
context:
space:
mode:
authorraven <citrons@mondecitronne.com>2026-03-20 14:29:52 -0500
committerraven <citrons@mondecitronne.com>2026-03-20 14:29:52 -0500
commitc3d63652a4b80add587ee17f5c9f3773417203ad (patch)
treee26e1d36f912f1bca210e1aaa3e314668d0b010b /server/chat.go
initial commit
Diffstat (limited to 'server/chat.go')
-rw-r--r--server/chat.go61
1 files changed, 61 insertions, 0 deletions
diff --git a/server/chat.go b/server/chat.go
new file mode 100644
index 0000000..a32da17
--- /dev/null
+++ b/server/chat.go
@@ -0,0 +1,61 @@
+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("&f> &" + string([]byte{color}))
+ }
+ return packets
+}