func (s *session) addParty(p *party) {
	s.parties[p.id] = p
	// write last chunk (so the newly joined parties won't stare
	// at a blank screen)
	getRecentWrite := func() []byte {
		s.writer.Lock()
		defer s.writer.Unlock()
		data := make([]byte, 0, 1024)
		for i := range s.writer.recentWrites {
			data = append(data, s.writer.recentWrites[i]...)
		}
		return data
	}
	p.Write(getRecentWrite())

	// register this party as one of the session writers
	// (output will go to it)
	s.writer.addWriter(string(p.id), p, true)
	p.ctx.addCloser(p)
	s.term.Add(1)

	// update session on the session server
	storageUpdate := func(db rsession.Service) {
		dbSession, err := db.GetSession(s.id)
		if err != nil {
			log.Error(err)
			return
		}
		dbSession.Parties = append(dbSession.Parties, rsession.Party{
			ID:         p.id,
			User:       p.user,
			ServerID:   p.serverID,
			RemoteAddr: p.site,
			LastActive: p.getLastActive(),
		})
		db.UpdateSession(rsession.UpdateRequest{
			ID:      dbSession.ID,
			Parties: &dbSession.Parties,
		})
	}
	if s.registry.srv.sessionServer != nil {
		go storageUpdate(s.registry.srv.sessionServer)
	}

	p.ctx.Infof("[SESSION] new party joined: %v", p.String())

	// this goroutine keeps pumping party's input into the session
	go func() {
		defer s.term.Add(-1)
		_, err := io.Copy(s.term.pty, p)
		p.ctx.Infof("party.io.copy(%v) closed", p.id)
		if err != nil {
			log.Error(err)
		}
	}()
}
// addParty is called when a new party joins the session.
addParty is called when a new party joins the session.
// addParty is called when a new party joins the session .
func (s *session) addParty(p *party) {
	s.parties[p.id] = p
	getRecentWrite := func() []byte {
		s.writer.Lock()
		defer s.writer.Unlock()
		data := make([]byte, 0, 1024)
		for i := range s.writer.recentWrites {
			data = append(data, s.writer.recentWrites[i]...)
		}
		return data
	}
	p.Write(getRecentWrite())
	s.writer.addWriter(string(p.id), p, true)
	p.ctx.addCloser(p)
	s.term.Add(1)
	storageUpdate := func(db rsession.Service) {
		dbSession, err := db.GetSession(s.id)
		if err != nil {
			log.Error(err)
			return
		}
		dbSession.Parties = append(dbSession.Parties, rsession.Party{
			ID:         p.id,
			User:       p.user,
			ServerID:   p.serverID,
			RemoteAddr: p.site,
			LastActive: p.getLastActive(),
		})
		db.UpdateSession(rsession.UpdateRequest{
			ID:      dbSession.ID,
			Parties: &dbSession.Parties,
		})
	}
	if s.registry.srv.sessionServer != nil {
		go storageUpdate(s.registry.srv.sessionServer)
	}
	p.ctx.Infof("[SESSION] new party joined: %v", p.String())
	go func() {
		defer s.term.Add(-1)
		_, err := io.Copy(s.term.pty, p)
		p.ctx.Infof("party.io.copy(%v) closed", p.id)
		if err != nil {
			log.Error(err)
		}
	}()
}
func ( s * session ) addParty ( p * party ) { s . parties [ p . id ] = p getRecentWrite := func ( ) [ ] byte { s . writer . Lock ( ) defer s . writer . Unlock ( ) data := make ( [ ] byte , 0 , 1024 ) for i := range s . writer . recentWrites { data = append ( data , s . writer . recentWrites [ i ] ... ) } return data } p . Write ( getRecentWrite ( ) ) s . writer . addWriter ( string ( p . id ) , p , true ) p . ctx . addCloser ( p ) s . term . Add ( 1 ) storageUpdate := func ( db rsession . Service ) { dbSession , err := db . GetSession ( s . id ) if err != nil { log . Error ( err ) return } dbSession . Parties = append ( dbSession . Parties , rsession . Party { ID : p . id , User : p . user , ServerID : p . serverID , RemoteAddr : p . site , LastActive : p . getLastActive ( ) , } ) db . UpdateSession ( rsession . UpdateRequest { ID : dbSession . ID , Parties : & dbSession . Parties , } ) } if s . registry . srv . sessionServer != nil { go storageUpdate ( s . registry . srv . sessionServer ) } p . ctx . Infof ( " " , p . String ( ) ) go func ( ) { defer s . term . Add ( - 1 ) _ , err := io . Copy ( s . term . pty , p ) p . ctx . Infof ( " " , p . id ) if err != nil { log . Error ( err ) } } ( ) }
addParty is called when a new party joins the session.
addParty is called when a new party joins the session .
// write last chunk (so the newly joined parties won't stare // at a blank screen) // register this party as one of the session writers // (output will go to it) // update session on the session server // this goroutine keeps pumping party's input into the session