Commit 41e2d791 authored by Andrei Mihu's avatar Andrei Mihu Committed by Chris Molozian
Browse files

Improve how user presences are reported in realtime matches. (#29)

parent e63260ab
Loading
Loading
Loading
Loading
+10 −8
Original line number Diff line number Diff line
@@ -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.

+6 −4
Original line number Diff line number Diff line
@@ -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;

@@ -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 {
@@ -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;
}
+21 −6
Original line number Diff line number Diff line
@@ -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) {
@@ -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) {
@@ -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(),
				},