mirror of
				https://github.com/shazow/ssh-chat.git
				synced 2025-10-24 17:14:49 +02:00 
			
		
		
		
	This commit is contained in:
		
						commit
						8c690d0676
					
				| @ -1,4 +1,4 @@ | ||||
| FROM golang:1.3.3 | ||||
| FROM golang:1.4 | ||||
| MAINTAINER Alvin Lai <al@alvinlai.com> | ||||
| 
 | ||||
| RUN apt-get update | ||||
|  | ||||
							
								
								
									
										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. | ||||
|    /whois $NAME         - Display information about another connected user. | ||||
|    /msg $NAME $MESSAGE  - Sends a private message to a user. | ||||
|    /motd                - Prints the Message of the Day | ||||
| ` + RESET | ||||
| 
 | ||||
| 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. | ||||
|    /op $NAME            - Promote a user to server operator. | ||||
|    /silence $NAME       - Revoke a user's ability to speak. | ||||
|    /motd $MESSAGE    - Sets the Message of the Day | ||||
| ` + RESET | ||||
| 
 | ||||
| const ABOUT_TEXT string = SYSTEM_MESSAGE_FORMAT + `-> ssh-chat is made by @shazow. | ||||
| @ -319,6 +321,21 @@ func (c *Client) handleShell(channel ssh.Channel) { | ||||
| 				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) | ||||
| 				} | ||||
| 			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: | ||||
| 				c.SysMsg("Invalid command: %s", line) | ||||
|  | ||||
							
								
								
									
										20
									
								
								server.go
									
									
									
									
									
								
							
							
						
						
									
										20
									
								
								server.go
									
									
									
									
									
								
							| @ -30,6 +30,7 @@ type Server struct { | ||||
| 	lock      sync.Mutex | ||||
| 	count     int | ||||
| 	history   *History | ||||
| 	motd      string | ||||
| 	admins    map[string]struct{}   // fingerprint lookup | ||||
| 	bannedPk  map[string]*time.Time // fingerprint lookup | ||||
| 	bannedIp  map[net.Addr]*time.Time | ||||
| @ -47,6 +48,7 @@ func NewServer(privateKey []byte) (*Server, error) { | ||||
| 		clients:  Clients{}, | ||||
| 		count:    0, | ||||
| 		history:  NewHistory(HISTORY_LEN), | ||||
| 		motd:     "Message of the Day! Modify with /motd", | ||||
| 		admins:   map[string]struct{}{}, | ||||
| 		bannedPk: map[string]*time.Time{}, | ||||
| 		bannedIp: map[net.Addr]*time.Time{}, | ||||
| @ -115,8 +117,26 @@ func (s *Server) Privmsg(nick, message string, sender *Client) error { | ||||
| 	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) { | ||||
| 	go func() { | ||||
| 		s.MotdUnicast(client) | ||||
| 		client.SendLines(s.history.Get(10)) | ||||
| 		client.SysMsg("Welcome to ssh-chat. Enter /help for more.") | ||||
| 	}() | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user