mirror of
https://github.com/shazow/ssh-chat.git
synced 2025-04-26 21:32:15 +03:00
add MOTD output and command
This commit is contained in:
parent
cc01deb4bb
commit
0ece568c4f
17
client.go
17
client.go
@ -22,6 +22,7 @@ const HELP_TEXT string = SYSTEM_MESSAGE_FORMAT + `-> Available commands:
|
|||||||
/nick $NAME - Rename yourself to a new name.
|
/nick $NAME - Rename yourself to a new name.
|
||||||
/whois $NAME - Display information about another connected user.
|
/whois $NAME - Display information about another connected user.
|
||||||
/msg $NAME $MESSAGE - Sends a private message to a user.
|
/msg $NAME $MESSAGE - Sends a private message to a user.
|
||||||
|
/motd - Prints the Message of the Day
|
||||||
` + RESET
|
` + RESET
|
||||||
|
|
||||||
const OP_HELP_TEXT string = SYSTEM_MESSAGE_FORMAT + `-> Available operator commands:
|
const OP_HELP_TEXT string = SYSTEM_MESSAGE_FORMAT + `-> Available operator commands:
|
||||||
@ -33,6 +34,7 @@ const OP_HELP_TEXT string = SYSTEM_MESSAGE_FORMAT + `-> Available operator comma
|
|||||||
/kick $NAME - Kick em' out.
|
/kick $NAME - Kick em' out.
|
||||||
/op $NAME - Promote a user to server operator.
|
/op $NAME - Promote a user to server operator.
|
||||||
/silence $NAME - Revoke a user's ability to speak.
|
/silence $NAME - Revoke a user's ability to speak.
|
||||||
|
/motd $MESSAGE - Sets the Message of the Day
|
||||||
` + RESET
|
` + RESET
|
||||||
|
|
||||||
const ABOUT_TEXT string = SYSTEM_MESSAGE_FORMAT + `-> ssh-chat is made by @shazow.
|
const ABOUT_TEXT string = SYSTEM_MESSAGE_FORMAT + `-> ssh-chat is made by @shazow.
|
||||||
@ -311,6 +313,21 @@ func (c *Client) handleShell(channel ssh.Channel) {
|
|||||||
if err := c.Server.Privmsg(parts[1], parts[2], c); nil != err {
|
if err := c.Server.Privmsg(parts[1], parts[2], c); nil != err {
|
||||||
c.Msg <- fmt.Sprintf("Unable to send message to %v: %v", parts[1], err)
|
c.Msg <- fmt.Sprintf("Unable to send message to %v: %v", parts[1], err)
|
||||||
}
|
}
|
||||||
|
case "/motd": /* print motd */
|
||||||
|
if !c.Server.IsOp(c) {
|
||||||
|
c.Server.MotdUnicast(c)
|
||||||
|
} else if len(parts) < 2 {
|
||||||
|
c.Server.MotdUnicast(c)
|
||||||
|
} else {
|
||||||
|
var newmotd string
|
||||||
|
if (len(parts) == 2) {
|
||||||
|
newmotd = parts[1]
|
||||||
|
} else {
|
||||||
|
newmotd = parts[1] + " " + parts[2]
|
||||||
|
}
|
||||||
|
c.Server.SetMotd(c, newmotd)
|
||||||
|
c.Server.MotdBroadcast(c)
|
||||||
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
c.SysMsg("Invalid command: %s", line)
|
c.SysMsg("Invalid command: %s", line)
|
||||||
|
20
server.go
20
server.go
@ -30,6 +30,7 @@ type Server struct {
|
|||||||
lock sync.Mutex
|
lock sync.Mutex
|
||||||
count int
|
count int
|
||||||
history *History
|
history *History
|
||||||
|
motd string
|
||||||
admins map[string]struct{} // fingerprint lookup
|
admins map[string]struct{} // fingerprint lookup
|
||||||
bannedPk map[string]*time.Time // fingerprint lookup
|
bannedPk map[string]*time.Time // fingerprint lookup
|
||||||
bannedIp map[net.Addr]*time.Time
|
bannedIp map[net.Addr]*time.Time
|
||||||
@ -47,6 +48,7 @@ func NewServer(privateKey []byte) (*Server, error) {
|
|||||||
clients: Clients{},
|
clients: Clients{},
|
||||||
count: 0,
|
count: 0,
|
||||||
history: NewHistory(HISTORY_LEN),
|
history: NewHistory(HISTORY_LEN),
|
||||||
|
motd: "Message of the Day! Modify with /motd",
|
||||||
admins: map[string]struct{}{},
|
admins: map[string]struct{}{},
|
||||||
bannedPk: map[string]*time.Time{},
|
bannedPk: map[string]*time.Time{},
|
||||||
bannedIp: map[net.Addr]*time.Time{},
|
bannedIp: map[net.Addr]*time.Time{},
|
||||||
@ -110,8 +112,26 @@ func (s *Server) Privmsg(nick, message string, sender *Client) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *Server) SetMotd(client *Client, motd string) {
|
||||||
|
s.lock.Lock()
|
||||||
|
s.motd = motd
|
||||||
|
s.lock.Unlock()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Server) MotdUnicast(client *Client) {
|
||||||
|
client.SysMsg("/** MOTD")
|
||||||
|
client.SysMsg(" * " + ColorString("36", s.motd)) /* a nice cyan color */
|
||||||
|
client.SysMsg(" **/")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Server) MotdBroadcast(client *Client) {
|
||||||
|
s.Broadcast(ContinuousFormat(SYSTEM_MESSAGE_FORMAT, fmt.Sprintf(" * New MOTD set by %s.", client.ColoredName())), client)
|
||||||
|
s.Broadcast(" /**\r\n" + " * " + ColorString("36", s.motd) + "\r\n **/", client)
|
||||||
|
}
|
||||||
|
|
||||||
func (s *Server) Add(client *Client) {
|
func (s *Server) Add(client *Client) {
|
||||||
go func() {
|
go func() {
|
||||||
|
s.MotdUnicast(client)
|
||||||
client.SendLines(s.history.Get(10))
|
client.SendLines(s.history.Get(10))
|
||||||
client.SysMsg("Welcome to ssh-chat. Enter /help for more.")
|
client.SysMsg("Welcome to ssh-chat. Enter /help for more.")
|
||||||
}()
|
}()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user