예제 #1
0
// BroadcastPacket sends a packet to all online players.
func (l Players) BroadcastPacket(pkt packet.Packet) {
	l.RLock()
	for _, p := range l.list {
		if p.Ready {
			pkt.WriteTo(p.Conn)
		}
	}
	l.RUnlock()
}
예제 #2
0
파일: login.go 프로젝트: KellyLSB/minero-go
func (s *Server) HandleLogin(sender *player.Player) {
	var r packet.Packet

	r = &packet.LoginInfo{
		Entity:     33,
		LevelType:  "default",
		GameMode:   1,
		Dimension:  0,
		Difficulty: 2,
		MaxPlayers: 32,
	}
	r.WriteTo(sender.Conn)

	// BUG(toqueteos): Load nearby chunks
	for z := int32(-1); z < 2; z++ {
		for x := int32(-1); x < 2; x++ {
			VirtualChunks(x, z, 64).WriteTo(sender.Conn)
		}
	}

	const (
		startX = 8.0
		startY = 65.0
		startZ = 8.0
	)

	// Client's spawn position
	r = &packet.SpawnPosition{X: int32(startX), Y: int32(startY), Z: int32(startZ)}
	r.WriteTo(sender.Conn)

	// Client Pos & Look
	r = &packet.PlayerPosLook{
		startX, startY, startZ, // X, Y, Z
		startY + 1.6, // Stance
		0.0, 0.0,     // Yaw + Pitch
		true, // OnGround
	}
	r.WriteTo(sender.Conn)

	// Send nearby clients new client's info
	r = &packet.EntityNamedSpawn{
		Entity: sender.Id(),
		Name:   sender.Name,
		X:      startX, Y: startY, Z: startZ,
		Yaw:      0.0,
		Pitch:    0.0,
		Item:     0,
		Metadata: player.JustLoginMetadata(sender.Name),
	}
	s.BroadcastPacket(r)

	// Instantiate all other users on new client
	s.BroadcastLogin(sender)

	// Save player to server list
	s.AddPlayer(sender)
}