aboutsummaryrefslogtreecommitdiff
path: root/plugin_chat.go
diff options
context:
space:
mode:
Diffstat (limited to 'plugin_chat.go')
-rw-r--r--plugin_chat.go21
1 files changed, 21 insertions, 0 deletions
diff --git a/plugin_chat.go b/plugin_chat.go
new file mode 100644
index 0000000..a21526f
--- /dev/null
+++ b/plugin_chat.go
@@ -0,0 +1,21 @@
+package proxy
+
+import "sync"
+
+var (
+ onChatMsgs []func(*ClientConn, string) string
+ onChatMsgMu sync.RWMutex
+)
+
+// RegisterOnChatMsg registers a handler that is called
+// when a client sends a chat message that is not a proxy command.
+// The returned string overrides the original message.
+// Later handlers will receive the modified message.
+// Handlers are called in registration order.
+// If the final message is empty, it is not forwarded to the upstream server.
+func RegisterOnChatMsg(handler func(*ClientConn, string) string) {
+ onChatMsgMu.Lock()
+ defer onChatMsgMu.Unlock()
+
+ onChatMsgs = append(onChatMsgs, handler)
+}