Skip to content

Commit

Permalink
[feature] Add game event origin (autoRef) to game events
Browse files Browse the repository at this point in the history
  • Loading branch information
g3force committed Jan 2, 2019
1 parent ffc25b6 commit b6541a0
Show file tree
Hide file tree
Showing 4 changed files with 178 additions and 155 deletions.
4 changes: 4 additions & 0 deletions internal/app/controller/autoRefConnection.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,21 @@ func (c *GameController) ProcessAutoRefRequests(id string, request refproto.Auto
}

totalProposals := 0
var origins []string
for _, proposal := range c.Engine.State.GameEventProposals {
if proposal.GameEvent.Type == event.GameEvent.Type && proposal.ValidUntil.After(c.Engine.TimeProvider()) {
totalProposals++
origins = append(origins, proposal.ProposerId)
}
}

majority := int(math.Floor(float64(len(c.AutoRefServer.Clients)) / 2.0))
if totalProposals > majority {
event.GameEvent.Origins = origins
c.OnNewEvent(event)
}
} else {
event.GameEvent.Origins = []string{id}
c.OnNewEvent(event)
}
}
Expand Down
2 changes: 2 additions & 0 deletions internal/app/controller/gameEvent.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ func (g GameEventType) Valid() bool {
type GameEvent struct {
Type GameEventType `json:"type"`
Details GameEventDetails `json:"details"`
Origins []string `json:"origins"`
}

// String converts the game event into a string
Expand Down Expand Up @@ -266,6 +267,7 @@ func (e GameEvent) IsContinueGame() bool {
func (e GameEvent) ToProto() *refproto.GameEvent {
protoEvent := new(refproto.GameEvent)
protoEvent.Type = new(refproto.GameEventType)
protoEvent.Origin = e.Origins
switch e.Type {
case GameEventNone:
return nil
Expand Down
Loading

0 comments on commit b6541a0

Please sign in to comment.