Esempio n. 1
0
func (a *Account) CreatePlayer(mailbox rpc.Mailbox, msg *rpc.Message) (errcode int32, reply *rpc.Message) {
	args := &c2s.Create{}
	if server.Check(server.ParseProto(msg, args)) {
		return 0, nil
	}

	player := App.Players.GetPlayer(mailbox.Id)
	if player == nil {
		//角色没有找到
		return 0, nil
	}
	if player.State != STATE_LOGGED {
		log.LogWarning("player state not logged")
		return 0, nil
	}
	obj, err := App.CreateRole("Player", args)
	if err != nil {
		log.LogError(err)
		return 0, nil
	}

	save := share.GetSaveData(obj)
	server.Check(App.DbBridge.createRole(mailbox, obj, player.Account, args.GetName(), int(args.GetIndex()), save))
	App.Destroy(obj.GetObjId())
	return 0, nil
}
Esempio n. 2
0
func (gd *GlobalDataHelper) SaveData(wait chan struct{}, quit bool) error {
	if gd.dataset == nil {
		return nil
	}
	db := GetAppByType("database")
	if db == nil {
		return ErrAppNotFound
	}

	if wait != nil {
		gd.wait = wait
	}

	core.apper.OnPerSaveGlobalData(quit)
	return db.CallBack(nil, "Database.UpdateObject", gd.OnSaveDataSet, share.GetSaveData(gd.dataset), share.DBParams{})
}
Esempio n. 3
0
//operater function
//创建数据集合
func (gd *GlobalDataHelper) createDataSet() error {
	if gd.dataset == nil {
		ent, err := core.CreateContainer(core.globalset, core.maxglobalentry)
		if err != nil {
			return fmt.Errorf("create global data failed, %s", err.Error())
		}

		ent.SetDbId(core.GetUid())
		ent.Set("Name", "GlobalData")
		gd.dataset = ent
		gd.isnew = true
	}

	db := GetAppByType("database")
	if db == nil {
		return ErrAppNotFound
	}

	return db.CallBack(nil, "Database.SaveObject", gd.OnSaveDataSet, share.GetSaveData(gd.dataset), share.DBParams{})
}