2015-10-27 21:21:06 -07:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"../../internal/server"
|
|
|
|
"fmt"
|
|
|
|
"github.com/abiosoft/ishell"
|
2015-10-28 18:12:20 -07:00
|
|
|
"github.com/gorilla/websocket"
|
2015-10-27 21:21:06 -07:00
|
|
|
"runtime"
|
2015-10-28 17:24:21 -07:00
|
|
|
"strings"
|
2015-10-27 21:21:06 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
func commandLineConsole() {
|
|
|
|
|
|
|
|
shell := ishell.NewShell()
|
|
|
|
|
2015-11-08 16:44:16 -08:00
|
|
|
shell.Register("help", func(args ...string) (string, error) {
|
|
|
|
shell.PrintCommands()
|
|
|
|
return "", nil
|
|
|
|
})
|
|
|
|
|
2015-10-27 21:21:06 -07:00
|
|
|
shell.Register("clientcount", func(args ...string) (string, error) {
|
|
|
|
server.GlobalSubscriptionInfo.RLock()
|
|
|
|
count := len(server.GlobalSubscriptionInfo.Members)
|
|
|
|
server.GlobalSubscriptionInfo.RUnlock()
|
|
|
|
return fmt.Sprintln(count, "clients connected"), nil
|
|
|
|
})
|
|
|
|
|
|
|
|
shell.Register("globalnotice", func(args ...string) (string, error) {
|
|
|
|
msg := server.ClientMessage{
|
|
|
|
MessageID: -1,
|
|
|
|
Command: "message",
|
|
|
|
Arguments: args[0],
|
|
|
|
}
|
|
|
|
server.PublishToAll(msg)
|
|
|
|
return "Message sent.", nil
|
|
|
|
})
|
|
|
|
|
2015-10-28 17:24:21 -07:00
|
|
|
shell.Register("publish", func(args ...string) (string, error) {
|
|
|
|
if len(args) < 4 {
|
|
|
|
return "Usage: publish [room.sirstendec | _ALL] -1 reload_ff 23", nil
|
|
|
|
}
|
|
|
|
|
|
|
|
target := args[0]
|
|
|
|
line := strings.Join(args[1:], " ")
|
|
|
|
msg := server.ClientMessage{}
|
|
|
|
err := server.UnmarshalClientMessage([]byte(line), websocket.TextMessage, &msg)
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
|
|
|
|
var count int
|
|
|
|
if target == "_ALL" {
|
|
|
|
count = server.PublishToAll(msg)
|
|
|
|
} else {
|
|
|
|
count = server.PublishToChat(target, msg)
|
|
|
|
}
|
|
|
|
return fmt.Sprintf("Published to %d clients", count), nil
|
|
|
|
})
|
|
|
|
|
2015-10-27 21:21:06 -07:00
|
|
|
shell.Register("memstatsbysize", func(args ...string) (string, error) {
|
|
|
|
runtime.GC()
|
|
|
|
|
|
|
|
m := runtime.MemStats{}
|
|
|
|
runtime.ReadMemStats(&m)
|
|
|
|
for _, val := range m.BySize {
|
|
|
|
if val.Mallocs == 0 {
|
|
|
|
continue
|
|
|
|
}
|
2015-11-01 13:17:35 -08:00
|
|
|
shell.Print(fmt.Sprintf("%5d: %6d outstanding (%d total)\n", val.Size, val.Mallocs-val.Frees, val.Mallocs))
|
2015-10-27 21:21:06 -07:00
|
|
|
}
|
|
|
|
shell.Println(m.NumGC, "collections occurred")
|
|
|
|
return "", nil
|
|
|
|
})
|
|
|
|
|
2015-11-08 16:44:16 -08:00
|
|
|
shell.Register("authorizeeveryone", func(args ...string) (string, error) {
|
|
|
|
if len(args) == 0 {
|
|
|
|
if server.Configuation.SendAuthToNewClients {
|
|
|
|
return "All clients are recieving auth challenges upon claiming a name.", nil
|
|
|
|
} else {
|
|
|
|
return "All clients are not recieving auth challenges upon claiming a name.", nil
|
|
|
|
}
|
|
|
|
} else if args[0] == "on" {
|
|
|
|
server.Configuation.SendAuthToNewClients = true
|
|
|
|
return "All new clients will recieve auth challenges upon claiming a name.", nil
|
|
|
|
} else if args[0] == "off" {
|
|
|
|
server.Configuation.SendAuthToNewClients = false
|
|
|
|
return "All new clients will not recieve auth challenges upon claiming a name.", nil
|
|
|
|
} else {
|
|
|
|
return "Usage: authorizeeveryone [ on | off ]", nil
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2015-11-01 13:17:35 -08:00
|
|
|
shell.Register("panic", func(args ...string) (string, error) {
|
|
|
|
go func() {
|
|
|
|
panic("requested panic")
|
|
|
|
}()
|
|
|
|
return "", nil
|
|
|
|
})
|
|
|
|
|
2015-10-27 21:21:06 -07:00
|
|
|
shell.Start()
|
|
|
|
}
|