当前位置: 首页>>代码示例>>Golang>>正文


Golang WSContext.Diet方法代码示例

本文整理汇总了Golang中github.com/zond/diplicity/common.WSContext.Diet方法的典型用法代码示例。如果您正苦于以下问题:Golang WSContext.Diet方法的具体用法?Golang WSContext.Diet怎么用?Golang WSContext.Diet使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/zond/diplicity/common.WSContext的用法示例。


在下文中一共展示了WSContext.Diet方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: CreateMessage

func CreateMessage(c common.WSContext) (err error) {
	// load the  message provided by the client
	message := &Message{}
	c.Data().Overwrite(message)
	if message.RecipientIds == nil {
		message.RecipientIds = map[string]bool{}
	}

	message.Body = strings.TrimSpace(message.Body)
	if message.Body == "" {
		return
	}

	// and the game
	game := &Game{Id: message.GameId}
	if err := c.DB().Get(game); err != nil {
		return err
	}
	// and the member
	sender, err := game.Member(c.DB(), c.Principal())
	if err != nil {
		return
	}

	return message.Send(c.Diet(), game, sender)
}
开发者ID:JorenC,项目名称:diplicity,代码行数:26,代码来源:controller.go

示例2: AddMember

func AddMember(c common.WSContext) error {
	var state GameState
	c.Data().Overwrite(&state)
	return c.Transact(func(c common.WSContext) error {
		game := Game{Id: state.Game.Id}
		if err := c.DB().Get(&game); err != nil {
			return fmt.Errorf("Game not found")
		}
		if game.State != common.GameStateCreated {
			return fmt.Errorf("%+v already started")
		}
		variant, found := common.VariantMap[game.Variant]
		if !found {
			return fmt.Errorf("Unknown variant %v", game.Variant)
		}
		if alreadyMember, err := game.Member(c.DB(), c.Principal()); err != nil {
			return err
		} else if alreadyMember != nil {
			return fmt.Errorf("%+v is already member of %v", alreadyMember, game.Id)
		}
		me := &user.User{Id: kol.Id(c.Principal())}
		if err := c.DB().Get(me); err != nil {
			return err
		}
		if game.Disallows(me) {
			return fmt.Errorf("Is not allowed to join this game due to game settings")
		}
		already, err := game.Members(c.DB())
		if err != nil {
			return err
		}
		if disallows, err := already.Disallows(c.DB(), me); err != nil {
			return err
		} else if disallows {
			return fmt.Errorf("Is not allowed to join this game due to blacklistings")
		}
		if len(already) < len(variant.Nations) {
			member := Member{
				GameId:           state.Game.Id,
				UserId:           kol.Id(c.Principal()),
				PreferredNations: state.Members[0].PreferredNations,
			}
			if err := c.DB().Set(&member); err != nil {
				return err
			}
			if len(already) == len(variant.Nations)-1 {
				if err := game.start(c.Diet()); err != nil {
					return err
				}
				c.Infof("Started %v", game.Id)
			}
		}
		return nil
	})
}
开发者ID:JorenC,项目名称:diplicity,代码行数:55,代码来源:controller.go

示例3: setPhaseCommitted

func setPhaseCommitted(c common.WSContext, commit bool) (err error) {
	phaseId, err := base64.URLEncoding.DecodeString(c.Data().GetString("PhaseId"))
	if err != nil {
		return
	}
	return c.Transact(func(c common.WSContext) (err error) {
		phase := &Phase{Id: phaseId}
		if err = c.DB().Get(phase); err != nil {
			return
		}
		game, err := phase.Game(c.DB())
		if err != nil {
			return
		}
		members, err := game.Members(c.DB())
		if err != nil {
			return
		}
		member := members.Get(c.Principal())
		if member == nil {
			err = fmt.Errorf("Not member of game")
			return
		}
		if member.NoOrders {
			c.Infof("%+v has no orders to give", member)
			err = fmt.Errorf("No orders to give")
			return
		}
		member.Committed = commit
		member.NoWait = false
		if err = c.DB().Set(member); err != nil {
			return
		}
		if !phase.Resolved {
			count := 0
			for _, m := range members {
				if m.Committed || m.NoWait {
					count++
				}
			}
			if count == len(members) {
				if err = game.resolve(c.Diet(), phase); err != nil {
					return
				}
				c.Infof("Resolved %v", game.Id)
				return
			}
		}
		err = c.DB().Set(phase)
		return
	})
}
开发者ID:arlm,项目名称:diplicity,代码行数:52,代码来源:rpc.go


注:本文中的github.com/zond/diplicity/common.WSContext.Diet方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。