mirror of
https://github.com/shazow/ssh-chat.git
synced 2025-04-15 00:20:37 +03:00
Merge
This commit is contained in:
commit
b9a929d0d4
23
client.go
23
client.go
@ -173,6 +173,15 @@ func (c *Client) Fingerprint() string {
|
||||
return c.Conn.Permissions.Extensions["fingerprint"]
|
||||
}
|
||||
|
||||
// Emote formats and sends an emote
|
||||
func (c *Client) Emote(message string) {
|
||||
formatted := fmt.Sprintf("** %s%s", c.ColoredName(), message)
|
||||
if c.IsSilenced() || len(message) > 1000 {
|
||||
c.SysMsg("Message rejected")
|
||||
}
|
||||
c.Server.Broadcast(formatted, nil)
|
||||
}
|
||||
|
||||
func (c *Client) handleShell(channel ssh.Channel) {
|
||||
defer channel.Close()
|
||||
|
||||
@ -229,12 +238,16 @@ func (c *Client) handleShell(channel ssh.Channel) {
|
||||
if me == "" {
|
||||
me = " is at a loss for words."
|
||||
}
|
||||
msg := fmt.Sprintf("** %s%s", c.ColoredName(), me)
|
||||
if c.IsSilenced() || len(msg) > 1000 {
|
||||
c.SysMsg("Message rejected.")
|
||||
} else {
|
||||
c.Server.Broadcast(msg, nil, false)
|
||||
c.Emote(me)
|
||||
case "/slap":
|
||||
slappee := "themself"
|
||||
if len(parts) > 1 {
|
||||
slappee = parts[1]
|
||||
if len(parts[1]) > 100 {
|
||||
slappee = "some long-named jerk"
|
||||
}
|
||||
}
|
||||
c.Emote(fmt.Sprintf(" slaps %s around a bit with a large trout.", slappee))
|
||||
case "/nick":
|
||||
if len(parts) == 2 {
|
||||
c.Server.Rename(c, parts[1])
|
||||
|
13
colors.go
13
colors.go
@ -42,9 +42,20 @@ func DeColorString(s string) string {
|
||||
return s
|
||||
}
|
||||
|
||||
func randomReadableColor() int {
|
||||
for {
|
||||
i := rand.Intn(256)
|
||||
if (16 <= i && i <= 18) || (232 <= i && i <= 237) {
|
||||
// Remove the ones near black, this is kinda sadpanda.
|
||||
continue
|
||||
}
|
||||
return i
|
||||
}
|
||||
}
|
||||
|
||||
// RandomColor256 returns a random (of 256) color
|
||||
func RandomColor256() string {
|
||||
return fmt.Sprintf("38;05;%d", rand.Intn(256))
|
||||
return fmt.Sprintf("38;05;%d", randomReadableColor())
|
||||
}
|
||||
|
||||
// RandomColor returns a random color
|
||||
|
@ -167,7 +167,7 @@ func (s *Server) Add(client *Client) {
|
||||
|
||||
newName, err := s.proposeName(client.Name)
|
||||
if err != nil {
|
||||
client.SysMsg("Your name '%s' is not available, renamed to '%s'. Use /nick <name> to change it.", client.ColoredName(), ColorString(client.Color, newName))
|
||||
client.SysMsg("Your name '%s' is not available, renamed to '%s'. Use /nick <name> to change it.", client.Name, ColorString(client.Color, newName))
|
||||
}
|
||||
|
||||
client.Rename(newName)
|
||||
@ -175,7 +175,7 @@ func (s *Server) Add(client *Client) {
|
||||
num := len(s.clients)
|
||||
s.Unlock()
|
||||
|
||||
s.Broadcast(ContinuousFormat(systemMessageFormat, fmt.Sprintf(" * %s joined. (Total connected: %d)", client.ColoredName(), num)), client, false)
|
||||
s.Broadcast(ContinuousFormat(systemMessageFormat, fmt.Sprintf(" * %s joined. (Total connected: %d)", client.Name, num)), client)
|
||||
}
|
||||
|
||||
// Remove removes the given client from the list of clients
|
||||
@ -184,7 +184,7 @@ func (s *Server) Remove(client *Client) {
|
||||
delete(s.clients, strings.ToLower(client.Name))
|
||||
s.Unlock()
|
||||
|
||||
s.SysMsg("%s left.", client.ColoredName())
|
||||
s.SysMsg("%s left.", client.Name)
|
||||
}
|
||||
|
||||
func (s *Server) proposeName(name string) (string, error) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user