aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--chat.go4
-rw-r--r--process.go33
2 files changed, 31 insertions, 6 deletions
diff --git a/chat.go b/chat.go
index 61e8ca8..6257c8b 100644
--- a/chat.go
+++ b/chat.go
@@ -9,6 +9,10 @@ import (
"github.com/anon55555/mt"
)
+// ChatCmdTimeout is the time needed until a user is warned
+// about a chat command that's taking long to execute.
+var ChatCmdTimeout = 10 * time.Second
+
// SendChatMsg sends a chat message to the ClientConn.
func (cc *ClientConn) SendChatMsg(msg ...string) {
cc.SendCmd(&mt.ToCltChatMsg{
diff --git a/process.go b/process.go
index 5208c97..3fe0c24 100644
--- a/process.go
+++ b/process.go
@@ -5,6 +5,7 @@ import (
"fmt"
"net"
"strings"
+ "time"
"github.com/HimbeerserverDE/srp"
"github.com/anon55555/mt"
@@ -432,12 +433,32 @@ func (cc *ClientConn) process(pkt mt.Pkt) {
srv.swapAOID(&cmd.Pointed.(*mt.PointedAO).ID)
}
case *mt.ToSrvChatMsg:
- result, isCmd := onChatMsg(cc, cmd)
- if !isCmd {
- break
- } else if result != "" {
- cc.SendChatMsg(result)
- }
+ done := make(chan struct{})
+
+ go func(done chan<- struct{}) {
+ result, isCmd := onChatMsg(cc, cmd)
+ if !isCmd {
+ if srv == nil {
+ cc.Log("->", "no server")
+ return
+ }
+
+ srv.Send(pkt)
+ } else if result != "" {
+ cc.SendChatMsg(result)
+ }
+
+ close(done)
+ }(done)
+
+ go func(done <-chan struct{}) {
+ select {
+ case <-done:
+ case <-time.After(ChatCmdTimeout):
+ cmdName := strings.Split(cmd.Msg, " ")[0]
+ cc.SendChatMsg("Command", cmdName, "is taking suspiciously long to execute.")
+ }
+ }(done)
return
}