Apply env vars SSHCHAT_TIMESTAMP and SSHCHAT_THEME

This commit is contained in:
Chris Miller 2020-01-10 00:52:12 +00:00 committed by Andrey Petrov
parent c0a2f32bd4
commit dd2fadd6c1

22
host.go
View File

@ -96,6 +96,28 @@ func (h *Host) Connect(term *sshd.Terminal) {
cfg := user.Config()
cfg.Theme = &h.theme
user.SetConfig(cfg)
env := term.Env()
for _, e := range env {
switch e.Key {
case "SSHCHAT_TIMESTAMP":
if e.Value != "" && e.Value != "0" {
cmd := "/timestamp"
if e.Value != "1" {
cmd += " " + e.Value
}
if msg, ok := message.NewPublicMsg(cmd, user).ParseCommand(); ok {
h.Room.HandleMsg(msg)
}
}
case "SSHCHAT_THEME":
cmd := "/theme " + e.Value
if msg, ok := message.NewPublicMsg(cmd, user).ParseCommand(); ok {
h.Room.HandleMsg(msg)
}
}
}
go user.Consume()
// Close term once user is closed.