Skip to content

Commit

Permalink
Improve how user presences are reported in realtime matches. (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
zyro authored and novabyte committed Feb 17, 2017
1 parent e63260a commit 41e2d79
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 18 deletions.
18 changes: 10 additions & 8 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,23 @@ The format is based on [keep a changelog](http://keepachangelog.com/) and this p
### Added
- Include Dockerfile and Docker instructions.
- Use a default limit in topic message listings if one is not provided.
- Improve logging around topic presence diff processing.
- Improve log messages in topic presence diff checks.
- Report self presence in realtime match create and join.

### Changed
- Improve warning message on migration database creation.
- Improve warn message when database is created in migrate subcommand.
- Print database connections to logs on server start.
- Use byte slices for most database operations.
- Use byte slices with most database operations.
- Standardize match presence field names across chat and realtime protocol.
- Improve concurrency for closed sockets.

### Fixed
- Enforce concurrency control on outgoing socket messages.
- Improve concurrency for closed sockets.
- Correct session lookup for realtime message routing.
- Fix input validation when sending topic messages.
- Correct handling of IDs in various login options.
- Fix session lookup in realtime message router.
- Fix input validation when chat messages are sent.
- Fix how IDs are handled in various login options.
- Fix presence service shutdown sequence.
- More graceful handling of session operations while connection is closing.
- More graceful handling of session operations while connection is closed.
- Fix batch user fetch query construction.
- Fix duplicate leaves reported in topic presence diff messages.

Expand Down
10 changes: 6 additions & 4 deletions server/api.proto
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ message Envelope {
TMatchLeave match_leave = 43;
TMatchDataSend match_data_send = 44;
TMatch match = 45;
TMatchUsers match_users = 46;
TMatchPresences match_presences = 46;
MatchData match_data = 47;
MatchPresence match_presence = 48;

Expand Down Expand Up @@ -405,13 +405,15 @@ message TopicPresence {
message TMatchCreate {}
message TMatch {
bytes id = 1;
UserPresence self = 2;
}

message TMatchJoin {
bytes match_id = 1;
}
message TMatchUsers {
repeated UserPresence users = 1;
message TMatchPresences {
repeated UserPresence presences = 1;
UserPresence self = 2;
}

message TMatchDataSend {
Expand All @@ -422,7 +424,7 @@ message TMatchDataSend {

message MatchData {
bytes match_id = 1;
UserPresence user = 2;
UserPresence presence = 2;
int64 op_code = 3;
bytes data = 4;
}
Expand Down
27 changes: 21 additions & 6 deletions server/pipeline_match.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,13 @@ func (p *pipeline) matchCreate(logger zap.Logger, session *session, envelope *En

p.tracker.Track(session.id, "match:"+matchID.String(), session.userID, PresenceMeta{})

session.Send(&Envelope{CollationId: envelope.CollationId, Payload: &Envelope_Match{Match: &TMatch{Id: matchID.Bytes()}}})
session.Send(&Envelope{CollationId: envelope.CollationId, Payload: &Envelope_Match{Match: &TMatch{
Id: matchID.Bytes(),
Self: &UserPresence{
UserId: session.userID.Bytes(),
SessionId: session.id.Bytes(),
},
}}})
}

func (p *pipeline) matchJoin(logger zap.Logger, session *session, envelope *Envelope) {
Expand All @@ -44,15 +50,24 @@ func (p *pipeline) matchJoin(logger zap.Logger, session *session, envelope *Enve

p.tracker.Track(session.id, topic, session.userID, PresenceMeta{})

users := make([]*UserPresence, len(ps))
for i := 0; i < len(ps); i++ {
userPresences := make([]*UserPresence, len(ps)+1)
for i := 0; i < len(ps)-1; i++ {
p := ps[i]
users[i] = &UserPresence{
userPresences[i] = &UserPresence{
UserId: p.UserID.Bytes(),
SessionId: p.ID.SessionID.Bytes(),
}
}
session.Send(&Envelope{CollationId: envelope.CollationId, Payload: &Envelope_MatchUsers{MatchUsers: &TMatchUsers{Users: users}}})
self := &UserPresence{
UserId: session.userID.Bytes(),
SessionId: session.id.Bytes(),
}
userPresences[len(ps)-1] = self

session.Send(&Envelope{CollationId: envelope.CollationId, Payload: &Envelope_MatchPresences{MatchPresences: &TMatchPresences{
Presences: userPresences,
Self: self,
}}})
}

func (p *pipeline) matchLeave(logger zap.Logger, session *session, envelope *Envelope) {
Expand Down Expand Up @@ -133,7 +148,7 @@ func (p *pipeline) matchDataSend(logger zap.Logger, session *session, envelope *
Payload: &Envelope_MatchData{
MatchData: &MatchData{
MatchId: matchIDBytes,
User: &UserPresence{
Presence: &UserPresence{
UserId: session.userID.Bytes(),
SessionId: session.id.Bytes(),
},
Expand Down

0 comments on commit 41e2d79

Please sign in to comment.