@@ -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
@@ -295,13 +295,12 @@ func (h *Host) AutoCompleteFunction(u *message.User) func(line string, pos int,
295295}
296296
297297// GetUser returns a message.User based on a name.
298- func (h * Host ) GetUser (name string ) (* message. User , bool ) {
298+ func (h * Host ) GetUser (name string ) (chat. Member , bool ) {
299299 m , ok := h .MemberByID (name )
300300 if ! ok {
301301 return nil , false
302302 }
303- u , ok := m .Member .(* message.User )
304- return u , ok
303+ return m .Member , true
305304}
306305
307306// InitCommands adds host-specific commands to a Commands container. These will
@@ -331,7 +330,7 @@ func (h *Host) InitCommands(c *chat.Commands) {
331330 txt := fmt .Sprintf ("[Sent PM to %s]" , target .Name ())
332331 ms := message .NewSystemMsg (txt , msg .From ())
333332 room .Send (ms )
334- target .SetReplyTo (msg .From ())
333+ target .( Replier ). SetReplyTo (msg .From ())
335334 return nil
336335 },
337336 })
@@ -347,7 +346,7 @@ func (h *Host) InitCommands(c *chat.Commands) {
347346 return errors .New ("must specify message" )
348347 }
349348
350- target := msg .From ().ReplyTo ()
349+ target := msg .From ().( Replier ). ReplyTo ()
351350 if target == nil {
352351 return errors .New ("no message to reply to" )
353352 }
@@ -380,7 +379,7 @@ func (h *Host) InitCommands(c *chat.Commands) {
380379 // FIXME: Handle many clients
381380 clients := h .findClients (target )
382381 var whois string
383- switch room .IsOp (msg .From ()) {
382+ switch room .IsOp (msg .From ().(chat. Member ) ) {
384383 case true :
385384 whois = whoisAdmin (clients )
386385 case false :
@@ -416,7 +415,7 @@ func (h *Host) InitCommands(c *chat.Commands) {
416415 PrefixHelp : "USER [DURATION]" ,
417416 Help : "Set USER as admin." ,
418417 Handler : func (room * chat.Room , msg message.CommandMsg ) error {
419- if ! room .IsOp (msg .From ()) {
418+ if ! room .IsOp (msg .From ().(chat. Member ) ) {
420419 return errors .New ("must be op" )
421420 }
422421
@@ -459,7 +458,7 @@ func (h *Host) InitCommands(c *chat.Commands) {
459458 Help : "Ban USER from the server." ,
460459 Handler : func (room * chat.Room , msg message.CommandMsg ) error {
461460 // TODO: Would be nice to specify what to ban. Key? Ip? etc.
462- if ! room .IsOp (msg .From ()) {
461+ if ! room .IsOp (msg .From ().(chat. Member ) ) {
463462 return errors .New ("must be op" )
464463 }
465464
@@ -486,7 +485,7 @@ func (h *Host) InitCommands(c *chat.Commands) {
486485
487486 body := fmt .Sprintf ("%s was banned by %s." , target .Name (), msg .From ().Name ())
488487 room .Send (message .NewAnnounceMsg (body ))
489- target .Close ()
488+ target .(io. Closer ). Close ()
490489
491490 logger .Debugf ("Banned: \n -> %s" , whoisAdmin (clients ))
492491
@@ -500,7 +499,7 @@ func (h *Host) InitCommands(c *chat.Commands) {
500499 PrefixHelp : "USER" ,
501500 Help : "Kick USER from the server." ,
502501 Handler : func (room * chat.Room , msg message.CommandMsg ) error {
503- if ! room .IsOp (msg .From ()) {
502+ if ! room .IsOp (msg .From ().(chat. Member ) ) {
504503 return errors .New ("must be op" )
505504 }
506505
@@ -516,7 +515,7 @@ func (h *Host) InitCommands(c *chat.Commands) {
516515
517516 body := fmt .Sprintf ("%s was kicked by %s." , target .Name (), msg .From ().Name ())
518517 room .Send (message .NewAnnounceMsg (body ))
519- target .Close ()
518+ target .(io. Closer ). Close ()
520519 return nil
521520 },
522521 })
@@ -538,7 +537,7 @@ func (h *Host) InitCommands(c *chat.Commands) {
538537 room .Send (message .NewSystemMsg (motd , user ))
539538 return nil
540539 }
541- if ! room .IsOp (user ) {
540+ if ! room .IsOp (user .(chat. Member ) ) {
542541 return errors .New ("must be OP to modify the MOTD" )
543542 }
544543
0 commit comments