Skip to content

Commit

Permalink
bugfix: Keep compatible to older clients
Browse files Browse the repository at this point in the history
GameEvent.type was a required field, so new enum values causes
the protobuf parser to raise an error.
To avoid errors on older clients, game events and proposed game events
were added to new lists in the Referee message.
That way, old clients will not receive any game events, but
they will also not crash.
  • Loading branch information
g3force committed May 9, 2020
1 parent bc4520c commit 5c9e3d7
Show file tree
Hide file tree
Showing 7 changed files with 517 additions and 559 deletions.
21 changes: 7 additions & 14 deletions internal/app/publish/datamapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,17 @@ import (
"time"
)

func mapProposals(groups []*state.ProposalGroup) []*state.ProposedGameEvent {
var mappedEvents []*state.ProposedGameEvent
func mapProposals(groups []*state.ProposalGroup) []*state.GameEventProposalGroup {
var mappedGroups []*state.GameEventProposalGroup
for _, group := range groups {
mappedGroup := state.GameEventProposalGroup{}
mappedGroup.GameEvent = []*state.GameEvent{}
for _, proposal := range group.Proposals {
proposer := ""
if len(proposal.GameEvent.Origin) > 0 {
proposer = proposal.GameEvent.Origin[0]
}
var validUntil uint64
//noinspection GoDeprecation
mappedEvents = append(mappedEvents, &state.ProposedGameEvent{
ValidUntil: &validUntil, // required in protobuf ref msg... Add zero value
ProposerId: &proposer,
GameEvent: proposal.GameEvent,
})
mappedGroup.GameEvent = append(mappedGroup.GameEvent, proposal.GameEvent)
}
mappedGroups = append(mappedGroups, &mappedGroup)
}
return mappedEvents
return mappedGroups
}

func mapCommand(command *state.Command) (c *state.Referee_Command) {
Expand Down
2 changes: 1 addition & 1 deletion internal/app/publish/messagegenerator.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func (g *MessageGenerator) StateToRefereeMessage(matchState *state.State) (r *st
r = newRefereeMessage()
r.DesignatedPosition = mapLocation(matchState.PlacementPos)
r.GameEvents = matchState.GameEvents
r.ProposedGameEvents = mapProposals(matchState.ProposalGroups)
r.GameEventProposals = mapProposals(matchState.ProposalGroups)

r.Command = mapCommand(matchState.Command)
*r.CommandCounter = g.commandCounter
Expand Down
388 changes: 194 additions & 194 deletions internal/app/state/ssl_gc_game_event.pb.go

Large diffs are not rendered by default.

238 changes: 112 additions & 126 deletions internal/app/state/ssl_gc_referee_message.pb.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion proto/ssl_gc_game_event.proto
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import "ssl_gc_geometry.proto";
// An autoRef should ideally set all fields, except if there are good reasons to not do so.
message GameEvent {

required Type type = 40;
optional Type type = 40;

// The origins of this game event.
// Empty, if it originates from game controller.
Expand Down
18 changes: 9 additions & 9 deletions proto/ssl_gc_referee_message.proto
Original file line number Diff line number Diff line change
Expand Up @@ -183,10 +183,12 @@ message Referee {

// All game events that were detected since the last RUNNING state.
// Will be cleared as soon as the game is continued.
repeated GameEvent game_events = 13;
reserved 13;
repeated GameEvent game_events = 16;

// All non-finished proposed game events that may be processed next.
repeated ProposedGameEvent proposed_game_events = 14;
reserved 14;
repeated GameEventProposalGroup game_event_proposals = 17;

// The time in microseconds that is remaining until the current action times out
// The time will not be reset. It can get negative.
Expand All @@ -198,12 +200,10 @@ message Referee {
optional int32 current_action_time_remaining = 15;
}

message ProposedGameEvent {
// The UNIX timestamp when the game event proposal will time out, in microseconds.
// Deprecated: Value will always be zero
required uint64 valid_until = 1 [deprecated = true];
// The identifier of the proposer.
required string proposer_id = 2;
// List of matching proposals
message GameEventProposalGroup {
// The proposed game event.
required GameEvent game_event = 3;
repeated GameEvent game_event = 1;
// Whether the proposal group was accepted
optional bool accepted = 2;
}
Loading

0 comments on commit 5c9e3d7

Please sign in to comment.