Beispiel #1
0
func method_register(args APIData, session Session, context ServerContext) (bool, APIData) {
	var server = context.(DriftServerContext)
	var response = make(APIData)

	account, ok := accounts.CreateAccount(
		args["name"].(string),
		args["password"].(string),
		server)

	if !ok {
		response["message"] = "User exists"
		return false, response
	}

	fmt.Printf(
		"Registered account: %s\n",
		account.Name)

	return true, response
}
Beispiel #2
0
func createShips() {
	var server = buildServer()

	var manager = server.SectorManager

	var sector, ok = manager.Ensure(0, 0)

	if !ok {
		sector, ok = manager.Create(0, 0, "Home")
		if !ok {
			fmt.Printf("Sector creation error\n")
			return
		}
	}

	fmt.Printf("Sector: %v\n", sector.Name)

	var db = server.DB()
	var account = db.ReadOne("account", "sandbox").(*accounts.Account)

	if account == nil {
		account, ok = accounts.CreateAccount("sandbox", "password", server)
		if !ok {
			fmt.Printf("User load error\n")
			return
		}
	}

	fmt.Printf("User: %v\n", account.Name)

	var sectorLink = []loge.LogeKey{loge.LogeKey(sector.StorageKey())}
	for i := 0; i < 1000; i++ {
		name := fmt.Sprintf("sandbox%03d", i)
		var id = uuid.New()

		var body = &simulation.PoweredBody{
			ShipID: id,
			Coords: sector.Coords,
		}

		body.Position.X = float64(rand.Intn(1000))
		body.Position.Y = float64(rand.Intn(1000))
		body.Velocity.X = rand.Float64()
		body.Velocity.Y = rand.Float64()
		body.Thrust.X = rand.Float64()
		body.Thrust.Y = rand.Float64()

		var rot = math.Pi / 20
		body.Spin.X = math.Cos(rot)
		body.Spin.Y = math.Sin(rot)

		ship := ships.NewShip(id, account.ID(), name)
		ship.Location = body

		db.Transact(func(t *loge.Transaction) {
			var id = loge.LogeKey(id)
			t.Set("ship", id, ship)
			t.Set("shiplocation", id, ship.Location)
			t.SetLinks("shiplocation", "sector", id, sectorLink)
		}, 0)
	}

	fmt.Printf("Sector: %s (%d, %d)\n", sector.Name, sector.Coords.X, sector.Coords.Y)

	sector.DumpShips()

	// for i := 0; i < 100; i++ {
	// 	sector.Tick()
	// 	sector.DumpShips()
	// }

}