From a7d55b39d1fccdc81bc61b867cf78cba347197cf Mon Sep 17 00:00:00 2001 From: Mygod Date: Mon, 26 Jun 2023 13:20:23 -0400 Subject: [PATCH 01/10] Send raid lobbies to webhook This sends all raid lobbies directly to webhook and skips persisting to DB. Adds a new webhook type raid_lobby. Fixes #107. --- decoder/gym.go | 89 ++++++++++++++++++++++++++----------------- main.go | 29 ++++++++++++++ webhooks/collector.go | 1 + 3 files changed, 83 insertions(+), 36 deletions(-) diff --git a/decoder/gym.go b/decoder/gym.go index ce66a965..43cffe86 100644 --- a/decoder/gym.go +++ b/decoder/gym.go @@ -329,22 +329,24 @@ func hasChangesGym(old *Gym, new *Gym) bool { } type GymDetailsWebhook struct { - Id string `json:"id"` - Name string `json:"name"` - Url string `json:"url"` - Latitude float64 `json:"latitude"` - Longitude float64 `json:"longitude"` - Team int64 `json:"team"` - GuardPokemonId int64 `json:"guard_pokemon_id"` - SlotsAvailable int64 `json:"slots_available"` - ExRaidEligible int64 `json:"ex_raid_eligible"` - InBattle bool `json:"in_battle"` - SponsorId int64 `json:"sponsor_id"` - PartnerId int64 `json:"partner_id"` - PowerUpPoints int64 `json:"power_up_points"` - PowerUpLevel int64 `json:"power_up_level"` - PowerUpEndTimestamp int64 `json:"power_up_end_timestamp"` - ArScanEligible int64 `json:"ar_scan_eligible"` + Id string `json:"id"` + Name string `json:"name"` + Url string `json:"url"` + Latitude float64 `json:"latitude"` + Longitude float64 `json:"longitude"` + Team int64 `json:"team"` + GuardPokemonId int64 `json:"guard_pokemon_id"` + SlotsAvailable int64 `json:"slots_available"` + ExRaidEligible int64 `json:"ex_raid_eligible"` + InBattle bool `json:"in_battle"` + SponsorId int64 `json:"sponsor_id"` + PartnerId int64 `json:"partner_id"` + PowerUpPoints int64 `json:"power_up_points"` + PowerUpLevel int64 `json:"power_up_level"` + PowerUpEndTimestamp int64 `json:"power_up_end_timestamp"` + ArScanEligible int64 `json:"ar_scan_eligible"` + LobbyPlayerCount int32 `json:"lobby_player_count"` + LobbyJoinEndTimestamp int64 `json:"lobby_join_end_timestamp"` //"id": id, //"name": name ?? "Unknown", @@ -374,30 +376,45 @@ func createGymFortWebhooks(oldGym *Gym, gym *Gym) { } } +func makeGymWebhook(gym *Gym) *GymDetailsWebhook { + return &GymDetailsWebhook{ + Id: gym.Id, + Name: gym.Name.ValueOrZero(), + Url: gym.Url.ValueOrZero(), + Latitude: gym.Lat, + Longitude: gym.Lon, + Team: gym.TeamId.ValueOrZero(), + GuardPokemonId: gym.GuardingPokemonId.ValueOrZero(), + SlotsAvailable: func() int64 { + if gym.AvailableSlots.Valid { + return gym.AvailableSlots.Int64 + } else { + return 6 + } + }(), + ExRaidEligible: gym.ExRaidEligible.ValueOrZero(), + InBattle: func() bool { return gym.InBattle.ValueOrZero() != 0 }(), + } +} + +func CreateGymLobbyPlayerCountWebhooks(ctx context.Context, db db.DbDetails, lobby *pogo.RaidLobbyPlayerCountProto) bool { + gym, _ := getGymRecord(ctx, db, lobby.GymId) + if gym == nil { // skip reporting for unseen gyms + return false + } + gymDetails := makeGymWebhook(gym) + gymDetails.LobbyPlayerCount = lobby.PlayerCount + gymDetails.LobbyJoinEndTimestamp = lobby.LobbyJoinUntilMs + areas := MatchStatsGeofence(gym.Lat, gym.Lon) + webhooks.AddMessage(webhooks.RaidLobby, gymDetails, areas) + return true +} + func createGymWebhooks(oldGym *Gym, gym *Gym) { areas := MatchStatsGeofence(gym.Lat, gym.Lon) if oldGym == nil || (oldGym.AvailableSlots != gym.AvailableSlots || oldGym.TeamId != gym.TeamId || oldGym.InBattle != gym.InBattle) { - gymDetails := GymDetailsWebhook{ - Id: gym.Id, - Name: gym.Name.ValueOrZero(), - Url: gym.Url.ValueOrZero(), - Latitude: gym.Lat, - Longitude: gym.Lon, - Team: gym.TeamId.ValueOrZero(), - GuardPokemonId: gym.GuardingPokemonId.ValueOrZero(), - SlotsAvailable: func() int64 { - if gym.AvailableSlots.Valid { - return gym.AvailableSlots.Int64 - } else { - return 6 - } - }(), - ExRaidEligible: gym.ExRaidEligible.ValueOrZero(), - InBattle: func() bool { return gym.InBattle.ValueOrZero() != 0 }(), - } - - webhooks.AddMessage(webhooks.GymDetails, gymDetails, areas) + webhooks.AddMessage(webhooks.GymDetails, makeGymWebhook(gym), areas) } if gym.RaidSpawnTimestamp.ValueOrZero() > 0 && diff --git a/main.go b/main.go index d860f399..19ac328e 100644 --- a/main.go +++ b/main.go @@ -267,6 +267,9 @@ func decode(ctx context.Context, method int, protoData *ProtoData) { case pogo.Method_METHOD_GET_MAP_FORTS: result = decodeGetMapForts(ctx, protoData.Data) processed = true + case pogo.Method_METHOD_GET_RAID_LOBBY_COUNTER: + result = decodeGetRaidLobbyCounter(ctx, protoData.Data) + processed = true default: log.Debugf("Did not process hook type %s", pogo.Method(method)) } @@ -436,6 +439,32 @@ func decodeGetMapForts(ctx context.Context, sDec []byte) string { return "No forts updated" } +func decodeGetRaidLobbyCounter(ctx context.Context, sDec []byte) string { + decodedRaidLobbyCounter := &pogo.GetRaidLobbyCounterOutProto{} + if err := proto.Unmarshal(sDec, decodedRaidLobbyCounter); err != nil { + log.Errorf("Failed to parse %s", err) + return fmt.Sprintf("Failed to parse %s", err) + } + + if decodedRaidLobbyCounter.Result != pogo.GetRaidLobbyCounterOutProto_SUCCESS { + return fmt.Sprintf(`GetRaidLobbyCounterOutProto: Ignored non-success value %d:%s`, + decodedRaidLobbyCounter.Result, + pogo.GetRaidLobbyCounterOutProto_Result_name[int32(decodedRaidLobbyCounter.Result)]) + } + + processedLobbies := 0 + for _, lobby := range decodedRaidLobbyCounter.RaidLobbyPlayerCount { + if decoder.CreateGymLobbyPlayerCountWebhooks(ctx, dbDetails, lobby) { + processedLobbies += 1 + } + } + + if processedLobbies > 0 { + return fmt.Sprintf("Updated %d lobbies", processedLobbies) + } + return "No lobbies updated" +} + func decodeGetGymInfo(ctx context.Context, sDec []byte) string { decodedGymInfo := &pogo.GymGetInfoOutProto{} if err := proto.Unmarshal(sDec, decodedGymInfo); err != nil { diff --git a/webhooks/collector.go b/webhooks/collector.go index 438fca3b..8d2eb263 100644 --- a/webhooks/collector.go +++ b/webhooks/collector.go @@ -27,6 +27,7 @@ var webhookCollections map[string]*WebhookList const GymDetails = "gym_details" const Raid = "raid" +const RaidLobby = "raid_lobby" const Pokemon = "pokemon" const Quest = "quest" const Pokestop = "pokestop" From 812d336fa0b391beef29a023493c906466063d47 Mon Sep 17 00:00:00 2001 From: Mygod Date: Mon, 26 Jun 2023 14:01:14 -0400 Subject: [PATCH 02/10] Change webhook to use raid type --- decoder/gym.go | 114 +++++++++++++++++++++--------------------- main.go | 2 +- webhooks/collector.go | 1 - 3 files changed, 57 insertions(+), 60 deletions(-) diff --git a/decoder/gym.go b/decoder/gym.go index 43cffe86..91167dd5 100644 --- a/decoder/gym.go +++ b/decoder/gym.go @@ -376,37 +376,54 @@ func createGymFortWebhooks(oldGym *Gym, gym *Gym) { } } -func makeGymWebhook(gym *Gym) *GymDetailsWebhook { - return &GymDetailsWebhook{ - Id: gym.Id, - Name: gym.Name.ValueOrZero(), - Url: gym.Url.ValueOrZero(), - Latitude: gym.Lat, - Longitude: gym.Lon, - Team: gym.TeamId.ValueOrZero(), - GuardPokemonId: gym.GuardingPokemonId.ValueOrZero(), - SlotsAvailable: func() int64 { - if gym.AvailableSlots.Valid { - return gym.AvailableSlots.Int64 +func makeRaidWebhook(gym *Gym) map[string]interface{} { + return map[string]interface{}{ + "gym_id": gym.Id, + "gym_name": func() string { + if !gym.Name.Valid { + return "Unknown" } else { - return 6 + return gym.Name.String } }(), - ExRaidEligible: gym.ExRaidEligible.ValueOrZero(), - InBattle: func() bool { return gym.InBattle.ValueOrZero() != 0 }(), + "gym_url": gym.Url.ValueOrZero(), + "latitude": gym.Lat, + "longitude": gym.Lon, + "team_id": gym.TeamId.ValueOrZero(), + "spawn": gym.RaidSpawnTimestamp.ValueOrZero(), + "start": gym.RaidBattleTimestamp.ValueOrZero(), + "end": gym.RaidEndTimestamp.ValueOrZero(), + "level": gym.RaidLevel.ValueOrZero(), + "pokemon_id": gym.RaidPokemonId.ValueOrZero(), + "cp": gym.RaidPokemonCp.ValueOrZero(), + "gender": gym.RaidPokemonGender.ValueOrZero(), + "form": gym.RaidPokemonForm.ValueOrZero(), + "alignment": gym.RaidPokemonAlignment.ValueOrZero(), + "costume": gym.RaidPokemonCostume.ValueOrZero(), + "evolution": gym.RaidPokemonEvolution.ValueOrZero(), + "move_1": gym.RaidPokemonMove1.ValueOrZero(), + "move_2": gym.RaidPokemonMove2.ValueOrZero(), + "ex_raid_eligible": gym.ExRaidEligible.ValueOrZero(), + "is_exclusive": gym.RaidIsExclusive.ValueOrZero(), + "sponsor_id": gym.SponsorId.ValueOrZero(), + "partner_id": gym.PartnerId.ValueOrZero(), + "power_up_points": gym.PowerUpPoints.ValueOrZero(), + "power_up_level": gym.PowerUpLevel.ValueOrZero(), + "power_up_end_timestamp": gym.PowerUpEndTimestamp.ValueOrZero(), + "ar_scan_eligible": gym.ArScanEligible.ValueOrZero(), } } -func CreateGymLobbyPlayerCountWebhooks(ctx context.Context, db db.DbDetails, lobby *pogo.RaidLobbyPlayerCountProto) bool { +func CreateRaidLobbyPlayerCountWebhooks(ctx context.Context, db db.DbDetails, lobby *pogo.RaidLobbyPlayerCountProto) bool { gym, _ := getGymRecord(ctx, db, lobby.GymId) if gym == nil { // skip reporting for unseen gyms return false } - gymDetails := makeGymWebhook(gym) - gymDetails.LobbyPlayerCount = lobby.PlayerCount - gymDetails.LobbyJoinEndTimestamp = lobby.LobbyJoinUntilMs + payload := makeRaidWebhook(gym) + payload["lobby_player_count"] = lobby.PlayerCount + payload["lobby_join_end_timestamp"] = lobby.LobbyJoinUntilMs areas := MatchStatsGeofence(gym.Lat, gym.Lon) - webhooks.AddMessage(webhooks.RaidLobby, gymDetails, areas) + webhooks.AddMessage(webhooks.Raid, payload, areas) return true } @@ -414,7 +431,24 @@ func createGymWebhooks(oldGym *Gym, gym *Gym) { areas := MatchStatsGeofence(gym.Lat, gym.Lon) if oldGym == nil || (oldGym.AvailableSlots != gym.AvailableSlots || oldGym.TeamId != gym.TeamId || oldGym.InBattle != gym.InBattle) { - webhooks.AddMessage(webhooks.GymDetails, makeGymWebhook(gym), areas) + webhooks.AddMessage(webhooks.GymDetails, GymDetailsWebhook{ + Id: gym.Id, + Name: gym.Name.ValueOrZero(), + Url: gym.Url.ValueOrZero(), + Latitude: gym.Lat, + Longitude: gym.Lon, + Team: gym.TeamId.ValueOrZero(), + GuardPokemonId: gym.GuardingPokemonId.ValueOrZero(), + SlotsAvailable: func() int64 { + if gym.AvailableSlots.Valid { + return gym.AvailableSlots.Int64 + } else { + return 6 + } + }(), + ExRaidEligible: gym.ExRaidEligible.ValueOrZero(), + InBattle: func() bool { return gym.InBattle.ValueOrZero() != 0 }(), + }, areas) } if gym.RaidSpawnTimestamp.ValueOrZero() > 0 && @@ -427,43 +461,7 @@ func createGymWebhooks(oldGym *Gym, gym *Gym) { if (raidBattleTime > now && gym.RaidLevel.ValueOrZero() > 0) || (raidEndTime > now && gym.RaidPokemonId.ValueOrZero() > 0) { - raidHook := map[string]interface{}{ - "gym_id": gym.Id, - "gym_name": func() string { - if !gym.Name.Valid { - return "Unknown" - } else { - return gym.Name.String - } - }(), - "gym_url": gym.Url.ValueOrZero(), - "latitude": gym.Lat, - "longitude": gym.Lon, - "team_id": gym.TeamId.ValueOrZero(), - "spawn": gym.RaidSpawnTimestamp.ValueOrZero(), - "start": gym.RaidBattleTimestamp.ValueOrZero(), - "end": gym.RaidEndTimestamp.ValueOrZero(), - "level": gym.RaidLevel.ValueOrZero(), - "pokemon_id": gym.RaidPokemonId.ValueOrZero(), - "cp": gym.RaidPokemonCp.ValueOrZero(), - "gender": gym.RaidPokemonGender.ValueOrZero(), - "form": gym.RaidPokemonForm.ValueOrZero(), - "alignment": gym.RaidPokemonAlignment.ValueOrZero(), - "costume": gym.RaidPokemonCostume.ValueOrZero(), - "evolution": gym.RaidPokemonEvolution.ValueOrZero(), - "move_1": gym.RaidPokemonMove1.ValueOrZero(), - "move_2": gym.RaidPokemonMove2.ValueOrZero(), - "ex_raid_eligible": gym.ExRaidEligible.ValueOrZero(), - "is_exclusive": gym.RaidIsExclusive.ValueOrZero(), - "sponsor_id": gym.SponsorId.ValueOrZero(), - "partner_id": gym.PartnerId.ValueOrZero(), - "power_up_points": gym.PowerUpPoints.ValueOrZero(), - "power_up_level": gym.PowerUpLevel.ValueOrZero(), - "power_up_end_timestamp": gym.PowerUpEndTimestamp.ValueOrZero(), - "ar_scan_eligible": gym.ArScanEligible.ValueOrZero(), - } - - webhooks.AddMessage(webhooks.Raid, raidHook, areas) + webhooks.AddMessage(webhooks.Raid, makeRaidWebhook(gym), areas) } } diff --git a/main.go b/main.go index 19ac328e..a43d021a 100644 --- a/main.go +++ b/main.go @@ -454,7 +454,7 @@ func decodeGetRaidLobbyCounter(ctx context.Context, sDec []byte) string { processedLobbies := 0 for _, lobby := range decodedRaidLobbyCounter.RaidLobbyPlayerCount { - if decoder.CreateGymLobbyPlayerCountWebhooks(ctx, dbDetails, lobby) { + if decoder.CreateRaidLobbyPlayerCountWebhooks(ctx, dbDetails, lobby) { processedLobbies += 1 } } diff --git a/webhooks/collector.go b/webhooks/collector.go index 8d2eb263..438fca3b 100644 --- a/webhooks/collector.go +++ b/webhooks/collector.go @@ -27,7 +27,6 @@ var webhookCollections map[string]*WebhookList const GymDetails = "gym_details" const Raid = "raid" -const RaidLobby = "raid_lobby" const Pokemon = "pokemon" const Quest = "quest" const Pokestop = "pokestop" From 518e9592b1476ed056ddc1df822fad6d8b1191c2 Mon Sep 17 00:00:00 2001 From: Mygod Date: Mon, 26 Jun 2023 14:02:04 -0400 Subject: [PATCH 03/10] Undo changes to gym details --- decoder/gym.go | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/decoder/gym.go b/decoder/gym.go index 91167dd5..08340194 100644 --- a/decoder/gym.go +++ b/decoder/gym.go @@ -329,24 +329,22 @@ func hasChangesGym(old *Gym, new *Gym) bool { } type GymDetailsWebhook struct { - Id string `json:"id"` - Name string `json:"name"` - Url string `json:"url"` - Latitude float64 `json:"latitude"` - Longitude float64 `json:"longitude"` - Team int64 `json:"team"` - GuardPokemonId int64 `json:"guard_pokemon_id"` - SlotsAvailable int64 `json:"slots_available"` - ExRaidEligible int64 `json:"ex_raid_eligible"` - InBattle bool `json:"in_battle"` - SponsorId int64 `json:"sponsor_id"` - PartnerId int64 `json:"partner_id"` - PowerUpPoints int64 `json:"power_up_points"` - PowerUpLevel int64 `json:"power_up_level"` - PowerUpEndTimestamp int64 `json:"power_up_end_timestamp"` - ArScanEligible int64 `json:"ar_scan_eligible"` - LobbyPlayerCount int32 `json:"lobby_player_count"` - LobbyJoinEndTimestamp int64 `json:"lobby_join_end_timestamp"` + Id string `json:"id"` + Name string `json:"name"` + Url string `json:"url"` + Latitude float64 `json:"latitude"` + Longitude float64 `json:"longitude"` + Team int64 `json:"team"` + GuardPokemonId int64 `json:"guard_pokemon_id"` + SlotsAvailable int64 `json:"slots_available"` + ExRaidEligible int64 `json:"ex_raid_eligible"` + InBattle bool `json:"in_battle"` + SponsorId int64 `json:"sponsor_id"` + PartnerId int64 `json:"partner_id"` + PowerUpPoints int64 `json:"power_up_points"` + PowerUpLevel int64 `json:"power_up_level"` + PowerUpEndTimestamp int64 `json:"power_up_end_timestamp"` + ArScanEligible int64 `json:"ar_scan_eligible"` //"id": id, //"name": name ?? "Unknown", From d9b8c68a643b84a1aece76e14254934f03cf368f Mon Sep 17 00:00:00 2001 From: Mygod Date: Mon, 26 Jun 2023 18:34:01 -0400 Subject: [PATCH 04/10] Update main.go as suggested by @na-ji Co-authored-by: Naji Astier --- main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.go b/main.go index a43d021a..8f974f51 100644 --- a/main.go +++ b/main.go @@ -449,7 +449,7 @@ func decodeGetRaidLobbyCounter(ctx context.Context, sDec []byte) string { if decodedRaidLobbyCounter.Result != pogo.GetRaidLobbyCounterOutProto_SUCCESS { return fmt.Sprintf(`GetRaidLobbyCounterOutProto: Ignored non-success value %d:%s`, decodedRaidLobbyCounter.Result, - pogo.GetRaidLobbyCounterOutProto_Result_name[int32(decodedRaidLobbyCounter.Result)]) + decodedRaidLobbyCounter.Result.String()) } processedLobbies := 0 From ad3b092ddf6b6011efaa39c1e478de211dffc5f2 Mon Sep 17 00:00:00 2001 From: Mygod Date: Thu, 29 Jun 2023 12:57:43 -0400 Subject: [PATCH 05/10] Cache lobbies in memory --- decoder/gym.go | 25 +++++++++++++++++++++---- main.go | 6 ++---- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/decoder/gym.go b/decoder/gym.go index 08340194..a338a392 100644 --- a/decoder/gym.go +++ b/decoder/gym.go @@ -56,6 +56,8 @@ type Gym struct { PowerUpPoints null.Int `db:"power_up_points"` PowerUpEndTimestamp null.Int `db:"power_up_end_timestamp"` Description null.String `db:"description"` + LobbyPlayerCount int32 + LobbyJoinEndMs int64 //`id` varchar(35) NOT NULL, //`lat` double(18,14) NOT NULL, //`lon` double(18,14) NOT NULL, @@ -374,8 +376,8 @@ func createGymFortWebhooks(oldGym *Gym, gym *Gym) { } } -func makeRaidWebhook(gym *Gym) map[string]interface{} { - return map[string]interface{}{ +func makeRaidWebhook(gym *Gym) (payload map[string]interface{}) { + payload = map[string]interface{}{ "gym_id": gym.Id, "gym_name": func() string { if !gym.Name.Valid { @@ -410,16 +412,31 @@ func makeRaidWebhook(gym *Gym) map[string]interface{} { "power_up_end_timestamp": gym.PowerUpEndTimestamp.ValueOrZero(), "ar_scan_eligible": gym.ArScanEligible.ValueOrZero(), } + if gym.LobbyPlayerCount > 0 { + payload["lobby_player_count"] = gym.LobbyPlayerCount + payload["lobby_join_end_ms"] = gym.LobbyJoinEndMs + } + return } func CreateRaidLobbyPlayerCountWebhooks(ctx context.Context, db db.DbDetails, lobby *pogo.RaidLobbyPlayerCountProto) bool { + gymMutex, _ := gymStripedMutex.GetLock(lobby.GymId) + gymMutex.Lock() + defer gymMutex.Unlock() + gym, _ := getGymRecord(ctx, db, lobby.GymId) if gym == nil { // skip reporting for unseen gyms return false } + if gym.LobbyPlayerCount == lobby.PlayerCount && + (lobby.PlayerCount == 0 || gym.LobbyJoinEndMs == lobby.LobbyJoinUntilMs) { + // skip unchanged lobbies or empty lobby updates + return false + } + gym.LobbyPlayerCount = lobby.PlayerCount + gym.LobbyJoinEndMs = lobby.LobbyJoinUntilMs + gymCache.Set(gym.Id, *gym, ttlcache.DefaultTTL) payload := makeRaidWebhook(gym) - payload["lobby_player_count"] = lobby.PlayerCount - payload["lobby_join_end_timestamp"] = lobby.LobbyJoinUntilMs areas := MatchStatsGeofence(gym.Lat, gym.Lon) webhooks.AddMessage(webhooks.Raid, payload, areas) return true diff --git a/main.go b/main.go index 8f974f51..9aab0d75 100644 --- a/main.go +++ b/main.go @@ -459,10 +459,8 @@ func decodeGetRaidLobbyCounter(ctx context.Context, sDec []byte) string { } } - if processedLobbies > 0 { - return fmt.Sprintf("Updated %d lobbies", processedLobbies) - } - return "No lobbies updated" + return fmt.Sprintf("Updated %d/%d lobbies", + processedLobbies, len(decodedRaidLobbyCounter.RaidLobbyPlayerCount)) } func decodeGetGymInfo(ctx context.Context, sDec []byte) string { From 137f4bb252ce33245278c763a1aeb723cdb79243 Mon Sep 17 00:00:00 2001 From: Mygod Date: Sun, 23 Jul 2023 11:44:16 -0400 Subject: [PATCH 06/10] Update routes.go to add log --- routes.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/routes.go b/routes.go index ea9ff365..8a6031d1 100644 --- a/routes.go +++ b/routes.go @@ -75,7 +75,7 @@ func Raw(c *gin.Context) { pogodroidHeader := r.Header.Get("origin") userAgent := r.Header.Get("User-Agent") - //log.Infof("Raw: Received data from %s", body) + log.Infof("Raw: Received data from %s", body) //log.Infof("User agent is %s", userAgent) if pogodroidHeader != "" { From f1e6b6433d201f7a5b0ad29c85821f8f7848b44b Mon Sep 17 00:00:00 2001 From: Mygod Date: Sun, 23 Jul 2023 14:57:09 -0400 Subject: [PATCH 07/10] Always send lobby info in webhook --- decoder/gym.go | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/decoder/gym.go b/decoder/gym.go index a338a392..86a23260 100644 --- a/decoder/gym.go +++ b/decoder/gym.go @@ -411,10 +411,8 @@ func makeRaidWebhook(gym *Gym) (payload map[string]interface{}) { "power_up_level": gym.PowerUpLevel.ValueOrZero(), "power_up_end_timestamp": gym.PowerUpEndTimestamp.ValueOrZero(), "ar_scan_eligible": gym.ArScanEligible.ValueOrZero(), - } - if gym.LobbyPlayerCount > 0 { - payload["lobby_player_count"] = gym.LobbyPlayerCount - payload["lobby_join_end_ms"] = gym.LobbyJoinEndMs + "lobby_player_count": gym.LobbyPlayerCount, + "lobby_join_end_ms": gym.LobbyJoinEndMs, } return } From 563b0fb9de12c9c0320138433994ef24b1a3b613 Mon Sep 17 00:00:00 2001 From: Fabio1988 <35898099+Fabio1988@users.noreply.github.com> Date: Sun, 23 Jul 2023 21:26:18 +0200 Subject: [PATCH 08/10] Update routes.go --- routes.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/routes.go b/routes.go index 8a6031d1..ea9ff365 100644 --- a/routes.go +++ b/routes.go @@ -75,7 +75,7 @@ func Raw(c *gin.Context) { pogodroidHeader := r.Header.Get("origin") userAgent := r.Header.Get("User-Agent") - log.Infof("Raw: Received data from %s", body) + //log.Infof("Raw: Received data from %s", body) //log.Infof("User agent is %s", userAgent) if pogodroidHeader != "" { From 3b8e4e35ba5ac7b3a50fe953b3f412fb4cb7c7f2 Mon Sep 17 00:00:00 2001 From: Mygod Date: Tue, 25 Jul 2023 18:30:26 -0400 Subject: [PATCH 09/10] Add Method_METHOD_GET_RAID_LOBBY_COUNTER to protos.md --- protos.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/protos.md b/protos.md index 9f1d63a8..cd8292ae 100644 --- a/protos.md +++ b/protos.md @@ -43,6 +43,10 @@ requires the proto request to be present in the raw. - Provides confirmation of a real or decoy Giovanni +`Method_METHOD_GET_RAID_LOBBY_COUNTER` + +- Bulk lobby query for gyms + # Social actions - The master `ClientAction_CLIENT_ACTION_PROXY_SOCIAL_ACTION` proto will be From 686f2ed8c73f3a151a175c8505091be91866715f Mon Sep 17 00:00:00 2001 From: Mygod Date: Thu, 27 Jul 2023 17:20:07 -0400 Subject: [PATCH 10/10] Add ProcessLobbies to scanContext --- config/config.go | 1 + decoder/scanarea.go | 3 +++ main.go | 4 +++- 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/config/config.go b/config/config.go index 6184b73b..5cfa9081 100644 --- a/config/config.go +++ b/config/config.go @@ -95,6 +95,7 @@ type scanRule struct { ProcessCells *bool `koanf:"cells"` ProcessPokestops *bool `koanf:"pokestops"` ProcessGyms *bool `koanf:"gyms"` + ProcessLobbies *bool `koanf:"lobbies"` } var Config configDefinition diff --git a/decoder/scanarea.go b/decoder/scanarea.go index 6091fcdf..be46da12 100644 --- a/decoder/scanarea.go +++ b/decoder/scanarea.go @@ -14,6 +14,7 @@ type ScanParameters struct { ProcessPokestops bool ProcessGyms bool ProcessCells bool + ProcessLobbies bool } func FindScanConfiguration(scanContext string, lat, lon float64) ScanParameters { @@ -59,6 +60,7 @@ func FindScanConfiguration(scanContext string, lat, lon float64) ScanParameters ProcessWeather: defaultTrue(rule.ProcessWeather), ProcessPokestops: defaultTrue(rule.ProcessPokestops), ProcessGyms: defaultTrue(rule.ProcessGyms), + ProcessLobbies: defaultTrue(rule.ProcessLobbies), } } @@ -70,5 +72,6 @@ func FindScanConfiguration(scanContext string, lat, lon float64) ScanParameters ProcessWeather: true, ProcessGyms: true, ProcessPokestops: true, + ProcessLobbies: true, } } diff --git a/main.go b/main.go index 1a5df9b7..64975a3a 100644 --- a/main.go +++ b/main.go @@ -290,7 +290,9 @@ func decode(ctx context.Context, method int, protoData *ProtoData) { result = decodeGetMapForts(ctx, protoData.Data) processed = true case pogo.Method_METHOD_GET_RAID_LOBBY_COUNTER: - result = decodeGetRaidLobbyCounter(ctx, protoData.Data) + if getScanParameters(protoData).ProcessLobbies { + result = decodeGetRaidLobbyCounter(ctx, protoData.Data) + } processed = true default: log.Debugf("Did not process hook type %s", pogo.Method(method))