@@ -35,7 +35,7 @@ type Host struct {
3535 mu sync.Mutex
3636 motd string
3737 count int
38- clients map [* message. User ][]Client
38+ clients map [chat. Member ][]Client
3939}
4040
4141// NewHost creates a Host on top of an existing listener.
@@ -46,7 +46,7 @@ func NewHost(listener *sshd.SSHListener, auth *Auth) *Host {
4646 listener : listener ,
4747 commands : chat.Commands {},
4848 auth : auth ,
49- clients : map [* message. User ][]Client {},
49+ clients : map [chat. Member ][]Client {},
5050 }
5151
5252 // Make our own commands registry instance.
@@ -75,7 +75,7 @@ func (h *Host) SetMotd(motd string) {
7575// Connect a specific Terminal to this host and its room.
7676func (h * Host ) Connect (term * sshd.Terminal ) {
7777 requestedName := term .Conn .Name ()
78- user := message .NewScreen (requestedName , term )
78+ user := message .BufferedScreen (requestedName , term )
7979
8080 client := h .addClient (user , term .Conn )
8181 defer h .removeClient (user , client )
@@ -180,7 +180,7 @@ func (h *Host) Connect(term *sshd.Terminal) {
180180 logger .Debugf ("[%s] Leaving: %s" , term .Conn .RemoteAddr (), user .Name ())
181181}
182182
183- func (h * Host ) addClient (user * message. User , conn sshd.Connection ) * Client {
183+ func (h * Host ) addClient (user chat. Member , conn sshd.Connection ) * Client {
184184 client := Client {
185185 user : user ,
186186 conn : conn ,
@@ -195,7 +195,7 @@ func (h *Host) addClient(user *message.User, conn sshd.Connection) *Client {
195195 return & client
196196}
197197
198- func (h * Host ) removeClient (user * message. User , client * Client ) {
198+ func (h * Host ) removeClient (user chat. Member , client * Client ) {
199199 h .mu .Lock ()
200200 defer h .mu .Unlock ()
201201
@@ -212,7 +212,7 @@ func (h *Host) removeClient(user *message.User, client *Client) {
212212 }
213213}
214214
215- func (h * Host ) findClients (user * message. User ) []Client {
215+ func (h * Host ) findClients (user chat. Member ) []Client {
216216 h .mu .Lock ()
217217 defer h .mu .Unlock ()
218218 return h .clients [user ]
@@ -244,7 +244,7 @@ func (h *Host) completeCommand(partial string) string {
244244}
245245
246246// AutoCompleteFunction returns a callback for terminal autocompletion
247- func (h * Host ) AutoCompleteFunction (u * message. User ) func (line string , pos int , key rune ) (newLine string , newPos int , ok bool ) {
247+ func (h * Host ) AutoCompleteFunction (u Replier ) func (line string , pos int , key rune ) (newLine string , newPos int , ok bool ) {
248248 return func (line string , pos int , key rune ) (newLine string , newPos int , ok bool ) {
249249 if key != 9 {
250250 return
@@ -301,13 +301,12 @@ func (h *Host) AutoCompleteFunction(u *message.User) func(line string, pos int,
301301}
302302
303303// GetUser returns a message.User based on a name.
304- func (h * Host ) GetUser (name string ) (* message. User , bool ) {
304+ func (h * Host ) GetUser (name string ) (chat. Member , bool ) {
305305 m , ok := h .MemberByID (name )
306306 if ! ok {
307307 return nil , false
308308 }
309- u , ok := m .Member .(* message.User )
310- return u , ok
309+ return m .Member , true
311310}
312311
313312// InitCommands adds host-specific commands to a Commands container. These will
@@ -337,7 +336,7 @@ func (h *Host) InitCommands(c *chat.Commands) {
337336 txt := fmt .Sprintf ("[Sent PM to %s]" , target .Name ())
338337 ms := message .NewSystemMsg (txt , msg .From ())
339338 room .Send (ms )
340- target .SetReplyTo (msg .From ())
339+ target .( Replier ). SetReplyTo (msg .From ())
341340 return nil
342341 },
343342 })
@@ -353,7 +352,7 @@ func (h *Host) InitCommands(c *chat.Commands) {
353352 return errors .New ("must specify message" )
354353 }
355354
356- target := msg .From ().ReplyTo ()
355+ target := msg .From ().( Replier ). ReplyTo ()
357356 if target == nil {
358357 return errors .New ("no message to reply to" )
359358 }
@@ -392,7 +391,7 @@ func (h *Host) InitCommands(c *chat.Commands) {
392391 // FIXME: Handle many clients
393392 clients := h .findClients (target )
394393 var whois string
395- switch room .IsOp (msg .From ()) {
394+ switch room .IsOp (msg .From ().(chat. Member ) ) {
396395 case true :
397396 whois = whoisAdmin (clients )
398397 case false :
@@ -428,7 +427,7 @@ func (h *Host) InitCommands(c *chat.Commands) {
428427 PrefixHelp : "USER [DURATION]" ,
429428 Help : "Set USER as admin." ,
430429 Handler : func (room * chat.Room , msg message.CommandMsg ) error {
431- if ! room .IsOp (msg .From ()) {
430+ if ! room .IsOp (msg .From ().(chat. Member ) ) {
432431 return errors .New ("must be op" )
433432 }
434433
@@ -471,7 +470,7 @@ func (h *Host) InitCommands(c *chat.Commands) {
471470 Help : "Ban USER from the server." ,
472471 Handler : func (room * chat.Room , msg message.CommandMsg ) error {
473472 // TODO: Would be nice to specify what to ban. Key? Ip? etc.
474- if ! room .IsOp (msg .From ()) {
473+ if ! room .IsOp (msg .From ().(chat. Member ) ) {
475474 return errors .New ("must be op" )
476475 }
477476
@@ -498,7 +497,7 @@ func (h *Host) InitCommands(c *chat.Commands) {
498497
499498 body := fmt .Sprintf ("%s was banned by %s." , target .Name (), msg .From ().Name ())
500499 room .Send (message .NewAnnounceMsg (body ))
501- target .Close ()
500+ target .(io. Closer ). Close ()
502501
503502 logger .Debugf ("Banned: \n -> %s" , whoisAdmin (clients ))
504503
@@ -512,7 +511,7 @@ func (h *Host) InitCommands(c *chat.Commands) {
512511 PrefixHelp : "USER" ,
513512 Help : "Kick USER from the server." ,
514513 Handler : func (room * chat.Room , msg message.CommandMsg ) error {
515- if ! room .IsOp (msg .From ()) {
514+ if ! room .IsOp (msg .From ().(chat. Member ) ) {
516515 return errors .New ("must be op" )
517516 }
518517
@@ -528,7 +527,7 @@ func (h *Host) InitCommands(c *chat.Commands) {
528527
529528 body := fmt .Sprintf ("%s was kicked by %s." , target .Name (), msg .From ().Name ())
530529 room .Send (message .NewAnnounceMsg (body ))
531- target .Close ()
530+ target .(io. Closer ). Close ()
532531 return nil
533532 },
534533 })
@@ -550,7 +549,7 @@ func (h *Host) InitCommands(c *chat.Commands) {
550549 room .Send (message .NewSystemMsg (motd , user ))
551550 return nil
552551 }
553- if ! room .IsOp (user ) {
552+ if ! room .IsOp (user .(chat. Member ) ) {
554553 return errors .New ("must be OP to modify the MOTD" )
555554 }
556555
0 commit comments