Beispiel #1
0
func onStart(glctx gl.Context, u *uistate.UIState) {
	flag.Set("v23.credentials", "/sdcard/credentials")
	vlog.Log.Configure(vlog.OverridePriorConfiguration(true), vlog.LogToStderr(true))
	vlog.Log.Configure(vlog.OverridePriorConfiguration(true), vlog.Level(0))
	ctx, shutdown := v23.Init()
	u.Shutdown = shutdown
	u.Ctx = ctx
	u.Service = syncbase.NewService(util.MountPoint + "/croupier/" + util.SBName)
	namespace := v23.GetNamespace(u.Ctx)
	allAccess := access.AccessList{In: []security.BlessingPattern{"..."}}
	permissions := access.Permissions{
		"Admin":   allAccess,
		"Write":   allAccess,
		"Read":    allAccess,
		"Resolve": allAccess,
		"Debug":   allAccess,
	}
	namespace.SetPermissions(u.Ctx, util.MountPoint, permissions, "")
	namespace.SetPermissions(u.Ctx, util.MountPoint+"/croupier", permissions, "")
	u.Service.SetPermissions(u.Ctx, permissions, "")
	u.Images = glutil.NewImages(glctx)
	fps = debug.NewFPS(u.Images)
	u.Eng = glsprite.Engine(u.Images)
	u.Texs = texture.LoadTextures(u.Eng)
	u.CurTable = table.InitializeGame(u.NumPlayers, u.Texs)
	sound.InitPlayers(u)
	sync.CreateTables(u)
	// Create watch stream to update game state based on Syncbase updates
	go sync.UpdateSettings(u)
}
Beispiel #2
0
func (d *delegate) Initialize(mctx application.Context) {
	// TODO(bjornick): Calling init multiple times in the same process
	// will be bad.  For now, this is ok because this is the only
	// vanadium service that will be used in the demos and each go library
	// will be in its own process.
	roaming.SetArgs(mctx)
	d.ctx, d.shutdown = v23.Init()

	if *flagTestMode {
		// Inject a mock plugin.
		df, _ := idiscovery.NewFactory(d.ctx, mock.New())
		fdiscovery.InjectFactory(df)

		// Start a mounttable and set the namespace roots.
		//
		// Note that we need to listen on a local IP address in order to
		// accept connections within a GCE instance.
		d.ctx = v23.WithListenSpec(d.ctx, rpc.ListenSpec{Addrs: rpc.ListenAddrs{{Protocol: "tcp", Address: "127.0.0.1:0"}}})
		name, _, err := mounttablelib.StartServers(d.ctx, v23.GetListenSpec(d.ctx), "", "", "", "", "mounttable")
		if err != nil {
			panic(err)
		}
		ns := v23.GetNamespace(d.ctx)
		ns.SetRoots(name)
	}
}
Beispiel #3
0
func doGlob(ctx *context.T, globPrefix string) error {
	globPattern := globPrefix + "*"
	found := make(map[string]bool)
	for {
		ch, err := v23.GetNamespace(ctx).Glob(ctx, globPattern)
		if err != nil {
			return err
		}
		for v := range ch {
			switch entry := v.(type) {
			case *naming.GlobReplyEntry:
				if name, servers := entry.Value.Name, entry.Value.Servers; len(name) != 0 && !found[name] && len(servers) != 0 {
					epStr, _ := naming.SplitAddressName(servers[0].Server)
					ep, err := naming.ParseEndpoint(epStr)
					if err != nil {
						continue
					}

					found[name] = true
					printName(name, globPrefix, ep.BlessingNames())
				}
			}
		}
	}
}
Beispiel #4
0
func lockObjectName(ctx *context.T) string {
	nsroots := v23.GetNamespace(ctx).Roots()
	if len(nsroots) == 0 {
		return ""
	}
	return naming.Join(nsroots[0], locklib.LockSuffix)
}
Beispiel #5
0
func (nm *V23Manager) getReadyToRun(ch chan bool) {
	defer nm.mu.Unlock()
	if nm.chatty {
		log.Printf("Calling v23.Init")
	}
	nm.ctx, nm.shutdown = v23.Init()
	if nm.shutdown == nil {
		log.Panic("shutdown nil")
	}
	if nm.chatty {
		log.Printf("Setting root to %v", nm.namespaceRoot)
	}
	v23.GetNamespace(nm.ctx).SetRoots(nm.namespaceRoot)

	nm.initialPlayerNumbers = nm.playerNumbers()
	if nm.chatty {
		log.Printf("Found %d players.", len(nm.initialPlayerNumbers))
	}
	sort.Ints(nm.initialPlayerNumbers)
	myId := 1
	if len(nm.initialPlayerNumbers) > 0 {
		myId = nm.initialPlayerNumbers[len(nm.initialPlayerNumbers)-1] + 1
	}

	if nm.isGameMaster {
		myId = 999
	}

	nm.relay = relay.MakeRelay()
	nm.myself = model.NewPlayer(myId)
	if nm.isGameMaster {
		if nm.chatty {
			log.Printf("I am game master.")
		}
		nm.isReady = true
		ch <- true
		return
	}
	if nm.chatty {
		log.Printf("I am player %v\n", nm.myself)
	}

	myName := nm.serverName(nm.Me().Id())
	if nm.chatty {
		log.Printf("Calling myself %s\n", myName)
	}
	ctx, s, err := v23.WithNewServer(nm.ctx, myName, ifc.GameServiceServer(nm.relay), MakeAuthorizer())
	if err != nil {
		log.Panic("Error creating server:", err)
		ch <- false
		return
	}
	saveEndpointToFile(s)
	nm.ctx = ctx
	nm.isReady = true
	ch <- true
}
Beispiel #6
0
// Return array of known players.
func (nm *V23Manager) playerNumbers() (list []int) {
	list = []int{}
	rCtx, cancel := context.WithTimeout(nm.ctx, time.Minute)
	defer cancel()
	if nm.chatty {
		log.Printf("Recovering namespace.")
	}
	ns := v23.GetNamespace(rCtx)
	if nm.chatty {
		log.Printf("namespace == %T %v", ns, ns)
	}
	pattern := nm.rootName + "*"
	if nm.chatty {
		log.Printf("Calling glob with %T=%v, pattern=%v\n",
			rCtx, rCtx, pattern)
	}
	c, err := ns.Glob(rCtx, pattern)
	if err != nil {
		log.Printf("ns.Glob(%v) failed: %v", pattern, err)
		return
	}
	if nm.chatty {
		log.Printf("Awaiting response from Glob request.")
	}
	for res := range c {
		if nm.chatty {
			log.Printf("Got a result: %v\n", res)
		}
		switch v := res.(type) {
		case *naming.GlobReplyEntry:
			name := v.Value.Name
			if nm.chatty {
				log.Printf("Raw name is: %v\n", name)
			}
			if name != "" {
				putativeNumber := name[len(nm.rootName):]
				n, err := strconv.ParseInt(putativeNumber, 10, 32)
				if err != nil {
					log.Println(err)
				} else {
					list = append(list, int(n))
				}
				if nm.chatty {
					log.Println("Found player: ", v.Value.Name)
				}
			}
		default:
		}
	}
	if nm.chatty {
		log.Printf("Finished processing glob response.")
	}
	return
}