// Redirect sends the Peer to the minetest server named newsrv
Redirect sends the Peer to the minetest server named newsrv
// Redirect sends the Peer to the minetest server named newsrv
func (p *Peer) Redirect(newsrv string) error {
	p.redirectMu.Lock()
	defer p.redirectMu.Unlock()
	defer processRedirectDone(p, newsrv)
	straddr, ok := GetConfKey("servers:" + newsrv + ":address").(string)
	if !ok {
		return ErrServerDoesNotExist
	}
	if p.Server().Addr().String() == straddr {
		return ErrAlreadyConnected
	}
	srvaddr, err := net.ResolveUDPAddr("udp", straddr)
	if err != nil {
		return err
	}
	conn, err := net.DialUDP("udp", nil, srvaddr)
	if err != nil {
		return err
	}
	srv, err := Connect(conn, conn.RemoteAddr())
	if err != nil {
		return err
	}
	data := make([]byte, 6+len(p.aoIDs)*2)
	data[0] = uint8(0x00)
	data[1] = uint8(ToClientActiveObjectRemoveAdd)
	binary.BigEndian.PutUint16(data[2:4], uint16(len(p.aoIDs)))
	i := 4
	for ao := range p.aoIDs {
		binary.BigEndian.PutUint16(data[i:2+i], ao)
		i += 2
	}
	binary.BigEndian.PutUint16(data[i:2+i], uint16(0))
	if len(detachedinvs[newsrv]) > 0 {
		for i := range detachedinvs[newsrv] {
			data := make([]byte, 2+len(detachedinvs[newsrv][i]))
			data[0] = uint8(0x00)
			data[1] = uint8(ToClientDetachedInventory)
			copy(data[2:], detachedinvs[newsrv][i])
			ack, err := p.Send(rudp.Pkt{Data: data})
			if err != nil {
				return err
			}
			<-ack
		}
	}
	ack, err := p.Send(rudp.Pkt{Data: data})
	if err != nil {
		return err
	}
	<-ack
	p.aoIDs = make(map[uint16]bool)
	p.Server().stopForwarding()
	fin := make(chan *Peer) 
	go Init(p, srv, true, false, fin)
	<-fin
	p.SetServer(srv)
	go Proxy(p, srv)
	go Proxy(srv, p)
	for ch := range p.modChs {
		data := make([]byte, 4+len(ch))
		data[0] = uint8(0x00)
		data[1] = uint8(ToServerModChannelJoin)
		binary.BigEndian.PutUint16(data[2:4], uint16(len(ch)))
		copy(data[4:], []byte(ch))
		ack, err := srv.Send(rudp.Pkt{Data: data})
		if err != nil {
			log.Print(err)
		}
		<-ack
	}
	log.Print(p.Addr().String() + " redirected to " + newsrv)
	return nil
}
func ( p * Peer ) Redirect ( newsrv string ) error { p . redirectMu . Lock ( ) defer p . redirectMu . Unlock ( ) defer processRedirectDone ( p , newsrv ) straddr , ok := GetConfKey ( " " + newsrv + " " ) . ( string ) if ! ok { return ErrServerDoesNotExist } if p . Server ( ) . Addr ( ) . String ( ) == straddr { return ErrAlreadyConnected } srvaddr , err := net . ResolveUDPAddr ( " " , straddr ) if err != nil { return err } conn , err := net . DialUDP ( " " , nil , srvaddr ) if err != nil { return err } srv , err := Connect ( conn , conn . RemoteAddr ( ) ) if err != nil { return err } data := make ( [ ] byte , 6 + len ( p . aoIDs ) * 2 ) data [ 0 ] = uint8 ( 0x00 ) data [ 1 ] = uint8 ( ToClientActiveObjectRemoveAdd ) binary . BigEndian . PutUint16 ( data [ 2 : 4 ] , uint16 ( len ( p . aoIDs ) ) ) i := 4 for ao := range p . aoIDs { binary . BigEndian . PutUint16 ( data [ i : 2 + i ] , ao ) i += 2 } binary . BigEndian . PutUint16 ( data [ i : 2 + i ] , uint16 ( 0 ) ) if len ( detachedinvs [ newsrv ] ) > 0 { for i := range detachedinvs [ newsrv ] { data := make ( [ ] byte , 2 + len ( detachedinvs [ newsrv ] [ i ] ) ) data [ 0 ] = uint8 ( 0x00 ) data [ 1 ] = uint8 ( ToClientDetachedInventory ) copy ( data [ 2 : ] , detachedinvs [ newsrv ] [ i ] ) ack , err := p . Send ( rudp . Pkt { Data : data } ) if err != nil { return err } <- ack } } ack , err := p . Send ( rudp . Pkt { Data : data } ) if err != nil { return err } <- ack p . aoIDs = make ( map [ uint16 ] bool ) p . Server ( ) . stopForwarding ( ) fin := make ( chan * Peer ) go Init ( p , srv , true , false , fin ) <- fin p . SetServer ( srv ) go Proxy ( p , srv ) go Proxy ( srv , p ) for ch := range p . modChs { data := make ( [ ] byte , 4 + len ( ch ) ) data [ 0 ] = uint8 ( 0x00 ) data [ 1 ] = uint8 ( ToServerModChannelJoin ) binary . BigEndian . PutUint16 ( data [ 2 : 4 ] , uint16 ( len ( ch ) ) ) copy ( data [ 4 : ] , [ ] byte ( ch ) ) ack , err := srv . Send ( rudp . Pkt { Data : data } ) if err != nil { log . Print ( err ) } <- ack } log . Print ( p . Addr ( ) . String ( ) + " " + newsrv ) return nil }
Redirect sends the Peer to the minetest server named newsrv
Redirect sends the Peer to the minetest server named newsrv
// Remove active objects // close-only // Rejoin mod channels