Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 36 additions & 3 deletions server/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,12 @@ type SessionClient struct {
system string

// do not compare directly; use isPrivatedTo
private, singleplayer bool
private bool
// 1 = hide everybody but party members and friends
// 2 = hide everybody (singleplayer)
// 4 = hide friends
// 8 = hide party members
privateHideType int

hideLocation bool
partyId int
Expand Down Expand Up @@ -172,9 +177,37 @@ func (c *SessionClient) disconnect() {
writeLog(c.uuid, "sess", "disconnect", 200)
}

func (c *SessionClient) isSingleplayer() bool {
hideAll := 2
// hide strangers, friends, and party members
hideAllImplicit := 1 | 4 | 8
return (c.privateHideType & hideAll) != 0 ||
(c.privateHideType & hideAllImplicit) == hideAllImplicit
}

func (c *SessionClient) isPrivatedTo(other *SessionClient) bool {
return (c.private || other.private) && ((c.singleplayer || other.singleplayer) ||
(other.partyId == 0 || c.partyId != other.partyId) && !c.onlineFriends[other.uuid])
if !c.private && !other.private {
return false
}

const hideStrangers = 1
const hideAll = 2
const hideFriends = 4
const hideParty = 8

privateHideType := c.privateHideType | other.privateHideType

if (privateHideType & hideAll) != 0 {
return true
}

areFriends := c.onlineFriends[other.uuid]
arePartyMembers := other.partyId != 0 && c.partyId == other.partyId
areStrangers := !areFriends && !arePartyMembers

return (areStrangers && (privateHideType & hideStrangers) != 0) ||
(areFriends && (privateHideType & hideFriends) != 0) ||
(arePartyMembers && (privateHideType & hideParty) != 0)
}

func (c *SessionClient) isBlockedWith(other *SessionClient) bool {
Expand Down
2 changes: 1 addition & 1 deletion server/friends.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func getPlayerFriendData(uuid string) (playerFriends []*PlayerFriend, err error)
playerFriend.Badge = client.badge
playerFriend.Medals = client.medals

if client.roomC != nil && !(client.hideLocation && client.singleplayer) {
if client.roomC != nil && !(client.hideLocation && client.isSingleplayer()) {
playerFriend.MapId = client.roomC.mapId
playerFriend.PrevMapId = client.roomC.prevMapId
playerFriend.PrevLocations = client.roomC.prevLocations
Expand Down
9 changes: 7 additions & 2 deletions server/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -1334,8 +1334,13 @@ func (c *SessionClient) handlePr(msg []string) error {
return errors.New("segment count mismatch")
}

c.singleplayer = msg[1] == "2"
c.private = c.singleplayer || msg[1] == "1"
privateHideType, err := strconv.Atoi(msg[1])
if err != nil {
return err
}

c.privateHideType = privateHideType
c.private = privateHideType != 0

return nil
}
Expand Down
4 changes: 2 additions & 2 deletions server/party.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,13 @@ func getPartyData(partyId int) (*Party, error) {
member.Badge = client.badge
member.Medals = client.medals

if client.roomC != nil && !(client.hideLocation && client.singleplayer) {
if client.roomC != nil && !(client.hideLocation && client.isSingleplayer()) {
member.MapId = client.roomC.mapId
member.PrevMapId = client.roomC.prevMapId
member.PrevLocations = client.roomC.prevLocations
member.X = client.roomC.x
member.Y = client.roomC.y
} else if client.roomC != nil && (client.hideLocation && client.singleplayer) {
} else if client.roomC != nil && (client.hideLocation && client.isSingleplayer()) {
member.MapId = "0000"
member.PrevMapId = "0000"
member.PrevLocations = ""
Expand Down