mirror of
https://github.com/shazow/ssh-chat.git
synced 2025-04-29 06:41:34 +03:00
Less beeps!
This commit is contained in:
parent
fa224c8935
commit
cd50bf5caa
12
server.go
12
server.go
@ -16,6 +16,9 @@ import (
|
|||||||
const MAX_NAME_LENGTH = 32
|
const MAX_NAME_LENGTH = 32
|
||||||
const HISTORY_LEN = 20
|
const HISTORY_LEN = 20
|
||||||
|
|
||||||
|
const SYSTEM_MESSAGE_FORMAT string = "\033[1;3;90m"
|
||||||
|
const BEEP string = "\007"
|
||||||
|
|
||||||
var RE_STRIP_TEXT = regexp.MustCompile("[^0-9A-Za-z_.-]")
|
var RE_STRIP_TEXT = regexp.MustCompile("[^0-9A-Za-z_.-]")
|
||||||
|
|
||||||
type Clients map[string]*Client
|
type Clients map[string]*Client
|
||||||
@ -78,9 +81,8 @@ func (s *Server) Len() int {
|
|||||||
return len(s.clients)
|
return len(s.clients)
|
||||||
}
|
}
|
||||||
|
|
||||||
const SYSTEM_MESSAGE_FORMAT string = "\033[1;3;90m"
|
|
||||||
func (s *Server) SysMsg(msg string, args ...interface{}) {
|
func (s *Server) SysMsg(msg string, args ...interface{}) {
|
||||||
s.Broadcast(ContinuousFormat(SYSTEM_MESSAGE_FORMAT, " * " + fmt.Sprintf(msg, args...)), nil)
|
s.Broadcast(ContinuousFormat(SYSTEM_MESSAGE_FORMAT, " * "+fmt.Sprintf(msg, args...)), nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) Broadcast(msg string, except *Client) {
|
func (s *Server) Broadcast(msg string, except *Client) {
|
||||||
@ -92,8 +94,8 @@ func (s *Server) Broadcast(msg string, except *Client) {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
/* Add an ascii BEL to ding clients when they're mentioned */
|
/* Add an ascii BEL to ding clients when they're mentioned */
|
||||||
if strings.Contains(msg, client.Name) {
|
if strings.HasPrefix(msg, fmt.Sprintf("%s:", client.Name)) {
|
||||||
client.Msg <- msg + "\007"
|
client.Msg <- msg + BEEP
|
||||||
} else {
|
} else {
|
||||||
client.Msg <- msg
|
client.Msg <- msg
|
||||||
}
|
}
|
||||||
@ -108,7 +110,7 @@ func (s *Server) Privmsg(nick, message string, sender *Client) error {
|
|||||||
return fmt.Errorf("no client with that nick")
|
return fmt.Errorf("no client with that nick")
|
||||||
}
|
}
|
||||||
/* Send the message */
|
/* Send the message */
|
||||||
target.Msg <- fmt.Sprintf("\007[PM from %v] %v", sender.Name, message)
|
target.Msg <- fmt.Sprintf(BEEP+"[PM from %v] %v", sender.Name, message)
|
||||||
logger.Debugf("PM from %v to %v: %v", sender.Name, nick, message)
|
logger.Debugf("PM from %v to %v: %v", sender.Name, nick, message)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user