Skip to content

Commit b6541a0

Browse files
committed
[feature] Add game event origin (autoRef) to game events
1 parent ffc25b6 commit b6541a0

File tree

4 files changed

+178
-155
lines changed

4 files changed

+178
-155
lines changed

internal/app/controller/autoRefConnection.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,21 @@ func (c *GameController) ProcessAutoRefRequests(id string, request refproto.Auto
3434
}
3535

3636
totalProposals := 0
37+
var origins []string
3738
for _, proposal := range c.Engine.State.GameEventProposals {
3839
if proposal.GameEvent.Type == event.GameEvent.Type && proposal.ValidUntil.After(c.Engine.TimeProvider()) {
3940
totalProposals++
41+
origins = append(origins, proposal.ProposerId)
4042
}
4143
}
4244

4345
majority := int(math.Floor(float64(len(c.AutoRefServer.Clients)) / 2.0))
4446
if totalProposals > majority {
47+
event.GameEvent.Origins = origins
4548
c.OnNewEvent(event)
4649
}
4750
} else {
51+
event.GameEvent.Origins = []string{id}
4852
c.OnNewEvent(event)
4953
}
5054
}

internal/app/controller/gameEvent.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ func (g GameEventType) Valid() bool {
115115
type GameEvent struct {
116116
Type GameEventType `json:"type"`
117117
Details GameEventDetails `json:"details"`
118+
Origins []string `json:"origins"`
118119
}
119120

120121
// String converts the game event into a string
@@ -266,6 +267,7 @@ func (e GameEvent) IsContinueGame() bool {
266267
func (e GameEvent) ToProto() *refproto.GameEvent {
267268
protoEvent := new(refproto.GameEvent)
268269
protoEvent.Type = new(refproto.GameEventType)
270+
protoEvent.Origin = e.Origins
269271
switch e.Type {
270272
case GameEventNone:
271273
return nil

0 commit comments

Comments
 (0)