func (self *Message) Updated(d *kol.DB, old *Message) { g := Game{Id: self.GameId} if err := d.Get(&g); err != nil { panic(err) } d.EmitUpdate(&g) }
func (self Members) Disallows(d *kol.DB, asking *user.User) (result bool, err error) { var askerList map[string]bool if askerList, err = asking.Blacklistings(d); err != nil { return } for _, member := range self { if askerList[member.UserId.String()] { result = true return } } for _, member := range self { memberUser := &user.User{Id: member.UserId} if err = d.Get(memberUser); err != nil { return } var memberList map[string]bool if memberList, err = memberUser.Blacklistings(d); err != nil { return } if memberList[asking.Id.String()] { result = true return } } return }
func (self *Member) Created(d *kol.DB) { g := Game{Id: self.GameId} if err := d.Get(&g); err != nil { panic(err) } d.EmitUpdate(&g) }
func (self *Member) Deleted(d *kol.DB) { g := Game{Id: self.GameId} if err := d.Get(&g); err == nil { d.EmitUpdate(&g) } else if err != kol.NotFound { panic(err) } }
func (self *Member) Updated(d *kol.DB, old *Member) { if old != self { g := Game{Id: self.GameId} if err := d.Get(&g); err != nil { panic(err) } d.EmitUpdate(&g) } }
func Get(d *kol.DB) (result time.Duration, err error) { epoch := &Epoch{ Id: kol.Id(epochKey), } if err = d.Get(epoch); err != nil { if err == kol.NotFound { err = nil } else { return } } result = epoch.At + time.Now().Sub(time.Unix(0, atomic.LoadInt64(&deltaPoint))) return }
func (self *Member) ReliabilityDelta(d *kol.DB, i int) (err error) { user := &user.User{Id: self.UserId} if err = d.Get(user); err != nil { return } if i > 0 { user.HeldDeadlines += i } else { user.MissedDeadlines -= i } if err = d.Set(user); err != nil { return } return }
func (self *Game) Users(d *kol.DB) (result user.Users, err error) { members, err := self.Members(d) if err != nil { return } result = make(user.Users, len(members)) for index, member := range members { user := user.User{Id: member.UserId} if err = d.Get(&user); err != nil { return } result[index] = user } return }
func (self *Member) ToState(d *kol.DB, g *Game, email string, isMember bool, isAdmin bool) (result *MemberState, err error) { result = &MemberState{ Member: &Member{ Id: self.Id, }, User: &user.User{}, } secretNation := false secretEmail := false secretNickname := false var flag common.SecretFlag switch g.State { case common.GameStateCreated: flag = common.SecretBeforeGame case common.GameStateStarted: flag = common.SecretDuringGame case common.GameStateEnded: flag = common.SecretAfterGame default: panic(fmt.Errorf("Unknown game state for %+v", g)) } secretNation, secretEmail, secretNickname = g.SecretNation&flag == flag, g.SecretEmail&flag == flag, g.SecretNickname&flag == flag isMe := string(self.UserId) == email if isAdmin || isMe || !secretNation { result.Member.Nation = self.Nation } if isAdmin || isMe || !secretEmail || !secretNickname { foundUser := &user.User{Id: self.UserId} if err = d.Get(foundUser); err != nil { return } if isAdmin || (isMember && (isMe || !secretEmail)) { result.User.Email = foundUser.Email } if isAdmin || (isMe || !secretNickname) { result.User.Nickname = foundUser.Nickname } if isAdmin || isMe { result.Member.Committed = self.Committed result.Member.Options = self.Options result.Member.NoOrders = self.NoOrders } } return }
func (self *Phase) Game(d *kol.DB) (result *Game, err error) { result = &Game{Id: self.GameId} err = d.Get(result) return }